From 0411f09a43902b3e487c032c38c2670425194c62 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 23:05:41 +0400 Subject: [PATCH] Added install tool, moved all local configs and entry points to environments --- apps/advanced/.gitignore | 1 + apps/advanced/README.md | 5 +- apps/advanced/console/controllers/.gitkeep | 0 .../console/controllers/HelloController.php | 29 ------ .../console/controllers/InstallController.php | 13 --- apps/advanced/console/models/.gitkeep | 1 + .../dev/backstage/config/main-local.php | 3 + .../dev/backstage/config/params-local.php | 3 + .../environments/dev/backstage/www/index.php | 14 +++ .../dev/common/config/params-local.php | 3 + .../environments/dev/console/config/main-local.php | 3 + .../dev/console/config/params-local.php | 3 + .../dev/frontend/config/main-local.php | 3 + .../dev/frontend/config/params-local.php | 3 + .../environments/dev/frontend/www/index.php | 15 +++ apps/advanced/environments/dev/yii | 25 +++++ apps/advanced/environments/index.php | 38 +++++++ apps/advanced/install | 111 +++++++++++++++++++++ .../install/dev/backstage/config/main-local.php | 3 - .../install/dev/backstage/config/params-local.php | 3 - apps/advanced/install/dev/backstage/www/index.php | 14 --- .../install/dev/common/config/params-local.php | 3 - .../install/dev/console/config/main-local.php | 3 - .../install/dev/console/config/params-local.php | 3 - .../install/dev/frontend/config/main-local.php | 3 - .../install/dev/frontend/config/params-local.php | 3 - apps/advanced/install/dev/frontend/www/index.php | 15 --- apps/advanced/yii | 26 ----- 28 files changed, 227 insertions(+), 122 deletions(-) create mode 100644 apps/advanced/.gitignore create mode 100644 apps/advanced/console/controllers/.gitkeep delete mode 100644 apps/advanced/console/controllers/HelloController.php delete mode 100644 apps/advanced/console/controllers/InstallController.php create mode 100644 apps/advanced/console/models/.gitkeep create mode 100644 apps/advanced/environments/dev/backstage/config/main-local.php create mode 100644 apps/advanced/environments/dev/backstage/config/params-local.php create mode 100644 apps/advanced/environments/dev/backstage/www/index.php create mode 100644 apps/advanced/environments/dev/common/config/params-local.php create mode 100644 apps/advanced/environments/dev/console/config/main-local.php create mode 100644 apps/advanced/environments/dev/console/config/params-local.php create mode 100644 apps/advanced/environments/dev/frontend/config/main-local.php create mode 100644 apps/advanced/environments/dev/frontend/config/params-local.php create mode 100644 apps/advanced/environments/dev/frontend/www/index.php create mode 100644 apps/advanced/environments/dev/yii create mode 100644 apps/advanced/environments/index.php create mode 100644 apps/advanced/install delete mode 100644 apps/advanced/install/dev/backstage/config/main-local.php delete mode 100644 apps/advanced/install/dev/backstage/config/params-local.php delete mode 100644 apps/advanced/install/dev/backstage/www/index.php delete mode 100644 apps/advanced/install/dev/common/config/params-local.php delete mode 100644 apps/advanced/install/dev/console/config/main-local.php delete mode 100644 apps/advanced/install/dev/console/config/params-local.php delete mode 100644 apps/advanced/install/dev/frontend/config/main-local.php delete mode 100644 apps/advanced/install/dev/frontend/config/params-local.php delete mode 100644 apps/advanced/install/dev/frontend/www/index.php delete mode 100644 apps/advanced/yii diff --git a/apps/advanced/.gitignore b/apps/advanced/.gitignore new file mode 100644 index 0000000..b1cf719 --- /dev/null +++ b/apps/advanced/.gitignore @@ -0,0 +1 @@ +/yii \ No newline at end of file diff --git a/apps/advanced/README.md b/apps/advanced/README.md index 08f0b0d..f088fc8 100644 --- a/apps/advanced/README.md +++ b/apps/advanced/README.md @@ -20,12 +20,10 @@ DIRECTORY STRUCTURE ``` common config/ contains shared configurations - env/ contains environment-based overrides models/ contains model classes used in both backstage and frontend console config/ contains console configurations controllers/ contains console controllers (commands) - env/ contains environment-based overrides migrations/ contains database migrations models/ contains console-specific model classes runtime/ contains files generated during runtime @@ -33,7 +31,6 @@ backstage assets/ contains application assets such as JavaScript and CSS config/ contains backstage configurations controllers/ contains Web controller classes - env/ contains environment-based overrides models/ contains backstage-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application @@ -42,12 +39,12 @@ frontend assets/ contains application assets such as JavaScript and CSS config/ contains frontend configurations controllers/ contains Web controller classes - env/ contains environment-based overrides models/ contains frontend-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application www/ contains the entry script and Web resources vendor/ contains dependent 3rd-party packages +environments/ contains environment-based overrides ``` diff --git a/apps/advanced/console/controllers/.gitkeep b/apps/advanced/console/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/advanced/console/controllers/HelloController.php b/apps/advanced/console/controllers/HelloController.php deleted file mode 100644 index 603c6e8..0000000 --- a/apps/advanced/console/controllers/HelloController.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @since 2.0 - */ -class HelloController extends Controller -{ - /** - * This command echos what you have entered as the message. - * @param string $message the message to be echoed. - */ - public function actionIndex($message = 'hello world') - { - echo $message."\n"; - } -} \ No newline at end of file diff --git a/apps/advanced/console/controllers/InstallController.php b/apps/advanced/console/controllers/InstallController.php deleted file mode 100644 index cbc2227..0000000 --- a/apps/advanced/console/controllers/InstallController.php +++ /dev/null @@ -1,13 +0,0 @@ -run(); diff --git a/apps/advanced/environments/dev/common/config/params-local.php b/apps/advanced/environments/dev/common/config/params-local.php new file mode 100644 index 0000000..2670143 --- /dev/null +++ b/apps/advanced/environments/dev/common/config/params-local.php @@ -0,0 +1,3 @@ +run(); diff --git a/apps/advanced/environments/dev/yii b/apps/advanced/environments/dev/yii new file mode 100644 index 0000000..d763217 --- /dev/null +++ b/apps/advanced/environments/dev/yii @@ -0,0 +1,25 @@ +#!/usr/bin/env php +run(); diff --git a/apps/advanced/environments/index.php b/apps/advanced/environments/index.php new file mode 100644 index 0000000..ff907d2 --- /dev/null +++ b/apps/advanced/environments/index.php @@ -0,0 +1,38 @@ + array( + * 'path' => 'directory storing the local files', + * 'writable' => array( + * // list of directories that should be set writable + * ), + * ), + * ); + * ``` + */ +return array( + 'Development' => array( + 'path' => 'dev', + 'writable' => array( + // handled by composer.json already + ), + 'executable' => array( + 'yiic', + ), + ), + 'Production' => array( + 'path' => 'prod', + 'writable' => array( + // handled by composer.json already + ), + 'executable' => array( + 'yiic', + ), + ), +); diff --git a/apps/advanced/install b/apps/advanced/install new file mode 100644 index 0000000..2204acd --- /dev/null +++ b/apps/advanced/install @@ -0,0 +1,111 @@ + $name) { + echo " [$i] $name\n"; +} +echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] '; +$answer = trim(fgets(STDIN)); +if (!ctype_digit($answer) || !isset($envNames[$answer])) { + echo "\n Quit installation.\n"; + return; +} + +$env = $envs[$envNames[$answer]]; +echo "\n Install the application under '{$envNames[$answer]}' environment? [yes|no] "; +$answer = trim(fgets(STDIN)); +if (strncasecmp($answer, 'y', 1)) { + echo "\n Quit installation.\n"; + return; +} + +echo "\n Start installation ...\n\n"; +$files = getFileList("$root/install/{$env['path']}"); +$all = false; +foreach ($files as $file) { + if (!copyFile($root, "install/{$env['path']}/$file", $file, $all)) { + break; + } +} + +if (isset($env['writable'])) { + foreach ($env['writable'] as $writable) { + echo " chmod 0777 $writable\n"; + @chmod("$root/$writable", 0777); + } +} + +if (isset($env['executable'])) { + foreach ($env['executable'] as $executable) { + echo " chmod 0755 $executable\n"; + @chmod("$root/$executable", 0755); + } +} + +echo "\n ... installation completed.\n\n"; + +function getFileList($root, $basePath = '') +{ + $files = array(); + $handle = opendir($root); + while (($path = readdir($handle)) !== false) { + if ($path === '.svn' || $path === '.' || $path === '..') { + continue; + } + $fullPath = "$root/$path"; + $relativePath = $basePath === '' ? $path : "$basePath/$path"; + if (is_dir($fullPath)) { + $files = array_merge($files, getFileList($fullPath, $relativePath)); + } else { + $files[] = $relativePath; + } + } + closedir($handle); + return $files; +} + +function copyFile($root, $source, $target, &$all) +{ + if (!is_file($root . '/' . $source)) { + echo " skip $target ($source not exist)\n"; + return true; + } + if (is_file($root . '/' . $target)) { + if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) { + echo " unchanged $target\n"; + return true; + } + if ($all) { + echo " overwrite $target\n"; + } else { + echo " exist $target\n"; + echo " ...overwrite? [Yes|No|All|Quit] "; + $answer = trim(fgets(STDIN)); + if (!strncasecmp($answer, 'q', 1)) { + return false; + } else { + if (!strncasecmp($answer, 'y', 1)) { + echo " overwrite $target\n"; + } else { + if (!strncasecmp($answer, 'a', 1)) { + echo " overwrite $target\n"; + $all = true; + } else { + echo " skip $target\n"; + return true; + } + } + } + } + file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); + return true; + } + echo " generate $target\n"; + @mkdir(dirname($root . '/' . $target), 0777, true); + file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); + return true; +} diff --git a/apps/advanced/install/dev/backstage/config/main-local.php b/apps/advanced/install/dev/backstage/config/main-local.php deleted file mode 100644 index 5b61b0e..0000000 --- a/apps/advanced/install/dev/backstage/config/main-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); diff --git a/apps/advanced/install/dev/common/config/params-local.php b/apps/advanced/install/dev/common/config/params-local.php deleted file mode 100644 index 2670143..0000000 --- a/apps/advanced/install/dev/common/config/params-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); diff --git a/apps/advanced/yii b/apps/advanced/yii deleted file mode 100644 index 77d58cb..0000000 --- a/apps/advanced/yii +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env php -run();