Upgrade to 3.8.1.1

This commit is contained in:
Bastian Allgeier
2022-10-25 11:51:57 +02:00
parent 9c93e01c3a
commit de62b5f553
10 changed files with 107 additions and 63 deletions

View File

@@ -3,7 +3,7 @@
"description": "The Kirby 3 core", "description": "The Kirby 3 core",
"license": "proprietary", "license": "proprietary",
"type": "kirby-cms", "type": "kirby-cms",
"version": "3.8.1", "version": "3.8.1.1",
"keywords": [ "keywords": [
"kirby", "kirby",
"cms", "cms",

2
kirby/composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "5e9506721e0c7075e680219a6dff9d0b", "content-hash": "7e1f67ac895b8dc38cd8c53188565545",
"packages": [ "packages": [
{ {
"name": "claviska/simpleimage", "name": "claviska/simpleimage",

View File

@@ -29,7 +29,7 @@
"days.tue": "Ti", "days.tue": "Ti",
"days.wed": "Ke", "days.wed": "Ke",
"debugging": "Debugging", "debugging": "Virheenkäsittelytila",
"delete": "Poista", "delete": "Poista",
"delete.all": "Poista kaikki", "delete.all": "Poista kaikki",
@@ -162,7 +162,7 @@
"error.template.default.notFound": "Oletussivupohjaa ei ole määritetty", "error.template.default.notFound": "Oletussivupohjaa ei ole määritetty",
"error.unexpected": "An unexpected error occurred! Enable debug mode for more info: https://getkirby.com/docs/reference/system/options/debug", "error.unexpected": "Pahus, määrittelemätön virhe! Laita virheenkäsittelytila päälle saadaksesi lisätietoja: https://getkirby.com/docs/reference/system/options/debug",
"error.user.changeEmail.permission": "Sinulla ei ole oikeutta vaihtaa käyttäjän \"{name}\" sähköpostiosoitetta", "error.user.changeEmail.permission": "Sinulla ei ole oikeutta vaihtaa käyttäjän \"{name}\" sähköpostiosoitetta",
"error.user.changeLanguage.permission": "Sinulla ei ole oikeutta vaihtaa käyttäjän \"{name}\" kieltä", "error.user.changeLanguage.permission": "Sinulla ei ole oikeutta vaihtaa käyttäjän \"{name}\" kieltä",
@@ -493,14 +493,14 @@
"sort": "Järjestele", "sort": "Järjestele",
"stats.empty": "Ei raportteja", "stats.empty": "Ei raportteja",
"system.issues.content": "The content folder seems to be exposed", "system.issues.content": "Content-kansio näyttäisi olevan julkinen",
"system.issues.eol.kirby": "Your installed Kirby version has reached end-of-life and will not receive further security updates", "system.issues.eol.kirby": "Your installed Kirby version has reached end-of-life and will not receive further security updates",
"system.issues.eol.plugin": "Your installed version of the { plugin } plugin is has reached end-of-life and will not receive further security updates", "system.issues.eol.plugin": "Your installed version of the { plugin } plugin is has reached end-of-life and will not receive further security updates",
"system.issues.debug": "Debugging must be turned off in production", "system.issues.debug": "Virheenkäsittelytila pitää poistaa käytöstä tuotantoympäristössä",
"system.issues.git": "The .git folder seems to be exposed", "system.issues.git": ".git-kansio näyttäisi olevan julkinen",
"system.issues.https": "Suosittelemme HTTPS:n käyttöä kaikilla sivustoillasi", "system.issues.https": "Suosittelemme HTTPS:n käyttöä kaikilla sivustoillasi",
"system.issues.kirby": "The kirby folder seems to be exposed", "system.issues.kirby": "Kirby-kansio näyttäisi olevan julkinen",
"system.issues.site": "The site folder seems to be exposed", "system.issues.site": "Site-kansio näyttäisi olevan julkinen",
"system.issues.vulnerability.kirby": "Asennuksesi voi olla altis seuraaville haavoittuvuuksille ({ severity } vakavuus): { description }", "system.issues.vulnerability.kirby": "Asennuksesi voi olla altis seuraaville haavoittuvuuksille ({ severity } vakavuus): { description }",
"system.issues.vulnerability.plugin": "Asennuksesi käyttämä liitännäinen { plugin } voi olla altis haavoittuvuudelle ({ severity } vakavuus): { description }", "system.issues.vulnerability.plugin": "Asennuksesi käyttämä liitännäinen { plugin } voi olla altis haavoittuvuudelle ({ severity } vakavuus): { description }",
"system.updateStatus": "Päivitysten tilanne", "system.updateStatus": "Päivitysten tilanne",

File diff suppressed because one or more lines are too long

View File

@@ -925,14 +925,14 @@ class App
} }
if ($code === 'default') { if ($code === 'default') {
return $this->languages()->default(); return $this->defaultLanguage();
} }
if ($code !== null) { if ($code !== null) {
return $this->languages()->find($code); return $this->languages()->find($code);
} }
return $this->language = $this->language ?? $this->languages()->default(); return $this->language = $this->language ?? $this->defaultLanguage();
} }
/** /**

View File

@@ -9,6 +9,7 @@ use Kirby\Form\Form;
use Kirby\Toolkit\Str; use Kirby\Toolkit\Str;
use Kirby\Uuid\Identifiable; use Kirby\Uuid\Identifiable;
use Kirby\Uuid\Uuid; use Kirby\Uuid\Uuid;
use Kirby\Uuid\Uuids;
use Throwable; use Throwable;
/** /**
@@ -93,24 +94,26 @@ abstract class ModelWithContent extends Model implements Identifiable
// don't normalize field keys (already handled by the `Data` class) // don't normalize field keys (already handled by the `Data` class)
return $this->content = new Content($this->readContent(), $this, false); return $this->content = new Content($this->readContent(), $this, false);
}
// multi language support // get the targeted language
} else { $language = $this->kirby()->language($languageCode);
// only fetch from cache for the default language
if ( // stop if the language does not exist
$languageCode === null && if ($language === null) {
$this->content instanceof Content throw new InvalidArgumentException('Invalid language: ' . $languageCode);
) { }
// only fetch from cache for the current language
if ($languageCode === null && $this->content instanceof Content) {
return $this->content; return $this->content;
} }
// get the translation by code // get the translation by code
if ($translation = $this->translation($languageCode)) { $translation = $this->translation($language->code());
// don't normalize field keys (already handled by the `ContentTranslation` class) // don't normalize field keys (already handled by the `ContentTranslation` class)
$content = new Content($translation->content(), $this, false); $content = new Content($translation->content(), $this, false);
} else {
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}
// only store the content for the current language // only store the content for the current language
if ($languageCode === null) { if ($languageCode === null) {
@@ -119,7 +122,6 @@ abstract class ModelWithContent extends Model implements Identifiable
return $content; return $content;
} }
}
/** /**
* Returns the absolute path to the content file * Returns the absolute path to the content file
@@ -375,11 +377,16 @@ abstract class ModelWithContent extends Model implements Identifiable
*/ */
public function readContent(string $languageCode = null): array public function readContent(string $languageCode = null): array
{ {
try { $file = $this->contentFile($languageCode);
return Data::read($this->contentFile($languageCode));
} catch (Throwable) { // only if the content file really does not exist, it's ok
// to return empty content. Otherwise this could lead to
// content loss in case of file reading issues
if (file_exists($file) === false) {
return []; return [];
} }
return Data::read($file);
} }
/** /**
@@ -462,6 +469,11 @@ abstract class ModelWithContent extends Model implements Identifiable
} }
} }
// remove UUID for non-default languages
if (Uuids::enabled() === true && isset($content['uuid']) === true) {
$content['uuid'] = null;
}
// merge the translation with the new data // merge the translation with the new data
$translation->update($content, true); $translation->update($content, true);
} }
@@ -567,7 +579,11 @@ abstract class ModelWithContent extends Model implements Identifiable
*/ */
public function translation(string $languageCode = null) public function translation(string $languageCode = null)
{ {
return $this->translations()->find($languageCode ?? $this->kirby()->language()->code()); if ($language = $this->kirby()->language($languageCode)) {
return $this->translations()->find($language->code());
}
return null;
} }
/** /**

View File

@@ -36,8 +36,9 @@ abstract class Handler
public static function read(string $file): array public static function read(string $file): array
{ {
$contents = F::read($file); $contents = F::read($file);
if ($contents === false) { if ($contents === false) {
throw new Exception('The file "' . $file . '" does not exist'); throw new Exception('The file "' . $file . '" does not exist or cannot be read');
} }
return static::decode($contents); return static::decode($contents);

View File

@@ -577,14 +577,14 @@ class F
public static function read(string $file): string|false public static function read(string $file): string|false
{ {
if ( if (
is_file($file) !== true && is_readable($file) !== true &&
Str::startsWith($file, 'https://') !== true && Str::startsWith($file, 'https://') !== true &&
Str::startsWith($file, 'http://') !== true Str::startsWith($file, 'http://') !== true
) { ) {
return false; return false;
} }
return @file_get_contents($file); return file_get_contents($file);
} }
/** /**

View File

@@ -60,22 +60,11 @@ abstract class ModelUuid extends Uuid
return $id; return $id;
} }
// generate ID and write to content file // generate a new ID (to be saved in the content file)
$id = static::generate(); $id = static::generate();
// make sure Kirby has the required permissions // store the new UUID
// for the update action $this->storeId($id);
$kirby = App::instance();
$user = $kirby->auth()->currentUserFromImpersonation();
$kirby->impersonate('kirby');
$this->model = $this->model->save(['uuid' => $id]);
$kirby->impersonate($user);
// TODO: replace the above in 3.9.0 with
// App::instance()->impersonate(
// 'kirby',
// fn () => $this->model = $this->model->save(['uuid' => $id])
// );
// update the Uri object // update the Uri object
$this->uri->host($id); $this->uri->host($id);
@@ -91,7 +80,45 @@ abstract class ModelUuid extends Uuid
*/ */
public static function retrieveId(Identifiable $model): string|null public static function retrieveId(Identifiable $model): string|null
{ {
return $model->content()->get('uuid')->value(); return $model->content('default')->get('uuid')->value();
}
/**
* Stores the UUID for the model and makes sure
* to update the content file and content object cache
*/
protected function storeId(string $id): void
{
// get the content array from the page
$data = $this->model->content('default')->toArray();
// check for an empty content array
// and read content from file again,
// just to be sure we don't lose content
if (empty($data) === true) {
usleep(1000);
$data = $this->model->readContent('default');
}
// add the UUID to the content array
if (empty($data['uuid']) === true) {
$data['uuid'] = $id;
}
// overwrite the content in memory for the current request
if ($this->model->kirby()->multilang() === true) {
// update the default translation instead of the content object
// (the default content object is always freshly loaded from the
// default translation afterwards, so updating the default
// content object would not have any effect)
$this->model->translation('default')->update($data);
} else {
$this->model->content('default')->update($data);
}
// overwrite the content in the file;
// use the most basic write method to avoid object cloning
$this->model->writeContent($data, 'default');
} }
/** /**

View File

@@ -1,8 +1,8 @@
<?php return array( <?php return array(
'root' => array( 'root' => array(
'name' => 'getkirby/cms', 'name' => 'getkirby/cms',
'pretty_version' => '3.8.1', 'pretty_version' => '3.8.1.1',
'version' => '3.8.1.0', 'version' => '3.8.1.1',
'reference' => NULL, 'reference' => NULL,
'type' => 'kirby-cms', 'type' => 'kirby-cms',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
@@ -38,8 +38,8 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'getkirby/cms' => array( 'getkirby/cms' => array(
'pretty_version' => '3.8.1', 'pretty_version' => '3.8.1.1',
'version' => '3.8.1.0', 'version' => '3.8.1.1',
'reference' => NULL, 'reference' => NULL,
'type' => 'kirby-cms', 'type' => 'kirby-cms',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',