Skip to content

Commit

Permalink
sites テーブルにプラグインなどでアソシエーションした場合、サイト情報が保存できない問題を改善
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Feb 26, 2024
1 parent 795559f commit caf866d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions plugins/baser-core/src/Model/Table/ContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ protected function updateSystemData($content)
}
}
if ($content->site_id) {
$site = $this->Sites->find()->where(['id' => $content->site_id])->first();
$site = $this->Sites->find()->where(['Sites.id' => $content->site_id])->first();
}
// URLを更新
$content->url = $this->createUrl($content->id);
Expand All @@ -961,7 +961,10 @@ protected function updateSystemData($content)
}
$content = $this->updatePublishDate($content);
if (!empty($content->parent_id)) {
$parent = $this->find()->select(['name', 'status', 'publish_begin', 'publish_end'])->where(['id' => $content->parent_id])->first();
$parent = $this->find()
->select(['Contents.name', 'Contents.status', 'Contents.publish_begin', 'Contents.publish_end'])
->where(['Contents.id' => $content->parent_id])
->first();
// 親フォルダが非公開の場合は自身も非公開
if (!$parent->status) {
$content->status = $parent->status;
Expand All @@ -988,7 +991,10 @@ protected function updateSystemData($content)
}
// main_site_content_id を更新
if (!$content->isNew() && $site->main_site_id) {
$mainSiteContent = $this->find()->select(['id'])->where(['site_id' => $site->main_site_id, 'url' => $url])->first();
$mainSiteContent = $this->find()
->select(['Contents.id'])
->where(['Contents.site_id' => $site->main_site_id, 'Contents.url' => $url])
->first();
$content->main_site_content_id = $mainSiteContent->id ?? null;
} else {
$content->main_site_content_id = null;
Expand Down Expand Up @@ -1052,7 +1058,7 @@ public function isPublishById($id)
*/
public function updateChildren($id)
{
$children = $this->find('children', ['for' => $id])->order('lft');
$children = $this->find('children', ['for' => $id])->order('Contents.lft');
$result = true;
if (!$children->all()->isEmpty()) {
foreach($children as $child) {
Expand Down Expand Up @@ -1105,16 +1111,16 @@ public function deleteByType($type, $entityId = null)
$plugin = 'BaserCore';
}
$conditions = [
'plugin' => $plugin,
'type' => $type,
'alias_id' => null
'Contents.plugin' => $plugin,
'Contents.type' => $type,
'Contents.alias_id' => null
];
if ($entityId) {
$conditions['Content.entity_id'] = $entityId;
}
$softDelete = $this->softDelete(null);
$this->softDelete(false);
$id = $this->field('id', $conditions);
$id = $this->field('Contents.id', $conditions);
$result = $this->removeFromTree($id, true);
$this->softDelete($softDelete);
return $result;
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/src/Service/SitesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public function getIndex(array $queryParams = []): Query
$query->limit($queryParams['limit']);
}
if (!empty($queryParams['name'])) {
$query->where(['name LIKE' => '%' . $queryParams['name'] . '%']);
$query->where(['Sites.name LIKE' => '%' . $queryParams['name'] . '%']);
}
if (isset($queryParams['status'])) {
$query->where(['status' => $queryParams['status']]);
$query->where(['Sites.status' => $queryParams['status']]);
}
return $query;
}
Expand Down

0 comments on commit caf866d

Please sign in to comment.