Skip to content

Commit

Permalink
コンテンツツリーをリセットした場合、URLが空になってしまう問題を改善
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Feb 27, 2024
1 parent adda7e9 commit dd255dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Error\BcException;
use BaserCore\Service\Admin\UtilitiesAdminServiceInterface;
use BaserCore\Service\UtilitiesService;
use BaserCore\Service\UtilitiesServiceInterface;
use BaserCore\Utility\BcUtil;
use BaserCore\Annotation\UnitTest;
Expand Down Expand Up @@ -193,7 +194,7 @@ public function log_maintenance(UtilitiesAdminServiceInterface $service, string

/**
* コンテンツ管理のツリー構造をリセットする
* @param UtilitiesServiceInterface $service
* @param UtilitiesServiceInterface|UtilitiesService $service
* @checked
* @noTodo
* @unitTest
Expand Down
18 changes: 8 additions & 10 deletions plugins/baser-core/src/Model/Table/ContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1313,10 +1313,9 @@ public function resetTree()
$this->removeBehavior('Tree');
$this->updatingRelated = false;

$beforeSaveListeners = $this->getEventManager()->listeners('Model.beforeSave');
$this->getEventManager()->off('Model.beforeSave', $beforeSaveListeners);
$afterSaveListeners = $this->getEventManager()->listeners('Model.afterSave');
$this->getEventManager()->off('Model.afterSave', $afterSaveListeners);
$eventManager = $this->getEventManager();
$beforeSaveListeners = BcUtil::offEvent($eventManager, 'Model.beforeSave');
$afterSaveListeners = BcUtil::offEvent($eventManager, 'Model.afterSave');

$this->getConnection()->begin();
$result = true;
Expand All @@ -1343,7 +1342,7 @@ public function resetTree()
$content->rght = $count;
$content->level = $siteRoot->level + 1;
$content->parent_id = $siteRoot->id;
if (!$this->save($content, false)) $result = false;
if (!$this->save($content)) $result = false;
}
}
if ($siteRoot->id == 1) {
Expand All @@ -1362,15 +1361,14 @@ public function resetTree()
$this->addBehavior('Tree');
$this->updatingRelated = true;

$this->getEventManager()->on('Model.beforeSave', $beforeSaveListeners);
$this->getEventManager()->on('Model.afterSave', $afterSaveListeners);
BcUtil::onEvent($eventManager, 'Model.beforeSave', $beforeSaveListeners);
BcUtil::onEvent($eventManager, 'Model.afterSave', $afterSaveListeners);

$contents = $this->find()->order(['lft'])->all();
if ($contents) {
foreach($contents as $content) {
// バリデーションをオンにする事で同名コンテンツを強制的にリネームする
// beforeValidate でリネーム処理を入れている為
// (第二引数を false に設定しない)
// setDirty を利用して同名コンテンツを強制的にリネームする
$content->setDirty('name', true);
if (!$this->save($content)) $result = false;
}
}
Expand Down

0 comments on commit dd255dd

Please sign in to comment.