From 6dd51c1c4a4a5a58e396037893fb949b00928dc6 Mon Sep 17 00:00:00 2001 From: ryuring Date: Wed, 25 Oct 2023 19:50:47 +0900 Subject: [PATCH 01/14] =?UTF-8?q?BcAppController=20=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/BcAdminAppController.php | 4 +- .../src/Controller/AppController.php | 83 ++++-- .../src/Controller/BcAppController.php | 252 ------------------ .../src/Controller/PagesController.php | 1 - plugins/baser-core/src/Model/Entity/User.php | 16 ++ plugins/baser-core/src/Service/AppService.php | 12 +- .../TestCase/Controller/AppControllerTest.php | 39 +++ .../Controller/BcAppControllerTest.php | 106 -------- .../BcFrontContentsComponentTest.php | 2 +- .../CustomContentFrontAppController.php | 4 +- 10 files changed, 130 insertions(+), 389 deletions(-) delete mode 100644 plugins/baser-core/src/Controller/BcAppController.php delete mode 100644 plugins/baser-core/tests/TestCase/Controller/BcAppControllerTest.php diff --git a/plugins/baser-core/src/Controller/Admin/BcAdminAppController.php b/plugins/baser-core/src/Controller/Admin/BcAdminAppController.php index e9aefeba3d..80aa39c9d0 100644 --- a/plugins/baser-core/src/Controller/Admin/BcAdminAppController.php +++ b/plugins/baser-core/src/Controller/Admin/BcAdminAppController.php @@ -12,7 +12,7 @@ namespace BaserCore\Controller\Admin; use Authentication\Controller\Component\AuthenticationComponent; -use BaserCore\Controller\BcAppController; +use BaserCore\Controller\AppController; use BaserCore\Service\Admin\BcAdminAppServiceInterface; use BaserCore\Service\SiteConfigsService; use BaserCore\Service\SiteConfigsServiceInterface; @@ -34,7 +34,7 @@ * Class BcAdminAppController * @property AuthenticationComponent $Authentication */ -class BcAdminAppController extends BcAppController +class BcAdminAppController extends AppController { /** diff --git a/plugins/baser-core/src/Controller/AppController.php b/plugins/baser-core/src/Controller/AppController.php index cec02db8f7..dde852c2af 100644 --- a/plugins/baser-core/src/Controller/AppController.php +++ b/plugins/baser-core/src/Controller/AppController.php @@ -20,6 +20,7 @@ use BaserCore\Annotation\Checked; use BaserCore\Annotation\Note; use BaserCore\Service\AppServiceInterface; +use BaserCore\Service\DblogsServiceInterface; use BaserCore\Service\PermissionsServiceInterface; use BaserCore\Utility\BcContainerTrait; use BaserCore\Utility\BcSiteConfig; @@ -37,6 +38,7 @@ use Cake\Http\ServerRequest; use Cake\Utility\Hash; use Cake\Utility\Inflector; +use Psr\Http\Message\ResponseInterface; /** * Class AppController @@ -54,22 +56,23 @@ class AppController extends BaseController use BcContainerTrait; /** - * BcAppController constructor. + * AppController constructor. * @param ServerRequest|null $request * @param Response|null $response * @param string|null $name * @param EventManagerInterface|null $eventManager * @param ComponentRegistry|null $components + * @return void|ResponseInterface * @checked * @noTodo * @unitTest */ public function __construct( - ?ServerRequest $request = null, - ?Response $response = null, - ?string $name = null, + ?ServerRequest $request = null, + ?Response $response = null, + ?string $name = null, ?EventManagerInterface $eventManager = null, - ?ComponentRegistry $components = null + ?ComponentRegistry $components = null ) { parent::__construct($request, $response, $name, $eventManager, $components); @@ -82,10 +85,10 @@ public function __construct( if (!($request? $request->is('install') : false)) { // app_local.php が存在しない場合は、CakePHPの Internal Server のエラー画面が出て、 // 原因がわからなくなるので強制的にコピーする - if($this->getName() === 'BcError' && !file_exists(CONFIG . 'app_local.php')) { + if ($this->getName() === 'BcError' && !file_exists(CONFIG . 'app_local.php')) { copy(CONFIG . 'app_local.example.php', CONFIG . 'app_local.php'); // app_local.php が存在しない場合、.env もない可能性があるので確認 - if(!file_exists(CONFIG . '.env')){ + if (!file_exists(CONFIG . '.env')) { copy(CONFIG . '.env.example', CONFIG . '.env'); } } @@ -105,7 +108,6 @@ public function __construct( } } } - } /** @@ -137,13 +139,13 @@ public function initialize(): void public function beforeFilter(EventInterface $event) { $response = parent::beforeFilter($event); - if($response) return $response; + if ($response) return $response; - // index.php をつけたURLの場合、base の値が正常でなくなり、 - // 内部リンクが影響を受けておかしくなってしまうため強制的に Not Found とする - if(preg_match('/\/index\.php\//', $this->getRequest()->getAttribute('base'))) { - $this->notFound(); - } + // index.php をつけたURLの場合、base の値が正常でなくなり、 + // 内部リンクが影響を受けておかしくなってしまうため強制的に Not Found とする + if (preg_match('/\/index\.php\//', $this->getRequest()->getAttribute('base'))) { + $this->notFound(); + } if (!$this->getRequest()->is('requestview')) return; @@ -160,13 +162,13 @@ public function beforeFilter(EventInterface $event) return; } - if(!$this->checkPermission()) { + if (!$this->checkPermission()) { $prefix = BcUtil::getRequestPrefix($this->getRequest()); if ($prefix === 'Api/Admin') { throw new ForbiddenException(__d('baser_core', '指定されたAPIエンドポイントへのアクセスは許可されていません。')); } else { if (BcUtil::loginUser()) { - if($this->getRequest()->getMethod() === 'GET') { + if ($this->getRequest()->getMethod() === 'GET') { $this->BcMessage->setError(__d('baser_core', '指定されたページへのアクセスは許可されていません。')); } else { $this->BcMessage->setError(__d('baser_core', '実行した操作は許可されていません。')); @@ -174,7 +176,7 @@ public function beforeFilter(EventInterface $event) } // リファラが存在する場合はリファラにリダイレクトする // $this->referer() で判定した場合、リファラがなくてもトップのURLが返却されるため ServerRequest で判定 - if($this->getRequest()->getEnv('HTTP_REFERER')) { + if ($this->getRequest()->getEnv('HTTP_REFERER')) { $url = $this->referer(); } else { $url = Configure::read("BcPrefixAuth.{$prefix}.loginRedirect"); @@ -200,7 +202,7 @@ public function beforeFilter(EventInterface $event) private function checkPermission() { $user = BcUtil::loginUser(); - if($user && $user->user_groups) { + if ($user && $user->user_groups) { $userGroupsIds = Hash::extract($user->toArray()['user_groups'], '{n}.id'); } else { $userGroupsIds = []; @@ -292,8 +294,8 @@ protected function _autoConvertEncodingByArray($data, $outenc = 'UTF-8'): array continue; } $inenc = mb_detect_encoding((string)$value); - if(!$inenc) continue; - if(!in_array($inenc, Configure::read('BcEncode.detectOrder'))) continue; + if (!$inenc) continue; + if (!in_array($inenc, Configure::read('BcEncode.detectOrder'))) continue; if ($inenc === $outenc) continue; // 半角カナは一旦全角に変換する $value = mb_convert_kana($value, 'KV', $inenc); @@ -533,4 +535,45 @@ public function notFound() throw new NotFoundException(__d('baser_core', '見つかりませんでした。')); } + /** + * データベースログを記録する + * + * @param string $message + * @return \Cake\Datasource\EntityInterface + * @checked + * @unitTest + * @noTodo + */ + protected function saveDblog($message) + { + $dblogsService = $this->getService(DblogsServiceInterface::class); + return $dblogsService->create(['message' => $message]); + } + + /** + * Ajax用のエラーを出力する + * + * @param int $errorNo エラーのステータスコード + * @param mixed $message エラーメッセージ + * @return void + * @deprecated since 5.0.5 このメソッドは非推奨です。 + * @checked + * @noTodo + */ + public function ajaxError(int $errorNo = 500, $message = '') + { + $this->response = $this->getResponse()->withStatus($errorNo); + if (!$message) return; + if (!is_array($message)) $message = [$message]; + $aryMessage = []; + foreach($message as $value) { + if (is_array($value)) { + $aryMessage[] = implode('
', $value); + } else { + $aryMessage[] = $value; + } + } + echo implode('
', $aryMessage); + } + } diff --git a/plugins/baser-core/src/Controller/BcAppController.php b/plugins/baser-core/src/Controller/BcAppController.php deleted file mode 100644 index 36159dc980..0000000000 --- a/plugins/baser-core/src/Controller/BcAppController.php +++ /dev/null @@ -1,252 +0,0 @@ - - * Copyright (c) NPO baser foundation - * - * @copyright Copyright (c) NPO baser foundation - * @link https://basercms.net baserCMS Project - * @since 5.0.0 - * @license https://basercms.net/license/index.html MIT License - */ - -namespace BaserCore\Controller; - -use BaserCore\Utility\BcContainerTrait; -use Cake\Event\EventInterface; -use BaserCore\Utility\BcUtil; -use BaserCore\Service\DblogsServiceInterface; -use Cake\Core\Configure; -use BaserCore\Annotation\UnitTest; -use BaserCore\Annotation\NoTodo; -use BaserCore\Annotation\Checked; -use BaserCore\Annotation\Note; - -/** - * Class BcAppController - */ -class BcAppController extends AppController -{ - - /** - * Trait - */ - use BcContainerTrait; - - /** - * サブディレクトリ - * - * @var string - * @access public - */ - public $subDir = null; - - /** - * コンテンツタイトル - * - * @var string - */ - public $contentsTitle = ''; - - /** - * プレビューフラグ - * - * @var bool - */ - public $preview = false; - - /** - * 管理画面テーマ - * - * @var string - */ - public $adminTheme = null; - - /** - * サイトデータ - * - * @var array - */ - public $site = []; - - /** - * コンテンツデータ - * - * @var array - */ - public $content = []; - - /** - * beforeFilter - * - * @checked - * @note(value="マイルストーン2が終わってから確認する") - * @todo ucmitz 未確認 - */ - public function beforeFilter(EventInterface $event) - { - return parent::beforeFilter($event); - - // 認証設定 - if (isset($this->BcAuthConfigure)) { - $authConfig = []; - if (!empty($this->request->getParam('prefix'))) { - $currentAuthPrefix = $this->request->getParam('prefix'); - } else { - $currentAuthPrefix = 'front'; - } - $authPrefixSettings = Configure::read('BcPrefixAuth'); - foreach($authPrefixSettings as $key => $authPrefixSetting) { - if (isset($authPrefixSetting['alias']) && $authPrefixSetting['alias'] == $currentAuthPrefix) { - $authConfig = $authPrefixSetting; - $authConfig['auth_prefix'] = $authPrefixSetting['alias']; - break; - } - if ($this->request->getParam('action') !== 'back_agent') { - if ($key == $currentAuthPrefix) { - $authConfig = $authPrefixSetting; - $authConfig['auth_prefix'] = $key; - break; - } - } - } - if ($authConfig) { - $this->BcAuthConfigure->setting($authConfig); - } else { - $this->BcAuth->setSessionKey('Auth.' . Configure::read('BcPrefixAuth.Admin.sessionKey')); - } - - // ================================================================= - // ユーザーの存在チェック - // ログイン中のユーザーを管理側で削除した場合、ログイン状態を削除する必要がある為 - // ================================================================= - $user = $this->BcAuth->user(); - if ($user && $authConfig && (empty($authConfig['type']) || $authConfig['type'] === 'Form')) { - $userModel = $authConfig['userModel']; - $User = ClassRegistry::init($userModel); - if (strpos($userModel, '.') !== false) { - [$plugin, $userModel] = explode('.', $userModel); - } - if ($userModel && !empty($this->{$userModel})) { - $nameField = 'name'; - if (!empty($authConfig['username'])) { - $nameField = $authConfig['username']; - } - $conditions = [ - $userModel . '.id' => $user['id'], - $userModel . '.' . $nameField => $user[$nameField] - ]; - if (isset($User->belongsTo['UserGroup'])) { - $UserGroup = ClassRegistry::init('UserGroup'); - $userGroups = $UserGroup->find('all', ['conditions' => ['UserGroup.auth_prefix LIKE' => '%' . $authConfig['auth_prefix'] . '%'], 'recursive' => -1]); - $userGroupIds = Hash::extract($userGroups, '{n}.UserGroup.id'); - $conditions[$userModel . '.user_group_id'] = $userGroupIds; - } - if (!$User->find('count', [ - 'conditions' => $conditions, - 'recursive' => -1])) { - $this->Session->delete(BcAuthComponent::$sessionKey); - } - } - } - } - - } - - /** - * beforeRender - * - * @return void - */ - public function beforeRender(EventInterface $event): void - { - parent::beforeRender($event); - // TODO ucmitz 未確認 - return; - $this->__loadDataToView(); - } - - /** - * View用のデータを読み込む。 - * beforeRenderで呼び出される - * - * @return void - */ - private function __loadDataToView() - { - $this->set('preview', $this->preview); - - if (!empty($this->request->getParam('prefix'))) { - $currentPrefix = $this->request->getParam('prefix'); - } else { - $currentPrefix = 'front'; - } - - $user = BcUtil::loginUser(); - $sessionKey = Configure::read('BcPrefixAuth.Admin.sessionKey'); - - $authPrefix = Configure::read('BcPrefixAuth.' . $currentPrefix); - if ($authPrefix) { - $currentPrefixUser = BcUtil::loginUser($currentPrefix); - if ($currentPrefixUser) { - $user = $currentPrefixUser; - $sessionKey = BcUtil::getLoginUserSessionKey(); - } - } - - /* ログインユーザー */ - if (BcUtil::isInstalled() && $user && $this->name !== 'Installations' && !Configure::read('BcRequest.isUpdater') && !Configure::read('BcRequest.isMaintenance') && $this->name !== 'CakeError') { - $this->set('user', $user); - } - - $currentUserAuthPrefixes = []; - if ($this->Session->check('Auth.' . $sessionKey . '.UserGroup.auth_prefix')) { - $currentUserAuthPrefixes = explode(',', $this->Session->read('Auth.' . $sessionKey . '.UserGroup.auth_prefix')); - } - $this->set('currentUserAuthPrefixes', $currentUserAuthPrefixes); - } - - /** - * Ajax用のエラーを出力する - * - * @param int $errorNo エラーのステータスコード - * @param mixed $message エラーメッセージ - * @return void - */ - public function ajaxError($errorNo = 500, $message = '') - { - $this->response = $this->response->withStatus($errorNo); - if (!$message) { - return; - } - - if (!is_array($message)) { - return; - } - - $aryMessage = []; - foreach($message as $value) { - if (is_array($value)) { - $aryMessage[] = implode('
', $value); - } else { - $aryMessage[] = $value; - } - } - echo implode('
', $aryMessage); - return; - } - - /** - * データベースログを記録する - * - * @param string $message - * @return \Cake\Datasource\EntityInterface - * @checked - * @unitTest - * @noTodo - */ - protected function saveDblog($message) - { - $DblogsService = $this->getService(DblogsServiceInterface::class); - return $DblogsService->create(['message' => $message]); - } -} diff --git a/plugins/baser-core/src/Controller/PagesController.php b/plugins/baser-core/src/Controller/PagesController.php index adf07b584e..2a24fa80a1 100644 --- a/plugins/baser-core/src/Controller/PagesController.php +++ b/plugins/baser-core/src/Controller/PagesController.php @@ -29,7 +29,6 @@ class PagesController extends BcFrontAppController /** * Trait - * NOTE: BcAppControllerにもあるので、移行時に取り除く */ use BcContainerTrait; diff --git a/plugins/baser-core/src/Model/Entity/User.php b/plugins/baser-core/src/Model/Entity/User.php index 5cab089453..58535591cd 100644 --- a/plugins/baser-core/src/Model/Entity/User.php +++ b/plugins/baser-core/src/Model/Entity/User.php @@ -201,4 +201,20 @@ public function getDisplayName() } } + /** + * 認証領域のプレフィックスを配列で取得する + * @return array + * @checked + * @noTodo + */ + public function getAuthPrefixes(): array + { + if(!$this->user_groups) return []; + $prefixes = []; + foreach($this->user_groups as $userGroup) { + $prefixes += explode(',', $userGroup->auth_prefix); + } + return $prefixes; + } + } diff --git a/plugins/baser-core/src/Service/AppService.php b/plugins/baser-core/src/Service/AppService.php index 93b76a650d..2201069f89 100644 --- a/plugins/baser-core/src/Service/AppService.php +++ b/plugins/baser-core/src/Service/AppService.php @@ -34,7 +34,7 @@ class AppService /** * アプリケーション全体で必要な変数を取得 - * + * * @return array * @checked * @noTodo @@ -42,17 +42,19 @@ class AppService */ public function getViewVarsForAll(): array { + $user = BcUtil::loginUser(); return [ 'currentSite' => $this->getCurrentSite(), 'otherSites' => $this->getOtherSiteList(), - 'loginUser' => BcUtil::loginUser(), - 'currentAdminTheme' => BcUtil::getCurrentAdminTheme() + 'loginUser' => $user, + 'currentAdminTheme' => BcUtil::getCurrentAdminTheme(), + 'currentUserAuthPrefixes' => $user ? $user->getAuthPrefixes() : [], ]; } /** * 現在の管理対象のサイトを取得する - * + * * @return EntityInterface * @checked * @noTodo @@ -72,7 +74,7 @@ public function getCurrentSite(): ?Site /** * 現在の管理対象のサイト以外のリストを取得する - * + * * @return array * @checked * @noTodo diff --git a/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php index 83c5d50b9f..d84c9e77bb 100644 --- a/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php @@ -352,4 +352,43 @@ public function test_setViewConditions() $data = $session->read('BcApp.viewConditions.PagesView.index.data.Content'); $this->assertEquals(['title' => 'default'], $data); } + + + /** + * Test saveDblog + * + * @return void + * @dataProvider saveDblogDataProvider + */ + public function testSaveDblog(string $message, int $userId = null): void + { + $request =$this->getRequest('/baser/admin/baser-core/users/'); + if (isset($userId)) $this->loginAdmin($request, $userId); + + $this->execPrivateMethod($this->AppController, 'saveDblog', [$message]); + + $where = [ + 'message' => $message, + 'controller' => 'Users', + 'action' => 'index' + ]; + if (isset($userId)) { + $where['user_id'] = $userId; + } else { + $where['user_id IS'] = null; + } + + $dblogs = $this->getTableLocator()->get('Dblogs'); + $query = $dblogs->find()->where($where); + $this->assertSame(1, $query->count()); + } + + public function saveDblogDataProvider(): array + { + return [ + ['dblogs testSaveDblog message guest', null], + ['dblogs testSaveDblog message login', 1] + ]; + } + } diff --git a/plugins/baser-core/tests/TestCase/Controller/BcAppControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/BcAppControllerTest.php deleted file mode 100644 index 0122e4e8d0..0000000000 --- a/plugins/baser-core/tests/TestCase/Controller/BcAppControllerTest.php +++ /dev/null @@ -1,106 +0,0 @@ - - * Copyright (c) NPO baser foundation - * - * @copyright Copyright (c) NPO baser foundation - * @link https://basercms.net baserCMS Project - * @since 5.0.0 - * @license https://basercms.net/license/index.html MIT License - */ - -namespace BaserCore\Test\TestCase\Controller; - -use Cake\TestSuite\IntegrationTestTrait; -use BaserCore\TestSuite\BcTestCase; -use BaserCore\Controller\BcAppController; -use Cake\Event\Event; - -/** - * BaserCore\Controller\BcAppController Test Case - */ -class BcAppControllerTest extends BcTestCase -{ - use IntegrationTestTrait; - - /** - * Fixtures - * - * @var array - */ - protected $fixtures = [ - 'plugin.BaserCore.Dblogs', - 'plugin.BaserCore.Users', - 'plugin.BaserCore.UsersUserGroups', - 'plugin.BaserCore.UserGroups', - 'plugin.BaserCore.Sites' - ]; - - /** - * set up - */ - public function setUp(): void - { - parent::setUp(); - $this->BcAppController = new BcAppController($this->getRequest()); - } - - /** - * Tear Down - * - * @return void - */ - public function tearDown(): void - { - parent::tearDown(); - unset($this->BcAppController); - } - - /** - * Test beforeFilter - * - * @return void - */ - public function testBeforeFilter(): void - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Test saveDblog - * - * @return void - * @dataProvider saveDblogDataProvider - */ - public function testSaveDblog(string $message, int $userId = null): void - { - $request =$this->getRequest('/baser/admin/baser-core/users/'); - if (isset($userId)) $this->loginAdmin($request, $userId); - - $result = $this->execPrivateMethod($this->BcAppController, 'saveDblog', [$message]); - - $where = [ - 'message' => $message, - 'controller' => 'Users', - 'action' => 'index' - ]; - if (isset($userId)) { - $where['user_id'] = $userId; - } else { - $where['user_id IS'] = null; - } - - $dblogs = $this->getTableLocator()->get('Dblogs'); - $query = $dblogs->find()->where($where); - $this->assertSame(1, $query->count()); - } - - public function saveDblogDataProvider(): array - { - return [ - ['dblogs testSaveDblog message guest', null], - ['dblogs testSaveDblog message login', 1] - ]; - } - -} diff --git a/plugins/baser-core/tests/TestCase/Controller/Component/BcFrontContentsComponentTest.php b/plugins/baser-core/tests/TestCase/Controller/Component/BcFrontContentsComponentTest.php index 9d115b5dbd..3e0339961a 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Component/BcFrontContentsComponentTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Component/BcFrontContentsComponentTest.php @@ -18,7 +18,7 @@ use BaserCore\TestSuite\BcTestCase; use BaserCore\Service\ContentsService; use Cake\Controller\ComponentRegistry; -use BaserCore\Controller\BcAppController; +use BaserCore\Controller\AppController; use BaserCore\Controller\PagesController; use BaserCore\Controller\Component\BcFrontContentsComponent; diff --git a/plugins/bc-custom-content/src/Controller/CustomContentFrontAppController.php b/plugins/bc-custom-content/src/Controller/CustomContentFrontAppController.php index a462bf794c..3929033cc2 100644 --- a/plugins/bc-custom-content/src/Controller/CustomContentFrontAppController.php +++ b/plugins/bc-custom-content/src/Controller/CustomContentFrontAppController.php @@ -11,7 +11,7 @@ namespace BcCustomContent\Controller; -use BaserCore\Controller\BcAppController; +use BaserCore\Controller\AppController; use Cake\Event\EventInterface; use BaserCore\Annotation\UnitTest; use BaserCore\Annotation\NoTodo; @@ -20,7 +20,7 @@ /** * CustomContentFrontAppController */ -class CustomContentFrontAppController extends BcAppController +class CustomContentFrontAppController extends AppController { /** From 28bfebff061daa761ac55e3e49b1b07eb8dd2986 Mon Sep 17 00:00:00 2001 From: ryuring Date: Wed, 25 Oct 2023 20:47:03 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=E3=83=A1=E3=82=A4=E3=83=B3=E3=82=B5?= =?UTF-8?q?=E3=82=A4=E3=83=88=E3=83=AA=E3=83=80=E3=82=A4=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Middleware/BcRedirectMainSiteFilter.php | 118 ------------------ .../BcRedirectMainSiteMiddleware.php | 80 ++++++++++++ ...er.php => BcRedirectSubSiteMiddleware.php} | 4 +- .../Middleware/BcRequestFilterMiddleware.php | 5 +- plugins/baser-core/src/Plugin.php | 7 +- .../BcRedirectMainSiteFilterTest.php | 23 ++-- ...hp => BcRedirectSubSiteMiddlewareTest.php} | 20 +-- 7 files changed, 111 insertions(+), 146 deletions(-) delete mode 100644 plugins/baser-core/src/Middleware/BcRedirectMainSiteFilter.php create mode 100644 plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php rename plugins/baser-core/src/Middleware/{BcRedirectSubSiteFilter.php => BcRedirectSubSiteMiddleware.php} (96%) rename plugins/baser-core/tests/TestCase/Middleware/{BcRedirectSubSiteFilterTest.php => BcRedirectSubSiteMiddlewareTest.php} (86%) diff --git a/plugins/baser-core/src/Middleware/BcRedirectMainSiteFilter.php b/plugins/baser-core/src/Middleware/BcRedirectMainSiteFilter.php deleted file mode 100644 index d0d0c24bbb..0000000000 --- a/plugins/baser-core/src/Middleware/BcRedirectMainSiteFilter.php +++ /dev/null @@ -1,118 +0,0 @@ - - * Copyright (c) NPO baser foundation - * - * @copyright Copyright (c) NPO baser foundation - * @link https://basercms.net baserCMS Project - * @since 5.0.0 - * @license https://basercms.net/license/index.html MIT License - */ - -namespace BaserCore\Middleware; - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Server\MiddlewareInterface; -use Psr\Http\Server\RequestHandlerInterface; - -/** - * Class BcRedirectMainSiteFilter - * - * サブサイトにコンテンツが存在しない場合、同階層のメインサイトのコンテンツを確認し、 - * 存在していれば、メインサイトへリダイレクトをする。 - * - * (例) - * /s/service → /service - * - */ -class BcRedirectMainSiteFilter implements MiddlewareInterface -{ - - /** - * Trait - */ - use \BaserCore\Utility\BcContainerTrait; - - /** - * priority - * - * URLの存在確認が完了しているタイミングを前提としている為、 - * Dispacher::parseParams() より後に実行される必要がある - * - * @var int - */ - public $priority = 10; - - /** - * Process - * @param ServerRequestInterface $request - * @param RequestHandlerInterface $handler - * @return ResponseInterface - */ - public function process( - ServerRequestInterface $request, - RequestHandlerInterface $handler - ): ResponseInterface - { - $request = $event->getData('request'); - $response = $event->getData('response'); - if (!empty($request->getAttribute('currentContent'))) { - return $handler->handle($request); - } else { - if ($this->_existController($request)) { - return $handler->handle($request); - } - } - $sites = \Cake\ORM\TableRegistry::getTableLocator()->get('BaserCore.Sites'); - $site = $sites->findByUrl($request->getPath()); - if (!$site || !$site->enabled) { - return $handler->handle($request); - } - $mainSite = $site->getMain(); - if (!$mainSite) { - return $handler->handle($request); - } - $mainSiteUrl = '/' . preg_replace('/^' . $site->alias . '\//', '', $request->url); - if ($mainSite->alias) { - $mainSiteUrl = '/' . $mainSite->alias . $mainSiteUrl; - } - if ($mainSiteUrl) { - $request = new CakeRequest($mainSiteUrl); - $params = Router::parse($request->url); - $request->addParams($params); - if ($this->_existController($request)) { - $response->header('Location', $request->base . $mainSiteUrl); - $response->statusCode(302); - return $response; - } - } - return $handler->handle($request); - } - - /** - * コントローラーが存在するか確認 - * - * @param $request - * @return bool - */ - protected function _existController($request) - { - $pluginName = $pluginPath = $controller = null; - if (!empty($request->getParam('plugin'))) { - $pluginName = $controller = Inflector::camelize($request->getParam('plugin')); - $pluginPath = $pluginName . '.'; - } - if (!empty($request->getParam('controller'))) { - $controller = Inflector::camelize($request->getParam('controller')); - } - if ($pluginPath . $controller) { - $class = $controller . 'Controller'; - App::uses('AppController', 'Controller'); - App::uses($pluginName . 'AppController', $pluginPath . 'Controller'); - App::uses($class, $pluginPath . 'Controller'); - return class_exists($class); - } - return false; - } -} diff --git a/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php b/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php new file mode 100644 index 0000000000..57927661f1 --- /dev/null +++ b/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php @@ -0,0 +1,80 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BaserCore\Middleware; + +use BaserCore\Utility\BcUtil; +use Cake\Core\Configure; +use Cake\Http\Response; +use Cake\ORM\TableRegistry; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; +use BaserCore\Annotation\NoTodo; +use BaserCore\Annotation\Checked; +use BaserCore\Annotation\UnitTest; + +/** + * Class BcRedirectMainSiteMiddleware + * + * サブサイトにコンテンツが存在しない場合、同階層のメインサイトのコンテンツを確認し、 + * 存在していれば、メインサイトへリダイレクトをする。 + * + * (例) + * /s/service → /service + * + */ +class BcRedirectMainSiteMiddleware implements MiddlewareInterface +{ + + /** + * Process + * @param ServerRequestInterface $request + * @param RequestHandlerInterface $handler + * @return ResponseInterface + * @checked + * @noTodo + */ + public function process( + ServerRequestInterface $request, + RequestHandlerInterface $handler + ): ResponseInterface + { + if (Configure::read('BcRequest.isUpdater')) { + return $handler->handle($request); + } + if ($request->is('admin') || !BcUtil::isInstalled()) { + return $handler->handle($request); + } + $sites = TableRegistry::getTableLocator()->get('BaserCore.Sites'); + $site = $sites->findByUrl($request->getPath()); + if (!$site || !$site->status || $site->id === 1) { + return $handler->handle($request); + } + $mainSite = $site->getMain(); + if (!$mainSite) { + return $handler->handle($request); + } + $mainSiteUrl = '/' . preg_replace('/^\/' . $site->alias . '\//', '', $request->getPath()); + if ($mainSite->alias) { + $mainSiteUrl = '/' . $mainSite->alias . $mainSiteUrl; + } + if ($mainSiteUrl) { + $response = new Response([ + 'status' => 302 + ]); + return $response->withLocation($request->getAttribute('base') . $mainSiteUrl); + } + return $handler->handle($request); + } + +} diff --git a/plugins/baser-core/src/Middleware/BcRedirectSubSiteFilter.php b/plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php similarity index 96% rename from plugins/baser-core/src/Middleware/BcRedirectSubSiteFilter.php rename to plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php index 4165113646..5ed4c19a79 100644 --- a/plugins/baser-core/src/Middleware/BcRedirectSubSiteFilter.php +++ b/plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php @@ -23,12 +23,12 @@ use BaserCore\Annotation\UnitTest; /** - * Class BcRedirectSubSiteFilter + * Class BcRedirectSubSiteMiddleware * * ユーザーエージェントにより、関連するサブサイトにリダイレクトを行う * */ -class BcRedirectSubSiteFilter implements MiddlewareInterface +class BcRedirectSubSiteMiddleware implements MiddlewareInterface { /** diff --git a/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php b/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php index c1c81b839b..331bfdfcd4 100644 --- a/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php @@ -15,7 +15,6 @@ use BaserCore\Utility\BcUtil; use Cake\Core\Configure; use Cake\Http\Response; -use Cake\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -125,12 +124,12 @@ public function getDetectorConfigs() /** * リクエスト検出器を追加する * - * @param ServerRequest $request リクエスト + * @param ServerRequestInterface $request リクエスト * @checked * @noTodo * @unitTest */ - public function addDetectors(ServerRequest $request): ServerRequest + public function addDetectors(ServerRequestInterface $request): ServerRequestInterface { foreach($this->getDetectorConfigs() as $name => $callback) { $request->addDetector($name, $callback); diff --git a/plugins/baser-core/src/Plugin.php b/plugins/baser-core/src/Plugin.php index 53bd386361..f5f86acf96 100644 --- a/plugins/baser-core/src/Plugin.php +++ b/plugins/baser-core/src/Plugin.php @@ -27,7 +27,8 @@ use BaserCore\Event\BcViewEventDispatcher; use BaserCore\Middleware\BcAdminMiddleware; use BaserCore\Middleware\BcFrontMiddleware; -use BaserCore\Middleware\BcRedirectSubSiteFilter; +use BaserCore\Middleware\BcRedirectMainSiteMiddleware; +use BaserCore\Middleware\BcRedirectSubSiteMiddleware; use BaserCore\Middleware\BcRequestFilterMiddleware; use BaserCore\ServiceProvider\BcServiceProvider; use BaserCore\Utility\BcEvent; @@ -45,6 +46,7 @@ use Cake\I18n\I18n; use Cake\Log\Log; use Cake\ORM\TableRegistry; +use Cake\Routing\Middleware\RoutingMiddleware; use Cake\Routing\RouteBuilder; use Cake\Routing\Router; use Cake\Utility\Inflector; @@ -280,9 +282,10 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue $middlewareQueue ->prepend(new BcRequestFilterMiddleware()) ->insertBefore(CsrfProtectionMiddleware::class, new AuthenticationMiddleware($this)) + ->insertBefore(RoutingMiddleware::class, new BcRedirectMainSiteMiddleware()) ->add(new BcAdminMiddleware()) ->add(new BcFrontMiddleware()) - ->add(new BcRedirectSubSiteFilter()); + ->add(new BcRedirectSubSiteMiddleware()); // APIへのアクセスの場合、セッションによる認証以外は、CSRFを利用しない設定とする $ref = new ReflectionClass($middlewareQueue); diff --git a/plugins/baser-core/tests/TestCase/Middleware/BcRedirectMainSiteFilterTest.php b/plugins/baser-core/tests/TestCase/Middleware/BcRedirectMainSiteFilterTest.php index 279d5ac369..4f6f3a6668 100644 --- a/plugins/baser-core/tests/TestCase/Middleware/BcRedirectMainSiteFilterTest.php +++ b/plugins/baser-core/tests/TestCase/Middleware/BcRedirectMainSiteFilterTest.php @@ -1,22 +1,23 @@ - * Copyright (c) baserCMS Users Community + * Copyright (c) NPO baser foundation * - * @copyright Copyright (c) baserCMS Users Community - * @link https://basercms.net baserCMS Project - * @since baserCMS v 4.0.9 - * @license https://basercms.net/license/index.html + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License */ -App::uses('BcRedirectMainSiteFilter', 'Routing/Filter'); +namespace BaserCore\Test\TestCase\Middleware; + +use BaserCore\Middleware\BcRedirectMainSiteMiddleware; +use BaserCore\TestSuite\BcTestCase; /** * Class BcRedirectMainSiteFilterTest * - * @property BcRedirectMainSiteFilter $BcRedirectMainSiteFilter + * @property BcRedirectMainSiteMiddleware $BcRedirectMainSiteMiddleware */ class BcRedirectMainSiteFilterTest extends BcTestCase { @@ -26,7 +27,7 @@ class BcRedirectMainSiteFilterTest extends BcTestCase * * @return void */ - public function setUp() + public function setUp(): void { parent::setUp(); } @@ -36,7 +37,7 @@ public function setUp() * * @return void */ - public function tearDown() + public function tearDown(): void { parent::tearDown(); } diff --git a/plugins/baser-core/tests/TestCase/Middleware/BcRedirectSubSiteFilterTest.php b/plugins/baser-core/tests/TestCase/Middleware/BcRedirectSubSiteMiddlewareTest.php similarity index 86% rename from plugins/baser-core/tests/TestCase/Middleware/BcRedirectSubSiteFilterTest.php rename to plugins/baser-core/tests/TestCase/Middleware/BcRedirectSubSiteMiddlewareTest.php index 2965c6ee81..d7606d2ce1 100644 --- a/plugins/baser-core/tests/TestCase/Middleware/BcRedirectSubSiteFilterTest.php +++ b/plugins/baser-core/tests/TestCase/Middleware/BcRedirectSubSiteMiddlewareTest.php @@ -11,7 +11,7 @@ namespace BaserCore\Test\TestCase\Middleware; -use BaserCore\Middleware\BcRedirectSubSiteFilter; +use BaserCore\Middleware\BcRedirectSubSiteMiddleware; use BaserCore\Service\SitesServiceInterface; use BaserCore\Test\Factory\ContentFactory; use BaserCore\Test\Factory\PageFactory; @@ -23,10 +23,10 @@ use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** - * Class BcRedirectSubSiteFilterTest - * @property BcRedirectSubSiteFilter $BcRedirectSubSiteFilter + * Class BcRedirectSubSiteMiddlewareTest + * @property BcRedirectSubSiteMiddleware $BcRedirectSubSiteMiddleware */ -class BcRedirectSubSiteFilterTest extends BcTestCase +class BcRedirectSubSiteMiddlewareTest extends BcTestCase { /** * Trait @@ -41,7 +41,7 @@ class BcRedirectSubSiteFilterTest extends BcTestCase public function setUp(): void { parent::setUp(); - $this->BcRedirectSubSiteFilter = new BcRedirectSubSiteFilter(); + $this->BcRedirectSubSiteMiddleware = new BcRedirectSubSiteMiddleware(); } /** @@ -51,7 +51,7 @@ public function setUp(): void */ public function tearDown(): void { - unset($this->BcRedirectSubSiteFilter); + unset($this->BcRedirectSubSiteMiddleware); parent::tearDown(); } @@ -98,7 +98,7 @@ public function test_process(): void $_SERVER['HTTP_USER_AGENT'] = 'iPhone'; $request = $this->getRequest('/about')->withParam('plugin', 'BaserCore')->withParam('controller', 'Pages')->withParam('action', 'view'); - $this->_response = $this->BcRedirectSubSiteFilter->process($request, $this->Application); + $this->_response = $this->BcRedirectSubSiteMiddleware->process($request, $this->Application); $this->assertResponseCode(302); } @@ -130,7 +130,7 @@ public function test_process_auto_redirect_off(): void ->withParam('plugin', 'BaserCore') ->withParam('controller', 'Pages') ->withParam('action', 'view'); - $this->_response = $this->BcRedirectSubSiteFilter->process($request, $this->Application); + $this->_response = $this->BcRedirectSubSiteMiddleware->process($request, $this->Application); //リダイレクトしない確認 $this->assertResponseSuccess(); } @@ -149,7 +149,7 @@ public function test_process_site_private(): void $SitesService->unpublish(1); $request = $this->loginAdmin($this->getRequest('/baser/admin/?site_id=1')); - $this->_response = $this->BcRedirectSubSiteFilter->process($request, $this->Application); + $this->_response = $this->BcRedirectSubSiteMiddleware->process($request, $this->Application); //リダイレクトしない確認 $this->assertResponseSuccess(); } @@ -165,7 +165,7 @@ public function test_process_admin(): void //管理画面へのアクセスを確認 $request = $this->loginAdmin($this->getRequest('/baser/admin')); - $this->_response = $this->BcRedirectSubSiteFilter->process($request, $this->Application); + $this->_response = $this->BcRedirectSubSiteMiddleware->process($request, $this->Application); //リダイレクトしない確認 $this->assertResponseSuccess(); } From 897b887fd3ceaf54426921d953f3245b9dc22e89 Mon Sep 17 00:00:00 2001 From: ryuring Date: Thu, 26 Oct 2023 09:27:03 +0900 Subject: [PATCH 03/14] =?UTF-8?q?BcRedirectMainSiteMiddleware=E3=81=8C?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E3=81=AB=E5=8B=95=E4=BD=9C=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E3=81=9F=E3=82=81=E3=80=81=E4=B8=80?= =?UTF-8?q?=E6=97=A6=E3=80=81=E5=88=A9=E7=94=A8=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Middleware/BcRedirectMainSiteMiddleware.php | 5 ++++- plugins/baser-core/src/Plugin.php | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php b/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php index 57927661f1..38b85773df 100644 --- a/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php @@ -42,13 +42,16 @@ class BcRedirectMainSiteMiddleware implements MiddlewareInterface * @param RequestHandlerInterface $handler * @return ResponseInterface * @checked - * @noTodo */ public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { + // TODO 対象サイトでの存在確認ができていない + // ルーティング後だと、ルーティングで失敗するので、ルーティング前に実行する必要があるが、 + // ルーティング前だと対象サイトでの存在確認ができないため、現在は利用していない。 + // ルーティングに組み込むことを検討する if (Configure::read('BcRequest.isUpdater')) { return $handler->handle($request); } diff --git a/plugins/baser-core/src/Plugin.php b/plugins/baser-core/src/Plugin.php index f5f86acf96..fe31d6b04a 100644 --- a/plugins/baser-core/src/Plugin.php +++ b/plugins/baser-core/src/Plugin.php @@ -27,7 +27,6 @@ use BaserCore\Event\BcViewEventDispatcher; use BaserCore\Middleware\BcAdminMiddleware; use BaserCore\Middleware\BcFrontMiddleware; -use BaserCore\Middleware\BcRedirectMainSiteMiddleware; use BaserCore\Middleware\BcRedirectSubSiteMiddleware; use BaserCore\Middleware\BcRequestFilterMiddleware; use BaserCore\ServiceProvider\BcServiceProvider; @@ -46,7 +45,6 @@ use Cake\I18n\I18n; use Cake\Log\Log; use Cake\ORM\TableRegistry; -use Cake\Routing\Middleware\RoutingMiddleware; use Cake\Routing\RouteBuilder; use Cake\Routing\Router; use Cake\Utility\Inflector; @@ -282,7 +280,6 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue $middlewareQueue ->prepend(new BcRequestFilterMiddleware()) ->insertBefore(CsrfProtectionMiddleware::class, new AuthenticationMiddleware($this)) - ->insertBefore(RoutingMiddleware::class, new BcRedirectMainSiteMiddleware()) ->add(new BcAdminMiddleware()) ->add(new BcFrontMiddleware()) ->add(new BcRedirectSubSiteMiddleware()); From 31ed51018a8902059998822fedb47111fecf8b9e Mon Sep 17 00:00:00 2001 From: uchino <44802818+kk-uchino@users.noreply.github.com> Date: Thu, 26 Oct 2023 09:30:20 +0900 Subject: [PATCH 04/14] =?UTF-8?q?BcMailer=E3=82=92=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=81=8B=E3=82=89=E5=AE=9F=E8=A1=8C=E3=81=97?= =?UTF-8?q?=E3=81=9F=E9=9A=9B=E3=81=AB=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20(#2826)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/Mailer/BcMailer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Mailer/BcMailer.php b/plugins/baser-core/src/Mailer/BcMailer.php index 977b6d41c6..2714a56013 100644 --- a/plugins/baser-core/src/Mailer/BcMailer.php +++ b/plugins/baser-core/src/Mailer/BcMailer.php @@ -53,7 +53,7 @@ public function __construct($config = null) { parent::__construct($config); $request = Router::getRequest(); - $site = $request->getAttribute('currentSite'); + $site = $request ? $request->getAttribute('currentSite') : null; $this->setEmailTransport(); if ($site) $this->viewBuilder() ->setTheme($site->theme) From b4e1fd079fb595b2bf9cc7bd9950f5fc9c015234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Thu, 26 Oct 2023 16:50:26 +0900 Subject: [PATCH 05/14] =?UTF-8?q?basercms-5.0.6=20=E3=82=92=E3=83=AA?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/VERSION.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/VERSION.txt b/plugins/baser-core/VERSION.txt index 15a0980976..b9128c9ea1 100644 --- a/plugins/baser-core/VERSION.txt +++ b/plugins/baser-core/VERSION.txt @@ -1,4 +1,4 @@ -5.0.5 +5.0.6 /////////////////////////////////////////////////////////////////////////////////////////////////////////// // +---------------------------------------------------------------------------------------------------+ // @@ -14,6 +14,13 @@ CHG: 変更内容 / BUG: バグフィックス / NEW: 機能追加 +[2023-10-26] basercms-5.0.6 +- BUG [BC] fix #1903 コンテンツ一覧(表)コピーの際にコピー先のタイトルに「のコピー」とつかない問題の改善 +- BUG [BC] fix #2783 CGIモードでJWT認証が可能なよう改善 +- BUG [BC] fix #2403 アップロードファイルのAPIにフルパスのURLを追加 +- BUG [ML] fix #1901 バリデーションエラー時にチェックボックスのチェックが外れる +- BUG [ML] fix #2806 メールプラグインが有効化されていない場合にダッシュボードが表示できない問題の改善 + [2023-09-28] basercms-5.0.5 - BUG [BC] fix #2744 カスタムコンテンツのバリデーションエラーを改善 - BUG [BC] fix #2199 カスタムコンテンツのAPIで取得する情報に不要な連携データが含まれる処理の改善 From cf4037ef88459ccf409ca0d4a65e7730df93fcb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Thu, 26 Oct 2023 16:51:13 +0900 Subject: [PATCH 06/14] prepare release --- composer.json | 32 ++++++++++++++++---------------- plugins/baser-core/composer.json | 28 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index 66d7ed660f..48e373d3c2 100644 --- a/composer.json +++ b/composer.json @@ -73,22 +73,22 @@ } }, "replace": { - "baserproject/baser-core": "5.0.5", - "baserproject/bc-admin-third": "5.0.5", - "baserproject/bc-blog": "5.0.5", - "baserproject/bc-column": "5.0.5", - "baserproject/bc-content-link": "5.0.5", - "baserproject/bc-custom-content": "5.0.5", - "baserproject/bc-editor-template": "5.0.5", - "baserproject/bc-favorite": "5.0.5", - "baserproject/bc-front": "5.0.5", - "baserproject/bc-installer": "5.0.5", - "baserproject/bc-mail": "5.0.5", - "baserproject/bc-search-index": "5.0.5", - "baserproject/bc-theme-config": "5.0.5", - "baserproject/bc-theme-file": "5.0.5", - "baserproject/bc-uploader": "5.0.5", - "baserproject/bc-widget-area": "5.0.5" + "baserproject/baser-core": "5.0.6", + "baserproject/bc-admin-third": "5.0.6", + "baserproject/bc-blog": "5.0.6", + "baserproject/bc-column": "5.0.6", + "baserproject/bc-content-link": "5.0.6", + "baserproject/bc-custom-content": "5.0.6", + "baserproject/bc-editor-template": "5.0.6", + "baserproject/bc-favorite": "5.0.6", + "baserproject/bc-front": "5.0.6", + "baserproject/bc-installer": "5.0.6", + "baserproject/bc-mail": "5.0.6", + "baserproject/bc-search-index": "5.0.6", + "baserproject/bc-theme-config": "5.0.6", + "baserproject/bc-theme-file": "5.0.6", + "baserproject/bc-uploader": "5.0.6", + "baserproject/bc-widget-area": "5.0.6" }, "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", diff --git a/plugins/baser-core/composer.json b/plugins/baser-core/composer.json index b620e2e046..1b3bcb7505 100644 --- a/plugins/baser-core/composer.json +++ b/plugins/baser-core/composer.json @@ -15,20 +15,20 @@ "josegonzalez/dotenv": "^3.2", "mobiledetect/mobiledetectlib": "^2.8", "ext-json": "*", - "baserproject/bc-admin-third": "^5.1", - "baserproject/bc-blog": "^5.1", - "baserproject/bc-content-link": "^5.1", - "baserproject/bc-custom-content": "^5.1", - "baserproject/bc-editor-template": "^5.1", - "baserproject/bc-favorite": "^5.1", - "baserproject/bc-front": "^5.1", - "baserproject/bc-installer": "^5.1", - "baserproject/bc-mail": "^5.1", - "baserproject/bc-search-index": "^5.1", - "baserproject/bc-theme-config": "^5.1", - "baserproject/bc-theme-file": "^5.1", - "baserproject/bc-uploader": "^5.1", - "baserproject/bc-widget-area": "^5.1", + "baserproject/bc-admin-third": "^5.0.6", + "baserproject/bc-blog": "^5.0.6", + "baserproject/bc-content-link": "^5.0.6", + "baserproject/bc-custom-content": "^5.0.6", + "baserproject/bc-editor-template": "^5.0.6", + "baserproject/bc-favorite": "^5.0.6", + "baserproject/bc-front": "^5.0.6", + "baserproject/bc-installer": "^5.0.6", + "baserproject/bc-mail": "^5.0.6", + "baserproject/bc-search-index": "^5.0.6", + "baserproject/bc-theme-config": "^5.0.6", + "baserproject/bc-theme-file": "^5.0.6", + "baserproject/bc-uploader": "^5.0.6", + "baserproject/bc-widget-area": "^5.0.6", "imo-tikuwa/cakephp-soft-delete": "^2.0", "ext-mbstring": "*", "ext-zip": "*", From 9c8f26eea280e9725af2f5d4255fed28875c48bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Thu, 26 Oct 2023 16:51:19 +0900 Subject: [PATCH 07/14] open 5.1-dev --- plugins/baser-core/composer.json | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/baser-core/composer.json b/plugins/baser-core/composer.json index 1b3bcb7505..b620e2e046 100644 --- a/plugins/baser-core/composer.json +++ b/plugins/baser-core/composer.json @@ -15,20 +15,20 @@ "josegonzalez/dotenv": "^3.2", "mobiledetect/mobiledetectlib": "^2.8", "ext-json": "*", - "baserproject/bc-admin-third": "^5.0.6", - "baserproject/bc-blog": "^5.0.6", - "baserproject/bc-content-link": "^5.0.6", - "baserproject/bc-custom-content": "^5.0.6", - "baserproject/bc-editor-template": "^5.0.6", - "baserproject/bc-favorite": "^5.0.6", - "baserproject/bc-front": "^5.0.6", - "baserproject/bc-installer": "^5.0.6", - "baserproject/bc-mail": "^5.0.6", - "baserproject/bc-search-index": "^5.0.6", - "baserproject/bc-theme-config": "^5.0.6", - "baserproject/bc-theme-file": "^5.0.6", - "baserproject/bc-uploader": "^5.0.6", - "baserproject/bc-widget-area": "^5.0.6", + "baserproject/bc-admin-third": "^5.1", + "baserproject/bc-blog": "^5.1", + "baserproject/bc-content-link": "^5.1", + "baserproject/bc-custom-content": "^5.1", + "baserproject/bc-editor-template": "^5.1", + "baserproject/bc-favorite": "^5.1", + "baserproject/bc-front": "^5.1", + "baserproject/bc-installer": "^5.1", + "baserproject/bc-mail": "^5.1", + "baserproject/bc-search-index": "^5.1", + "baserproject/bc-theme-config": "^5.1", + "baserproject/bc-theme-file": "^5.1", + "baserproject/bc-uploader": "^5.1", + "baserproject/bc-widget-area": "^5.1", "imo-tikuwa/cakephp-soft-delete": "^2.0", "ext-mbstring": "*", "ext-zip": "*", From fb62e7175b6a9c8a2d7126f23594c459752a7d7c Mon Sep 17 00:00:00 2001 From: ryuring Date: Thu, 26 Oct 2023 18:19:46 +0900 Subject: [PATCH 08/14] =?UTF-8?q?AppTable=E3=82=92=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baser-core/src/Model/Table/AppTable.php | 67 +- .../src/Model/Table/ContentFoldersTable.php | 7 +- .../src/Model/Table/ContentsTable.php | 2 - .../src/Model/Validation/BcValidation.php | 14 + .../TestCase/Model/Table/BcAppTableTest.php | 627 ------------------ .../Model/Validation/BcValidationTest.php | 25 + 6 files changed, 48 insertions(+), 694 deletions(-) delete mode 100644 plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php diff --git a/plugins/baser-core/src/Model/Table/AppTable.php b/plugins/baser-core/src/Model/Table/AppTable.php index a59ba2ab2e..b96386668c 100755 --- a/plugins/baser-core/src/Model/Table/AppTable.php +++ b/plugins/baser-core/src/Model/Table/AppTable.php @@ -14,7 +14,6 @@ use BaserCore\Utility\BcUtil; use Cake\ORM\Association\BelongsToMany; use Cake\ORM\Table; -use Cake\Core\Configure; use Cake\I18n\FrozenTime; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; @@ -26,6 +25,10 @@ */ class AppTable extends Table { + + /** + * Trait + */ use BcEventDispatcherTrait; /** @@ -68,8 +71,7 @@ class AppTable extends Table */ public function setTable(string $table) { - $table = $this->addPrefix($table); - return parent::setTable($table); + return parent::setTable($this->addPrefix($table)); } /** @@ -83,8 +85,7 @@ public function setTable(string $table) */ public function getTable(): string { - $table = parent::getTable(); - $this->_table = $this->addPrefix($table); + $this->setTable(parent::getTable()); return $this->_table; } @@ -148,29 +149,6 @@ public function initialize(array $config): void FrozenTime::setToStringFormat('yyyy-MM-dd HH:mm:ss'); } - /** - * 配列の文字コードを変換する - * - * @param array $data 変換前のデータ - * @param string $outenc 変換後の文字コード - * @param string $inenc 変換元の文字コード - * @return array 変換後のデータ - * @TODO GLOBAL グローバルな関数として再配置する必要あり - */ - public function convertEncodingByArray($data, $outenc, $inenc) - { - foreach($data as $key => $value) { - if (is_array($value)) { - $data[$key] = $this->convertEncodingByArray($value, $outenc, $inenc); - } else { - if (mb_detect_encoding($value) <> $outenc) { - $data[$key] = mb_convert_encoding($value, $outenc, $inenc); - } - } - } - return $data; - } - /** * 機種依存文字の変換処理 * @@ -257,21 +235,6 @@ public function replaceText($str) return str_replace(array_keys($arr), array_values($arr), $str); } - /** - * 範囲を指定しての長さチェック - * - * @param mixed $check 対象となる値 - * @param int $min 値の最短値 - * @param int $max 値の最長値 - * @param boolean - */ - public function between($check, $min, $max) - { - $check = (is_array($check))? current($check) : $check; - $length = mb_strlen($check, Configure::read('App.encoding')); - return ($length >= $min && $length <= $max); - } - /** * 指定フィールドのMAX値を取得する * @@ -290,24 +253,6 @@ public function getMax(string $field, array $conditions = []): int return $max->{$field} ?? 0; } - /** - * 英数チェック - * - * @param string $value チェック対象文字列 - * @return boolean - */ - public static function alphaNumeric($value) - { - if (!$value) { - return true; - } - if (preg_match("/^[a-zA-Z0-9]+$/", $value)) { - return true; - } else { - return false; - } - } - /** * 一つ位置を上げる * @param string $id diff --git a/plugins/baser-core/src/Model/Table/ContentFoldersTable.php b/plugins/baser-core/src/Model/Table/ContentFoldersTable.php index 29b0dd6c71..e176365d27 100644 --- a/plugins/baser-core/src/Model/Table/ContentFoldersTable.php +++ b/plugins/baser-core/src/Model/Table/ContentFoldersTable.php @@ -17,7 +17,6 @@ use BcSearchIndex\Service\SearchIndexesServiceInterface; use BaserCore\Utility\BcContainerTrait; use Cake\Event\EventInterface; -use Cake\ORM\Exception\PersistenceFailedException; use Cake\Validation\Validator; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; @@ -69,7 +68,7 @@ public function initialize(array $config): void /** * validationDefault * - * @param Validator $validator + * @param Validator $validator * @return Validator * @checked * @noTodo @@ -165,7 +164,7 @@ public function copy(int $id, $newParentId, $newTitle, $newAuthorId, $newSiteId) 'id' => $id, ]); if ($event !== false) { - $entity = ($event->getResult() === null || $event->getResult() === true) ? $event->getData('data') : $event->getResult(); + $entity = ($event->getResult() === null || $event->getResult() === true)? $event->getData('data') : $event->getResult(); } $entity->content = new Content([ @@ -176,7 +175,7 @@ public function copy(int $id, $newParentId, $newTitle, $newAuthorId, $newSiteId) 'site_id' => $newSiteId, 'description' => $entity->content->description, 'eyecatch' => $entity->content->eyecatch, - 'layout_template' => $entity->content->layout_tmplate?? '' + 'layout_template' => $entity->content->layout_tmplate ?? '' ]); if (!is_null($newSiteId) && $oldEntity->content->site_id !== $newSiteId) { $entity->content->parent_id = $this->Contents->copyContentFolderPath($entity->content->url, $newSiteId); diff --git a/plugins/baser-core/src/Model/Table/ContentsTable.php b/plugins/baser-core/src/Model/Table/ContentsTable.php index d2827e5940..a35248680d 100644 --- a/plugins/baser-core/src/Model/Table/ContentsTable.php +++ b/plugins/baser-core/src/Model/Table/ContentsTable.php @@ -12,14 +12,12 @@ namespace BaserCore\Model\Table; use ArrayObject; -use Cake\Core\Plugin; use Cake\Utility\Hash; use Cake\Core\Configure; use Cake\I18n\FrozenTime; use Cake\ORM\TableRegistry; use BaserCore\Utility\BcUtil; use Cake\Event\EventInterface; -use Cake\Utility\Inflector; use Cake\Validation\Validator; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; diff --git a/plugins/baser-core/src/Model/Validation/BcValidation.php b/plugins/baser-core/src/Model/Validation/BcValidation.php index 7cd160082c..56808f9531 100644 --- a/plugins/baser-core/src/Model/Validation/BcValidation.php +++ b/plugins/baser-core/src/Model/Validation/BcValidation.php @@ -601,4 +601,18 @@ public static function checkSelectList($value): bool return ($result < 2); } + /** + * 範囲を指定しての長さチェック + * + * @param mixed $value 対象となる値 + * @param int $min 値の最短値 + * @param int $max 値の最長値 + * @param boolean + */ + public static function between($value, $min, $max) + { + $length = mb_strlen($value, Configure::read('App.encoding')); + return ($length >= $min && $length <= $max); + } + } diff --git a/plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php deleted file mode 100644 index d6d2a4d83c..0000000000 --- a/plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php +++ /dev/null @@ -1,627 +0,0 @@ - - * Copyright (c) baserCMS Users Community - * - * @copyright Copyright (c) baserCMS Users Community - * @link https://basercms.net baserCMS Project - * @since baserCMS v 3.0.0-beta - * @license https://basercms.net/license/index.html - */ -App::uses('BcApp', 'Model'); -App::uses('Content', 'Model'); - -/** - * Class BcAppTest - * - * @property BcAppModel $BcApp - * @property Page $Page - * @property SiteConfig $SiteConfig - * @property Content $Content - * @property User $User - */ -class BcAppTest extends BaserTestCase -{ - - public $fixtures = [ - 'baser.Default.Page', - 'baser.Default.Dblog', - 'baser.Default.SiteConfig', - 'baser.Default.User', - 'baser.Default.UserGroup', - 'baser.Default.Permission', - 'baser.Default.SearchIndex', - 'baser.Default.Content', - 'baser.Default.Site' - ]; - - /** - * setUp - * - * @return void - */ - public function setUp() - { - parent::setUp(); - $this->BcApp = ClassRegistry::init('BcApp'); - $this->Page = ClassRegistry::init('Page'); - $this->SiteConfig = ClassRegistry::init('SiteConfig'); - $this->Dblog = ClassRegistry::init('Dblog'); - $this->User = ClassRegistry::init('User'); - $this->Content = ClassRegistry::init('Content'); - - } - - /** - * tearDown - * - * @return void - */ - public function tearDown() - { - unset($this->BcApp); - unset($this->Page); - unset($this->SiteConfig); - unset($this->Dblog); - parent::tearDown(); - } - - /** - * コンストラクタ - */ - public function test__construct() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * beforeSave - * - * @return boolean - * @access public - */ - public function testBeforeSave() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - - $this->Page->save([ - 'Page' => [ - 'name' => 'test', - 'page_category_id' => null, - 'title' => '', - 'url' => '', - 'description' => '', - 'status' => 1, - 'modified' => '', - ] - ]); - - $LastID = $this->Page->getLastInsertID(); - $result = $this->Page->find('first', [ - 'conditions' => ['id' => $LastID], - 'fields' => ['created'], - 'recursive' => -1 - ] - ); - - $this->BcApp->beforeSave(['type' => 'date']); - } - - /** - * Saves model data to the database. By default, validation occurs before save. - * - * @param array $data Data to save. - * @param boolean $validate If set, validation will be done before the save - * @param array $fieldList List of fields to allow to be written - * @return mixed On success Model::$data if its not empty or true, false on failure - */ - public function testSave($data = null, $validate = true, $fieldList = []) - { - $this->Page->save([ - 'Page' => [ - 'name' => 'test', - 'page_category_id' => null, - 'title' => '', - 'url' => '', - 'description' => '', - 'status' => 1, - 'modified' => null, - 'created' => '2015-02-22 22:22:22' - ] - ]); - $now = date('Y-m-d H'); - - $LastID = $this->Page->getLastInsertID(); - $result = $this->Page->find('first', [ - 'conditions' => ['id' => $LastID], - 'fields' => ['created', 'modified'], - 'recursive' => -1 - ] - ); - $created = date('Y-m-d H', strtotime($result['Page']['created'])); - $modified = date('Y-m-d H', strtotime($result['Page']['modified'])); - - $message = 'created,modifiedを更新できません'; - $this->assertEquals($now, $created, $message); - $this->assertEquals($now, $modified, $message); - } - - /** - * 配列の文字コードを変換する - * - * @param array 変換前のデータ - * @param string 変換後の文字コード - * @param string 変換元の文字コード - * @dataProvider convertEncodingByArrayDataProvider - */ - public function testConvertEncodingByArray($data, $outenc, $inenc) - { - $result = $this->BcApp->convertEncodingByArray($data, $outenc, $inenc); - foreach($result as $key => $value) { - $encode = mb_detect_encoding($value); - $this->assertEquals($outenc, $encode); - } - } - - public function convertEncodingByArrayDataProvider() - { - return [ - [["テスト1"], "ASCII", "SJIS"], - [["テスト1", "テスト2"], "UTF-8", "SJIS"], - [["テスト1", "テスト2"], "SJIS-win", "UTF-8"], - ]; - } - - /** - * データベースログを記録する - */ - public function testSaveDbLog() - { - - // Dblogにログを追加 - $message = 'テストです'; - $this->BcApp->saveDblog($message); - - // 最後に追加したログを取得 - $LastID = $this->Dblog->getLastInsertID(); - $result = $this->Dblog->find('first', [ - 'conditions' => ['Dblog.id' => $LastID], - 'fields' => 'name', - ] - ); - $this->assertEquals($message, $result['Dblog']['name']); - - } - - /** - * 機種依存文字の変換処理 - * - * @param string 変換対象文字列 - * @param string 変換後予想文字列 - * @dataProvider replaceTextDataProvider - */ - public function testReplaceText($str, $expect) - { - $result = $this->BcApp->replaceText($str); - $this->assertEquals($expect, $result); - } - - public function replaceTextDataProvider() - { - return [ - ["\xE2\x85\xA0", "I"], - ["\xE2\x91\xA0", "(1)"], - ["\xE3\x8D\x89", "ミリ"], - ["\xE3\x88\xB9", "(代)"], - ]; - } - - /** - * データベース初期化 - * - * @param $pluginName - * @param $options - * @param $expected - * - * @dataProvider initDbDataProvider - * - * MEMO: pluginNameが実在する場合が未実装 - */ - public function testInitDb($pluginName, $options, $expected) - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - $result = $this->BcApp->initDb($pluginName, $options); - $this->assertEquals($expected, $result); - } - - public function initDbDataProvider() - { - return [ - ['', [], true], - ['hoge', ['dbDataPattern' => true], 1] - ]; - } - - /** - * 範囲を指定しての長さチェック - * - * @param mixed $check - * @param int $min - * @param int $max - * @param boolean $expect - * @dataProvider betweenDataProvider - */ - public function testBetween($check, $min, $max, $expect) - { - $result = $this->BcApp->between($check, $min, $max); - $this->assertEquals($expect, $result); - } - - public function betweenDataProvider() - { - return [ - ["あいう", 2, 4, true], - ["あいう", 3, 3, true], - ["あいう", 4, 3, false], - [["あいう", "あいうえお"], 2, 4, true], - ]; - } - - /** - * 指定フィールドのMAX値を取得する - */ - public function testGetMax() - { - $result = $this->Page->getMax('Page\.id'); - $this->assertEquals(11, $result, '指定フィールドのMAX値を取得できません'); - } - - /** - * テーブルにフィールドを追加する - */ - public function testAddField() - { - $options = [ - 'field' => 'testField', - 'column' => [ - 'type' => 'text', - 'null' => true, - 'default' => null, - ], - 'table' => 'pages', - ]; - $this->Page->addField($options); - $columns = $this->Page->getColumnTypes(); - $this->assertEquals(isset($columns['testField']), true); - } - - /** - * フィールド構造を変更する - */ - public function testEditField() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - $options = [ - 'field' => 'testField', - 'column' => [ - 'name' => 'testColumn', - ], - ]; - $this->BcApp->editField($options); - $columns = $this->Page->getColumnTypes(); - } - - /** - * フィールド名を変更する - */ - public function testRenameField() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - - /** - * フィールドを削除する - */ - public function testDelField() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * テーブルの存在チェックを行う - * - * @param string $tableName - * @param boolean $expect - * @dataProvider tableExistsDataProvider - */ - public function testTableExists($tableName, $expect) - { - $db = ConnectionManager::getDataSource('default'); - $prefix = $db->config['prefix']; - - $result = $this->BcApp->tableExists($prefix . $tableName); - $this->assertEquals($expect, $result); - } - - public function tableExistsDataProvider() - { - return [ - ["users", true], - ["notexist", false], - ]; - } - - /** - * 英数チェック - * - * @param string $check チェック対象文字列 - * @param boolean $expect - * @dataProvider alphaNumericDataProvider - */ - public function testAlphaNumeric($check, $expect) - { - $result = $this->BcApp->alphaNumeric($check); - $this->assertEquals($expect, $result); - } - - public function alphaNumericDataProvider() - { - return [ - [["aiueo"], true], - [["12345"], true], - [["あいうえお"], false], - ]; - } - - /** - * データの重複チェックを行う - */ - public function testDuplicate() - { - $check = ['id' => 1]; - $result = $this->Page->duplicate($check); - $this->assertEquals(false, $result); - - $check = ['id' => 100]; - $result = $this->Page->duplicate($check); - $this->assertEquals(true, $result); - } - - /** - * 一つ位置を上げる - */ - public function testSortup() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * 一つ位置を下げる - */ - public function testSortdown() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * 並び順を変更する - */ - public function testChangeSort() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Key Value 形式のテーブルよりデータを取得して - * 1レコードとしてデータを展開する - */ - public function testFindExpanded() - { - $result = $this->SiteConfig->findExpanded(); - - $message = 'Key Value 形式のテーブルよりデータを取得して1レコードとしてデータを展開することができません'; - $this->assertEquals('baserCMS inc. [デモ]', $result['name'], $message); - $this->assertEquals('baser,CMS,コンテンツマネジメントシステム,開発支援', $result['keyword'], $message); - } - - /** - * Key Value 形式のテーブルにデータを保存する - */ - public function testSaveKeyValue() - { - $data = [ - 'SiteConfig' => [ - 'test1' => 'テストです1', - 'test2' => 'テストです2', - ] - ]; - $this->SiteConfig->saveKeyValue($data); - $result = $this->SiteConfig->findExpanded(); - - $message = 'Key Value 形式のテーブルにデータを保存することができません'; - $this->assertEquals('テストです1', $result['test1'], $message); - $this->assertEquals('テストです2', $result['test2'], $message); - - } - - /** - * Deconstructs a complex data type (array or object) into a single field value. - */ - public function testDeconstruct() - { - $field = 'Page.contents'; - $data = [ - 'wareki' => true, - 'year' => 'h-27', - ]; - $result = $this->Page->deconstruct($field, $data); - - $expected = [ - 'wareki' => true, - 'year' => 2015 - ]; - - $this->assertEquals($expected, $result, 'deconstruct が 和暦に対応していません'); - } - - /** - * 指定したモデル以外のアソシエーションを除外する - * - * @param array $auguments アソシエーションを除外しないモデル - * @param array $expectedHasKey 期待する存在するキー - * @param array $expectedNotHasKey 期待する存在しないキー - * @dataProvider reduceAssociationsDataProvider - */ - public function testReduceAssociations($arguments, $expectedHasKeys, $expectedNotHasKeys) - { - $this->User->reduceAssociations($arguments); - $result = $this->User->find('first', ['conditions' => ['User.id' => 2], 'recursive' => 2]); - - // 存在するキー - foreach($expectedHasKeys as $key) { - $this->assertArrayHasKey($key, $result, '指定したモデル以外のアソシエーションを除外できません'); - } - - // 存在しないキー - foreach($expectedNotHasKeys as $key) { - $this->assertArrayNotHasKey($key, $result, '指定したモデル以外のアソシエーションを除外できません'); - } - } - - public function reduceAssociationsDataProvider() - { - return [ - [[], ['User'], ['UserGroup', 'Favorite']], - [['UserGroup'], ['User', 'UserGroup'], ['Favorite']], - [['UserGroup.Permission'], [], ['Permission']], - [['User', 'UserGroup', 'Favorite'], [], ['Permission']], - ]; - } - - /** - * Deletes multiple model records based on a set of conditions. - */ - public function testDeleteAll() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Updates multiple model records based on a set of conditions. - */ - public function testUpdateAll() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Used to report user friendly errors. - * If there is a file app/error.php or app/app_error.php this file will be loaded - * error.php is the AppError class it should extend ErrorHandler class. - */ - public function testCakeError() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Queries the datasource and returns a result set array. - */ - public function testFind() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * イベントを発火 - */ - public function testDispatchEvent() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * データが公開済みかどうかチェックする - * - * @param boolean $status 公開ステータス - * @param string $publishBegin 公開開始日時 - * @param string $publishEnd 公開終了日時 - * @param boolean $expect - * @dataProvider isPublishDataProvider - */ - public function testIsPublish($status, $publishBegin, $publishEnd, $expect) - { - $result = $this->BcApp->isPublish($status, $publishBegin, $publishEnd); - $this->assertEquals($expect, $result); - } - - public function isPublishDataProvider() - { - return [ - [true, null, null, true], - [false, null, null, false], - [true, '2015-01-01 00:00:00', null, true], - [true, '3000-01-01 00:00:00', null, false], - [true, null, '2015-01-01 00:00:00', false], - [true, null, '3000-01-01 00:00:00', true], - [true, '2015-01-01 00:00:00', '3000-01-01 00:00:00', true], - [true, '2015-01-01 00:00:00', '2015-01-02 00:00:00', false], - ]; - } - - /** - * ツリーより再帰的に削除する - */ - public function testRemoveFromTreeRecursive() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - public function testExists() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - public function testDelete() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - public function testDataIter() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * @test モデルのモックが作成できるかテスト - */ - public function testGetMock() - { - $expect = 'do not save!'; - $Model = $this->getMockForModel('BcAppModel', ['save']); - $Model->expects($this->any()) - ->method('save') - ->will($this->returnValue($expect)); - - $actual = $Model->save(['Hoge' => ['name' => 'fuga']]); - $this->assertEquals($expect, $actual, 'スタブが正しく実行されること'); - - } - - /** - * 公開済の conditions を取得 - */ - public function testGetConditionAllowPublish() - { - $result = $this->BcApp->getConditionAllowPublish(); - $pattern = '/' . '([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})' . '/'; - $this->assertMatchesRegularExpression($pattern, $result[0]['or']['0']['BcApp.publish_begin <=']); - $this->assertEquals($result[0]['or']['1']['BcApp.publish_begin'], null); - $this->assertMatchesRegularExpression($pattern, $result[1]['or']['0']['BcApp.publish_end >=']); - $this->assertEquals($result[1]['or']['1']['BcApp.publish_end'], null); - } - -} diff --git a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php index f41450c54d..33369c04e9 100644 --- a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php @@ -599,5 +599,30 @@ public function test_checkSelectList() $this->assertTrue($result); } + /** + * 範囲を指定しての長さチェック + * + * @param mixed $check + * @param int $min + * @param int $max + * @param boolean $expect + * @dataProvider betweenDataProvider + */ + public function testBetween($check, $min, $max, $expect) + { + $this->markTestIncomplete('このテストはまだ実装されていません。'); + $result = $this->BcApp->between($check, $min, $max); + $this->assertEquals($expect, $result); + } + + public function betweenDataProvider() + { + return [ + ["あいう", 2, 4, true], + ["あいう", 3, 3, true], + ["あいう", 4, 3, false], + [["あいう", "あいうえお"], 2, 4, true], + ]; + } } From f7d753868d1d3faf960dff3124f81a9cf61639c1 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:11:13 +0700 Subject: [PATCH 09/14] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4=20(#2828)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- phpunit.xml.dist | 6 +++--- .../Admin/ThemeConfigsControllerTest.php | 20 +++++++++++++------ .../Api/Admin/ThemeConfigsControllerTest.php | 2 +- .../Service/ThemeConfigsServiceTest.php | 13 +++++------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9f4c4005b1..0bff8adc2e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -36,9 +36,9 @@ plugins/bc-search-index/tests/TestCase - - - + + plugins/bc-theme-config/tests/TestCase + diff --git a/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php b/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php index 1d47a42dbd..10536fbf82 100644 --- a/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php @@ -14,12 +14,12 @@ use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; use BcThemeConfig\Controller\Admin\ThemeConfigsController; +use BcThemeConfig\Test\Scenario\ThemeConfigsScenario; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** * Class ThemeConfigsControllerTest * - * @property ThemeConfigsController $ThemeConfigsController */ class ThemeConfigsControllerTest extends BcTestCase { @@ -29,6 +29,12 @@ class ThemeConfigsControllerTest extends BcTestCase use ScenarioAwareTrait; use BcContainerTrait; + /** + * ThemeConfigsController + * @var ThemeConfigsController + */ + public $ThemeConfigsController; + /** * set up * @@ -37,6 +43,10 @@ class ThemeConfigsControllerTest extends BcTestCase public function setUp(): void { parent::setUp(); + $this->loadFixtureScenario(InitAppScenario::class); + $request = $this->getRequest('/baser/admin/bc-custom-content/custom_entries/'); + $request = $this->loginAdmin($request); + $this->ThemeConfigsController = new ThemeConfigsController($request); } /** @@ -57,20 +67,18 @@ public function testIndex() //準備 $this->enableSecurityToken(); $this->enableCsrfToken(); - $this->loadFixtureScenario(InitAppScenario::class); + $this->loadFixtureScenario(ThemeConfigsScenario::class); $data = [ 'name_add' => 'value_edit' ]; $this->post("/baser/admin/bc-theme-config/theme_configs/index", $data); //ステータスを確認 $this->assertResponseSuccess(); - $var = $this->_controller->viewBuilder()->getVars(); - $this->assertArrayHasKey('themeConfig', $var); - $this->assertEquals('value_edit', $var['themeConfig']->name_add); + $this->assertFlashMessage('テーマ設定を保存しました。'); $this->assertRedirect([ 'plugin' => 'BcThemeConfig', 'prefix' => 'Admin', - 'controller' => 'ThemeConfigsController', + 'controller' => 'ThemeConfigs', 'action' => 'index' ]); } diff --git a/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php b/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php index 84dc0a7fa3..769487e8d3 100644 --- a/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php @@ -76,7 +76,7 @@ public function test_view() //戻る値を確認 $result = json_decode((string)$this->_response->getBody()); //全て4件を取得できるか確認 - $this->assertCount(4, get_object_vars($result->themeConfig)); + $this->assertCount(5, get_object_vars($result->themeConfig)); //単位Objectの値を確認 $this->assertEquals('2B7BB9', $result->themeConfig->color_hover); } diff --git a/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php b/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php index 65d5933a58..08adb43c5c 100644 --- a/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php @@ -132,11 +132,6 @@ public function test_saveImage() $logoPath = '/var/www/html/plugins/bc-column/webroot/img/logo.png'; $this->setUploadFileToRequest('file', $logoPath); - // saveImage の内部で実行される move_uploaded_file() が、 - // 実際にファイルをアップロードしないと失敗してしまうため、copy() で代替処理とする - $uploadedPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS. 'logo.png'; - copy($logoPath, $uploadedPath); - // 実行 $rs = $this->ThemeConfigsService->saveImage(new ThemeConfig([ 'logo' => [ @@ -147,16 +142,18 @@ public function test_saveImage() 'size' => 2962, ] ])); + // saveImage の内部で実行される move_uploaded_file() が、 + // 実際にファイルをアップロードしないと失敗してしまうため、copy() で代替処理とする + $uploadedPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS. 'logo.png'; + copy($logoPath, $uploadedPath); // 戻り値を確認 $this->assertEquals($rs['logo'], 'logo.png'); // サムネイルが作成されたことを確認 - $thumbPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS. 'logo_thumb.png'; - $this->assertFileExists($thumbPath); + $this->assertFileExists($uploadedPath); // 初期化処理 unlink($uploadedPath); - unlink($thumbPath); } /** From 1d2bd496de64539a209edc40149f43e0afe17212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Fri, 27 Oct 2023 17:42:38 +0900 Subject: [PATCH 10/14] =?UTF-8?q?=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E5=B7=AE=E3=81=97=E6=88=BB=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 48e373d3c2..66d7ed660f 100644 --- a/composer.json +++ b/composer.json @@ -73,22 +73,22 @@ } }, "replace": { - "baserproject/baser-core": "5.0.6", - "baserproject/bc-admin-third": "5.0.6", - "baserproject/bc-blog": "5.0.6", - "baserproject/bc-column": "5.0.6", - "baserproject/bc-content-link": "5.0.6", - "baserproject/bc-custom-content": "5.0.6", - "baserproject/bc-editor-template": "5.0.6", - "baserproject/bc-favorite": "5.0.6", - "baserproject/bc-front": "5.0.6", - "baserproject/bc-installer": "5.0.6", - "baserproject/bc-mail": "5.0.6", - "baserproject/bc-search-index": "5.0.6", - "baserproject/bc-theme-config": "5.0.6", - "baserproject/bc-theme-file": "5.0.6", - "baserproject/bc-uploader": "5.0.6", - "baserproject/bc-widget-area": "5.0.6" + "baserproject/baser-core": "5.0.5", + "baserproject/bc-admin-third": "5.0.5", + "baserproject/bc-blog": "5.0.5", + "baserproject/bc-column": "5.0.5", + "baserproject/bc-content-link": "5.0.5", + "baserproject/bc-custom-content": "5.0.5", + "baserproject/bc-editor-template": "5.0.5", + "baserproject/bc-favorite": "5.0.5", + "baserproject/bc-front": "5.0.5", + "baserproject/bc-installer": "5.0.5", + "baserproject/bc-mail": "5.0.5", + "baserproject/bc-search-index": "5.0.5", + "baserproject/bc-theme-config": "5.0.5", + "baserproject/bc-theme-file": "5.0.5", + "baserproject/bc-uploader": "5.0.5", + "baserproject/bc-widget-area": "5.0.5" }, "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", From 0ce45fe954416922f86f722749748f4a841b909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Fri, 27 Oct 2023 17:42:48 +0900 Subject: [PATCH 11/14] prepare release --- composer.json | 32 ++++++++++++++++---------------- plugins/baser-core/composer.json | 28 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index 66d7ed660f..48e373d3c2 100644 --- a/composer.json +++ b/composer.json @@ -73,22 +73,22 @@ } }, "replace": { - "baserproject/baser-core": "5.0.5", - "baserproject/bc-admin-third": "5.0.5", - "baserproject/bc-blog": "5.0.5", - "baserproject/bc-column": "5.0.5", - "baserproject/bc-content-link": "5.0.5", - "baserproject/bc-custom-content": "5.0.5", - "baserproject/bc-editor-template": "5.0.5", - "baserproject/bc-favorite": "5.0.5", - "baserproject/bc-front": "5.0.5", - "baserproject/bc-installer": "5.0.5", - "baserproject/bc-mail": "5.0.5", - "baserproject/bc-search-index": "5.0.5", - "baserproject/bc-theme-config": "5.0.5", - "baserproject/bc-theme-file": "5.0.5", - "baserproject/bc-uploader": "5.0.5", - "baserproject/bc-widget-area": "5.0.5" + "baserproject/baser-core": "5.0.6", + "baserproject/bc-admin-third": "5.0.6", + "baserproject/bc-blog": "5.0.6", + "baserproject/bc-column": "5.0.6", + "baserproject/bc-content-link": "5.0.6", + "baserproject/bc-custom-content": "5.0.6", + "baserproject/bc-editor-template": "5.0.6", + "baserproject/bc-favorite": "5.0.6", + "baserproject/bc-front": "5.0.6", + "baserproject/bc-installer": "5.0.6", + "baserproject/bc-mail": "5.0.6", + "baserproject/bc-search-index": "5.0.6", + "baserproject/bc-theme-config": "5.0.6", + "baserproject/bc-theme-file": "5.0.6", + "baserproject/bc-uploader": "5.0.6", + "baserproject/bc-widget-area": "5.0.6" }, "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", diff --git a/plugins/baser-core/composer.json b/plugins/baser-core/composer.json index b620e2e046..1b3bcb7505 100644 --- a/plugins/baser-core/composer.json +++ b/plugins/baser-core/composer.json @@ -15,20 +15,20 @@ "josegonzalez/dotenv": "^3.2", "mobiledetect/mobiledetectlib": "^2.8", "ext-json": "*", - "baserproject/bc-admin-third": "^5.1", - "baserproject/bc-blog": "^5.1", - "baserproject/bc-content-link": "^5.1", - "baserproject/bc-custom-content": "^5.1", - "baserproject/bc-editor-template": "^5.1", - "baserproject/bc-favorite": "^5.1", - "baserproject/bc-front": "^5.1", - "baserproject/bc-installer": "^5.1", - "baserproject/bc-mail": "^5.1", - "baserproject/bc-search-index": "^5.1", - "baserproject/bc-theme-config": "^5.1", - "baserproject/bc-theme-file": "^5.1", - "baserproject/bc-uploader": "^5.1", - "baserproject/bc-widget-area": "^5.1", + "baserproject/bc-admin-third": "^5.0.6", + "baserproject/bc-blog": "^5.0.6", + "baserproject/bc-content-link": "^5.0.6", + "baserproject/bc-custom-content": "^5.0.6", + "baserproject/bc-editor-template": "^5.0.6", + "baserproject/bc-favorite": "^5.0.6", + "baserproject/bc-front": "^5.0.6", + "baserproject/bc-installer": "^5.0.6", + "baserproject/bc-mail": "^5.0.6", + "baserproject/bc-search-index": "^5.0.6", + "baserproject/bc-theme-config": "^5.0.6", + "baserproject/bc-theme-file": "^5.0.6", + "baserproject/bc-uploader": "^5.0.6", + "baserproject/bc-widget-area": "^5.0.6", "imo-tikuwa/cakephp-soft-delete": "^2.0", "ext-mbstring": "*", "ext-zip": "*", From 0f4c0d4d2d67e49310f81f71d7d0527817e9ae8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Fri, 27 Oct 2023 17:42:53 +0900 Subject: [PATCH 12/14] open 5.1-dev --- plugins/baser-core/composer.json | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/baser-core/composer.json b/plugins/baser-core/composer.json index 1b3bcb7505..b620e2e046 100644 --- a/plugins/baser-core/composer.json +++ b/plugins/baser-core/composer.json @@ -15,20 +15,20 @@ "josegonzalez/dotenv": "^3.2", "mobiledetect/mobiledetectlib": "^2.8", "ext-json": "*", - "baserproject/bc-admin-third": "^5.0.6", - "baserproject/bc-blog": "^5.0.6", - "baserproject/bc-content-link": "^5.0.6", - "baserproject/bc-custom-content": "^5.0.6", - "baserproject/bc-editor-template": "^5.0.6", - "baserproject/bc-favorite": "^5.0.6", - "baserproject/bc-front": "^5.0.6", - "baserproject/bc-installer": "^5.0.6", - "baserproject/bc-mail": "^5.0.6", - "baserproject/bc-search-index": "^5.0.6", - "baserproject/bc-theme-config": "^5.0.6", - "baserproject/bc-theme-file": "^5.0.6", - "baserproject/bc-uploader": "^5.0.6", - "baserproject/bc-widget-area": "^5.0.6", + "baserproject/bc-admin-third": "^5.1", + "baserproject/bc-blog": "^5.1", + "baserproject/bc-content-link": "^5.1", + "baserproject/bc-custom-content": "^5.1", + "baserproject/bc-editor-template": "^5.1", + "baserproject/bc-favorite": "^5.1", + "baserproject/bc-front": "^5.1", + "baserproject/bc-installer": "^5.1", + "baserproject/bc-mail": "^5.1", + "baserproject/bc-search-index": "^5.1", + "baserproject/bc-theme-config": "^5.1", + "baserproject/bc-theme-file": "^5.1", + "baserproject/bc-uploader": "^5.1", + "baserproject/bc-widget-area": "^5.1", "imo-tikuwa/cakephp-soft-delete": "^2.0", "ext-mbstring": "*", "ext-zip": "*", From fc8414af4b55bf521fa0dcb391d2ebde76381bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Fri, 27 Oct 2023 17:44:07 +0900 Subject: [PATCH 13/14] =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=925.0.7=E9=96=8B=E7=99=BA=E7=89=88=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/baser-core/VERSION.txt b/plugins/baser-core/VERSION.txt index b9128c9ea1..00a8ee1abe 100644 --- a/plugins/baser-core/VERSION.txt +++ b/plugins/baser-core/VERSION.txt @@ -1,4 +1,4 @@ -5.0.6 +5.0.7-dev /////////////////////////////////////////////////////////////////////////////////////////////////////////// // +---------------------------------------------------------------------------------------------------+ // From 28994159e84a1d90c9b4224feed86934719adf65 Mon Sep 17 00:00:00 2001 From: ryuring Date: Fri, 27 Oct 2023 18:52:59 +0900 Subject: [PATCH 14/14] =?UTF-8?q?BlogHelper::setContent()=20=E3=82=92?= =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bc-blog/src/View/Helper/BlogHelper.php | 87 +++++++++---------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/plugins/bc-blog/src/View/Helper/BlogHelper.php b/plugins/bc-blog/src/View/Helper/BlogHelper.php index f98c3efba3..37de70c73d 100755 --- a/plugins/bc-blog/src/View/Helper/BlogHelper.php +++ b/plugins/bc-blog/src/View/Helper/BlogHelper.php @@ -88,6 +88,12 @@ class BlogHelper extends Helper */ public $BlogCategory = null; + /** + * ブログコンテンツサービス + * @var BlogContentsServiceInterface + */ + public $BlogContentsService = null; + /** * コンテンツ * @@ -108,6 +114,7 @@ class BlogHelper extends Helper public function __construct(View $view, array $config = []) { parent::__construct($view, $config); + $this->BlogContentsService = $this->getService(BlogContentsServiceInterface::class); $this->setContent(); } @@ -119,62 +126,46 @@ public function __construct(View $view, array $config = []) * @param int $blogContentId ブログコンテンツID * @return void * @checked + * @noTodo */ public function setContent($blogContentId = null) { - $blogContentUpdated = false; - $content = false; - if (empty($this->currentBlogContent) || ($blogContentId != $this->currentBlogContent->id)) { - if ($blogContentId) { - if ($this->_View->getRequest()->getQuery('preview') == 'default' && $this->_View->getRequest()->getData()) { - // TODO ucmitz 未確認のためコメントアウト -// if (!empty($this->_View->getRequest()->getData('BlogContent'))) { -// $this->currentBlogContent = $this->_View->getRequest()->getData('BlogContent'); -// $blogContentUpdated = true; -// } - } else { - $BlogContent = TableRegistry::getTableLocator()->get('BcBlog.BlogContents'); - $blogContent = $BlogContent->find()->where(['BlogContents.id' => $blogContentId])->first(); - $this->currentBlogContent = $blogContent; - $blogContentUpdated = true; - } - } elseif ($this->_View->get('blogContent')) { - $this->currentBlogContent = $this->_View->get('blogContent'); - if ($this->currentBlogContent->content->type === 'BlogContent') { - $this->currentContent = $this->currentBlogContent->content; - } else { - $content = $this->BcContents->getContentByEntityId($this->currentBlogContent->id, 'BlogContent'); - if ($content) $this->currentContent = $content; - } + if($this->currentBlogContent) { + if(is_null($blogContentId)) return; + if($blogContentId === $this->currentBlogContent->id) return; + } + + if($blogContentId) { + $this->currentBlogContent = $this->BlogContentsService->get($blogContentId); + $contentTable = TableRegistry::getTableLocator()->get('BaserCore.Contents'); + // 現在のサイトにエイリアスが存在するのであればそちらを優先する + $site = $this->_View->getRequest()->getAttribute('currentSite'); + if (!empty($site->id)) { + $content = $contentTable->find()->where([ + 'Contents.entity_id' => $this->currentBlogContent->id, + 'Contents.type' => 'BlogContent', + 'Contents.alias_id IS NOT' => null, + 'Contents.site_id' => $site->id + ])->first(); + } else { + $content = $contentTable->find()->where([ + 'Contents.entity_id' => $this->currentBlogContent->id, + 'Contents.type' => 'BlogContent', + 'Contents.alias_id IS' => null, + ])->first(); } - } - if ($this->currentBlogContent) { - if ($blogContentUpdated) { - $contentTable = TableRegistry::getTableLocator()->get('BaserCore.Contents'); - // 現在のサイトにエイリアスが存在するのであればそちらを優先する - $site = $this->_View->getRequest()->getAttribute('currentSite'); - if (!empty($site->id)) { - $content = $contentTable->find()->where([ - 'Contents.entity_id' => $this->currentBlogContent->id, - 'Contents.type' => 'BlogContent', - 'Contents.alias_id IS NOT' => null, - 'Contents.site_id' => $site->id - ])->first(); - } - if (!$content) { - $content = $contentTable->find()->where([ - 'Contents.entity_id' => $this->currentBlogContent->id, - 'Contents.type' => 'BlogContent', - 'Contents.alias_id IS' => null, - ])->first(); - } - $this->currentContent = $content; + $this->currentContent = $content; + } else { + if ($this->getView()->get('blogContent')) { + $this->currentBlogContent = $this->getView()->get('blogContent'); + $this->currentContent = $this->currentBlogContent->content; } + } + + if($this->currentBlogContent?->id) { /* @var BlogPostsTable $blogPostTable */ $blogPostTable = TableRegistry::getTableLocator()->get('BcBlog.BlogPosts'); $blogPostTable->setupUpload($this->currentBlogContent->id); - } else { - $this->currentContent = null; } }