Upgrade to 3.8.0
This commit is contained in:
@@ -7,6 +7,7 @@ use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\LogicException;
|
||||
use Kirby\Filesystem\F;
|
||||
use Kirby\Form\Form;
|
||||
use Kirby\Uuid\Uuid;
|
||||
|
||||
/**
|
||||
* FileActions
|
||||
@@ -44,6 +45,9 @@ trait FileActions
|
||||
'filename' => $name . '.' . $oldFile->extension(),
|
||||
]);
|
||||
|
||||
// remove all public versions, lock and clear UUID cache
|
||||
$oldFile->unpublish();
|
||||
|
||||
if ($oldFile->exists() === false) {
|
||||
return $newFile;
|
||||
}
|
||||
@@ -52,14 +56,6 @@ trait FileActions
|
||||
throw new LogicException('The new file exists and cannot be overwritten');
|
||||
}
|
||||
|
||||
// remove the lock of the old file
|
||||
if ($lock = $oldFile->lock()) {
|
||||
$lock->remove();
|
||||
}
|
||||
|
||||
// remove all public versions
|
||||
$oldFile->unpublish();
|
||||
|
||||
// rename the main file
|
||||
F::move($oldFile->root(), $newFile->root());
|
||||
|
||||
@@ -75,6 +71,7 @@ trait FileActions
|
||||
F::move($oldFile->contentFile(), $newFile->contentFile());
|
||||
}
|
||||
|
||||
// update collections
|
||||
$newFile->parent()->files()->remove($oldFile->id());
|
||||
$newFile->parent()->files()->set($newFile->id(), $newFile);
|
||||
|
||||
@@ -155,7 +152,12 @@ trait FileActions
|
||||
F::copy($contentFile, $page->root() . '/' . basename($contentFile));
|
||||
}
|
||||
|
||||
return $page->clone()->file($this->filename());
|
||||
$copy = $page->clone()->file($this->filename());
|
||||
|
||||
// overwrite with new UUID (remove old, add new)
|
||||
$copy = $copy->save(['uuid' => Uuid::generate()]);
|
||||
|
||||
return $copy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,17 +186,22 @@ trait FileActions
|
||||
$file = static::factory($props);
|
||||
$upload = $file->asset($props['source']);
|
||||
|
||||
// gather content
|
||||
$content = $props['content'] ?? [];
|
||||
|
||||
// make sure that a UUID gets generated and
|
||||
// added to content right away
|
||||
$content['uuid'] = Uuid::generate();
|
||||
|
||||
// create a form for the file
|
||||
$form = Form::for($file, [
|
||||
'values' => $props['content'] ?? []
|
||||
]);
|
||||
$form = Form::for($file, ['values' => $content]);
|
||||
|
||||
// inject the content
|
||||
$file = $file->clone(['content' => $form->strings(true)]);
|
||||
|
||||
// run the hook
|
||||
return $file->commit('create', compact('file', 'upload'), function ($file, $upload) {
|
||||
// delete all public versions
|
||||
// remove all public versions, lock and clear UUID cache
|
||||
$file->unpublish();
|
||||
|
||||
// overwrite the original
|
||||
@@ -229,14 +236,9 @@ trait FileActions
|
||||
public function delete(): bool
|
||||
{
|
||||
return $this->commit('delete', ['file' => $this], function ($file) {
|
||||
// remove all versions in the media folder
|
||||
// remove all public versions, lock and clear UUID cache
|
||||
$file->unpublish();
|
||||
|
||||
// remove the lock of the old file
|
||||
if ($lock = $file->lock()) {
|
||||
$lock->remove();
|
||||
}
|
||||
|
||||
if ($file->kirby()->multilang() === true) {
|
||||
foreach ($file->translations() as $translation) {
|
||||
F::remove($file->contentFile($translation->code()));
|
||||
@@ -288,7 +290,7 @@ trait FileActions
|
||||
|
||||
return $this->commit('replace', $arguments, function ($file, $upload) {
|
||||
// delete all public versions
|
||||
$file->unpublish();
|
||||
$file->unpublish(true);
|
||||
|
||||
// overwrite the original
|
||||
if (F::copy($upload->root(), $file->root(), true) !== true) {
|
||||
@@ -300,14 +302,43 @@ trait FileActions
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$file = parent::save($data, $languageCode, $overwrite);
|
||||
|
||||
// update model in siblings collection
|
||||
$file->parent()->files()->set($file->id(), $file);
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all public versions of this file
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function unpublish()
|
||||
public function unpublish(bool $onlyMedia = false)
|
||||
{
|
||||
// unpublish media files
|
||||
Media::unpublish($this->parent()->mediaRoot(), $this);
|
||||
|
||||
if ($onlyMedia !== true) {
|
||||
// remove the lock
|
||||
$this->lock()?->remove();
|
||||
|
||||
// clear UUID cache
|
||||
$this->uuid()->clear();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user