Upgrade to 3.2.0
This commit is contained in:
@@ -3,13 +3,20 @@
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Closure;
|
||||
use Kirby\Data\Data;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\LogicException;
|
||||
use Kirby\Image\Image;
|
||||
use Kirby\Toolkit\F;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* FileActions
|
||||
*
|
||||
* @package Kirby Cms
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://getkirby.com/license
|
||||
*/
|
||||
trait FileActions
|
||||
{
|
||||
|
||||
@@ -21,7 +28,7 @@ trait FileActions
|
||||
* @param bool $sanitize
|
||||
* @return self
|
||||
*/
|
||||
public function changeName(string $name, bool $sanitize = true): self
|
||||
public function changeName(string $name, bool $sanitize = true)
|
||||
{
|
||||
if ($sanitize === true) {
|
||||
$name = F::safeName($name);
|
||||
@@ -45,6 +52,9 @@ trait FileActions
|
||||
throw new LogicException('The new file exists and cannot be overwritten');
|
||||
}
|
||||
|
||||
// remove the lock of the old file
|
||||
$oldFile->lock()->remove();
|
||||
|
||||
// remove all public versions
|
||||
$oldFile->unpublish();
|
||||
|
||||
@@ -108,6 +118,29 @@ trait FileActions
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the file to the given page
|
||||
*
|
||||
* @param Kirby\Cms\Page $page
|
||||
* @return Kirby\Cms\File
|
||||
*/
|
||||
public function copy(Page $page)
|
||||
{
|
||||
F::copy($this->root(), $page->root() . '/' . $this->filename());
|
||||
|
||||
if ($this->kirby()->multilang() === true) {
|
||||
foreach ($this->kirby()->languages() as $language) {
|
||||
$contentFile = $this->contentFile($language->code());
|
||||
F::copy($contentFile, $page->root() . '/' . basename($contentFile));
|
||||
}
|
||||
} else {
|
||||
$contentFile = $this->contentFile();
|
||||
F::copy($contentFile, $page->root() . '/' . basename($contentFile));
|
||||
}
|
||||
|
||||
return $page->clone()->file($this->filename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new file on disk and returns the
|
||||
* File object. The store is used to handle file
|
||||
@@ -117,7 +150,7 @@ trait FileActions
|
||||
* @param array $props
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $props): self
|
||||
public static function create(array $props)
|
||||
{
|
||||
if (isset($props['source'], $props['parent']) === false) {
|
||||
throw new InvalidArgumentException('Please provide the "source" and "parent" props for the File');
|
||||
@@ -126,8 +159,10 @@ trait FileActions
|
||||
// prefer the filename from the props
|
||||
$props['filename'] = F::safeName($props['filename'] ?? basename($props['source']));
|
||||
|
||||
$props['model'] = strtolower($props['template'] ?? 'default');
|
||||
|
||||
// create the basic file and a test upload object
|
||||
$file = new static($props);
|
||||
$file = File::factory($props);
|
||||
$upload = new Image($props['source']);
|
||||
|
||||
// create a form for the file
|
||||
@@ -176,8 +211,13 @@ trait FileActions
|
||||
public function delete(): bool
|
||||
{
|
||||
return $this->commit('delete', [$this], function ($file) {
|
||||
|
||||
// remove all versions in the media folder
|
||||
$file->unpublish();
|
||||
|
||||
// remove the lock of the old file
|
||||
$file->lock()->remove();
|
||||
|
||||
if ($file->kirby()->multilang() === true) {
|
||||
foreach ($file->translations() as $translation) {
|
||||
F::remove($file->contentFile($translation->code()));
|
||||
@@ -198,7 +238,7 @@ trait FileActions
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function publish(): self
|
||||
public function publish()
|
||||
{
|
||||
Media::publish($this->root(), $this->mediaRoot());
|
||||
return $this;
|
||||
@@ -226,7 +266,7 @@ trait FileActions
|
||||
* @param string $source
|
||||
* @return self
|
||||
*/
|
||||
public function replace(string $source): self
|
||||
public function replace(string $source)
|
||||
{
|
||||
return $this->commit('replace', [$this, new Image($source)], function ($file, $upload) {
|
||||
|
||||
@@ -248,7 +288,7 @@ trait FileActions
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function unpublish(): self
|
||||
public function unpublish()
|
||||
{
|
||||
Media::unpublish($this->parent()->mediaRoot(), $this->filename());
|
||||
return $this;
|
||||
|
Reference in New Issue
Block a user