Upgrade to 3.8.0
This commit is contained in:
@@ -13,6 +13,7 @@ use Kirby\Form\Form;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
use Kirby\Uuid\Uuid;
|
||||
|
||||
/**
|
||||
* PageActions
|
||||
@@ -88,10 +89,8 @@ trait PageActions
|
||||
// in multi-language installations the slug for the non-default
|
||||
// languages is stored in the text file. The changeSlugForLanguage
|
||||
// method takes care of that.
|
||||
if ($language = $this->kirby()->language($languageCode)) {
|
||||
if ($language->isDefault() === false) {
|
||||
return $this->changeSlugForLanguage($slug, $languageCode);
|
||||
}
|
||||
if ($this->kirby()->language($languageCode)?->isDefault() === false) {
|
||||
return $this->changeSlugForLanguage($slug, $languageCode);
|
||||
}
|
||||
|
||||
// if the slug stays exactly the same,
|
||||
@@ -108,11 +107,12 @@ trait PageActions
|
||||
'root' => null
|
||||
]);
|
||||
|
||||
// clear UUID cache recursively (for children and files as well)
|
||||
$oldPage->uuid()->clear(true);
|
||||
|
||||
if ($oldPage->exists() === true) {
|
||||
// remove the lock of the old page
|
||||
if ($lock = $oldPage->lock()) {
|
||||
$lock->remove();
|
||||
}
|
||||
$oldPage->lock()?->remove();
|
||||
|
||||
// actually move stuff on disk
|
||||
if (Dir::move($oldPage->root(), $newPage->root()) !== true) {
|
||||
@@ -182,16 +182,12 @@ trait PageActions
|
||||
*/
|
||||
public function changeStatus(string $status, int $position = null)
|
||||
{
|
||||
switch ($status) {
|
||||
case 'draft':
|
||||
return $this->changeStatusToDraft();
|
||||
case 'listed':
|
||||
return $this->changeStatusToListed($position);
|
||||
case 'unlisted':
|
||||
return $this->changeStatusToUnlisted();
|
||||
default:
|
||||
throw new InvalidArgumentException('Invalid status: ' . $status);
|
||||
}
|
||||
return match ($status) {
|
||||
'draft' => $this->changeStatusToDraft(),
|
||||
'listed' => $this->changeStatusToListed($position),
|
||||
'unlisted' => $this->changeStatusToUnlisted(),
|
||||
default => throw new InvalidArgumentException('Invalid status: ' . $status)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,6 +442,9 @@ trait PageActions
|
||||
}
|
||||
}
|
||||
|
||||
// overwrite with new UUID (remove old, add new)
|
||||
$copy = $copy->save(['uuid' => Uuid::generate()]);
|
||||
|
||||
// add copy to siblings
|
||||
static::updateParentCollections($copy, 'append', $parentModel);
|
||||
|
||||
@@ -465,13 +464,16 @@ trait PageActions
|
||||
$props['template'] = $props['model'] = strtolower($props['template'] ?? 'default');
|
||||
$props['isDraft'] = ($props['draft'] ?? true);
|
||||
|
||||
// make sure that a UUID gets generated and
|
||||
// added to content right away
|
||||
$props['content'] ??= [];
|
||||
$props['content']['uuid'] ??= Uuid::generate();
|
||||
|
||||
// create a temporary page object
|
||||
$page = Page::factory($props);
|
||||
|
||||
// create a form for the page
|
||||
$form = Form::for($page, [
|
||||
'values' => $props['content'] ?? []
|
||||
]);
|
||||
$form = Form::for($page, ['values' => $props['content']]);
|
||||
|
||||
// inject the content
|
||||
$page = $page->clone(['content' => $form->strings(true)]);
|
||||
@@ -593,6 +595,9 @@ trait PageActions
|
||||
public function delete(bool $force = false): bool
|
||||
{
|
||||
return $this->commit('delete', ['page' => $this, 'force' => $force], function ($page, $force) {
|
||||
// clear UUID cache
|
||||
$page->uuid()->clear();
|
||||
|
||||
// delete all files individually
|
||||
foreach ($page->files() as $file) {
|
||||
$file->delete();
|
||||
@@ -803,6 +808,25 @@ trait PageActions
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the content on disk
|
||||
*
|
||||
* @internal
|
||||
* @param array|null $data
|
||||
* @param string|null $languageCode
|
||||
* @param bool $overwrite
|
||||
* @return static
|
||||
*/
|
||||
public function save(array $data = null, string $languageCode = null, bool $overwrite = false)
|
||||
{
|
||||
$page = parent::save($data, $languageCode, $overwrite);
|
||||
|
||||
// overwrite the updated page in the parent collection
|
||||
static::updateParentCollections($page, 'set');
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a page from listed or
|
||||
* unlisted to draft.
|
||||
@@ -862,7 +886,10 @@ trait PageActions
|
||||
$page = parent::update($input, $languageCode, $validate);
|
||||
|
||||
// if num is created from page content, update num on content update
|
||||
if ($page->isListed() === true && in_array($page->blueprint()->num(), ['zero', 'default']) === false) {
|
||||
if (
|
||||
$page->isListed() === true &&
|
||||
in_array($page->blueprint()->num(), ['zero', 'default']) === false
|
||||
) {
|
||||
$page = $page->changeNum($page->createNum());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user