Upgrade to 3.9.7

This commit is contained in:
Bastian Allgeier
2023-10-06 12:54:54 +02:00
parent 035d655ca1
commit 474ecd14c7
54 changed files with 714 additions and 329 deletions

View File

@@ -67,10 +67,10 @@ class Api extends BaseApi
* Returns the file object for the given
* parent path and filename
*
* @param string|null $path Path to file's parent model
* @param string $path Path to file's parent model
* @throws \Kirby\Exception\NotFoundException if the file cannot be found
*/
public function file(string|null $path = null, string $filename): File|null
public function file(string $path, string $filename): File|null
{
return Find::file($path, $filename);
}

View File

@@ -203,7 +203,6 @@ class App
/**
* Applies a hook to the given value
*
* @internal
* @param string $name Full event name
* @param array $args Associative array of named event arguments
* @param string $modify Key in $args that is modified by the hooks
@@ -1675,7 +1674,6 @@ class App
/**
* Trigger a hook by name
*
* @internal
* @param string $name Full event name
* @param array $args Associative array of named event arguments
* @param \Kirby\Cms\Event|null $originalEvent Event object (internal use)

View File

@@ -73,7 +73,7 @@ trait AppErrors
$handler = null;
if ($this->option('debug') === true) {
if ($this->option('whoops', true) === true) {
if ($this->option('whoops', true) !== false) {
$handler = new PrettyPageHandler();
$handler->setPageTitle('Kirby CMS Debugger');
$handler->setResourcesPath(dirname(__DIR__, 2) . '/assets');
@@ -82,6 +82,14 @@ trait AppErrors
if ($editor = $this->option('editor')) {
$handler->setEditor($editor);
}
if ($blocklist = $this->option('whoops.blocklist')) {
foreach ($blocklist as $superglobal => $vars) {
foreach ($vars as $var) {
$handler->blacklist($superglobal, $var);
}
}
}
}
} else {
$handler = new CallbackHandler(function ($exception, $inspector, $run) {

View File

@@ -168,9 +168,7 @@ class Collection extends BaseCollection
}
// ignore upper/lowercase for group names
if ($i) {
$value = Str::lower($value);
}
$value = $i === true ? Str::lower($value) : (string)$value;
if (isset($groups->data[$value]) === false) {
// create a new entry for the group if it does not exist yet

View File

@@ -23,12 +23,12 @@ class Find
* Returns the file object for the given
* parent path and filename
*
* @param string|null $path Path to file's parent model
* @param string $path Path to file's parent model
* @param string $filename Filename
* @return \Kirby\Cms\File|null
* @throws \Kirby\Exception\NotFoundException if the file cannot be found
*/
public static function file(string $path = null, string $filename)
public static function file(string $path, string $filename)
{
$filename = urldecode($filename);
$file = static::parent($path)->file($filename);

View File

@@ -733,7 +733,7 @@ class Page extends ModelWithContent
*/
public function isListed(): bool
{
return $this->num() !== null;
return $this->isPublished() && $this->num() !== null;
}
/**
@@ -797,7 +797,7 @@ class Page extends ModelWithContent
*/
public function isUnlisted(): bool
{
return $this->isListed() === false;
return $this->isPublished() && $this->num() === null;
}
/**
@@ -811,7 +811,7 @@ class Page extends ModelWithContent
public function isVerified(string $token = null)
{
if (
$this->isDraft() === false &&
$this->isPublished() === true &&
$this->parents()->findBy('status', 'draft') === null
) {
return true;

View File

@@ -352,7 +352,7 @@ class User extends ModelWithContent
*/
public function isKirby(): bool
{
return $this->email() === 'kirby@getkirby.com';
return $this->isAdmin() && $this->id() === 'kirby';
}
/**
@@ -396,7 +396,7 @@ class User extends ModelWithContent
*/
public function isNobody(): bool
{
return $this->email() === 'nobody@getkirby.com';
return $this->role()->id() === 'nobody' && $this->id() === 'nobody';
}
/**
@@ -406,7 +406,9 @@ class User extends ModelWithContent
*/
public function language(): string
{
return $this->language ??= $this->credentials()['language'] ?? $this->kirby()->panelLanguage();
return $this->language ??=
$this->credentials()['language'] ??
$this->kirby()->panelLanguage();
}
/**

View File

@@ -301,8 +301,8 @@ class UserRules
*/
public static function validId(User $user, string $id): bool
{
if ($id === 'account') {
throw new InvalidArgumentException('"account" is a reserved word and cannot be used as user id');
if (in_array($id, ['account', 'kirby', 'nobody']) === true) {
throw new InvalidArgumentException('"' . $id . '" is a reserved word and cannot be used as user id');
}
if ($user->kirby()->users()->find($id)) {

View File

@@ -3,9 +3,10 @@
namespace Kirby\Database;
use Closure;
use Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Collection;
use Kirby\Toolkit\Obj;
use Kirby\Toolkit\Str;
use PDO;
use PDOStatement;
@@ -337,13 +338,16 @@ class Database
/**
* Executes a sql query, which is expected to return a set of results
*/
public function query(string $query, array $bindings = [], array $params = [])
{
public function query(
string $query,
array $bindings = [],
array $params = []
) {
$defaults = [
'flag' => null,
'method' => 'fetchAll',
'fetch' => 'Kirby\Toolkit\Obj',
'iterator' => 'Kirby\Toolkit\Collection',
'fetch' => Obj::class,
'iterator' => Collection::class,
];
$options = array_merge($defaults, $params);
@@ -359,7 +363,7 @@ class Database
) {
$flags = PDO::FETCH_ASSOC;
} else {
$flags = PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE;
$flags = PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE;
}
// add optional flags
@@ -368,7 +372,10 @@ class Database
}
// set the fetch mode
if ($options['fetch'] instanceof Closure || $options['fetch'] === 'array') {
if (
$options['fetch'] instanceof Closure ||
$options['fetch'] === 'array'
) {
$this->statement->setFetchMode($flags);
} else {
$this->statement->setFetchMode($flags, $options['fetch']);
@@ -379,8 +386,14 @@ class Database
// apply the fetch closure to all results if given
if ($options['fetch'] instanceof Closure) {
foreach ($results as $key => $result) {
$results[$key] = $options['fetch']($result, $key);
if ($options['method'] === 'fetchAll') {
// fetching multiple records
foreach ($results as $key => $result) {
$results[$key] = $options['fetch']($result, $key);
}
} elseif ($options['method'] === 'fetch' && $results !== false) {
// fetching a single record
$results = $options['fetch']($results, null);
}
}

View File

@@ -189,8 +189,12 @@ class Query
*
* @return $this
*/
public function fetch(string|Closure $fetch): static
public function fetch(string|callable|Closure $fetch): static
{
if (is_callable($fetch) === true) {
$fetch = Closure::fromCallable($fetch);
}
$this->fetch = $fetch;
return $this;
}
@@ -623,7 +627,7 @@ class Query
/**
* Selects only one row from a table
*/
public function first(): object|array|false
public function first(): mixed
{
return $this->query($this->offset(0)->limit(1)->build('select'), [
'fetch' => $this->fetch,
@@ -635,7 +639,7 @@ class Query
/**
* Selects only one row from a table
*/
public function row(): object|array|false
public function row(): mixed
{
return $this->first();
}
@@ -643,7 +647,7 @@ class Query
/**
* Selects only one row from a table
*/
public function one(): object|array|false
public function one(): mixed
{
return $this->first();
}

View File

@@ -531,7 +531,7 @@ class Collection extends Iterator implements Countable
$value = $this->getAttribute($item, $field);
// ignore upper/lowercase for group names
return $i === true ? Str::lower($value) : $value;
return $i === true ? Str::lower($value) : (string)$value;
});
}

View File

@@ -626,6 +626,8 @@ class Str
'alpha' => static::pool(['alphaLower', 'alphaUpper']),
'num' => range(0, 9),
'alphanum' => static::pool(['alpha', 'num']),
'base32' => array_merge(static::pool('alphaUpper'), range(2, 7)),
'base32hex' => array_merge(range(0, 9), range('A', 'V')),
default => $pool
};
}

View File

@@ -46,7 +46,7 @@ class SiteUuid extends Uuid
/**
* Pretends to fill cache - we don't need it in cache
*/
public function populate(): bool
public function populate(bool $force = false): bool
{
return true;
}

View File

@@ -46,7 +46,7 @@ class UserUuid extends Uuid
/**
* Pretends to fill cache - we don't need it in cache
*/
public function populate(): bool
public function populate(bool $force = false): bool
{
return true;
}

View File

@@ -309,7 +309,8 @@ class Uuid
// lazily fill cache by writing to cache
// whenever looked up from index to speed
// up future lookups of the same UUID
$this->populate();
// also force to update value again if it is already cached
$this->populate($this->isCached());
return $this->model;
}
@@ -320,12 +321,10 @@ class Uuid
/**
* Feeds the UUID into the cache
*
* @return bool
*/
public function populate(): bool
public function populate(bool $force = false): bool
{
if ($this->isCached() === true) {
if ($force === false && $this->isCached() === true) {
return true;
}