X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=src%2FConsole%2FInstaller.php;fp=src%2FConsole%2FInstaller.php;h=0000000000000000000000000000000000000000;hb=5ff0c9235788452f12520f523f72b3b90354864e;hp=1ba31fbd46248d58f3d89d39103229a886ebaebd;hpb=21b4f1ff8ddbe4982b375b95249e1e1c8a270340;p=umumu%2Fumumu.git diff --git a/src/Console/Installer.php b/src/Console/Installer.php deleted file mode 100644 index 1ba31fb..0000000 --- a/src/Console/Installer.php +++ /dev/null @@ -1,162 +0,0 @@ -getIO(); - - $rootDir = dirname(dirname(__DIR__)); - - static::createAppConfig($rootDir, $io); - - // ask if the permissions should be changed - if ($io->isInteractive()) { - $validator = (function ($arg) { - if (in_array($arg, ['Y', 'y', 'N', 'n'])) { - return $arg; - } - throw new Exception('This is not a valid answer. Please choose Y or n.'); - }); - $setFolderPermissions = $io->askAndValidate( - 'Set Folder Permissions ? (Default to Y) [Y,n]? ', - $validator, - false, - 'Y' - ); - - if (in_array($setFolderPermissions, ['Y', 'y'])) { - static::setFolderPermissions($rootDir, $io); - } - } else { - static::setFolderPermissions($rootDir, $io); - } - - static::setSecuritySalt($rootDir, $io); - - if (class_exists('\Cake\Codeception\Console\Installer')) { - \Cake\Codeception\Console\Installer::customizeCodeceptionBinary($event); - } - } - - /** - * Create the config/app.php file if it does not exist. - * - * @param string $dir The application's root directory. - * @param \Composer\IO\IOInterface $io IO interface to write to console. - * @return void - */ - public static function createAppConfig($dir, $io) - { - $appConfig = $dir . '/config/app.php'; - $defaultConfig = $dir . '/config/app.default.php'; - if (!file_exists($appConfig)) { - copy($defaultConfig, $appConfig); - $io->write('Created `config/app.php` file'); - } - } - - /** - * Set globally writable permissions on the "tmp" and "logs" directory. - * - * This is not the most secure default, but it gets people up and running quickly. - * - * @param string $dir The application's root directory. - * @param \Composer\IO\IOInterface $io IO interface to write to console. - * @return void - */ - public static function setFolderPermissions($dir, $io) - { - // Change the permissions on a path and output the results. - $changePerms = function ($path, $perms, $io) { - // Get current permissions in decimal format so we can bitmask it. - $currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4)); - if (($currentPerms & $perms) == $perms) { - return; - } - - $res = chmod($path, $currentPerms | $perms); - if ($res) { - $io->write('Permissions set on ' . $path); - } else { - $io->write('Failed to set permissions on ' . $path); - } - }; - - $walker = function ($dir, $perms, $io) use (&$walker, $changePerms) { - $files = array_diff(scandir($dir), ['.', '..']); - foreach ($files as $file) { - $path = $dir . '/' . $file; - - if (!is_dir($path)) { - continue; - } - - $changePerms($path, $perms, $io); - $walker($path, $perms, $io); - } - }; - - $worldWritable = bindec('0000000111'); - $walker($dir . '/tmp', $worldWritable, $io); - $changePerms($dir . '/tmp', $worldWritable, $io); - $changePerms($dir . '/logs', $worldWritable, $io); - } - - /** - * Set the security.salt value in the application's config file. - * - * @param string $dir The application's root directory. - * @param \Composer\IO\IOInterface $io IO interface to write to console. - * @return void - */ - public static function setSecuritySalt($dir, $io) - { - $config = $dir . '/config/app.php'; - $content = file_get_contents($config); - - $newKey = hash('sha256', $dir . php_uname() . microtime(true)); - $content = str_replace('__SALT__', $newKey, $content, $count); - - if ($count == 0) { - $io->write('No Security.salt placeholder to replace.'); - return; - } - - $result = file_put_contents($config, $content); - if ($result) { - $io->write('Updated Security.salt value in config/app.php'); - return; - } - $io->write('Unable to update Security.salt value.'); - } -}