Skip to content

Commit

Permalink
Merge branch '5.1.x' into unittest_CustomContentAppHelper__construct
Browse files Browse the repository at this point in the history
  • Loading branch information
TPGF00003 committed Nov 12, 2024
2 parents 0163ccd + f7fab89 commit a801062
Show file tree
Hide file tree
Showing 64 changed files with 1,146 additions and 169 deletions.
10 changes: 10 additions & 0 deletions plugins/baser-core/config/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@
*/
'enableRootRoutes' => false,

/**
* bc_formのテンプレートを指定
* config/bc_form.phpを差し替える
* プラグイン記法 (プラグイン名.テンプレート名)
*/
//basercms/plugins/baser-core/src/View/AppView.php
'AppFormTemplate' => 'BaserCore.bc_form',
//basercms/plugins/baser-core/src/View/BcAdminAppView.php
'AdminFormTemplate' => 'BaserCore.bc_form',

/**
* システムナビ
*
Expand Down
120 changes: 85 additions & 35 deletions plugins/baser-core/src/BaserCorePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function bootstrap(PluginApplicationInterface $app): void
}

/**
* プラグインロード
* テーマ・プラグインロード
*/
if (!filter_var(env('USE_DEBUG_KIT', true), FILTER_VALIDATE_BOOLEAN)) {
// 明示的に指定がない場合、DebugKitは重すぎるのでデバッグモードでも利用しない
Expand All @@ -164,19 +164,19 @@ public function bootstrap(PluginApplicationInterface $app): void
}

if (BcUtil::isTest()) $app->addPlugin('CakephpFixtureFactories');
$app->addPlugin('Authentication');
$app->addPlugin('Migrations');

$this->addTheme($app);

$plugins = BcUtil::getEnablePlugins();
if ($plugins) {
foreach($plugins as $plugin) {
if (BcUtil::includePluginClass($plugin->name)) {
$this->loadPlugin($app, $plugin->name, $plugin->priority);
}
}
}
// 利用可能なテーマを取得
$themes = $this->getAvailableThemes();
// プラグインを追加する前にテーマが保有するプラグインのパスをセット
$this->setupThemePlugin($themes);
// テーマが保有するプラグインも含めてプラグインを読み込む
$this->addPlugin($app);
// ======================================================
// テーマはプラグインの後に読み込む
// テーマもプラグインとして扱う場合があるため、
// その場合に、テーマでプラグインの設定等を上書きできるようにする
// ======================================================
$this->addTheme($app, $themes);

/**
* デフォルトテンプレートを設定する
Expand All @@ -194,50 +194,100 @@ public function bootstrap(PluginApplicationInterface $app): void
$event->on(new BcAuthenticationEventListener());
}

/**
* プラグインを追加する
* @param PluginApplicationInterface $app
* @return void
* @checked
* @noTodo
*/
public function addPlugin(PluginApplicationInterface $app): void
{
$app->addPlugin('Authentication');
$app->addPlugin('Migrations');

$plugins = BcUtil::getEnablePlugins();
if(!$plugins) return;
foreach($plugins as $plugin) {
if (!BcUtil::includePluginClass($plugin->name)) continue;
$this->loadPlugin($app, $plugin->name, $plugin->priority);
}
}

/**
* テーマを追加する
*
* テーマ内のプラグインも追加する
*
* @param PluginApplicationInterface $application
* @noTodo
* @checked
*/
public function addTheme(PluginApplicationInterface $application)
public function addTheme(PluginApplicationInterface $application, array $themes): void
{
$application->addPlugin(Inflector::camelize(Configure::read('BcApp.coreAdminTheme'), '-'));
$application->addPlugin(Inflector::camelize(Configure::read('BcApp.coreFrontTheme'), '-'));
if (!BcUtil::isInstalled()) return;
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
try {
$sites = $sitesTable->find()->where(['Sites.status' => true]);
} catch (MissingConnectionException) {
return;

foreach($themes as $theme) {
if(!BcUtil::includePluginClass($theme)) continue;
try {
$application->addPlugin($theme);
} catch (MissingPluginException $e) {
$this->log($e->getMessage());
}
}
}

/**
* テーマが保有するプラグインのパスを追加する
* @param array $themes
* @return void
* @checked
* @noTodo
*/
public function setupThemePlugin(array $themes): void
{
if (!BcUtil::isInstalled()) return;
if(!$themes) return;
$path = [];
foreach($sites as $site) {
if ($site->theme) {
if(!BcUtil::includePluginClass($site->theme)) continue;
try {
$application->addPlugin($site->theme);
$pluginPath = CorePlugin::path($site->theme) . 'plugins' . DS;
if (!is_dir($pluginPath)) continue;
$path[] = $pluginPath;
} catch (MissingPluginException $e) {
$this->log($e->getMessage());
}
}
foreach($themes as $theme) {
$pluginsPath = CorePlugin::path($theme) . 'plugins' . DS;
if (!is_dir($pluginsPath)) continue;
$path[] = $pluginsPath;
}
// テーマプラグインを追加
if($path) {
if(isset($path) && $path) {
Configure::write('App.paths.plugins', array_merge(
Configure::read('App.paths.plugins'),
$path
));
}
}

/**
* 利用可能なテーマを取得する
* @return array
* @checked
* @noTodo
*/
public function getAvailableThemes(): array
{
if (!BcUtil::isInstalled()) return [];
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
try {
$sites = $sitesTable->find()->where(['Sites.status' => true]);
} catch (MissingConnectionException) {
return [];
}
$themes = [];
foreach($sites as $site) {
if ($site->theme) {
if (!is_dir(CorePlugin::path($site->theme))) continue;
if(in_array($site->theme, $themes)) continue;
$themes[] = $site->theme;
}
}
return $themes;
}

/**
* デフォルトテンプレートを設定する
* @checked
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Command/ComposerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ComposerCommand extends Command
* @return \Cake\Console\ConsoleOptionParser
* @checked
* @noTodo
* @unitTest
*/
protected function buildOptionParser(\Cake\Console\ConsoleOptionParser $parser): \Cake\Console\ConsoleOptionParser
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/baser-core/src/Command/CreateReleaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function buildOptionParser(\Cake\Console\ConsoleOptionParser $parser):
* @return int|void|null
* @checked
* @noTodo
* @unitTest
*/
public function execute(Arguments $args, ConsoleIo $io)
{
Expand Down Expand Up @@ -109,6 +110,7 @@ public function execute(Arguments $args, ConsoleIo $io)
* @param string $packagePath
* @checked
* @noTodo
* @unitTest
*/
public function clonePackage(string $packagePath, string $branch)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Command/SetupInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SetupInstallCommand extends Command
* @return int|void|null
* @checked
* @noTodo
* @unitTest
*/
public function execute(Arguments $args, ConsoleIo $io)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Command/SetupTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SetupTestCommand extends Command
* @return int|void|null
* @checked
* @noTodo
* @unitTest
*/
public function execute(Arguments $args, ConsoleIo $io)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function beforeFilter(EventInterface $event)
* @return bool
* @noTodo
* @checked
* @unitTest
*/
private function checkPermission()
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/baser-core/src/Controller/BcFrontAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function initialize(): void
* @return Response|void
* @checked
* @noTodo
* @unitTest
*/
public function beforeFilter(EventInterface $event)
{
Expand All @@ -73,6 +74,7 @@ public function beforeFilter(EventInterface $event)
* @param EventInterface $event
* @checked
* @noTodo
* @unitTest
*/
public function beforeRender(EventInterface $event): void
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Controller/UploadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class UploadsController extends AppController
* @return \Cake\Http\Response
* @checked
* @noTodo
* @unitTest
*/
public function tmp()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UsersController extends BcFrontAppController
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function initialize(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PrefixOrmResolver extends OrmResolver implements ResolverInterface
* @return array|EntityInterface|null
* @checked
* @noTodo
* @unitTest
*/
public function find(array $conditions, $type = self::TYPE_AND): \ArrayAccess|array|null
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Mailer/Admin/BcAdminMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BcAdminMailer extends BcMailer
* @param null $config
* @checked
* @noTodo
* @unitTest
*/
public function __construct($config = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PasswordRequestMailer extends BcAdminMailer
* @param PasswordRequest|EntityInterface
* @checked
* @noTodo
* @unitTest
*/
public function resetPassword(EntityInterface $user, EntityInterface $passwordRequest)
{
Expand Down
4 changes: 4 additions & 0 deletions plugins/baser-core/src/Mailer/BcMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BcMailer extends Mailer
* @param null $config
* @checked
* @noTodo
* @unitTest
*/
public function __construct($config = null)
{
Expand All @@ -68,6 +69,7 @@ public function __construct($config = null)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function setEmailTransport()
{
Expand Down Expand Up @@ -105,6 +107,7 @@ public function setEmailTransport()
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getPlugin(): ?string
{
Expand All @@ -119,6 +122,7 @@ public function getPlugin(): ?string
* @psalm-return array{headers: string, message: string}
* @checked
* @noTodo
* @unitTest
*/
public function deliver(string $content = ''): array
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/baser-core/src/Model/Behavior/BcContentsBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function initialize(array $config): void
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getType(): string
{
Expand All @@ -86,6 +87,7 @@ public function getType(): string
* アソシエーション時に alias を除外する
* @checked
* @noTodo
* @unitTest
*/
public function offAlias(): void
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Model/Table/ContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public function getUniqueName($name, $parentId, $contentId = null)
$query = $this->find()->where(['name LIKE' => $name . '%', 'site_root' => false]);
if (isset($parentId)) $query = $query->andWhere(['parent_id' => $parentId]);
if ($contentId) {
$query = $query->andWhere(['id <>' => $contentId]);
$query = $query->andWhere(['Contents.id <>' => $contentId]);
}
$datas = $query->select('name')->orderBy('name')->all()->toArray();
$datas = Hash::extract($datas, '{n}.name');
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/src/Model/Table/SitesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function pluginExistsByDasherize($value)
*/
public function getPublishedAll(): ResultSetInterface
{
return $this->find()->where(['status' => true])->all();
return $this->find()->where(['Sites.status' => true])->all();
}

/**
Expand All @@ -236,7 +236,7 @@ public function getList($mainSiteId = null, $options = [])

$conditions = [];
if (!is_null($options['status'])) {
$conditions = ['status' => $options['status']];
$conditions = ['Sites.status' => $options['status']];
}

if (!is_null($mainSiteId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function getViewVarsForUpdate(EntityInterface $entity): array
* @return mixed|string
* @checked
* @noTodo
* @unitTest
*/
public function whichPhp()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Utility/BcAbstractDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ abstract class BcAbstractDetector
* @param array $config 設定の配列
* @checked
* @noTodo
* @unitTest
*/
public function __construct($name, array $config)
{
Expand Down
3 changes: 2 additions & 1 deletion plugins/baser-core/src/View/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use BaserCore\View\Helper\BcToolbarHelper;
use BaserCore\View\Helper\BcUploadHelper;
use Cake\View\View;
use Cake\Core\Configure;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use BaserCore\Annotation\UnitTest;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function initialize(): void
{
parent::initialize();
$this->addHelper('BaserCore.BcTime');
$this->addHelper('BaserCore.BcForm', ['templates' => 'BaserCore.bc_form']);
$this->addHelper('BaserCore.BcForm', ['templates' => Configure::read('BcApp.AppFormTemplate')]);
$this->addHelper('BaserCore.BcAdmin');
$this->addHelper('BaserCore.BcContents');
$this->addHelper('BaserCore.BcPage');
Expand Down
Loading

0 comments on commit a801062

Please sign in to comment.