diff --git a/apps/advanced/init b/apps/advanced/init index 4b1d1e4..a82de27 100755 --- a/apps/advanced/init +++ b/apps/advanced/init @@ -1,5 +1,19 @@ #!/usr/bin/env php <?php +/** + * Yii Application Initialization Tool + * + * In order to run in non-interactive mode: + * + * init --env=dev --overwrite=n + * + * @author Alexander Makarov <sam@rmcreative.ru> + * + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ + */ + $params = getParams(); $root = str_replace('\\', '/', __DIR__); $envs = require("$root/environments/index.php"); @@ -24,8 +38,7 @@ if (empty($params['env']) || $params['env'] === '1') { if (isset($envNames[$answer])) { $envName = $envNames[$answer]; } -} -else { +} else { $envName = $params['env']; } @@ -50,7 +63,7 @@ echo "\n Start initialization ...\n\n"; $files = getFileList("$root/environments/{$env['path']}"); $all = false; foreach ($files as $file) { - if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all)) { + if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all, $params)) { break; } } @@ -91,7 +104,7 @@ function getFileList($root, $basePath = '') return $files; } -function copyFile($root, $source, $target, &$all) +function copyFile($root, $source, $target, &$all, $params) { if (!is_file($root . '/' . $source)) { echo " skip $target ($source not exist)\n"; @@ -107,7 +120,9 @@ function copyFile($root, $source, $target, &$all) } else { echo " exist $target\n"; echo " ...overwrite? [Yes|No|All|Quit] "; - $answer = trim(fgets(STDIN)); + + + $answer = !empty($params['overwrite']) ? $params['overwrite'] : trim(fgets(STDIN)); if (!strncasecmp($answer, 'q', 1)) { return false; } else { diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 33d7cfa..13ebfce 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -70,6 +70,7 @@ Yii Framework 2 Change Log - Enh: Added support for using array-typed arguments for console commands (qiangxue) - Enh: Added support for installing packages conforming to PSR-4 standard (qiangxue) - Enh: Better exception message when class cannot be loaded (samdark) +- Enh: `init` of advanced application now allows to specify answer for overwriting files via `init --overwrite=n` (samdark) - Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic) - Chg #1519: `yii\web\User::loginRequired()` now returns the `Response` object instead of exiting the application (qiangxue) - Chg #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default (qiangxue)