update kirby to v5 and add refresh cache panel view button

This commit is contained in:
isUnknown 2025-09-10 14:28:38 +02:00
commit 9a86d41254
466 changed files with 19960 additions and 10497 deletions

View file

@ -2,9 +2,12 @@
namespace Kirby\Cms;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\F;
use Kirby\Uuid\HasUuids;
use Throwable;
/**
* The `$files` object extends the general
@ -19,6 +22,8 @@ use Kirby\Uuid\HasUuids;
* @link https://getkirby.com
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*
* @extends \Kirby\Cms\Collection<\Kirby\Cms\File>
*/
class Files extends Collection
{
@ -29,12 +34,17 @@ class Files extends Collection
*/
public static array $methods = [];
/**
* @var \Kirby\Cms\Page|\Kirby\Cms\Site|\Kirby\Cms\User
*/
protected object|null $parent = null;
/**
* Adds a single file or
* an entire second collection to the
* current collection
*
* @param \Kirby\Cms\Files|\Kirby\Cms\File|string $object
* @param static|\Kirby\Cms\File|string $object
* @return $this
* @throws \Kirby\Exception\InvalidArgumentException When no `File` or `Files` object or an ID of an existing file is passed
*/
@ -42,23 +52,25 @@ class Files extends Collection
{
// add a files collection
if ($object instanceof self) {
$this->data = array_merge($this->data, $object->data);
$this->data = [...$this->data, ...$object->data];
// add a file by id
// add a file by id
} elseif (
is_string($object) === true &&
$file = App::instance()->file($object)
) {
$this->__set($file->id(), $file);
// add a file object
// add a file object
} elseif ($object instanceof File) {
$this->__set($object->id(), $object);
// give a useful error message on invalid input;
// silently ignore "empty" values for compatibility with existing setups
// give a useful error message on invalid input;
// silently ignore "empty" values for compatibility with existing setups
} elseif (in_array($object, [null, false, true], true) !== true) {
throw new InvalidArgumentException('You must pass a Files or File object or an ID of an existing file to the Files collection');
throw new InvalidArgumentException(
message: 'You must pass a Files or File object or an ID of an existing file to the Files collection'
);
}
return $this;
@ -84,11 +96,48 @@ class Files extends Collection
return $this;
}
/**
* Deletes the files with the given IDs
* if they exist in the collection
*
* @throws \Kirby\Exception\Exception If not all files could be deleted
*/
public function delete(array $ids): void
{
$exceptions = [];
// delete all pages and collect errors
foreach ($ids as $id) {
try {
$model = $this->get($id);
if ($model instanceof File === false) {
throw new NotFoundException(
key: 'file.undefined'
);
}
$model->delete();
} catch (Throwable $e) {
$exceptions[$id] = $e;
}
}
if ($exceptions !== []) {
throw new Exception(
key: 'file.delete.multiple',
details: $exceptions
);
}
}
/**
* Creates a files collection from an array of props
*/
public static function factory(array $files, Page|Site|User $parent): static
{
public static function factory(
array $files,
Page|Site|User $parent
): static {
$collection = new static([], $parent);
foreach ($files as $props) {
@ -126,7 +175,7 @@ class Files extends Collection
* `null` for the current locale,
* `false` to disable number formatting
*/
public function niceSize($locale = null): string
public function niceSize(string|false|null $locale = null): string
{
return F::niceSize($this->size(), $locale);
}