Upgrade to 3.8.3

This commit is contained in:
Bastian Allgeier
2022-12-06 15:37:13 +01:00
parent f9e812cb0c
commit 8381ccb96c
69 changed files with 752 additions and 966 deletions

View File

@@ -1603,7 +1603,9 @@ class App
if ($options === false) {
return $text;
} elseif (is_array($options) === false) {
}
if (is_array($options) === false) {
$options = [];
}

View File

@@ -2,8 +2,10 @@
namespace Kirby\Cms;
use Kirby\Cms\Auth\Challenge;
use Kirby\Cms\Auth\Status;
use Kirby\Data\Data;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\LogicException;
use Kirby\Exception\NotFoundException;
@@ -133,7 +135,7 @@ class Auth
if (
$class &&
class_exists($class) === true &&
is_subclass_of($class, 'Kirby\Cms\Auth\Challenge') === true &&
is_subclass_of($class, Challenge::class) === true &&
$class::isAvailable($user, $mode) === true
) {
$challenge = $name;
@@ -543,7 +545,7 @@ class Auth
]
]);
} catch (Throwable $e) {
$details = is_a($e, 'Kirby\Exception\Exception') === true ? $e->getDetails() : [];
$details = $e instanceof Exception ? $e->getDetails() : [];
// log invalid login trial unless the rate limit is already active
if (($details['reason'] ?? null) !== 'rate-limited') {
@@ -848,7 +850,7 @@ class Auth
if (
isset(static::$challenges[$challenge]) === true &&
class_exists(static::$challenges[$challenge]) === true &&
is_subclass_of(static::$challenges[$challenge], 'Kirby\Cms\Auth\Challenge') === true
is_subclass_of(static::$challenges[$challenge], Challenge::class) === true
) {
$class = static::$challenges[$challenge];
if ($class::verify($user, $code) === true) {

View File

@@ -22,7 +22,7 @@ class Block extends Item
{
use HasMethods;
public const ITEMS_CLASS = '\Kirby\Cms\Blocks';
public const ITEMS_CLASS = Blocks::class;
/**
* @var \Kirby\Cms\Content

View File

@@ -20,7 +20,7 @@ use Throwable;
*/
class Blocks extends Items
{
public const ITEM_CLASS = '\Kirby\Cms\Block';
public const ITEM_CLASS = Block::class;
/**
* Return HTML when the collection is

View File

@@ -19,7 +19,7 @@ use Kirby\Toolkit\Str;
*/
class Fieldset extends Item
{
public const ITEMS_CLASS = '\Kirby\Cms\Fieldsets';
public const ITEMS_CLASS = Fieldsets::class;
protected $disabled;
protected $editable;

View File

@@ -19,7 +19,7 @@ use Kirby\Toolkit\Str;
*/
class Fieldsets extends Items
{
public const ITEM_CLASS = '\Kirby\Cms\Fieldset';
public const ITEM_CLASS = Fieldset::class;
protected static function createFieldsets($params)
{

View File

@@ -120,13 +120,12 @@ trait FileActions
$result = $callback(...$argumentValues);
if ($action === 'create') {
$argumentsAfter = ['file' => $result];
} elseif ($action === 'delete') {
$argumentsAfter = ['status' => $result, 'file' => $old];
} else {
$argumentsAfter = ['newFile' => $result, 'oldFile' => $old];
}
$argumentsAfter = match ($action) {
'create' => ['file' => $result],
'delete' => ['status' => $result, 'file' => $old],
default => ['newFile' => $result, 'oldFile' => $old]
};
$kirby->trigger('file.' . $action . ':after', $argumentsAfter);
$kirby->cache('pages')->flush();

View File

@@ -3,6 +3,7 @@
namespace Kirby\Cms;
use Kirby\Filesystem\F;
use Kirby\Filesystem\Mime;
use Kirby\Toolkit\Str;
/**
@@ -81,7 +82,10 @@ class FileBlueprint extends Blueprint
if (is_array($accept['extension']) === true) {
// determine the main MIME type for each extension
$restrictions[] = array_map(['Kirby\Filesystem\Mime', 'fromExtension'], $accept['extension']);
$restrictions[] = array_map(
[Mime::class, 'fromExtension'],
$accept['extension']
);
}
if (is_array($accept['type']) === true) {
@@ -89,7 +93,10 @@ class FileBlueprint extends Blueprint
$mimes = [];
foreach ($accept['type'] as $type) {
if ($extensions = F::typeToExtensions($type)) {
$mimes[] = array_map(['Kirby\Filesystem\Mime', 'fromExtension'], $extensions);
$mimes[] = array_map(
[Mime::class, 'fromExtension'],
$extensions
);
}
}
@@ -119,19 +126,15 @@ class FileBlueprint extends Blueprint
*/
protected function normalizeAccept($accept = null): array
{
if (is_string($accept) === true) {
$accept = [
'mime' => $accept
];
} elseif ($accept === true) {
$accept = match (true) {
is_string($accept) => ['mime' => $accept],
// explicitly no restrictions at all
$accept = [
'mime' => null
];
} elseif (empty($accept) === true) {
$accept === true => ['mime' => null],
// no custom restrictions
$accept = [];
}
empty($accept) === true => [],
// custom restrictions
default => $accept
};
$accept = array_change_key_case($accept);

View File

@@ -41,13 +41,14 @@ class FilePicker extends Picker
$model = $this->options['model'];
// find the right default query
if (empty($this->options['query']) === false) {
$query = $this->options['query'];
} elseif ($model instanceof File) {
$query = 'file.siblings';
} else {
$query = $model::CLASS_ALIAS . '.files';
}
$query = match (true) {
empty($this->options['query']) === false
=> $this->options['query'],
$model instanceof File
=> 'file.siblings',
default
=> $model::CLASS_ALIAS . '.files'
};
// fetch all files for the picker
$files = $model->query($query);

View File

@@ -24,7 +24,7 @@ class Item
{
use HasSiblings;
public const ITEMS_CLASS = '\Kirby\Cms\Items';
public const ITEMS_CLASS = Items::class;
/**
* @var string

View File

@@ -17,7 +17,7 @@ use Exception;
*/
class Items extends Collection
{
public const ITEM_CLASS = '\Kirby\Cms\Item';
public const ITEM_CLASS = Item::class;
/**
* @var array

View File

@@ -212,6 +212,15 @@ class Language extends Model
$language = new static($props);
// trigger before hook
$kirby->trigger(
'language.create:before',
[
'input' => $props,
'language' => $language
]
);
// validate the new language
LanguageRules::create($language);
@@ -222,7 +231,16 @@ class Language extends Model
}
// update the main languages collection in the app instance
App::instance()->languages(false)->append($language->code(), $language);
$kirby->languages(false)->append($language->code(), $language);
// trigger after hook
$kirby->trigger(
'language.create:after',
[
'input' => $props,
'language' => $language
]
);
return $language;
}
@@ -242,6 +260,11 @@ class Language extends Model
$code = $this->code();
$isLast = $languages->count() === 1;
// trigger before hook
$kirby->trigger('language.delete:before', [
'language' => $this
]);
if (F::remove($this->root()) !== true) {
throw new Exception('The language could not be deleted');
}
@@ -255,6 +278,11 @@ class Language extends Model
// get the original language collection and remove the current language
$kirby->languages(false)->remove($code);
// trigger after hook
$kirby->trigger('language.delete:after', [
'language' => $this
]);
return true;
}
@@ -660,6 +688,12 @@ class Language extends Model
// validate the updated language
LanguageRules::update($updated);
// trigger before hook
$kirby->trigger('language.update:before', [
'language' => $this,
'input' => $props
]);
// convert the current default to a non-default language
if ($updated->isDefault() === true) {
$kirby->defaultLanguage()?->clone(['default' => false])->save();
@@ -687,6 +721,13 @@ class Language extends Model
// make sure the language is also updated in the Kirby language collection
App::instance()->languages(false)->set($language->code(), $language);
// trigger after hook
$kirby->trigger('language.update:after', [
'newLanguage' => $language,
'oldLanguage' => $this,
'input' => $props
]);
return $language;
}
}

View File

@@ -17,7 +17,7 @@ class Layout extends Item
{
use HasMethods;
public const ITEMS_CLASS = '\Kirby\Cms\Layouts';
public const ITEMS_CLASS = Layouts::class;
/**
* @var \Kirby\Cms\Content

View File

@@ -19,7 +19,7 @@ class LayoutColumn extends Item
{
use HasMethods;
public const ITEMS_CLASS = '\Kirby\Cms\LayoutColumns';
public const ITEMS_CLASS = LayoutColumns::class;
/**
* @var \Kirby\Cms\Blocks

View File

@@ -14,5 +14,5 @@ namespace Kirby\Cms;
*/
class LayoutColumns extends Items
{
public const ITEM_CLASS = '\Kirby\Cms\LayoutColumn';
public const ITEM_CLASS = LayoutColumn::class;
}

View File

@@ -18,7 +18,7 @@ use Throwable;
*/
class Layouts extends Items
{
public const ITEM_CLASS = '\Kirby\Cms\Layout';
public const ITEM_CLASS = Layout::class;
public static function factory(array $items = null, array $params = [])
{

View File

@@ -97,16 +97,17 @@ class Media
{
$kirby = App::instance();
// assets
if (is_string($model) === true) {
$root = $kirby->root('media') . '/assets/' . $model . '/' . $hash;
// parent files for file model that already included hash
} elseif ($model instanceof File) {
$root = dirname($model->mediaRoot());
// model files
} else {
$root = $model->mediaRoot() . '/' . $hash;
}
$root = match (true) {
// assets
is_string($model)
=> $kirby->root('media') . '/assets/' . $model . '/' . $hash,
// parent files for file model that already included hash
$model instanceof File
=> dirname($model->mediaRoot()),
// model files
default
=> $model->mediaRoot() . '/' . $hash
};
try {
$thumb = $root . '/' . $filename;
@@ -117,11 +118,12 @@ class Media
return false;
}
if (is_string($model) === true) {
$source = $kirby->root('index') . '/' . $model . '/' . $options['filename'];
} else {
$source = $model->file($options['filename'])->root();
}
$source = match (true) {
is_string($model) === true
=> $kirby->root('index') . '/' . $model . '/' . $options['filename'],
default
=> $model->file($options['filename'])->root()
};
try {
$kirby->thumb($source, $thumb, $options);

View File

@@ -1060,9 +1060,24 @@ class Page extends ModelWithContent
$kirby->data = $this->controller($data, $contentType);
// trigger before hook and apply for `data`
$kirby->data = $kirby->apply('page.render:before', [
'contentType' => $contentType,
'data' => $kirby->data,
'page' => $this
], 'data');
// render the page
$html = $template->render($kirby->data);
// trigger after hook and apply for `html`
$html = $kirby->apply('page.render:after', [
'contentType' => $contentType,
'data' => $kirby->data,
'html' => $html,
'page' => $this
], 'html');
// cache the result
$response = $kirby->response();
if ($cache !== null && $response->cache() === true) {

View File

@@ -31,7 +31,7 @@ trait PageActions
* Adapts necessary modifications which page uuid, page slug and files uuid
* of copy objects for single or multilang environments
*/
protected function adaptCopy(Page $copy, bool $files = false): Page
protected function adaptCopy(Page $copy, bool $files = false, bool $children = false): Page
{
if ($this->kirby()->multilang() === true) {
foreach ($this->kirby()->languages() as $language) {
@@ -43,11 +43,21 @@ trait PageActions
) {
$copy = $copy->save(['uuid' => Uuid::generate()], $language->code());
// regenerate UUIDs of page files
if ($files !== false) {
foreach ($copy->files() as $file) {
$file->save(['uuid' => Uuid::generate()], $language->code());
}
}
// regenerate UUIDs of all page children
if ($children !== false) {
foreach ($copy->index(true) as $child) {
// always adapt files of subpages as they are currently always copied;
// but don't adapt children because we already operate on the index
$this->adaptCopy($child, true);
}
}
}
// remove all translated slugs
@@ -66,11 +76,21 @@ trait PageActions
if (Uuids::enabled() === true) {
$copy = $copy->save(['uuid' => Uuid::generate()]);
// regenerate UUIDs of page files
if ($files !== false) {
foreach ($copy->files() as $file) {
$file->save(['uuid' => Uuid::generate()]);
}
}
// regenerate UUIDs of all page children
if ($children !== false) {
foreach ($copy->index(true) as $child) {
// always adapt files of subpages as they are currently always copied;
// but don't adapt children because we already operate on the index
$this->adaptCopy($child, true);
}
}
}
return $copy;
@@ -484,7 +504,7 @@ trait PageActions
$copy = $parentModel->clone()->findPageOrDraft($slug);
// normalize copy object
$copy = $this->adaptCopy($copy, $files);
$copy = $this->adaptCopy($copy, $files, $children);
// add copy to siblings
static::updateParentCollections($copy, 'append', $parentModel);