From 9cd2e2271d66cf175504256caa5c3ead9504f700 Mon Sep 17 00:00:00 2001 From: ryuring Date: Sun, 21 Apr 2024 13:58:07 +0900 Subject: [PATCH 1/7] =?UTF-8?q?composer=20=E3=82=88=E3=82=8A=20"minimum-st?= =?UTF-8?q?ability":=20"dev"=20=E3=82=92=E5=89=8A=E9=99=A4=20fix=20#2063?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 5054d94c49..3ec6a2629b 100644 --- a/composer.json +++ b/composer.json @@ -125,7 +125,5 @@ "cakephp/plugin-installer": true, "dealerdirect/phpcodesniffer-composer-installer": true } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } From 6482f64fdb4774b23792ddbdd9b1aa7be2486ba3 Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 23 Apr 2024 09:03:16 +0900 Subject: [PATCH 2/7] =?UTF-8?q?Configure=20=E3=81=AE=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E5=80=A4=20BcRequest.isInstalled=20=E3=82=92=20BcEnv.isInstall?= =?UTF-8?q?ed=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/config/setting.php | 14 ++++++++++---- plugins/baser-core/src/BaserCorePlugin.php | 4 ++-- plugins/baser-core/src/Utility/BcUtil.php | 2 +- .../Middleware/BcRequestFilterMiddlewareTest.php | 4 ++-- .../TestCase/View/Helper/BcToolbarHelperTest.php | 4 ++-- .../Service/Admin/WidgetAreasAdminServiceTest.php | 2 +- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/plugins/baser-core/config/setting.php b/plugins/baser-core/config/setting.php index 58055fdce8..7c1196e6c3 100644 --- a/plugins/baser-core/config/setting.php +++ b/plugins/baser-core/config/setting.php @@ -173,7 +173,16 @@ /** * 現在のリクエストのホスト */ - 'host' => (isset($_SERVER['HTTP_HOST']))? $_SERVER['HTTP_HOST'] : null + 'host' => (isset($_SERVER['HTTP_HOST']))? $_SERVER['HTTP_HOST'] : null, + /** + * インストール済かどうか + * + * BaserCorePlugin::bootstrap() で設定する + * bootstrap の方が呼び出し順が早いため、こちらで設定すると再初期化となってしまうため + * コメントアウトのままとする + * ここで別途判定を入れた場合ユニットテストがやりにくくなるのでそのままにしておく + */ + // 'isInstalled' => null, ], /** @@ -567,9 +576,6 @@ 'BcRequest' => [ // アセットファイルかどうか 'asset' => false, - // Router がロード済かどうか - // TODO 不要か確認 - 'routerLoaded' => false, // アップデーターかどうか 'isUpdater' => false, // メンテナンスかどうか diff --git a/plugins/baser-core/src/BaserCorePlugin.php b/plugins/baser-core/src/BaserCorePlugin.php index 79e692fdef..c9b1e7fba1 100644 --- a/plugins/baser-core/src/BaserCorePlugin.php +++ b/plugins/baser-core/src/BaserCorePlugin.php @@ -89,8 +89,8 @@ public function bootstrap(PluginApplicationInterface $app): void * インストールされてない場合のテストをできるようにするため、Configure の設定を優先する */ $hasInstall = file_exists(CONFIG . 'install.php'); - if (is_null(Configure::read('BcRequest.isInstalled'))) { - Configure::write('BcRequest.isInstalled', $hasInstall); + if (is_null(Configure::read('BcEnv.isInstalled'))) { + Configure::write('BcEnv.isInstalled', $hasInstall); } /** diff --git a/plugins/baser-core/src/Utility/BcUtil.php b/plugins/baser-core/src/Utility/BcUtil.php index d769914fa2..17e12828a0 100644 --- a/plugins/baser-core/src/Utility/BcUtil.php +++ b/plugins/baser-core/src/Utility/BcUtil.php @@ -1093,7 +1093,7 @@ public static function getContentsItem(): array */ public static function isInstalled() { - return (bool)Configure::read('BcRequest.isInstalled'); + return (bool)Configure::read('BcEnv.isInstalled'); } /** diff --git a/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php b/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php index 451ad0495f..5126b73272 100644 --- a/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php +++ b/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php @@ -45,9 +45,9 @@ class BcRequestFilterMiddlewareTest extends BcTestCase public function setUp(): void { if (preg_match('/^testIsInstall/', $this->getName())) { - Configure::write('BcRequest.isInstalled', false); + Configure::write('BcEnv.isInstalled', false); } else { - Configure::write('BcRequest.isInstalled', true); + Configure::write('BcEnv.isInstalled', true); } parent::setUp(); $this->BcRequestFilterMiddleware = new BcRequestFilterMiddleware(); diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php index 1f35e4f75a..3df774d553 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php @@ -307,10 +307,10 @@ public function testGetLogoLink() $this->assertEquals('https://baserproject.github.io/5/operation/update', $bcToolbar->getLogoLink()); Configure::write('BcRequest.isUpdater', false); // インストーラー - Configure::write('BcRequest.isInstalled', false); + Configure::write('BcEnv.isInstalled', false); $bcToolbar = new BcToolbarHelper(new View(null, null, null, ['name' => 'Installations'])); $this->assertEquals('https://baserproject.github.io/5/introduce/', $bcToolbar->getLogoLink()); - Configure::write('BcRequest.isInstalled', true); + Configure::write('BcEnv.isInstalled', true); } /** diff --git a/plugins/bc-widget-area/tests/TestCase/Service/Admin/WidgetAreasAdminServiceTest.php b/plugins/bc-widget-area/tests/TestCase/Service/Admin/WidgetAreasAdminServiceTest.php index 43bbe51da0..7b487de1cf 100644 --- a/plugins/bc-widget-area/tests/TestCase/Service/Admin/WidgetAreasAdminServiceTest.php +++ b/plugins/bc-widget-area/tests/TestCase/Service/Admin/WidgetAreasAdminServiceTest.php @@ -76,7 +76,7 @@ public function test_getWidgetInfos() 'paths' => ['/var/www/html/plugins/bc-admin-third/templates/Admin/element/widget'] ], $result[0]); //正常系実行 - Configure::write('BcRequest.isInstalled', true); + Configure::write('BcEnv.isInstalled', true); $result = $this->execPrivateMethod($this->WidgetAreasAdminService, 'getWidgetInfos'); $this->assertCount(1, $result); $this->assertEquals('BaserCore', $result[0]['plugin']); From 95127ae13a6c6874f6d240f91758d444552de3d2 Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 23 Apr 2024 09:42:22 +0900 Subject: [PATCH 3/7] =?UTF-8?q?Configure=20=E3=81=AE=20BcRequest.asset=20?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AssetMiddleware が存在するため不要と判断 --- plugins/baser-core/config/setting.php | 2 - plugins/baser-core/src/BaserCorePlugin.php | 3 +- .../Middleware/BcRequestFilterMiddleware.php | 31 -------------- .../BcRequestFilterMiddlewareTest.php | 41 ------------------- .../src/BcCustomContentPlugin.php | 24 ++++------- 5 files changed, 11 insertions(+), 90 deletions(-) diff --git a/plugins/baser-core/config/setting.php b/plugins/baser-core/config/setting.php index 7c1196e6c3..08cd164551 100644 --- a/plugins/baser-core/config/setting.php +++ b/plugins/baser-core/config/setting.php @@ -574,8 +574,6 @@ * リクエスト情報 */ 'BcRequest' => [ - // アセットファイルかどうか - 'asset' => false, // アップデーターかどうか 'isUpdater' => false, // メンテナンスかどうか diff --git a/plugins/baser-core/src/BaserCorePlugin.php b/plugins/baser-core/src/BaserCorePlugin.php index c9b1e7fba1..7024663de4 100644 --- a/plugins/baser-core/src/BaserCorePlugin.php +++ b/plugins/baser-core/src/BaserCorePlugin.php @@ -45,6 +45,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; @@ -282,7 +283,7 @@ function loadPlugin(PluginApplicationInterface $application, $plugin, $priority) public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue { $middlewareQueue - ->prepend(new BcRequestFilterMiddleware()) + ->insertBefore(RoutingMiddleware::class, new BcRequestFilterMiddleware()) ->insertBefore(CsrfProtectionMiddleware::class, new AuthenticationMiddleware($this)) ->add(new BcAdminMiddleware()) ->add(new BcFrontMiddleware()) diff --git a/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php b/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php index 34533cac8f..3a7a8043c9 100644 --- a/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php @@ -48,12 +48,6 @@ public function process( $response = $this->redirectIfIsDeviceFile($request); if($response) return $response; } - - if ($this->isAsset($request)) { - Configure::write('BcRequest.asset', true); - return new Response(); - } - $request = $this->addDetectors($request); /** @@ -117,7 +111,6 @@ public function getDetectorConfigs() { $configs = []; $configs['admin'] = [$this, 'isAdmin']; - $configs['asset'] = [$this, 'isAsset']; $configs['install'] = [$this, 'isInstall']; $configs['maintenance'] = [$this, 'isMaintenance']; $configs['update'] = [$this, 'isUpdate']; @@ -162,30 +155,6 @@ public function isAdmin(ServerRequestInterface $request) return (bool)preg_match($regex, $request->getPath()); } - /** - * アセットのURLかどうかを判定 - * - * @param ServerRequestInterface $request リクエスト - * @return bool - * @checked - * @noTodo - * @unitTest - */ - public function isAsset(ServerRequestInterface $request) - { - $dirs = ['css', 'js', 'img']; - $exts = ['css', 'js', 'gif', 'jpg', 'jpeg', 'png', 'ico', 'svg', 'swf']; - - $dirRegex = implode('|', $dirs); - $extRegex = implode('|', $exts); - - $assetRegex = '/^\/(' . $dirRegex . ')\/.+\.(' . $extRegex . ')$/'; - $themeAssetRegex = '/^\/theme\/[^\/]+?\/(' . $dirRegex . ')\/.+\.(' . $extRegex . ')$/'; - - $uri = $request->getPath(); - return preg_match($assetRegex, $uri) || preg_match($themeAssetRegex, $uri); - } - /** * インストール用のURLかどうかを判定 * [注]ルーターによるURLパース後のみ diff --git a/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php b/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php index 5126b73272..c5f93ebdd0 100644 --- a/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php +++ b/plugins/baser-core/tests/TestCase/Middleware/BcRequestFilterMiddlewareTest.php @@ -71,9 +71,6 @@ public function testProcess(): void { $this->_response = $this->BcRequestFilterMiddleware->process($this->getRequest(), $this->Application); $this->assertResponseOk(); - $url = '/img/test.png'; - $this->_response = $this->BcRequestFilterMiddleware->process($this->getRequest($url), $this->Application); - $this->assertTrue(Configure::read('BcRequest.asset')); } /** @@ -145,44 +142,6 @@ public function isAdminDataProvider() ]; } - /** - * アセットのURLかどうかを判定 - * - * @param bool $expect 期待値 - * @param string $url URL文字列 - * @return void - * @dataProvider isAssetDataProvider - */ - public function testIsAsset($expect, $url) - { - $this->assertEquals($expect, $this->BcRequestFilterMiddleware->isAsset($this->getRequest($url))); - } - - /** - * isAsset用データプロバイダ - * - * @return array - */ - public function isAssetDataProvider() - { - return [ - [false, '/'], - [false, '/about'], - [false, '/img/test.html'], - [false, '/js/test.php'], - [false, '/css/file.cgi'], - [true, '/img/image.png'], - [true, '/js/startup.js'], - [true, '/css/main.css'], - [false, '/theme/example_theme/img/test.html'], - [false, '/theme/example_theme/js/test.php'], - [false, '/theme/example_theme/css/file.cgi'], - [true, '/theme/example_theme/img/image.png'], - [true, '/theme/example_theme/js/startup.js'], - [true, '/theme/example_theme/css/main.css'] - ]; - } - /** * インストール用のURLかどうかを判定 * diff --git a/plugins/bc-custom-content/src/BcCustomContentPlugin.php b/plugins/bc-custom-content/src/BcCustomContentPlugin.php index 726c0be34e..cd5c901906 100644 --- a/plugins/bc-custom-content/src/BcCustomContentPlugin.php +++ b/plugins/bc-custom-content/src/BcCustomContentPlugin.php @@ -80,7 +80,9 @@ public function bootstrap(PluginApplicationInterface $app): void /** * カスタムコンテンツコアのプラグインをロードする * + * @return void * @checked + * @noTodo */ public function loadPlugin(): void { @@ -94,21 +96,13 @@ public function loadPlugin(): void $Folder = new Folder($path); $files = $Folder->read(true, true, false); if (empty($files[0])) return; - - if (Configure::read('BcRequest.asset')) { - // TODO ucmitz 検証要 - foreach($files[0] as $pluginName) { - BcUtil::includePluginClass($pluginName); - } - } else { - foreach($files[0] as $pluginName) { - // 設定ファイルを読み込む - if (!BcUtil::includePluginClass($pluginName)) continue; - $pluginCollection = CakePlugin::getCollection(); - $plugin = $pluginCollection->create($pluginName); - $pluginCollection->add($plugin); - BcEvent::registerPluginEvent($pluginName); - } + foreach($files[0] as $pluginName) { + // 設定ファイルを読み込む + if (!BcUtil::includePluginClass($pluginName)) continue; + $pluginCollection = CakePlugin::getCollection(); + $plugin = $pluginCollection->create($pluginName); + $pluginCollection->add($plugin); + BcEvent::registerPluginEvent($pluginName); } } From 098b7239966eb9c4bcacff4053a5b96eea105aac Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 23 Apr 2024 10:38:31 +0900 Subject: [PATCH 4/7] =?UTF-8?q?Configure=20=E3=81=AE=20BcRequest.isUpdater?= =?UTF-8?q?=20=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 利用していなかったため --- plugins/baser-core/config/setting.php | 2 -- .../src/Controller/Admin/PluginsController.php | 2 +- .../Middleware/BcRedirectMainSiteMiddleware.php | 8 +------- .../Middleware/BcRedirectSubSiteMiddleware.php | 3 --- .../src/Middleware/BcRequestFilterMiddleware.php | 1 - plugins/baser-core/src/Utility/BcUtil.php | 12 ++++++------ .../src/View/Helper/BcToolbarHelper.php | 10 ++++++---- .../Controller/Admin/PluginsControllerTest.php | 2 -- .../TestCase/View/Helper/BcToolbarHelperTest.php | 16 ++++------------ 9 files changed, 18 insertions(+), 38 deletions(-) diff --git a/plugins/baser-core/config/setting.php b/plugins/baser-core/config/setting.php index 08cd164551..4eeaf7702c 100644 --- a/plugins/baser-core/config/setting.php +++ b/plugins/baser-core/config/setting.php @@ -574,8 +574,6 @@ * リクエスト情報 */ 'BcRequest' => [ - // アップデーターかどうか - 'isUpdater' => false, // メンテナンスかどうか 'isMaintenance' => false, ], diff --git a/plugins/baser-core/src/Controller/Admin/PluginsController.php b/plugins/baser-core/src/Controller/Admin/PluginsController.php index daebde7bca..b1d3966183 100644 --- a/plugins/baser-core/src/Controller/Admin/PluginsController.php +++ b/plugins/baser-core/src/Controller/Admin/PluginsController.php @@ -47,6 +47,7 @@ public function initialize(): void /** * Before Filter * @param \Cake\Event\EventInterface $event An Event instance + * @return Response|void * @checked * @unitTest * @noTodo @@ -56,7 +57,6 @@ public function beforeFilter(EventInterface $event) $response = parent::beforeFilter($event); if($response) return $response; $this->Security->setConfig('unlockedActions', ['reset_db', 'update_sort', 'batch']); - if(Configure::read('BcRequest.isUpdater')) $this->Authentication->allowUnauthenticated(['update']); } /** diff --git a/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php b/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php index 38b85773df..fb4b201ae3 100644 --- a/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php @@ -42,19 +42,13 @@ 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); - } if ($request->is('admin') || !BcUtil::isInstalled()) { return $handler->handle($request); } diff --git a/plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php b/plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php index 5ed4c19a79..3c976a03e4 100644 --- a/plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcRedirectSubSiteMiddleware.php @@ -56,9 +56,6 @@ public function process( RequestHandlerInterface $handler ): ResponseInterface { - if (Configure::read('BcRequest.isUpdater')) { - return $handler->handle($request); - } if ($request->is('admin') || !BcUtil::isInstalled()) { return $handler->handle($request); } diff --git a/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php b/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php index 3a7a8043c9..10e3b02303 100644 --- a/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php @@ -113,7 +113,6 @@ public function getDetectorConfigs() $configs['admin'] = [$this, 'isAdmin']; $configs['install'] = [$this, 'isInstall']; $configs['maintenance'] = [$this, 'isMaintenance']; - $configs['update'] = [$this, 'isUpdate']; $configs['page'] = [$this, 'isPage']; $configs['requestview'] = [$this, 'isRequestView']; diff --git a/plugins/baser-core/src/Utility/BcUtil.php b/plugins/baser-core/src/Utility/BcUtil.php index 17e12828a0..0e8628184e 100644 --- a/plugins/baser-core/src/Utility/BcUtil.php +++ b/plugins/baser-core/src/Utility/BcUtil.php @@ -1446,6 +1446,8 @@ public static function isWindows() * * @param mixed $url * @return mixed + * @checked + * @noTodo */ public static function addSessionId($url, $force = false) { @@ -1457,12 +1459,10 @@ public static function addSessionId($url, $force = false) return $url; } - $site = null; - if (!Configure::read('BcRequest.isUpdater')) { - $currentUrl = \Cake\Routing\Router::getRequest()->getPath(); - $sites = \Cake\ORM\TableRegistry::getTableLocator()->get('BaserCore.Sites'); - $site = $sites->findByUrl($currentUrl); - } + $currentUrl = \Cake\Routing\Router::getRequest()->getPath(); + $sites = \Cake\ORM\TableRegistry::getTableLocator()->get('BaserCore.Sites'); + $site = $sites->findByUrl($currentUrl); + // use_trans_sid が有効になっている場合、2重で付加されてしまう if ($site && $site->device == 'mobile' && Configure::read('BcAgent.mobile.sessionId') && (!ini_get('session.use_trans_sid') || $force)) { if (is_array($url)) { diff --git a/plugins/baser-core/src/View/Helper/BcToolbarHelper.php b/plugins/baser-core/src/View/Helper/BcToolbarHelper.php index 093b82f2fb..d22d1931af 100644 --- a/plugins/baser-core/src/View/Helper/BcToolbarHelper.php +++ b/plugins/baser-core/src/View/Helper/BcToolbarHelper.php @@ -130,7 +130,6 @@ public function isAvailableLogin(): bool if (BcUtil::loginUser()) return false; if ($this->_View->getName() === 'Installations') return false; if ($this->isLoginUrl()) return false; - if (Configure::read('BcRequest.isUpdater')) return false; return true; } @@ -286,11 +285,14 @@ public function isLoginUrl(): bool */ public function getLogoType(): string { - if ($this->_View->getName() === 'Installations') { + if ($this->getView()->getName() === 'Installations') { return 'install'; - } elseif (Configure::read('BcRequest.isUpdater')) { + } elseif ($this->getView()->getRequest()->getParam('controller') === 'Plugins' + && $this->getView()->getRequest()->getParam('action') === 'update' + && empty($this->getView()->getRequest()->getParam('pass')) + ) { return 'update'; - } elseif ($this->_View->getRequest()->getParam('prefix') === "Admin" || $this->isLoginUrl()) { + } elseif ($this->getView()->getRequest()->getParam('prefix') === "Admin" || $this->isLoginUrl()) { return 'normal'; } else { if ($this->BcAuth->isCurrentUserAdminAvailable()) { diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php index 4ad11db04b..7849ce40fa 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php @@ -102,11 +102,9 @@ public function testInitialize() */ public function testBeforeFilter() { - Configure::write('BcRequest.isUpdater', true); $event = new Event('Controller.beforeFilter', $this->PluginsController); $this->PluginsController->beforeFilter($event); $this->assertEquals($this->PluginsController->Security->getConfig('unlockedActions'), ['reset_db', 'update_sort', 'batch']); - $this->assertEquals(['update'], $this->PluginsController->Authentication->getUnauthenticatedActions()); } /** diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php index 3df774d553..71ee7820df 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcToolbarHelperTest.php @@ -139,10 +139,6 @@ public function testIsAvailableLogin() // インストーラーの場合 $toolbar = new BcToolbarHelper(new View(null, null, null, ['name' => 'Installations'])); $this->assertFalse($toolbar->isAvailableLogin()); - // アップデーターの場合 - Configure::write('BcRequest.isUpdater', true); - $this->assertFalse($this->BcToolbar->isAvailableLogin()); - Configure::write('BcRequest.isUpdater', false); // ログイン画面の場合 $toolbar = new BcToolbarHelper(new View($this->getRequest('/baser/admin/baser-core/users/login'))); $this->assertFalse($toolbar->isAvailableLogin()); @@ -281,9 +277,8 @@ public function testGetLogoType() $bcToolbar = new BcToolbarHelper(new View($this->getRequest('/baser/admin/baser-core/users/login'))); $this->assertEquals('normal', $bcToolbar->getLogoType()); // アップデーター - Configure::write('BcRequest.isUpdater', true); + $bcToolbar->getView()->setRequest($this->getRequest('/baser/admin/baser-core/plugins/update')); $this->assertEquals('update', $bcToolbar->getLogoType()); - Configure::write('BcRequest.isUpdater', false); // インストーラー $bcToolbar = new BcToolbarHelper(new View(null, null, null, ['name' => 'Installations'])); $this->assertEquals('install', $bcToolbar->getLogoType()); @@ -303,9 +298,8 @@ public function testGetLogoLink() $bcToolbar = new BcToolbarHelper(new View($this->getRequest('/baser/admin/baser-core/users/login'))); $this->assertEquals('https://localhost/', $bcToolbar->getLogoLink()); // アップデーター - Configure::write('BcRequest.isUpdater', true); + $bcToolbar->getView()->setRequest($this->getRequest('/baser/admin/baser-core/plugins/update')); $this->assertEquals('https://baserproject.github.io/5/operation/update', $bcToolbar->getLogoLink()); - Configure::write('BcRequest.isUpdater', false); // インストーラー Configure::write('BcEnv.isInstalled', false); $bcToolbar = new BcToolbarHelper(new View(null, null, null, ['name' => 'Installations'])); @@ -327,9 +321,8 @@ public function testGetLogoText() $bcToolbar = new BcToolbarHelper(new View($this->getRequest('/baser/admin/baser-core/users/login'))); $this->assertEquals('サイト表示', $bcToolbar->getLogoText()); // アップデーター - Configure::write('BcRequest.isUpdater', true); + $bcToolbar->getView()->setRequest($this->getRequest('/baser/admin/baser-core/plugins/update')); $this->assertEquals('アップデートマニュアル', $bcToolbar->getLogoText()); - Configure::write('BcRequest.isUpdater', false); // インストーラー $bcToolbar = new BcToolbarHelper(new View(null, null, null, ['name' => 'Installations'])); $this->assertEquals('インストールマニュアル', $bcToolbar->getLogoText()); @@ -358,11 +351,10 @@ public function testGetLogoLinkOptions() $this->assertTrue(in_array('bca-toolbar__logo-link', $options)); // アップデーター - Configure::write('BcRequest.isUpdater', true); + $bcToolbar->getView()->setRequest($this->getRequest('/baser/admin/baser-core/plugins/update')); $options = $bcToolbar->getLogoLinkOptions(); $this->assertTrue(in_array('bca-toolbar__logo-link', $options)); $this->assertTrue(in_array('_blank', $options)); - Configure::write('BcRequest.isUpdater', false); // インストーラー $bcToolbar = new BcToolbarHelper(new View(null, null, null, ['name' => 'Installations'])); From 8357a9138ac920bd0a973e79bc38edd7aa33829f Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 23 Apr 2024 10:42:25 +0900 Subject: [PATCH 5/7] =?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=E3=81=AE=E5=A4=B1=E6=95=97=E3=82=92?= =?UTF-8?q?=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/tests/TestCase/PluginTest.php | 7 +++++-- .../Model/Behavior/BcSearchIndexManagerBehavior.php | 12 +++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/PluginTest.php b/plugins/baser-core/tests/TestCase/PluginTest.php index c39364721d..f051dd4f17 100644 --- a/plugins/baser-core/tests/TestCase/PluginTest.php +++ b/plugins/baser-core/tests/TestCase/PluginTest.php @@ -12,6 +12,7 @@ namespace BaserCore\Test\TestCase; use App\Application; +use Authentication\Middleware\AuthenticationMiddleware; use BaserCore\BaserCorePlugin; use BaserCore\Service\SiteConfigsServiceInterface; use BaserCore\TestSuite\BcTestCase; @@ -22,6 +23,7 @@ use Cake\Event\EventManager; use Cake\Http\Middleware\CsrfProtectionMiddleware; use Cake\Http\MiddlewareQueue; +use Cake\Routing\Middleware\RoutingMiddleware; use Cake\Routing\Router; use Cake\Filesystem\File; @@ -175,9 +177,10 @@ public function testMiddleware(): void { $middleware = new MiddlewareQueue(); $middleware->add(CsrfProtectionMiddleware::class); + $middleware->add(RoutingMiddleware::class); $middlewareQueue = $this->Plugin->middleware($middleware); - $this->assertInstanceOf(BcRequestFilterMiddleware::class, $middlewareQueue->current()); - $this->assertEquals(6, $middlewareQueue->count()); + $this->assertInstanceOf(AuthenticationMiddleware::class, $middlewareQueue->current()); + $this->assertEquals(7, $middlewareQueue->count()); } /** diff --git a/plugins/bc-search-index/src/Model/Behavior/BcSearchIndexManagerBehavior.php b/plugins/bc-search-index/src/Model/Behavior/BcSearchIndexManagerBehavior.php index 78d4e68175..e2321b5dc8 100755 --- a/plugins/bc-search-index/src/Model/Behavior/BcSearchIndexManagerBehavior.php +++ b/plugins/bc-search-index/src/Model/Behavior/BcSearchIndexManagerBehavior.php @@ -200,12 +200,14 @@ public function saveSearchIndex($searchIndex) } $searchIndex['model'] = Inflector::classify($this->table->getAlias()); // タグ、空白を除外 - $searchIndex['detail'] = str_replace(["\r\n", "\r", "\n", "\t", "\s"], '', trim(strip_tags($searchIndex['detail']))); - // MySQLの場合、検索テーブル'detail'では半角65535以上の文字数は保存できないため、オーバーした分はカットする。※str_ends_with()は php8系~ - $db = ConnectionManager::get('default')->config()['driver']; - if (str_ends_with($db, 'Mysql') && mb_strlen($searchIndex['detail']) >= 21845) { - $searchIndex['detail'] = mb_substr($searchIndex['detail'],0, 21844); + if(!empty($searchIndex['detail'])) { + $searchIndex['detail'] = str_replace(["\r\n", "\r", "\n", "\t", "\s"], '', trim(strip_tags($searchIndex['detail']))); + // MySQLの場合、検索テーブル'detail'では半角65535以上の文字数は保存できないため、オーバーした分はカットする。※str_ends_with()は php8系~ + $db = ConnectionManager::get('default')->config()['driver']; + if (str_ends_with($db, 'Mysql') && mb_strlen($searchIndex['detail']) >= 21845) { + $searchIndex['detail'] = mb_substr($searchIndex['detail'], 0, 21844); + } } // 検索用データとして保存 From 53dbbf1d3241e2513675c8610e57db4ed44396e1 Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 23 Apr 2024 10:44:47 +0900 Subject: [PATCH 6/7] =?UTF-8?q?Configure=20BcRequest=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 利用していなかったため --- plugins/baser-core/config/setting.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugins/baser-core/config/setting.php b/plugins/baser-core/config/setting.php index 4eeaf7702c..e1e5ae4bdf 100644 --- a/plugins/baser-core/config/setting.php +++ b/plugins/baser-core/config/setting.php @@ -570,14 +570,6 @@ ] ], - /** - * リクエスト情報 - */ - 'BcRequest' => [ - // メンテナンスかどうか - 'isMaintenance' => false, - ], - /** * プレフィックス認証 * From 79f7ad1f5bafba9429fc693456b9b9ca3522fbf2 Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 23 Apr 2024 12:12:11 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=9E=E3=81=AE?= =?UTF-8?q?=E5=88=9D=E6=9C=9F=E3=83=87=E3=83=BC=E3=82=BF=E8=AA=AD=E8=BE=BC?= =?UTF-8?q?=E3=82=92=E8=A1=8C=E3=81=86=E3=81=A8=E3=82=B3=E3=83=B3=E3=83=86?= =?UTF-8?q?=E3=83=B3=E3=83=84=E7=AE=A1=E7=90=86=E3=81=AE=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E6=97=A5=E3=81=8C=E7=A9=BA=E6=AC=84=E3=81=AB=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E6=94=B9=E5=96=84=20fix=20#3183?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/BaserCorePlugin.php | 11 ++++ plugins/baser-core/src/BcPlugin.php | 6 ++- .../src/Service/BcDatabaseService.php | 8 ++- plugins/bc-blog/src/BcBlogPlugin.php | 14 ++++- .../src/BcCustomContentPlugin.php | 19 +++++-- .../src/Service/InstallationsService.php | 53 +------------------ .../Service/InstallationsServiceTest.php | 8 --- 7 files changed, 52 insertions(+), 67 deletions(-) diff --git a/plugins/baser-core/src/BaserCorePlugin.php b/plugins/baser-core/src/BaserCorePlugin.php index 7024663de4..9421950842 100644 --- a/plugins/baser-core/src/BaserCorePlugin.php +++ b/plugins/baser-core/src/BaserCorePlugin.php @@ -601,6 +601,17 @@ function(RouteBuilder $routes) { parent::routes($routes); } + /** + * 初期データ読み込み時の更新処理 + * @param array $options + * @return void + */ + public function updateDefaultData($options = []) : void + { + // コンテンツの作成日を更新 + $this->updateDateNow('BaserCore.Contents', ['created_date'], [], $options); + } + /** * services * @param ContainerInterface $container diff --git a/plugins/baser-core/src/BcPlugin.php b/plugins/baser-core/src/BcPlugin.php index a5cdc3e422..fe6e3c39c4 100644 --- a/plugins/baser-core/src/BcPlugin.php +++ b/plugins/baser-core/src/BcPlugin.php @@ -621,7 +621,11 @@ public function updateDateNow(string $table, array $fields, array $conditions = $options = array_merge([ 'connection' => 'default' ], $options); - $table = TableRegistry::getTableLocator()->get($table, ['connectionName' => $options['connection']]); + $tableOptions = []; + if($options['connection'] && $options['connection'] !== 'default') { + $tableOptions = ['connectionName' => $options['connection']]; + } + $table = TableRegistry::getTableLocator()->get($table, $tableOptions); $beforeSaveEvents = BcUtil::offEvent($table->getEventManager(), 'Model.beforeSave'); $afterSaveEvents = BcUtil::offEvent($table->getEventManager(), 'Model.afterSave'); diff --git a/plugins/baser-core/src/Service/BcDatabaseService.php b/plugins/baser-core/src/Service/BcDatabaseService.php index a1bbfeee1d..c262d35c1c 100644 --- a/plugins/baser-core/src/Service/BcDatabaseService.php +++ b/plugins/baser-core/src/Service/BcDatabaseService.php @@ -405,14 +405,18 @@ protected function _loadDefaultDataPattern($pattern, $theme, $plugin = 'BaserCor if (!$this->loadCsv(['path' => $file, 'encoding' => 'auto', 'dbConfigKeyName' => $dbConfigKeyName])) { $this->log(sprintf(__d('baser_core', '%s の読み込みに失敗。'), $file)); $result = false; - } else { - break; } } catch(\Throwable $e) { throw $e; } } } + try { + $pluginClass = Plugin::getCollection()->get($plugin); + if(method_exists($pluginClass, 'updateDefaultData')) { + $pluginClass->updateDefaultData(); + } + } catch (\Throwable) {} return $result; } diff --git a/plugins/bc-blog/src/BcBlogPlugin.php b/plugins/bc-blog/src/BcBlogPlugin.php index 069459decc..4dd4b3d97b 100755 --- a/plugins/bc-blog/src/BcBlogPlugin.php +++ b/plugins/bc-blog/src/BcBlogPlugin.php @@ -16,6 +16,7 @@ use BaserCore\Model\Table\SitesTable; use BaserCore\Utility\BcContainerTrait; use BcBlog\ServiceProvider\BcBlogServiceProvider; +use Cake\Core\Configure; use Cake\Core\ContainerInterface; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; @@ -48,12 +49,23 @@ public function install($options = []) : bool { $result = parent::install($options); // ブログ記事の投稿日を更新 - if(empty($options['db_init'])) { + if(Configure::read('BcEnv.isInstalled') && empty($options['db_init'])) { $this->updateDateNow('BcBlog.BlogPosts', ['posted'], [], $options); } return $result; } + /** + * 初期データ読み込み時の更新処理 + * @param array $options + * @return void + */ + public function updateDefaultData($options = []) : void + { + // ブログ記事の投稿日を更新 + $this->updateDateNow('BcBlog.BlogPosts', ['posted'], [], $options); + } + /** * プラグインをアンインストールする * diff --git a/plugins/bc-custom-content/src/BcCustomContentPlugin.php b/plugins/bc-custom-content/src/BcCustomContentPlugin.php index cd5c901906..d1231d4088 100644 --- a/plugins/bc-custom-content/src/BcCustomContentPlugin.php +++ b/plugins/bc-custom-content/src/BcCustomContentPlugin.php @@ -47,12 +47,25 @@ public function install($options = []): bool 'connection' => 'default' ], $options); $result = parent::install($options); - $table = TableRegistry::getTableLocator()->get('BcCustomContent.CustomEntries', ['connectionName' => $options['connection']]); - $table->setUp(1); - $this->updateDateNow('BcCustomContent.CustomEntries', ['published'], [], $options); + if(Configure::read('BcEnv.isInstalled') && empty($options['db_init'])) { + $table = TableRegistry::getTableLocator()->get('BcCustomContent.CustomEntries', ['connectionName' => $options['connection']]); + $table->setUp(1); + $this->updateDateNow('BcCustomContent.CustomEntries', ['published'], [], $options); + } return $result; } + /** + * 初期データ読み込み時の更新処理 + * @param array $options + * @return void + */ + public function updateDefaultData($options = []) : void + { + // エントリーの公開日を更新 + $this->updateDateNow('BcCustomContent.CustomEntries', ['published'], [], $options); + } + /** * services * @param ContainerInterface $container diff --git a/plugins/bc-installer/src/Service/InstallationsService.php b/plugins/bc-installer/src/Service/InstallationsService.php index 397bb10dd7..0267c7cf1b 100644 --- a/plugins/bc-installer/src/Service/InstallationsService.php +++ b/plugins/bc-installer/src/Service/InstallationsService.php @@ -357,61 +357,10 @@ public function setSiteName(string $name) */ public function executeDefaultUpdates(): bool { - $result = true; - if (!$this->_updateContents()) { - $this->log(__d('baser_core', 'コンテンツの更新に失敗しました。')); - $result = false; - } - if (!$this->_updateBlogPosts()) { - $this->log(__d('baser_core', 'ブログ記事の更新に失敗しました。')); - $result = false; - } /** @var SearchIndexesServiceInterface $searchIndexesService */ $searchIndexesService = $this->getService(SearchIndexesServiceInterface::class); $searchIndexesService->reconstruct(); - return $result; - } - - /** - * コンテンツの作成日を更新する - * - * @return bool - * @checked - * @noTodo - */ - protected function _updateContents(): bool - { - $contentsTable = TableRegistry::getTableLocator()->get('BaserCore.Contents'); - $contents = $contentsTable->find()->all(); - $result = true; - foreach($contents as $content) { - $content->created_date = new FrozenTime(); - if (!$contentsTable->save($content)) { - $result = false; - } - } - return $result; - } - - /** - * コンテンツの作成日を更新する - * - * @return bool - * @checked - * @noTodo - */ - protected function _updateBlogPosts(): bool - { - $table = TableRegistry::getTableLocator()->get('BcBlog.BlogPosts'); - $entities = $table->find()->all(); - $result = true; - foreach($entities as $entity) { - $entity->posted = new FrozenTime(); - if (!$table->save($entity)) { - $result = false; - } - } - return $result; + return true; } /** diff --git a/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php b/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php index 6696c1c91c..d1efe9038a 100644 --- a/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php +++ b/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php @@ -185,14 +185,6 @@ public function testExecuteDefaultUpdates() $this->assertTrue($result, 'データベースのデータに初期更新に失敗しました'); } - /** - * test _updateContents - */ - public function test_updateContents() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - /** * test installCorePlugin */