diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2542421 --- /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: | + ${{ github.repository }} ${{ 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..6da4321 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,168 @@ +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +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 9929d24..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: "h36o2iRlR3lPZEjWvpM7kyyIBFBWZap1SSGBVf2UcQzXq1EnxzrdKS6uGhGRrMNsaj+F/1DHUDBJraZRP/Gle64u/tkfJugSWZHAiQSDNQ/Q6J0Dnot1FGz467Apf+swGTsjoV0GPEIWCWiXsqgfqe3YQ6GtvWrZRft3OOOISUA=" - - 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: - - . 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/Controller/M17nController.php b/Controller/M17nController.php index c2abbbb..f714f2c 100644 --- a/Controller/M17nController.php +++ b/Controller/M17nController.php @@ -24,7 +24,7 @@ class M17nController extends M17nAppController { * @return void */ public function index() { - $this->redirect($this->request->referer()); + $this->redirect($this->request->referer(true)); } } diff --git a/Model/Behavior/M17nBehavior.php b/Model/Behavior/M17nBehavior.php index e92bd03..5c50565 100644 --- a/Model/Behavior/M17nBehavior.php +++ b/Model/Behavior/M17nBehavior.php @@ -157,8 +157,7 @@ public function isM17nGeneralPlugin(Model $model) { if (Current::read('Plugin.type') !== Plugin::PLUGIN_TYPE_FOR_FRAME) { return true; } - if (! Current::read('Room.id') || ! Current::read('Plugin.is_m17n') || - ! Current::read('Space.is_m17n')) { + if (! Current::read('Room.id') || ! Current::read('Plugin.is_m17n')) { return false; } @@ -260,7 +259,6 @@ public function beforeSave(Model $model, $options = array()) { $model->data[$model->alias] = Hash::remove($model->data[$model->alias], 'id'); $model->id = null; } - return parent::beforeSave($model, $options); } diff --git a/Model/Behavior/SaveM17nBehavior.php b/Model/Behavior/SaveM17nBehavior.php index 4e508a3..98c66ec 100644 --- a/Model/Behavior/SaveM17nBehavior.php +++ b/Model/Behavior/SaveM17nBehavior.php @@ -65,7 +65,7 @@ public function copyOrignalData(Model $model, $languageId) { continue; } - $plugin = $model->Plugin->find('first', array( + $plugin = $model->Plugin->cacheFindQuery('first', array( 'recursive' => -1, 'conditions' => array( 'key' => Inflector::underscore($pluginDir), diff --git a/Model/Language.php b/Model/Language.php index 5a3983a..6af17fe 100644 --- a/Model/Language.php +++ b/Model/Language.php @@ -36,13 +36,6 @@ class Language extends M17nAppModel { */ public $validate = array(); -/** - * 言語データ - * - * @var array - */ - public static $languages = array(); - /** * use behaviors * @@ -50,6 +43,7 @@ class Language extends M17nAppModel { */ public $actsAs = array( 'M17n.SaveM17n', + 'NetCommons.NetCommonsCache', ); /** @@ -62,7 +56,7 @@ class Language extends M17nAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = ValidateMerge::merge($this->validate, array( 'code' => array( 'notBlank' => array( 'rule' => array('notBlank'), @@ -115,7 +109,7 @@ public function getLanguage($type = null, $options = array()) { ]; } - $languages = $this->find($type, Hash::merge(array( + $languages = $this->cacheFindQuery($type, Hash::merge(array( 'recursive' => -1, 'conditions' => array( 'is_active' => true @@ -130,11 +124,7 @@ public function getLanguage($type = null, $options = array()) { * @return array */ public function getLanguages() { - if (self::$languages) { - return self::$languages; - } - - self::$languages = $this->find('all', array( + $result = $this->cacheFindQuery('all', array( 'recursive' => -1, 'fields' => [ 'id', 'code', 'weight', 'is_active' @@ -144,8 +134,22 @@ public function getLanguages() { ), 'order' => array('weight' => 'asc') )); + return $result; + } - return self::$languages; +/** + * 複数言語か否か + * + * @return bool + */ + public function isMultipleLang() { + $result = $this->cacheFindQuery('count', array( + 'recursive' => -1, + 'conditions' => array( + 'is_active' => true + ), + )); + return $result > 1; } /** @@ -154,22 +158,30 @@ public function getLanguages() { * @return array */ public function getLanguagesWithName() { - $languages = $this->find('all', array( + $languages = $this->cacheFindQuery('all', array( 'fields' => array('code', 'is_active'), 'recursive' => -1, )); - $activeLangs = []; - $enableLangs = []; - foreach ($languages as $lang) { - $code = $lang[$this->alias]['code']; - if (! isset($this->__labelLanguages[$code])) { - continue; - } - $enableLangs[$code] = __d('m17n', $this->__labelLanguages[$code]); - if ($lang[$this->alias]['is_active']) { - $activeLangs[] = $code; + $activeLangs = $this->cacheRead('activeLangs'); + $enableLangs = $this->cacheRead('enableLangs'); + if (! $activeLangs || ! $enableLangs) { + $activeLangs = []; + $enableLangs = []; + foreach ($languages as $lang) { + $code = $lang[$this->alias]['code']; + if (! isset($this->__labelLanguages[$code])) { + continue; + } + $enableLangs[$code] = __d('m17n', $this->__labelLanguages[$code]); + if ($lang[$this->alias]['is_active']) { + $activeLangs[] = $code; + } } + + //キャッシュの書き込み + $this->cacheWrite($activeLangs, 'activeLangs'); + $this->cacheWrite($enableLangs, 'enableLangs'); } return array($activeLangs, $enableLangs); @@ -209,7 +221,10 @@ public function saveActive($data) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - $languages = $this->find('list', array( + //キャッシュのクリア + $this->cacheClear(); + + $languages = $this->cacheFindQuery('list', array( 'recursive' => -1, 'conditions' => array( 'is_active' => true, @@ -231,7 +246,7 @@ public function saveActive($data) { public function validateActive($data) { $fieldName = 'Language.code'; - $languages = $this->find('list', array( + $languages = $this->cacheFindQuery('list', array( 'fields' => array('code', 'is_active'), 'recursive' => -1, )); diff --git a/README.md b/README.md index a0142ec..309583d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ M17n ==== -[![Build Status](https://travis-ci.org/NetCommons3/M17n.png?branch=master)](https://travis-ci.org/NetCommons3/M17n) -[![Coverage Status](https://coveralls.io/repos/NetCommons3/M17n/badge.png?branch=master)](https://coveralls.io/r/NetCommons3/M17n?branch=master) - -| dependencies | status | -| ------------ | ------ | -| composer.json | [![Dependency Status](https://www.versioneye.com/user/projects/5382a4cb14c1582c240000d0/badge.svg)](https://www.versioneye.com/user/projects/5382a4cb14c1582c240000d0) | +[![Tests Status](https://github.com/NetCommons3/M17n/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/M17n/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/M17n/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/M17n?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/m17n.svg?label=stable)](https://packagist.org/packages/netcommons/m17n) diff --git a/Test/Case/Model/Language/GetLanguagesTest.php b/Test/Case/Model/Language/GetLanguagesTest.php index 2baccea..4d399d4 100644 --- a/Test/Case/Model/Language/GetLanguagesTest.php +++ b/Test/Case/Model/Language/GetLanguagesTest.php @@ -84,23 +84,4 @@ public function testGetLanguages() { $this->assertEquals($expected, $result); } -/** - * getLanguages()の既に取得済みの場合のテスト - * - * @return void - */ - public function testGetLanguagesWithData() { - $model = $this->_modelName; - $methodName = $this->_methodName; - - Language::$languages = array('test dummy'); - - //テスト実施 - $result = $this->$model->$methodName(); - - //チェック - $expected = array('test dummy'); - $this->assertEquals($expected, $result); - } - } diff --git a/TestSuite/M17nGetTest.php b/TestSuite/M17nGetTest.php index 7e4acb3..1dc0b28 100644 --- a/TestSuite/M17nGetTest.php +++ b/TestSuite/M17nGetTest.php @@ -52,26 +52,4 @@ public function __construct($name = null, array $data = array(), $dataName = '') parent::__construct($name, $data, $dataName); } -/** - * setUp method - * - * @return void - */ - public function setUp() { - parent::setUp(); - - Language::$languages = array(); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - Language::$languages = array(); - - parent::tearDown(); - } - } 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/Elements/switch_language_form.ctp b/View/Elements/switch_language_form.ctp index c4f9d04..26ea706 100644 --- a/View/Elements/switch_language_form.ctp +++ b/View/Elements/switch_language_form.ctp @@ -16,14 +16,7 @@ $enable = array_flip( Hash::extract($switchLanguages, '{n}.Language.code') ); $options = $this->M17n->getLanguagesOptions($enable); -$langQuery = parse_url($this->request->header('REQUEST_URI'), PHP_URL_QUERY); -if (preg_match('/lang=[^&]*/i', $langQuery)) { - $langQuery = preg_replace('/lang=[^&]*/i', 'lang=%s', $langQuery); -} elseif ($langQuery) { - $langQuery .= '&lang=%s'; -} else { - $langQuery = 'lang=%s'; -} +$langCommonQuery = parse_url($this->request->header('REQUEST_URI'), PHP_URL_QUERY); ?>