diff --git a/.travis.yml b/.travis.yml index 4516b68..c8aed61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: php php: - - 5.4 - - 5.5 - - 5.6 - 7.0 - 7.1 - 7.2 @@ -22,6 +19,7 @@ env: - GIT_AUTHOR_EMAIL=ryuji@ryus.co.jp before_script: + - composer dumpautoload - export NETCOMMONS_BUILD_DIR=`dirname $TRAVIS_BUILD_DIR`/NetCommons3 - git clone git://github.com/NetCommons3/NetCommons3 $NETCOMMONS_BUILD_DIR - cd $NETCOMMONS_BUILD_DIR @@ -30,7 +28,7 @@ before_script: - . tools/build/plugins/cakephp/travis/environment.sh script: - - . tools/build/plugins/cakephp/travis/main.sh + - . app/Plugin/$PLUGIN_NAME/tools/build/travis/main.sh after_script: - . tools/build/plugins/cakephp/travis/post.sh diff --git a/Config/Migration/1564277047_add_db_type.php b/Config/Migration/1564277047_add_db_type.php index fa09aaa..c5c6e3d 100644 --- a/Config/Migration/1564277047_add_db_type.php +++ b/Config/Migration/1564277047_add_db_type.php @@ -1,4 +1,11 @@ helpers['Blocks.BlockTabs'] = array( 'mainTabs' => array( - 'block_index' => array('url' => array('controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbTypeKey() . '_blocks')), - 'frame_settings' => array('url' => array('controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbTypeKey() . '_frame_settings')), + 'block_index' => array( + 'url' => array( + 'controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance( + )->getDbTypeKey() . '_blocks' + ) + ), + 'frame_settings' => array( + 'url' => array( + 'controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance( + )->getDbTypeKey() . '_frame_settings' + ) + ), ), 'blockTabs' => array( - 'block_settings' => array('url' => array('controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbTypeKey() . '_blocks')), + 'block_settings' => array( + 'url' => array( + 'controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance( + )->getDbTypeKey() . '_blocks' + ) + ), 'mail_settings', - 'role_permissions' => array('url' => array('controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbTypeKey() . '_block_role_permissions')), + 'role_permissions' => array( + 'url' => array( + 'controller' => \NetCommons\Tinydb\Lib\CurrentDbType::instance( + )->getDbTypeKey() . '_block_role_permissions' + ) + ), ), ); parent::beforeRender($controller); diff --git a/Controller/TinydbAppController.php b/Controller/TinydbAppController.php index 17321ca..d2a8d88 100644 --- a/Controller/TinydbAppController.php +++ b/Controller/TinydbAppController.php @@ -50,6 +50,11 @@ abstract class TinydbAppController extends AppController { 'Tinydb.TinydbFrameSetting' ); +/** + * beforeFilter + * + * @return void + */ public function beforeFilter() { parent::beforeFilter(); @@ -58,9 +63,13 @@ public function beforeFilter() { $this->plugin ); $this->viewClass = 'Tinydb.Tinydb'; - } +/** + * beforeRender + * + * @return void + */ public function beforeRender() { if ($this->plugin !== 'TestTinydb') { // テスト以外だったら viewPathに含まれるプラグイン名をTinydbに変更 diff --git a/Controller/TinydbItemsEditController.php b/Controller/TinydbItemsEditController.php index db02348..4c56c61 100644 --- a/Controller/TinydbItemsEditController.php +++ b/Controller/TinydbItemsEditController.php @@ -255,14 +255,14 @@ public function delete() { ); } - /** - * ${CARET}_addFromItem - * - * @param $tinydbItem - * @return void - */ - protected function _addFromItem($tinydbItem) : void { -// 初期化したいフィールドはunsetする +/** + * ${CARET}_addFromItem + * + * @param array $tinydbItem TinydbItem data + * @return void + */ + protected function _addFromItem($tinydbItem) { + // 初期化したいフィールドはunsetする // 新規扱いにするのでidは削除する unset($tinydbItem['TinydbItem']['id']); unset($tinydbItem['TinydbItem']['key']); diff --git a/Controller/TinydbMailSettingsController.php b/Controller/TinydbMailSettingsController.php index 7d541c0..43312e3 100644 --- a/Controller/TinydbMailSettingsController.php +++ b/Controller/TinydbMailSettingsController.php @@ -51,7 +51,6 @@ public function beforeFilter() { $this->plugin ); $this->viewClass = 'Tinydb.Tinydb'; - } /** @@ -62,7 +61,6 @@ public function beforeFilter() { * @return void */ public function beforeRender() { - // viewPathに含まれるプラグイン名をTinydbに変更 $this->viewPath = str_replace($this->plugin, 'Tinydb', $this->viewPath); diff --git a/Lib/CurrentDbType.php b/Lib/CurrentDbType.php index a9719df..1d94bc2 100644 --- a/Lib/CurrentDbType.php +++ b/Lib/CurrentDbType.php @@ -1,55 +1,86 @@ dbType = \Inflector::camelize($dbType); + $this->__dbType = \Inflector::camelize($dbType); } +/** + * instance + * + * @return CurrentDbType + */ public static function instance() { //if (self::$selfInstance === null) { // throw new \LogicException('先にinitByFrame()で初期化してください'); //} - return self::$selfInstance; + return self::$__selfInstance; } - public function getDbType() : string { - return $this->dbType; +/** + * getDbType + * + * @return string + */ + public function getDbType() { + return $this->__dbType; } - public function getDbTypeKey() : string { - return \Inflector::underscore($this->dbType); +/** + * getDbTypeKey + * + * @return string + */ + public function getDbTypeKey() { + return \Inflector::underscore($this->__dbType); } - public function isSingleDb() : bool { - // TODO 複数DB使いたいのがでてきたら、DB毎に変更できるようにする +/** + * isSingleDb + * + * @return bool + */ + public function isSingleDb() { + // HACK 複数DB使いたいのがでてきたら、DB毎に変更できるようにする return true; } } \ No newline at end of file diff --git a/Lib/EventManager.php b/Lib/EventManager.php index 5c74309..b02d18b 100644 --- a/Lib/EventManager.php +++ b/Lib/EventManager.php @@ -1,17 +1,29 @@ callbacks[$event][] = $callable; + $this->__callbacks[$event][] = $callable; } +/** + * dispatch + * + * @param string $event event name + * @param mixed &$args 引数 + * @return void + */ public function dispatch(string $event, &...$args) { - foreach ($this->callbacks[$event] ?? [] as $callback) { + foreach ($this->__callbacks[$event] ?? [] as $callback) { call_user_func_array($callback, $args); } - } + +/** + * dispatchByArray + * + * @param string $event event name + * @param mixed &$args 引数 + * @return void + */ public function dispatchByArray(string $event, &$args) { - foreach ($this->callbacks[$event] ?? [] as $callback) { + foreach ($this->__callbacks[$event] ?? [] as $callback) { call_user_func_array($callback, $args); } } diff --git a/Lib/TinydbFunctions.php b/Lib/TinydbFunctions.php index faf6318..a046d23 100644 --- a/Lib/TinydbFunctions.php +++ b/Lib/TinydbFunctions.php @@ -1,4 +1,17 @@ __convertToTinydbFrame($frame); -// } -// -///** -// * フレームをTinydbのフレームにする -// * -// * @param array $frame Frame data -// * @return void -// */ -// private function __convertToTinydbFrame(array $frame) { -// $frame['Frame']['plugin_key'] = 'tinydb'; -// $dbType = Inflector::underscore(get_class($this)); -// $frame['Frame']['default_setting_action'] = 'tinydb_blocks/index/db_type:' . $dbType; -// $frameModel = ClassRegistry::init('Frames.Frame'); -// $frameModel->create(); -// $frameModel->save($frame, ['callbacks' => false]); -// } } \ No newline at end of file diff --git a/Model/Tinydb.php b/Model/Tinydb.php index b68a202..9229d79 100644 --- a/Model/Tinydb.php +++ b/Model/Tinydb.php @@ -108,7 +108,10 @@ public function beforeValidate($options = array()) { 'name' => array( 'notBlank' => array( 'rule' => array('notBlank'), - 'message' => sprintf(__tinydbd('net_commons', 'Please input %s.'), __tinydbd('tinydb', 'Tinydb name')), + 'message' => sprintf( + __tinydbd('net_commons', 'Please input %s.'), + __tinydbd('tinydb', 'Tinydb name') + ), 'required' => true ), ), diff --git a/Model/TinydbAppModel.php b/Model/TinydbAppModel.php index b739dfe..3ae725c 100644 --- a/Model/TinydbAppModel.php +++ b/Model/TinydbAppModel.php @@ -9,6 +9,14 @@ */ class TinydbAppModel extends AppModel { +/** + * TinydbAppModel constructor. + * + * @param int|bool $id id + * @param string|null $table table + * @param mixed|null $ds ds + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ public function __construct($id = false, $table = null, $ds = null) { $dbType = \NetCommons\Tinydb\Lib\CurrentDbType::instance(); if ($dbType !== null) { @@ -17,6 +25,13 @@ public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); } +/** + * _triggerEvent + * + * @param string $localEventName model event name + * @param mixed &$args 引数 + * @return void + */ protected function _triggerEvent(string $localEventName, &...$args) { $dbTypeInstance = \NetCommons\Tinydb\Lib\CurrentDbType::instance(); if ($dbTypeInstance === null) { @@ -27,6 +42,11 @@ protected function _triggerEvent(string $localEventName, &...$args) { \NetCommons\Tinydb\Lib\EventManager::instance()->dispatchByArray($fullEventName, $args); } +/** + * _setUpDbType + * + * @return void + */ protected function _setUpDbType() { // Migration実行時にdbType不定になるので $dbTypeInstance = \NetCommons\Tinydb\Lib\CurrentDbType::instance(); @@ -51,5 +71,4 @@ protected function _setUpDbType() { } } - } diff --git a/Model/TinydbItem.php b/Model/TinydbItem.php index 7b316db..0b4c9a3 100644 --- a/Model/TinydbItem.php +++ b/Model/TinydbItem.php @@ -42,7 +42,7 @@ class TinydbItem extends TinydbAppModel { 'fields' => array( 'title' => 'title', 'summary' => 'body1', - 'path' => '/:plugin_key/tinydb_items/view/:block_id/:content_key', + 'path' => '/:plugin_key/{{db_type}}_items/view/:block_id/:content_key', ), 'search_contents' => array('body2') ), @@ -111,8 +111,17 @@ class TinydbItem extends TinydbAppModel { ), ); +/** + * TinydbItem constructor. + * + * @param int|bool $id id + * @param string|null $table table + * @param mixed|null $ds ds + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ public function __construct($id = false, $table = null, $ds = null) { $this->_setUpDbType(); + $this->__setUpTopicsPath(); $this->_triggerEvent('TinydbItem.construct', $this); parent::__construct($id, $table, $ds); } @@ -149,6 +158,13 @@ public function beforeValidate($options = array()) { return parent::beforeValidate($options); } +/** + * afterSave + * + * @param bool $created created + * @param array $options options + * @return void + */ public function afterSave($created, $options = array()) { $this->_triggerEvent('TinydbItem.afterSave', $created, $options, $this->data); parent::afterSave($created, $options); @@ -183,7 +199,10 @@ protected function _getValidateSpecification() { 'title' => array( 'notBlank' => [ 'rule' => array('notBlank'), - 'message' => sprintf(__tinydbd('net_commons', 'Please input %s.'), __tinydbd('tinydb', 'Title')), + 'message' => sprintf( + __tinydbd('net_commons', 'Please input %s.'), + __tinydbd('tinydb', 'Title') + ), //'allowEmpty' => false, 'required' => true, //'last' => false, // Stop validation after this rule @@ -193,7 +212,10 @@ protected function _getValidateSpecification() { 'body1' => array( 'notBlank' => [ 'rule' => array('notBlank'), - 'message' => sprintf(__tinydbd('net_commons', 'Please input %s.'), __tinydbd('tinydb', 'Body1')), + 'message' => sprintf( + __tinydbd('net_commons', 'Please input %s.'), + __tinydbd('tinydb', 'Body1') + ), //'allowEmpty' => false, 'required' => true, //'last' => false, // Stop validation after this rule @@ -415,11 +437,9 @@ public function saveItem($data) { } // dbType別の保存 - // TODO バリデート $dbTypeModelName = key($this->hasOne ?? []); if ($dbTypeModelName) { $savedData[$dbTypeModelName]['tinydb_item_id'] = $this->id; - // TODO エラー処理 $this->$dbTypeModelName->save($savedData); } @@ -427,7 +447,6 @@ public function saveItem($data) { $this->set($savedData); $this->saveM17nData(); - $this->commit(); } catch (Exception $e) { @@ -477,4 +496,26 @@ public function yetPublish($tinydbItem) { return ($count == 0); } +/** + * 新着プラグインのパスをDbTypeにあわせて変更する + * + * @return void + */ + private function __setUpTopicsPath() { + $dbTypeInstance = \NetCommons\Tinydb\Lib\CurrentDbType::instance(); + if ($dbTypeInstance === null) { + return; + } + $dbType = $dbTypeInstance->getDbType(); + if ($dbType === 'Tinydb') { + return; + } + $snakeCaseDbType = Inflector::underscore($dbType); + $this->actsAs['Topics.Topics']['fields']['path'] = str_replace( + '{{db_type}}', + $snakeCaseDbType, + $this->actsAs['Topics.Topics']['fields']['path'] + ); + } + } diff --git a/Model/TinydbSetting.php b/Model/TinydbSetting.php index d6958d2..5b8d5b0 100644 --- a/Model/TinydbSetting.php +++ b/Model/TinydbSetting.php @@ -53,6 +53,15 @@ class TinydbSetting extends BlockBaseModel { ), ); +/** + * TinydbSetting constructor. + * + * @param bool|int|string|array $id Set this ID for this model on startup, + * can also be an array of options, see above. + * @param string|false $table Name of database table to use. + * @param string $ds DataSource connection name. + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ public function __construct($id = false, $table = null, $ds = null) { $dbTypeInstance = \NetCommons\Tinydb\Lib\CurrentDbType::instance(); if ($dbTypeInstance) { diff --git a/Test/Case/AllTinydbControllerTest.php b/Test/Case/AllTinydbControllerTest.php index 03daa58..1cebdda 100644 --- a/Test/Case/AllTinydbControllerTest.php +++ b/Test/Case/AllTinydbControllerTest.php @@ -1,5 +1,4 @@ attach('Test', function(&$first, &$second) { + $eventManager->attach('Test', function (&$first, &$second) { $first = 1; $second = 2; }); @@ -20,5 +34,4 @@ public function testDispatch() { $this->assertSame(1, $first); $this->assertSame(2, $second); } - } diff --git a/Test/Case/Model/AllTinydbModelTinydbFrameSettingTest.php b/Test/Case/Model/AllTinydbModelTinydbFrameSettingTest.php index 9527ebd..4e9ebb8 100644 --- a/Test/Case/Model/AllTinydbModelTinydbFrameSettingTest.php +++ b/Test/Case/Model/AllTinydbModelTinydbFrameSettingTest.php @@ -1,5 +1,4 @@ - SnsButton->facebook($contentUrl);?> -
SnsButton->twitter($contentUrl, $tinydbItem['TinydbItem']['title']);?>
diff --git a/View/TinydbItems/view.ctp b/View/TinydbItems/view.ctp index 0112e84..ad6b253 100644 --- a/View/TinydbItems/view.ctp +++ b/View/TinydbItems/view.ctp @@ -42,7 +42,6 @@ echo $this->TinydbOgp->ogpMetaByTinydbItem($tinydbItem); element('Tinydb.item_footer'); ?> -
@@ -58,18 +57,6 @@ echo $this->TinydbOgp->ogpMetaByTinydbItem($tinydbItem);
ContentComment->index($tinydbItem); ?> - - - element('ContentComments.index', array( - // 'pluginKey' => $this->request->params['plugin'], - // 'contentKey' => $tinydbItem['TinydbItem']['key'], - // 'isCommentApproved' => $tinydbSetting['use_comment_approval'], - // 'useComment' => $tinydbSetting['use_comment'], - // 'contentCommentCnt' => $tinydbItem['ContentCommentCnt']['cnt'], - // 'redirectUrl' => $this->NetCommonsHtml->url(array('plugin' => 'tinydb', 'controller' => 'tinydb_items', 'action' => 'view', 'frame_id' => Current::read('Frame.id'), 'key' => $tinydbItem['TinydbItem']['key'])), - // )); ?> - -
diff --git a/View/TinydbView.php b/View/TinydbView.php index ab2d6bf..4f3f804 100644 --- a/View/TinydbView.php +++ b/View/TinydbView.php @@ -1,7 +1,26 @@