Upgrade to 3.7.3
This commit is contained in:
@@ -19,17 +19,25 @@ trait HasChildren
|
||||
/**
|
||||
* The list of available published children
|
||||
*
|
||||
* @var \Kirby\Cms\Pages
|
||||
* @var \Kirby\Cms\Pages|null
|
||||
*/
|
||||
public $children;
|
||||
|
||||
/**
|
||||
* The list of available draft children
|
||||
*
|
||||
* @var \Kirby\Cms\Pages
|
||||
* @var \Kirby\Cms\Pages|null
|
||||
*/
|
||||
public $drafts;
|
||||
|
||||
/**
|
||||
* The combined list of available published
|
||||
* and draft children
|
||||
*
|
||||
* @var \Kirby\Cms\Pages|null
|
||||
*/
|
||||
public $childrenAndDrafts;
|
||||
|
||||
/**
|
||||
* Returns all published children
|
||||
*
|
||||
@@ -51,7 +59,11 @@ trait HasChildren
|
||||
*/
|
||||
public function childrenAndDrafts()
|
||||
{
|
||||
return $this->children()->merge($this->drafts());
|
||||
if (is_a($this->childrenAndDrafts, 'Kirby\Cms\Pages') === true) {
|
||||
return $this->childrenAndDrafts;
|
||||
}
|
||||
|
||||
return $this->childrenAndDrafts = $this->children()->merge($this->drafts());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -66,10 +66,7 @@ trait PageActions
|
||||
}
|
||||
|
||||
// overwrite the child in the parent page
|
||||
$newPage
|
||||
->parentModel()
|
||||
->children()
|
||||
->set($newPage->id(), $newPage);
|
||||
static::updateParentCollections($newPage, 'set');
|
||||
|
||||
return $newPage;
|
||||
});
|
||||
@@ -123,17 +120,13 @@ trait PageActions
|
||||
}
|
||||
|
||||
// remove from the siblings
|
||||
$oldPage->parentModel()->children()->remove($oldPage);
|
||||
static::updateParentCollections($oldPage, 'remove');
|
||||
|
||||
Dir::remove($oldPage->mediaRoot());
|
||||
}
|
||||
|
||||
// overwrite the new page in the parent collection
|
||||
if ($newPage->isDraft() === true) {
|
||||
$newPage->parentModel()->drafts()->set($newPage->id(), $newPage);
|
||||
} else {
|
||||
$newPage->parentModel()->children()->set($newPage->id(), $newPage);
|
||||
}
|
||||
static::updateParentCollections($newPage, 'set');
|
||||
|
||||
return $newPage;
|
||||
});
|
||||
@@ -167,7 +160,12 @@ trait PageActions
|
||||
$slug = null;
|
||||
}
|
||||
|
||||
return $page->save(['slug' => $slug], $languageCode);
|
||||
$newPage = $page->save(['slug' => $slug], $languageCode);
|
||||
|
||||
// overwrite the updated page in the parent collection
|
||||
static::updateParentCollections($newPage, 'set');
|
||||
|
||||
return $newPage;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -319,11 +317,7 @@ trait PageActions
|
||||
}
|
||||
|
||||
// update the parent collection
|
||||
if ($page->isDraft() === true) {
|
||||
$page->parentModel()->drafts()->set($page->id(), $page);
|
||||
} else {
|
||||
$page->parentModel()->children()->set($page->id(), $page);
|
||||
}
|
||||
static::updateParentCollections($page, 'set');
|
||||
|
||||
return $page;
|
||||
});
|
||||
@@ -343,11 +337,7 @@ trait PageActions
|
||||
$page = $page->save(['title' => $title], $languageCode);
|
||||
|
||||
// flush the parent cache to get children and drafts right
|
||||
if ($page->isDraft() === true) {
|
||||
$page->parentModel()->drafts()->set($page->id(), $page);
|
||||
} else {
|
||||
$page->parentModel()->children()->set($page->id(), $page);
|
||||
}
|
||||
static::updateParentCollections($page, 'set');
|
||||
|
||||
return $page;
|
||||
});
|
||||
@@ -457,11 +447,7 @@ trait PageActions
|
||||
}
|
||||
|
||||
// add copy to siblings
|
||||
if ($isDraft === true) {
|
||||
$parentModel->drafts()->append($copy->id(), $copy);
|
||||
} else {
|
||||
$parentModel->children()->append($copy->id(), $copy);
|
||||
}
|
||||
static::updateParentCollections($copy, 'append', $parentModel);
|
||||
|
||||
return $copy;
|
||||
}
|
||||
@@ -504,11 +490,7 @@ trait PageActions
|
||||
$page = $page->save($page->content()->toArray(), $languageCode);
|
||||
|
||||
// flush the parent cache to get children and drafts right
|
||||
if ($page->isDraft() === true) {
|
||||
$page->parentModel()->drafts()->append($page->id(), $page);
|
||||
} else {
|
||||
$page->parentModel()->children()->append($page->id(), $page);
|
||||
}
|
||||
static::updateParentCollections($page, 'append');
|
||||
|
||||
return $page;
|
||||
});
|
||||
@@ -643,10 +625,9 @@ trait PageActions
|
||||
}
|
||||
}
|
||||
|
||||
if ($page->isDraft() === true) {
|
||||
$page->parentModel()->drafts()->remove($page);
|
||||
} else {
|
||||
$page->parentModel()->children()->remove($page);
|
||||
static::updateParentCollections($page, 'remove');
|
||||
|
||||
if ($page->isDraft() === false) {
|
||||
$page->resortSiblingsAfterUnlisting();
|
||||
}
|
||||
|
||||
@@ -664,7 +645,6 @@ trait PageActions
|
||||
*/
|
||||
public function duplicate(string $slug = null, array $options = [])
|
||||
{
|
||||
|
||||
// create the slug for the duplicate
|
||||
$slug = Str::slug($slug ?? $this->slug() . '-' . Str::slug(I18n::translate('page.duplicate.appendix')));
|
||||
|
||||
@@ -722,8 +702,14 @@ trait PageActions
|
||||
}
|
||||
|
||||
// remove the page from the parent drafts and add it to children
|
||||
$page->parentModel()->drafts()->remove($page);
|
||||
$page->parentModel()->children()->append($page->id(), $page);
|
||||
$parentModel = $page->parentModel();
|
||||
$parentModel->drafts()->remove($page);
|
||||
$parentModel->children()->append($page->id(), $page);
|
||||
|
||||
// update the childrenAndDrafts() cache if it is initialized
|
||||
if ($parentModel->childrenAndDrafts !== null) {
|
||||
$parentModel->childrenAndDrafts()->set($page->id(), $page);
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
@@ -734,13 +720,14 @@ trait PageActions
|
||||
*/
|
||||
public function purge()
|
||||
{
|
||||
$this->blueprint = null;
|
||||
$this->children = null;
|
||||
$this->content = null;
|
||||
$this->drafts = null;
|
||||
$this->files = null;
|
||||
$this->inventory = null;
|
||||
$this->translations = null;
|
||||
$this->blueprint = null;
|
||||
$this->children = null;
|
||||
$this->childrenAndDrafts = null;
|
||||
$this->content = null;
|
||||
$this->drafts = null;
|
||||
$this->files = null;
|
||||
$this->inventory = null;
|
||||
$this->translations = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -788,6 +775,7 @@ trait PageActions
|
||||
|
||||
$parent = $this->parentModel();
|
||||
$parent->children = $parent->children()->sort('num', 'asc');
|
||||
$parent->childrenAndDrafts = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -812,6 +800,7 @@ trait PageActions
|
||||
}
|
||||
|
||||
$parent->children = $siblings->sort('num', 'asc');
|
||||
$parent->childrenAndDrafts = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -845,8 +834,14 @@ trait PageActions
|
||||
}
|
||||
|
||||
// remove the page from the parent children and add it to drafts
|
||||
$page->parentModel()->children()->remove($page);
|
||||
$page->parentModel()->drafts()->append($page->id(), $page);
|
||||
$parentModel = $page->parentModel();
|
||||
$parentModel->children()->remove($page);
|
||||
$parentModel->drafts()->append($page->id(), $page);
|
||||
|
||||
// update the childrenAndDrafts() cache if it is initialized
|
||||
if ($parentModel->childrenAndDrafts !== null) {
|
||||
$parentModel->childrenAndDrafts()->set($page->id(), $page);
|
||||
}
|
||||
|
||||
$page->resortSiblingsAfterUnlisting();
|
||||
|
||||
@@ -874,6 +869,37 @@ trait PageActions
|
||||
$page = $page->changeNum($page->createNum());
|
||||
}
|
||||
|
||||
// overwrite the updated page in the parent collection
|
||||
static::updateParentCollections($page, 'set');
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates parent collections with the new page object
|
||||
* after a page action
|
||||
*
|
||||
* @param \Kirby\Cms\Page $page
|
||||
* @param string $method Method to call on the parent collections
|
||||
* @param \Kirby\Cms\Page|null $parentMdel
|
||||
* @return void
|
||||
*/
|
||||
protected static function updateParentCollections($page, string $method, $parentModel = null): void
|
||||
{
|
||||
$parentModel ??= $page->parentModel();
|
||||
|
||||
// method arguments depending on the called method
|
||||
$args = $method === 'remove' ? [$page] : [$page->id(), $page];
|
||||
|
||||
if ($page->isDraft() === true) {
|
||||
$parentModel->drafts()->$method(...$args);
|
||||
} else {
|
||||
$parentModel->children()->$method(...$args);
|
||||
}
|
||||
|
||||
// update the childrenAndDrafts() cache if it is initialized
|
||||
if ($parentModel->childrenAndDrafts !== null) {
|
||||
$parentModel->childrenAndDrafts()->$method(...$args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user