Skip to content

Commit

Permalink
Merge branch 'dev-5.1' into unitTest_BlogCommentsService_Add
Browse files Browse the repository at this point in the history
  • Loading branch information
thangnn committed Feb 16, 2024
2 parents 31febb1 + 7e30e2f commit 105eb5e
Show file tree
Hide file tree
Showing 102 changed files with 791 additions and 553 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
._*
.Spotlight-V100
.Trashes
# Icon must end with two \r
Icon
Icon?
ehthumbs.db
Thumbs.db
.directory
Expand Down
284 changes: 133 additions & 151 deletions composer.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docker/.env

This file was deleted.

4 changes: 2 additions & 2 deletions plugins/baser-core/src/Controller/Admin/ThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function add(ThemesServiceInterface $service)
$name = $service->add($this->getRequest()->getUploadedFiles());
$this->BcMessage->setInfo(__d('baser_core', 'テーマファイル「{0}」を追加しました。', $name));
$this->redirect(['action' => 'index']);
} catch (BcException $e) {
$this->BcMessage->setError(__d('baser_core', 'ファイルのアップロードに失敗しました。') . $e->getMessage());
} catch (\Throwable $e) {
$this->BcMessage->setError(__d('baser_core', 'ファイルのアップロードに失敗しました。') . "\n" . $e->getMessage());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function initialize(): void
$this->loadComponent('FormProtection', [
'unlockedFields' => ['x', 'y', 'MAX_FILE_SIZE'],
'validationFailureCallback' => function (BadRequestException $exception) {
$message = __d('baser_core', '不正なリクエストと判断されました。<br>もしくは、システムが受信できるデータ上限より大きなデータが送信された可能性があります。') . "<br>" . $exception->getMessage();
$message = __d('baser_core', "不正なリクエストと判断されました\nもしくは、システムが受信できるデータ上限より大きなデータが送信された可能性があります。") . "\n" . $exception->getMessage();
throw new BadRequestException($message);
}
]);
Expand Down
15 changes: 9 additions & 6 deletions plugins/baser-core/src/Controller/BcErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
use BaserCore\Utility\BcContainer;
use BaserCore\Utility\BcUtil;
use Cake\Controller\ComponentRegistry;
use Cake\Datasource\Exception\MissingDatasourceConfigException;
use Cake\Database\Exception\MissingConnectionException;
use Cake\Event\EventInterface;
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use Cake\Event\EventManager;
use Cake\Event\EventManagerInterface;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
Expand Down Expand Up @@ -60,14 +61,14 @@ public function __construct(?ServerRequest $request = null, ?Response $response
*/
protected function getCurrent(ServerRequest $request): ServerRequest
{
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
$contentsTable = TableRegistry::getTableLocator()->get('BaserCore.Contents');
$url = BcUtil::fullUrl($request->getUri()->getPath());
try {
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
$contentsTable = TableRegistry::getTableLocator()->get('BaserCore.Contents');
} catch(MissingDatasourceConfigException $e) {
$site = $sitesTable->findByUrl($url);
} catch(MissingConnectionException) {
return $request;
}
$url = BcUtil::fullUrl($request->getUri()->getPath());
$site = $sitesTable->findByUrl($url);
$url = '/';
if($site->alias) $url .= $site->alias . '/';
$content = $contentsTable->findByUrl($url);
Expand Down Expand Up @@ -103,6 +104,8 @@ public function beforeRender(EventInterface $event): void
{
parent::beforeRender($event);
$this->viewBuilder()->setTemplatePath('Error');
// プラグイン等のイベントが残っているとエラー画面が正常に表示されない場合があるため、イベントを削除する
EventManager::instance()->off('View.beforeRender');
}

}
10 changes: 8 additions & 2 deletions plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use BaserCore\Utility\BcAgent;
use BaserCore\Utility\BcUtil;
use Cake\Core\Configure;
use Cake\Database\Exception\MissingConnectionException;
use Cake\Http\Response;
use Cake\ORM\TableRegistry;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand Down Expand Up @@ -92,8 +94,12 @@ public function process(
*/
public function redirectIfIsDeviceFile(ServerRequestInterface $request)
{
$sites = \Cake\ORM\TableRegistry::getTableLocator()->get('BaserCore.Sites');
$site = $sites->findByUrl($request->getPath());
$sites = TableRegistry::getTableLocator()->get('BaserCore.Sites');
try {
$site = $sites->findByUrl($request->getPath());
} catch (MissingConnectionException) {
return;
}
if ($site && $site->device) {
$param = preg_replace('/^\/' . $site->alias . '\//', '', $request->getPath());
if (preg_match('/^files/', $param)) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/src/Model/Validation/BcValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public static function fileExt($file, $exts)
}

// FILES形式のチェック
if (!empty($file['name'])) {
$ext = BcUtil::decodeContent($file['type'], $file['name']);
if (!is_string($file) && !empty($file->getClientMediaType())) {
$ext = BcUtil::decodeContent($file->getClientMediaType(), $file->getClientMediaType());
if (!in_array($ext, $exts)) {
return false;
}
Expand Down
30 changes: 14 additions & 16 deletions plugins/baser-core/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Cake\Core\ContainerInterface;
use Cake\Core\Exception\MissingPluginException;
use Cake\Core\PluginApplicationInterface;
use Cake\Database\Exception\MissingConnectionException;
use Cake\Event\EventManager;
use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Http\Middleware\HttpsEnforcerMiddleware;
Expand Down Expand Up @@ -199,7 +200,12 @@ public function addTheme(PluginApplicationInterface $application)
$application->addPlugin(Inflector::camelize(Configure::read('BcApp.coreFrontTheme'), '-'));
if (!BcUtil::isInstalled()) return;
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
$sites = $sitesTable->find()->where(['Sites.status' => true]);
try {
$sites = $sitesTable->find()->where(['Sites.status' => true]);
} catch (MissingConnectionException) {
return;
}

$path = [];
foreach($sites as $site) {
if ($site->theme) {
Expand Down Expand Up @@ -229,20 +235,12 @@ public function setupDefaultTemplatesPath()
{
$admin = Configure::read('BcApp.coreAdminTheme');
$front = Configure::read('BcApp.coreFrontTheme');
if (BcUtil::isAdminSystem() && empty($_REQUEST['preview'])) {
Configure::write('App.paths.templates', array_merge([
ROOT . DS . 'plugins' . DS . $admin . DS . 'templates' . DS,
ROOT . DS . 'vendor' . DS . 'baserproject' . DS . $admin . DS . 'templates' . DS
], Configure::read('App.paths.templates')));
} else {
Configure::write('App.paths.templates', array_merge([
ROOT . DS . 'plugins' . DS . $front . DS . 'templates' . DS,
ROOT . DS . 'vendor' . DS . 'baserproject' . DS . $front . DS . 'templates' . DS,
ROOT . DS . 'plugins' . DS . $admin . DS . 'templates' . DS,
ROOT . DS . 'vendor' . DS . 'baserproject' . DS . $admin . DS . 'templates' . DS
], Configure::read('App.paths.templates')));
}

Configure::write('App.paths.templates', array_merge([
ROOT . DS . 'plugins' . DS . $front . DS . 'templates' . DS,
ROOT . DS . 'vendor' . DS . 'baserproject' . DS . $front . DS . 'templates' . DS,
ROOT . DS . 'plugins' . DS . $admin . DS . 'templates' . DS,
ROOT . DS . 'vendor' . DS . 'baserproject' . DS . $admin . DS . 'templates' . DS
], Configure::read('App.paths.templates')));
}

/**
Expand Down Expand Up @@ -288,7 +286,7 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
if (Configure::read('BcApp.adminSsl') && !BcUtil::isConsole() && BcUtil::isAdminSystem()) {
$config = ['redirect' => false];
if(filter_var(env('TRUST_PROXY', false))) {
$config['trustProxies'] = !empty($_SERVER['HTTP_X_FORWARDED_FOR'])? [$_SERVER['HTTP_X_FORWARDED_FOR']] : [];
$config['trustedProxies'] = !empty($_SERVER['HTTP_X_FORWARDED_FOR'])? [$_SERVER['HTTP_X_FORWARDED_FOR']] : [];
}
$middlewareQueue->add(new HttpsEnforcerMiddleware($config));
}
Expand Down
5 changes: 4 additions & 1 deletion plugins/baser-core/src/Service/Admin/PluginsAdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class PluginsAdminService extends PluginsService implements PluginsAdminServiceI
*/
public function getViewVarsForInstall(EntityInterface $plugin): array
{
/** @var \BaserCore\Model\Entity\Plugin $plugin */
$installStatusMessage = $this->getInstallStatusMessage($plugin->name);
return [
'plugin' => $plugin,
'installStatusMessage' => $this->getInstallStatusMessage($plugin->name)
'installStatusMessage' => $installStatusMessage,
'installMessage' => (!$installStatusMessage)? $plugin->installMessage : '',
];
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/baser-core/src/Service/AppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use BaserCore\Model\Entity\Site;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcUtil;
use Cake\Database\Exception\MissingConnectionException;
use Cake\Datasource\EntityInterface;
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
Expand Down Expand Up @@ -66,7 +67,11 @@ public function getCurrentSite(): ?Site
$site = Router::getRequest()->getAttribute('currentSite');
if($site) {
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
return $sitesTable->find()->where(['id' => $site->id])->first();
try {
return $sitesTable->find()->where(['id' => $site->id])->first();
} catch (MissingConnectionException) {
return null;
}
} else {
return null;
}
Expand Down
17 changes: 11 additions & 6 deletions plugins/baser-core/src/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,28 @@ public function add(array $postData): string
}
$name = $postData['file']->getClientFileName();
$postData['file']->moveTo(TMP . $name);
$srcName = basename($name, '.zip');
$zip = new BcZip();
if (!$zip->extract(TMP . $name, TMP)) {
$srcName = $zip->extract(TMP . $name, TMP);
if (!$srcName) {
throw new BcException(__d('baser_core', 'アップロードしたZIPファイルの展開に失敗しました。'));
}

$num = 2;
$dstName = Inflector::camelize($srcName);
while(is_dir(BASER_THEMES . $dstName) || is_dir(BASER_THEMES . Inflector::dasherize($dstName))) {
$dstName = Inflector::camelize($srcName) . $num;
$num++;
}
$folder = new BcFolder(TMP . $srcName);
$folder->move( BASER_THEMES . $dstName,);
$folder->move(BASER_THEMES . $dstName);
unlink(TMP . $name);
BcUtil::changePluginNameSpace($dstName);
return $dstName;
$pluginPath = BcUtil::getPluginPath($dstName);
if(file_exists($pluginPath . 'src' . DS . 'Plugin.php')) {
BcUtil::changePluginNameSpace($dstName);
return $dstName;
} else {
(new BcFolder(BASER_THEMES . $dstName))->delete();
throw new BcException(__d('baser_core', 'テーマに Plugin クラスが存在しません。テーマのバージョンが違う可能性があります。'));
}
}

/**
Expand Down
36 changes: 24 additions & 12 deletions plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Cake\Cache\Cache;
use Cake\Core\Plugin;
use Cake\Core\Configure;
use Cake\Database\Exception\MissingConnectionException;
use Cake\Event\EventListenerInterface;
use Cake\Event\EventManagerInterface;
use Cake\Http\ServerRequest;
Expand Down Expand Up @@ -409,15 +410,14 @@ public static function getEnablePlugins($force = false)
}
if (!$enablePlugins) {
$enablePlugins = [];
$pluginsTable = TableRegistry::getTableLocator()->get('BaserCore.Plugins');; // ConnectionManager の前に呼出さないとエラーとなる
$prefix = self::getCurrentDbConfig()['prefix'];
// DBに接続できない場合、CakePHPのエラーメッセージが表示されてしまう為、 try を利用
try {
$pluginsTable = TableRegistry::getTableLocator()->get('BaserCore.Plugins');; // ConnectionManager の前に呼出さないとエラーとなる
} catch (Exception $ex) {
$sources = self::getCurrentDb()->getSchemaCollection()->listTables();
} catch (MissingConnectionException) {
return [];
}

$prefix = self::getCurrentDbConfig()['prefix'];
$sources = self::getCurrentDb()->getSchemaCollection()->listTables();
if (!is_array($sources) || in_array($prefix . strtolower('plugins'), array_map('strtolower', $sources))) {
$plugins = $pluginsTable->find('all', conditions: ['status' => true], order: 'priority');
TableRegistry::getTableLocator()->remove('Plugin');
Expand Down Expand Up @@ -1219,8 +1219,12 @@ public static function getCurrentTheme()
return $site->theme;
} else {
$sitesService = BcContainer::get()->get(SitesServiceInterface::class);
$site = $sitesService->get($site->main_site_id);
return $site->theme;
try {
$site = $sitesService->get($site->main_site_id);
return $site->theme;
} catch (MissingConnectionException) {
return $theme;
}
}
} elseif (self::getRootTheme()) {
return self::getRootTheme();
Expand All @@ -1239,8 +1243,12 @@ public static function getCurrentTheme()
public static function getRootTheme()
{
$sites = TableRegistry::getTableLocator()->get('BaserCore.Sites');
$site = $sites->getRootMain();
return (isset($site->theme))? $site->theme : null;
try {
$site = $sites->getRootMain();
return (isset($site->theme))? $site->theme : null;
} catch (MissingConnectionException) {
return null;
}
}

/**
Expand All @@ -1254,8 +1262,13 @@ public static function getRootTheme()
public static function getCurrentAdminTheme()
{
$adminTheme = Inflector::camelize(Inflector::underscore(Configure::read('BcApp.coreAdminTheme')));
if (BcUtil::isInstalled() && !empty(BcSiteConfig::get('admin_theme'))) {
$adminTheme = BcSiteConfig::get('admin_theme');
if (BcUtil::isInstalled()) {
try {
$siteConfigAdminTheme = BcSiteConfig::get('admin_theme');
if($siteConfigAdminTheme) return $siteConfigAdminTheme;
} catch (MissingConnectionException) {
return $adminTheme;
}
}
return $adminTheme;
}
Expand Down Expand Up @@ -1729,7 +1742,6 @@ public static function changePluginNameSpace($newPlugin)
return true;
}


/**
* httpからのフルURLを取得する
*
Expand Down
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Utility/BcZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function extract($source, $target)
$Folder = new BcFolder($extractedPath);
$Folder->chmod( 0777);
$this->Zip->close();
return true;
return $this->topArchiveName;
} else {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/baser-core/src/View/BcFrontAppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BaserCore\Utility\BcFolder;
use BaserCore\Utility\BcUtil;
use BaserCore\View\Helper\BcTextHelper;
use BcWidgetArea\View\Helper\BcWidgetAreaHelper;
use Cake\Core\Configure;
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
Expand All @@ -26,6 +27,7 @@
* BcFrontAppView
* @uses BcFrontAppView
* @property BcTextHelper $BcText
* @property BcWidgetAreaHelper $BcWidgetArea
*/
class BcFrontAppView extends AppView
{
Expand Down Expand Up @@ -65,7 +67,7 @@ protected function setThemeHelpers(): void
$files = $Folder->getFiles();
if (empty($files)) return;

foreach($files[1] as $file) {
foreach($files as $file) {
try {
$this->addHelper(Inflector::camelize($theme, '-') . '.' . basename($file, 'Helper.php'));
} catch (\Exception) {
Expand Down
2 changes: 2 additions & 0 deletions plugins/baser-core/src/View/Helper/BcAdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public function addAdminMainBodyHeaderLinks($links)
public function isAvailableSideBar()
{
if(!BcUtil::isInstalled()) return false;
if($this->getView()->getName() === 'Error') return false;
$prefix = $this->_View->getRequest()->getParam('prefix');
$loginAction = Router::url(Configure::read('BcPrefixAuth.' . $prefix . '.loginAction'));
$name = $this->_View->getName();
Expand Down Expand Up @@ -375,6 +376,7 @@ public function search(): void
public function contentsMenu(): void
{
if(!BcUtil::isInstalled()) return;
if($this->getView()->getName() === 'Error') return;
echo $this->_View->element('contents_menu', [
'isHelp' => (bool)($this->_View->get('help')),
'isLogin' => (bool)(BcUtil::loginUser()),
Expand Down
Loading

0 comments on commit 105eb5e

Please sign in to comment.