diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..592d72f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '3*' + +name: create_release + +jobs: + build: + name: create_release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + SLACK_MESSAGE: "Start Job" + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + NetCommons ${{ github.ref }} released. + draft: false + prerelease: false + + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Finish + uses: rtCamp/action-slack-notify@v2.2.0 + if: success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good + SLACK_MESSAGE: "Job Success" + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: danger + SLACK_MESSAGE: "Job Failure" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..eb2068b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,170 @@ +on: + push: + branches: + - main + - master + - availability + pull_request: + branches: + - main + - master + - availability + +name: tests + +jobs: + setup: + name: setup + runs-on: ubuntu-latest + steps: + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + + tests: + name: tests + needs: setup + runs-on: ubuntu-latest + strategy: + matrix: + php: [ '7.1', '7.2', '7.3', '7.4' ] + mysql: [ '5.7', '8.0' ] + + env: + NC3_BUILD_DIR: "/opt/nc3" + NC3_DOCKER_DIR: "/opt/docker" + NC3_GIT_URL: "git://github.com/NetCommons3/NetCommons3.git" + NC3_GIT_BRANCH: "master" + PLUGIN_BUILD_DIR: ${{ github.workspace }} + PHP_VERSION: ${{ matrix.php }} + MYSQL_VERSION: ${{ matrix.mysql }} + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: cakephp_test + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - name: Fix up git URLs + run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig + + - name: environment + run: | + echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}" + echo "PLUGIN_BUILD_DIR=${PLUGIN_BUILD_DIR}" + echo "PHP_VERSION=${PHP_VERSION}" + echo "MYSQL_VERSION=${MYSQL_VERSION}" + ls -al ${PLUGIN_BUILD_DIR} + + - name: docker-compose install + run: | + curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + chmod +x ~/docker-compose + sudo mv ~/docker-compose /usr/local/bin/docker-compose + docker-compose --version + + - name: git clone nc3 + run: git clone -b ${NC3_GIT_BRANCH} ${NC3_GIT_URL} ${NC3_BUILD_DIR} + + - name: git clone nc3_docker + run: git clone https://github.com/NetCommons3/nc3app-docker.git ${NC3_DOCKER_DIR} + + - name: docker-compose start + run: | + cd ${NC3_DOCKER_DIR} + docker-compose up -d + docker-compose start + + - run: docker ps + + - name: check libraries + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/start-on-docker.sh + + - name: nc3 build + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/app-build.sh + + - name: phpcs (PHP CodeSniffer) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpcs.sh + + - name: phpmd (PHP Mess Detector) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpmd.sh + + - name: phpcpd (PHP Copy/Paste Detector) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpcpd.sh + + - name: gjslint (JavaScript Style Check) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/gjslint.sh + + - name: phpdoc (PHP Documentor) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpdoc.sh + + - name: phpunit (PHP UnitTest) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpunit.sh + sudo -s chmod a+w -R ${NC3_BUILD_DIR}/build + +# - name: push coveralls +# env: +# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# COVERALLS_FLAG_NAME: ${{ matrix.php }} +# run: | +# cd ${NC3_BUILD_DIR} +# ls -la ${NC3_BUILD_DIR} +# vendors/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v + + - name: docker-compose remove + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose rm -f + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}(php${{ matrix.php }}, mysql${{ matrix.mysql }})" + SLACK_COLOR: danger + + teardown: + name: teardown + runs-on: ubuntu-latest + needs: tests + steps: + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Success + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b6975cd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: php - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - -sudo: false - -env: - matrix: - - NETCOMMONS_VERSION=master DB=mysql - global: - - secure: "PZ/zmD6ZnBGARSJnpH4PqX+iBx3N2n/foc9CLg4EQmZYKNb4gNwpQwuqIjM4IvBxl3P7gMIlbfbyOaOXdwbpgwkcIl+cAkl3rVzvKeLUWfbtnpZ2ObCzEo2iGdIPJ52RHRJG4ZEryXz7bKeVWvZnBQ0+clX4avYTS5ZdQ9+imuY=" - - GIT_COMMITTER_NAME=s-nakajima - - GIT_COMMITTER_EMAIL=nakajimashouhei@gmail.com - - GIT_AUTHOR_NAME=s-nakajima - - GIT_AUTHOR_EMAIL=nakajimashouhei@gmail.com - -before_script: - - export NETCOMMONS_BUILD_DIR=`dirname $TRAVIS_BUILD_DIR`/NetCommons3 - - git clone git://github.com/NetCommons3/NetCommons3 $NETCOMMONS_BUILD_DIR - - cd $NETCOMMONS_BUILD_DIR - - git checkout $NETCOMMONS_VERSION - - travis_wait . tools/build/plugins/cakephp/travis/pre.sh - - . tools/build/plugins/cakephp/travis/environment.sh - -script: - - travis_wait . tools/build/plugins/cakephp/travis/main.sh - -after_script: - - . tools/build/plugins/cakephp/travis/post.sh - -notifications: - email: - recipients: - - netcommons3@googlegroups.com - on_success: never # default: change - on_failure: always # default: always diff --git a/Console/Command/Task/CreateDatabaseTask.php b/Console/Command/Task/CreateDatabaseTask.php index 0f9c091..f41cf48 100644 --- a/Console/Command/Task/CreateDatabaseTask.php +++ b/Console/Command/Task/CreateDatabaseTask.php @@ -76,6 +76,17 @@ class CreateDatabaseTask extends InstallAppTask { public function execute() { parent::execute(); + //database.phpの初期化処理 + $configs = $this->InstallUtil->chooseDBByEnvironment(); + if (! $this->InstallUtil->saveDBConf($configs)) { + $message = __d( + 'install', + 'Failed to write %s. Please check permission.', + array(APP . 'Config' . DS . 'database.php') + ); + return $this->error($message); + } + //引数のセット $this->__prepare(); diff --git a/Console/Command/Task/InstallFinishTask.php b/Console/Command/Task/InstallFinishTask.php index 7629360..2cc6b67 100644 --- a/Console/Command/Task/InstallFinishTask.php +++ b/Console/Command/Task/InstallFinishTask.php @@ -11,6 +11,7 @@ App::uses('InstallAppTask', 'Install.Console/Command'); App::uses('Folder', 'Utility'); +App::uses('NetCommonsCache', 'NetCommons.Utility'); /** * Installの終了 @@ -73,6 +74,11 @@ public function execute() { $folder->delete(ROOT . DS . '.chef'); } + if (file_exists(APP . 'VERSION')) { + $ncCache = new NetCommonsCache('version', false, 'netcommons_core'); + $ncCache->write(trim(file_get_contents(APP . 'VERSION'))); + } + Configure::write('NetCommons.installed', true); $this->InstallUtil->saveAppConf(); } diff --git a/Console/Command/Task/InstallMigrationsTask.php b/Console/Command/Task/InstallMigrationsTask.php index 369a4ba..ea7b2c8 100644 --- a/Console/Command/Task/InstallMigrationsTask.php +++ b/Console/Command/Task/InstallMigrationsTask.php @@ -48,6 +48,11 @@ public function execute() { if (! $this->InstallUtil->installMigrations($connection, $plugins)) { return $this->error(__d('install', 'Failed to install migrations.')); } + + //Webrootへのコピー処理 + if (! $this->InstallUtil->installWebrootCopy()) { + return $this->error(__d('install', 'Failed to install webroot copies css,js,img')); + } } /** diff --git a/Console/Command/Task/InstallStartTask.php b/Console/Command/Task/InstallStartTask.php index 6995391..aa2f0c9 100644 --- a/Console/Command/Task/InstallStartTask.php +++ b/Console/Command/Task/InstallStartTask.php @@ -88,17 +88,6 @@ public function execute() { ); return $this->error($message); } - - //database.phpの初期化処理 - $configs = $this->InstallUtil->chooseDBByEnvironment(); - if (! $this->InstallUtil->saveDBConf($configs)) { - $message = __d( - 'install', - 'Failed to write %s. Please check permission.', - array(APP . 'Config' . DS . 'database.php') - ); - return $this->error($message); - } } /** diff --git a/Controller/InstallController.php b/Controller/InstallController.php index 1ce376d..9e96cb3 100644 --- a/Controller/InstallController.php +++ b/Controller/InstallController.php @@ -12,6 +12,7 @@ App::uses('InstallAppController', 'Install.Controller'); App::uses('InstallUtil', 'Install.Utility'); App::uses('InstallValidatorUtil', 'Install.Utility'); +App::uses('NetCommonsCache', 'NetCommons.Utility'); /** * Install Controller @@ -41,7 +42,8 @@ public function beforeFilter() { $this->layout = 'Install.default'; //テストのために必要 - if (substr(get_class($this->InstallUtil), 0, strlen('Mock_')) !== 'Mock_') { + if (empty($this->InstallUtil) || + substr(get_class($this->InstallUtil), 0, strlen('Mock_')) !== 'Mock_') { $this->InstallUtil = new InstallUtil(); } @@ -197,6 +199,13 @@ public function init_db() { return; } + //Webrootへのコピー処理 + if (! $this->InstallUtil->installWebrootCopy()) { + $this->response->statusCode(400); + CakeLog::error('Failed to install webroot copies css,js,img'); + $this->set('errors', [__d('install', 'Failed to install webroot copies css,js,img')]); + } + $this->redirect(array( 'action' => 'init_admin_user', '?' => ['language' => Configure::read('Config.language')] @@ -307,6 +316,11 @@ public function save_init_data() { public function finish() { $this->set('pageTitle', __d('install', 'Installed')); + if (file_exists(APP . 'VERSION')) { + $ncCache = new NetCommonsCache('version', false, 'netcommons_core'); + $ncCache->write(trim(file_get_contents(APP . 'VERSION'))); + } + Configure::write('NetCommons.installed', true); /* Configure::write('NetCommons.installed', false); */ $this->InstallUtil->saveAppConf(); diff --git a/Locale/eng/LC_MESSAGES/install.po b/Locale/eng/LC_MESSAGES/install.po index f1a6bf4..57ca368 100644 --- a/Locale/eng/LC_MESSAGES/install.po +++ b/Locale/eng/LC_MESSAGES/install.po @@ -327,6 +327,9 @@ msgstr "" msgid "Only alphabets and numbers are allowed." msgstr "" +msgid "Only alphabets, numbers, \"-\" and \"_\" are allowed." +msgstr "" + #: Install/Test/Case/Utility/InstallUtil/ValidatesDBConfTest.php:162;167 #: Install/Utility/InstallValidatorUtil.php:122 msgid "Login" @@ -387,3 +390,23 @@ msgstr "" msgid "Install" msgstr "" +msgid "Select the type of database server to use." +msgstr "" + +msgid "Enter the host name of the database server to use. If you do not understand well, there is almost no problem as 'localhost'." +msgstr "" + +msgid "Enter the port number of the database server to use. If you do not understand well, there is almost no problem as '3306'." +msgstr "" + +msgid "Enter the database name to use." +msgstr "" + +msgid "Table prefix of the database. This prefix is added to each table name to prevent duplication of names with existing tables. If you do not understand well, it is 'blank' and there is almost no problem." +msgstr "" + +msgid "User name of the database. Please enter the user account name in the above database." +msgstr "" + +msgid "Enter the password with the above ID." +msgstr "" diff --git a/Locale/install.pot b/Locale/install.pot index f1a6bf4..5e341ef 100644 --- a/Locale/install.pot +++ b/Locale/install.pot @@ -387,3 +387,23 @@ msgstr "" msgid "Install" msgstr "" +msgid "Select the type of database server to use." +msgstr "" + +msgid "Enter the host name of the database server to use. If you do not understand well, there is almost no problem as 'localhost'." +msgstr "" + +msgid "Enter the port number of the database server to use. If you do not understand well, there is almost no problem as '3306'." +msgstr "" + +msgid "Enter the database name to use." +msgstr "" + +msgid "Table prefix of the database. This prefix is added to each table name to prevent duplication of names with existing tables. If you do not understand well, it is 'blank' and there is almost no problem." +msgstr "" + +msgid "User name of the database. Please enter the user account name in the above database." +msgstr "" + +msgid "Enter the password with the above ID." +msgstr "" diff --git a/Locale/jpn/LC_MESSAGES/install.po b/Locale/jpn/LC_MESSAGES/install.po index f534195..7e55d1b 100644 --- a/Locale/jpn/LC_MESSAGES/install.po +++ b/Locale/jpn/LC_MESSAGES/install.po @@ -336,6 +336,10 @@ msgstr "ポート番号" msgid "Only alphabets and numbers are allowed." msgstr "半角英数字または記号(_のみ利用可)を入力してください。" +msgid "Only alphabets, numbers, \"-\" and \"_\" are allowed." +msgstr "半角英数字または記号(_-のみ利用可)を入力してください。" + + #: Install/Test/Case/Utility/InstallUtil/ValidatesDBConfTest.php:162;167 #: Install/Utility/InstallValidatorUtil.php:122 msgid "Login" @@ -450,3 +454,23 @@ msgstr "利用する言語" msgid "Site Setting" msgstr "サイト設定" +msgid "Select the type of database server to use." +msgstr "使用するデータベースサーバの種類を選択してください。" + +msgid "Enter the host name of the database server to use. If you do not understand well, there is almost no problem as 'localhost'." +msgstr "使用するデータベースサーバのホスト名を入力してください。よく分からない場合は、「localhost」として、ほぼ問題はありません。" + +msgid "Enter the port number of the database server to use. If you do not understand well, there is almost no problem as '3306'." +msgstr "使用するデータベースサーバのポート番号を入力してください。よく分からない場合は、「3306」として、ほぼ問題はありません。" + +msgid "Enter the database name to use." +msgstr "使用するデータベース名を入力してください。" + +msgid "Table prefix of the database. This prefix is added to each table name to prevent duplication of names with existing tables. If you do not understand well, it is 'blank' and there is almost no problem." +msgstr "データベースのテーブル接頭語です。各テーブル名にこの接頭語を付加し、既存テーブルとの名称の重複を防ぎます。よく分からない場合は、「空」のままで、ほぼ問題はありません。" + +msgid "User name of the database. Please enter the user account name in the above database." +msgstr "データベースのユーザ名です。上記データベースにおけるユーザアカウント名を入力してください。" + +msgid "Enter the password with the above ID." +msgstr "上記IDのパスワードを入力してください。" diff --git a/README.md b/README.md index e178467..08d5225 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ Install =========== -[![Build Status](https://travis-ci.org/NetCommons3/Install.png?branch=master)](https://travis-ci.org/NetCommons3/Install) -[![Coverage Status](https://coveralls.io/repos/NetCommons3/Install/badge.png?branch=master)](https://coveralls.io/r/NetCommons3/Install?branch=master) - -| dependencies | status | -| ------------ | ------ | -| composer.json | [![Dependency Status](https://www.versioneye.com/user/projects/5397f08a83add7bd8d000022/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5397f08a83add7bd8d000022) | +[![Tests Status](https://github.com/NetCommons3/Install/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Install/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/Install/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/Install?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/install.svg?label=stable)](https://packagist.org/packages/netcommons/install) diff --git a/Test/Case/Controller/InstallController/InitDbTest.php b/Test/Case/Controller/InstallController/InitDbTest.php index 5bbf531..e340ce4 100644 --- a/Test/Case/Controller/InstallController/InitDbTest.php +++ b/Test/Case/Controller/InstallController/InitDbTest.php @@ -143,7 +143,9 @@ public function testInitDbPost($testPrefix, $expectedPrefix) { $expected = $data; $this->controller->InstallUtil = $this->getMock( - 'InstallUtil', array('saveDBConf', 'createDB', 'installMigrations'), array('name' => 'InstallUtil') + 'InstallUtil', + array('saveDBConf', 'createDB', 'installMigrations', 'installWebrootCopy'), + array('name' => 'InstallUtil') ); $expected['prefix'] = $expectedPrefix; @@ -157,6 +159,9 @@ public function testInitDbPost($testPrefix, $expectedPrefix) { $this->controller->InstallUtil->expects($this->once())->method('installMigrations') ->will($this->returnValue(true)); + $this->controller->InstallUtil->expects($this->once())->method('installWebrootCopy') + ->will($this->returnValue(true)); + //テスト実行 $this->_testPostAction('post', $data, array('action' => 'init_db'), null, 'view'); @@ -194,7 +199,9 @@ public function testValidationError($debug) { $data['database'] = ''; $this->controller->InstallUtil = $this->getMock( - 'InstallUtil', array('saveDBConf', 'createDB', 'installMigrations'), ['name' => 'InstallUtil'] + 'InstallUtil', + array('saveDBConf', 'createDB', 'installMigrations', 'installWebrootCopy'), + array('name' => 'InstallUtil') ); $this->controller->InstallUtil->expects($this->exactly(0))->method('saveDBConf') @@ -206,6 +213,9 @@ public function testValidationError($debug) { $this->controller->InstallUtil->expects($this->exactly(0))->method('installMigrations') ->will($this->returnValue(true)); + $this->controller->InstallUtil->expects($this->exactly(0))->method('installWebrootCopy') + ->will($this->returnValue(true)); + //テスト実行 Configure::write('debug', $debug); $this->_testPostAction('post', $data, array('action' => 'init_db'), null, 'view'); @@ -237,7 +247,9 @@ public function testCreateDBError() { $data = $this->__postData(); $this->controller->InstallUtil = $this->getMock( - 'InstallUtil', array('saveDBConf', 'createDB', 'installMigrations'), array('name' => 'InstallUtil') + 'InstallUtil', + array('saveDBConf', 'createDB', 'installMigrations', 'installWebrootCopy'), + array('name' => 'InstallUtil') ); $this->controller->InstallUtil->expects($this->once())->method('saveDBConf') @@ -250,6 +262,9 @@ public function testCreateDBError() { $this->controller->InstallUtil->expects($this->exactly(0))->method('installMigrations') ->will($this->returnValue(true)); + $this->controller->InstallUtil->expects($this->exactly(0))->method('installWebrootCopy') + ->will($this->returnValue(true)); + //テスト実行 $this->_testPostAction('post', $data, array('action' => 'init_db'), null, 'view'); @@ -269,7 +284,9 @@ public function testInstallMigrationsError() { $data = $this->__postData(); $this->controller->InstallUtil = $this->getMock( - 'InstallUtil', array('saveDBConf', 'createDB', 'installMigrations'), array('name' => 'InstallUtil') + 'InstallUtil', + array('saveDBConf', 'createDB', 'installMigrations', 'installWebrootCopy'), + array('name' => 'InstallUtil') ); $this->controller->InstallUtil->expects($this->once())->method('saveDBConf') @@ -282,6 +299,9 @@ public function testInstallMigrationsError() { $this->controller->InstallUtil->expects($this->once())->method('installMigrations') ->will($this->returnValue(false)); + $this->controller->InstallUtil->expects($this->exactly(0))->method('installWebrootCopy') + ->will($this->returnValue(true)); + //テスト実行 $this->_testPostAction('post', $data, array('action' => 'init_db'), null, 'view'); diff --git a/Test/Case/Utility/InstallUtil/InstallMigrationsTest.php b/Test/Case/Utility/InstallUtil/InstallMigrationsTest.php index 229b803..b336336 100644 --- a/Test/Case/Utility/InstallUtil/InstallMigrationsTest.php +++ b/Test/Case/Utility/InstallUtil/InstallMigrationsTest.php @@ -79,12 +79,18 @@ private function __databaseClear() { $this->__initTableCount = 0; foreach ($tables as $table) { - $tableName = array_shift($table['TABLE_NAMES']); + $tableName = null; + if (array_key_exists('TABLE_NAMES', $table)) { + $tableName = array_shift($table['TABLE_NAMES']); + } elseif (array_key_exists('TABLES', $table)) { + $tableName = array_shift($table['TABLES']); + } + if (preg_match('/schema_migrations$/', $tableName)) { - $db->query('DELETE FROM ' . $tableName . ' WHERE type != \'Migrations\''); + $db->query('DELETE FROM `' . $tableName . '` WHERE type != \'Migrations\''); $this->__initTableCount++; } else { - $db->query('DROP TABLE ' . $tableName); + $db->query('DROP TABLE `' . $tableName . '`'); } } } diff --git a/Test/Case/Utility/InstallUtil/ValidatesDBConfTest.php b/Test/Case/Utility/InstallUtil/ValidatesDBConfTest.php index 8e08b22..7504e14 100644 --- a/Test/Case/Utility/InstallUtil/ValidatesDBConfTest.php +++ b/Test/Case/Utility/InstallUtil/ValidatesDBConfTest.php @@ -142,10 +142,13 @@ public function dataProviderValidationError() { ), ), array('data' => $data, 'field' => 'database', 'value' => 'あ', - 'message' => __d('install', 'Only alphabets and numbers are allowed.') + 'message' => __d('install', "Only alphabets, numbers, \"-\" and \"_\" are allowed.") ), - array('data' => $data, 'field' => 'database', 'value' => 'a-b', - 'message' => __d('install', 'Only alphabets and numbers are allowed.') + array('data' => $data, 'field' => 'database', 'value' => 'a_b', + 'message' => true + ), + array('data' => $data, 'field' => 'database', 'value' => 'a*b', + 'message' => __d('install', "Only alphabets, numbers, \"-\" and \"_\" are allowed.") ), //prefix diff --git a/Utility/InstallUtil.php b/Utility/InstallUtil.php index 3d49c3b..3a8cef4 100644 --- a/Utility/InstallUtil.php +++ b/Utility/InstallUtil.php @@ -15,6 +15,7 @@ App::uses('Security', 'Utility'); App::uses('ClassRegistry', 'Utility'); App::uses('InstallValidatorUtil', 'Install.Utility'); +App::uses('ConnectionManager', 'Model'); /** * Install Utility @@ -210,7 +211,7 @@ class InstallUtil { */ public $migrationPriorityPlugins = array( 'Files', 'Users', 'NetCommons', 'M17n', 'DataTypes', 'PluginManager', - 'Roles', 'Mails', 'SiteManager', 'Blocks', 'Boxes' + 'Roles', 'Mails', 'SiteManager', 'Rooms', 'Blocks', 'Boxes' ); /** @@ -608,10 +609,10 @@ public function installMigrations($connection = 'master', $addPlugins = [], $opt $SiteSetting->setDataSource($connection); $conditions = array( - 'key' => 'Config.language' + 'SiteSetting.key' => 'Config.language' ); $update = array( - 'value' => '\'' . Configure::read('Config.language') . '\'' + 'SiteSetting.value' => '\'' . Configure::read('Config.language') . '\'' ); if (! $SiteSetting->updateAll($update, $conditions)) { CakeLog::info( @@ -625,6 +626,15 @@ public function installMigrations($connection = 'master', $addPlugins = [], $opt } } + //キャッシュの削除 + Cache::clear(false, '_cake_model_'); + Cache::clear(false, '_cake_core_'); + + //DataSourceの中にあるlistSources()の$this->_sources変数を初期化することができないため、reconnect()する。 + $dataSource = ConnectionManager::getDataSource($connection); + $dataSource->cacheSources = false; + $dataSource->reconnect(); + $Plugin = ClassRegistry::init(Hash::get($options, 'PluginModel', 'PluginManager.Plugin')); if ($Plugin->updateVersionByComposer()) { CakeLog::info('[migration] Successfully updated version of composer plugins.'); @@ -651,6 +661,15 @@ public function installMigrations($connection = 'master', $addPlugins = [], $opt CakeLog::info('[migration] Failure migrated all plugins'); } + //DataSourceの中にあるlistSources()の$this->_sources変数を初期化することができないため、reconnect()する。 + $dataSource = ConnectionManager::getDataSource('master'); + $dataSource->cacheSources = false; + $dataSource->reconnect(); + + //キャッシュの削除 + Cache::clear(false, '_cake_model_'); + Cache::clear(false, '_cake_core_'); + return $result; } @@ -693,22 +712,27 @@ public function installBowerPackages($update) { $file->close(); foreach ($bower['dependencies'] as $package => $version) { + if (strpos($version, '#') !== false) { + $install = $version; + } else { + $install = $package . '#' . $version; + } CakeLog::info( - sprintf('[bower] Start bower install %s#%s for %s', $package, $version, $plugin) + sprintf('[bower] Start bower install %s for %s', $install, $plugin) ); $messages = array(); $ret = null; exec(sprintf( - 'cd %s && `which bower` --allow-root install %s#%s --save', - ROOT, escapeshellcmd($package), escapeshellcmd($version) + 'cd %s && `which bower` --allow-root install %s --save', + ROOT, escapeshellcmd($install) ), $messages, $ret); // Write logs $this->__commandOutputResults('bower', $messages); CakeLog::info( - sprintf('[bower] Successfully bower install %s#%s for %s', $package, $version, $plugin) + sprintf('[bower] Successfully bower install %s for %s', $install, $plugin) ); } } @@ -716,6 +740,32 @@ public function installBowerPackages($update) { return true; } +/** + * 各プラグインにあるimg(css,js)をapp/webroot/img(css,js)にコピーする + * + * @param array $options オプション(PluginModelを指定) + * @return bool Install succeed or not + */ + public function installWebrootCopy($options = []) { + $Plugin = ClassRegistry::init(Hash::get($options, 'PluginModel', 'PluginManager.Plugin')); + + CakeLog::info('[webroot copy] Start all plugins'); + + //pluginsテーブルの取得 + $plugins = $Plugin->find('all', array( + 'recursive' => -1, + )); + $plugins = $Plugin->convertSerializeData($plugins); + + foreach ($plugins as $plugin) { + $Plugin->copyToWebroot($plugin); + } + + CakeLog::info('[webroot copy] Successfully all plugins'); + + return true; + } + /** * bower packagesのインストール * diff --git a/Utility/InstallValidatorUtil.php b/Utility/InstallValidatorUtil.php index 123362e..cd940d0 100644 --- a/Utility/InstallValidatorUtil.php +++ b/Utility/InstallValidatorUtil.php @@ -112,8 +112,8 @@ public function validatesDBConf($options = array()) { 'required' => true, ), 'regex' => array( - 'rule' => array('custom', '/^[\w]+$/'), - 'message' => __d('install', 'Only alphabets and numbers are allowed.'), + 'rule' => array('custom', '/^[\w-]+$/'), + 'message' => __d('install', "Only alphabets, numbers, \"-\" and \"_\" are allowed."), ), ), 'prefix' => array( @@ -208,7 +208,11 @@ public function permissions() { $writables = array( APP . 'Config', APP . 'tmp', - APP . 'webroot' . DS . 'files' + APP . 'Uploads', + APP . 'webroot' . DS . 'css', + APP . 'webroot' . DS . 'js', + APP . 'webroot' . DS . 'img', + APP . 'webroot' . DS . 'theme' ); foreach ($writables as $path) { if (is_writable($path)) { diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..86fb650 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +3.3.7 diff --git a/View/Install/index.ctp b/View/Install/index.ctp index db8855b..80eea59 100644 --- a/View/Install/index.ctp +++ b/View/Install/index.ctp @@ -21,7 +21,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); -Form->create(false, array('url' => array( +NetCommonsForm->create(false, array('url' => array( //'plugin' => 'install', //'controller' => 'install', 'action' => 'index', @@ -75,4 +75,4 @@ from this site, etc.'), -Form->end(); +NetCommonsForm->end(); diff --git a/View/Install/init_admin_user.ctp b/View/Install/init_admin_user.ctp index 7fbbd3c..71700f1 100644 --- a/View/Install/init_admin_user.ctp +++ b/View/Install/init_admin_user.ctp @@ -13,7 +13,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); ?> Form->create(false, + echo $this->NetCommonsForm->create(false, array( 'url' => array( //'plugin' => 'install', @@ -88,4 +88,4 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); -Form->end(); +NetCommonsForm->end(); diff --git a/View/Install/init_db.ctp b/View/Install/init_db.ctp index 3840ce9..fe6ec3d 100644 --- a/View/Install/init_db.ctp +++ b/View/Install/init_db.ctp @@ -50,6 +50,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'label' => __d('install', 'Datasource'), 'div' => false, 'error' => false, + 'help' => __d('install', 'Select the type of database server to use.'), ) ); ?> @@ -60,6 +61,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'default' => $masterDB['host'], 'div' => false, 'error' => false, + 'help' => __d('install', "Enter the host name of the database server to use. If you do not understand well, there is almost no problem as 'localhost'."), ) ); ?> @@ -79,6 +81,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'default' => $masterDB['port'], 'div' => false, 'error' => false, + 'help' => __d('install', "Enter the port number of the database server to use. If you do not understand well, there is almost no problem as '3306'."), ) ); ?> @@ -98,6 +101,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'default' => 'nc3', 'div' => false, 'error' => false, + 'help' => __d('install', 'Enter the database name to use.'), ) ); ?> @@ -125,6 +129,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'placeholder' => 'nc3_', 'div' => false, 'error' => false, + 'help' => __d('install', "Table prefix of the database. This prefix is added to each table name to prevent duplication of names with existing tables. If you do not understand well, it is 'blank' and there is almost no problem."), ) ); ?> @@ -145,6 +150,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'placeholder' => __d('install', 'Username'), 'div' => false, 'error' => false, + 'help' => __d('install', 'User name of the database. Please enter the user account name in the above database.'), ) ); ?> @@ -164,6 +170,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); 'placeholder' => __d('install', 'Password'), 'div' => false, 'error' => false, + 'help' => __d('install', 'Enter the password with the above ID.'), ) ); ?> diff --git a/View/Install/init_permission.ctp b/View/Install/init_permission.ctp index 8fe96e7..76c4858 100644 --- a/View/Install/init_permission.ctp +++ b/View/Install/init_permission.ctp @@ -12,7 +12,7 @@ echo $this->NetCommonsHtml->script('/install/js/install.js'); echo $this->NetCommonsHtml->css('/install/css/install.css'); ?> -Form->create(false, array('url' => array( +NetCommonsForm->create(false, array('url' => array( //'plugin' => 'install', //'controller' => 'install', 'action' => 'init_permission', @@ -96,4 +96,4 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); -Form->end(); +NetCommonsForm->end(); diff --git a/View/Install/init_site_setting.ctp b/View/Install/init_site_setting.ctp index 49d699f..9e7cf35 100644 --- a/View/Install/init_site_setting.ctp +++ b/View/Install/init_site_setting.ctp @@ -20,7 +20,7 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); Form->create(false, + echo $this->NetCommonsForm->create(false, array( 'url' => array( //'plugin' => 'install', @@ -57,4 +57,4 @@ echo $this->NetCommonsHtml->css('/install/css/install.css'); -Form->end(); +NetCommonsForm->end(); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 24eff13..46a3df4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,8 @@ + + + app/Plugin/Install @@ -14,6 +17,6 @@ - +