Skip to content

Commit

Permalink
Merge pull request #4807 from getkirby/release/3.8.1.1
Browse files Browse the repository at this point in the history
3.8.1.1
  • Loading branch information
bastianallgeier authored Oct 25, 2022
2 parents 021ad65 + a4a1804 commit 04ef75b
Show file tree
Hide file tree
Showing 18 changed files with 491 additions and 83 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "The Kirby 3 core",
"license": "proprietary",
"type": "kirby-cms",
"version": "3.8.1",
"version": "3.8.1.1",
"keywords": [
"kirby",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions i18n/translations/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"days.tue": "Ti",
"days.wed": "Ke",

"debugging": "Debugging",
"debugging": "Virheenkäsittelytila",

"delete": "Poista",
"delete.all": "Poista kaikki",
Expand Down Expand Up @@ -162,7 +162,7 @@

"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.changeLanguage.permission": "Sinulla ei ole oikeutta vaihtaa käyttäjän \"{name}\" kieltä",
Expand Down Expand Up @@ -493,14 +493,14 @@
"sort": "Järjestele",

"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.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.git": "The .git folder seems to be exposed",
"system.issues.debug": "Virheenkäsittelytila pitää poistaa käytöstä tuotantoympäristössä",
"system.issues.git": ".git-kansio näyttäisi olevan julkinen",
"system.issues.https": "Suosittelemme HTTPS:n käyttöä kaikilla sivustoillasi",
"system.issues.kirby": "The kirby folder seems to be exposed",
"system.issues.site": "The site folder seems to be exposed",
"system.issues.kirby": "Kirby-kansio näyttäisi olevan julkinen",
"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.plugin": "Asennuksesi käyttämä liitännäinen { plugin } voi olla altis haavoittuvuudelle ({ severity } vakavuus): { description }",
"system.updateStatus": "Päivitysten tilanne",
Expand Down
2 changes: 1 addition & 1 deletion panel/dist/js/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion panel/src/components/Sections/FilesSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default {
}
},
created() {
this.load();
this.$events.$on("model.update", this.reload);
this.$events.$on("file.sort", this.reload);
},
Expand Down
1 change: 0 additions & 1 deletion panel/src/components/Sections/PagesSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default {
}
},
created() {
this.load();
this.$events.$on("page.changeStatus", this.reload);
this.$events.$on("page.sort", this.reload);
},
Expand Down
4 changes: 2 additions & 2 deletions src/Cms/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,14 +925,14 @@ public function language(string $code = null)
}

if ($code === 'default') {
return $this->languages()->default();
return $this->defaultLanguage();
}

if ($code !== null) {
return $this->languages()->find($code);
}

return $this->language = $this->language ?? $this->languages()->default();
return $this->language = $this->language ?? $this->defaultLanguage();
}

/**
Expand Down
66 changes: 41 additions & 25 deletions src/Cms/ModelWithContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kirby\Toolkit\Str;
use Kirby\Uuid\Identifiable;
use Kirby\Uuid\Uuid;
use Kirby\Uuid\Uuids;
use Throwable;

/**
Expand Down Expand Up @@ -93,32 +94,33 @@ public function content(string $languageCode = null)

// don't normalize field keys (already handled by the `Data` class)
return $this->content = new Content($this->readContent(), $this, false);
}

// multi language support
} else {
// only fetch from cache for the default language
if (
$languageCode === null &&
$this->content instanceof Content
) {
return $this->content;
}
// get the targeted language
$language = $this->kirby()->language($languageCode);

// get the translation by code
if ($translation = $this->translation($languageCode)) {
// don't normalize field keys (already handled by the `ContentTranslation` class)
$content = new Content($translation->content(), $this, false);
} else {
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}
// stop if the language does not exist
if ($language === null) {
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}

// only store the content for the current language
if ($languageCode === null) {
$this->content = $content;
}
// only fetch from cache for the current language
if ($languageCode === null && $this->content instanceof Content) {
return $this->content;
}

// get the translation by code
$translation = $this->translation($language->code());

// don't normalize field keys (already handled by the `ContentTranslation` class)
$content = new Content($translation->content(), $this, false);

return $content;
// only store the content for the current language
if ($languageCode === null) {
$this->content = $content;
}

return $content;
}

/**
Expand Down Expand Up @@ -375,11 +377,16 @@ public function query(string $query = null, string $expect = null)
*/
public function readContent(string $languageCode = null): array
{
try {
return Data::read($this->contentFile($languageCode));
} catch (Throwable) {
$file = $this->contentFile($languageCode);

// 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 Data::read($file);
}

/**
Expand Down Expand Up @@ -462,6 +469,11 @@ protected function saveTranslation(array $data = null, string $languageCode = nu
}
}

// remove UUID for non-default languages
if (Uuids::enabled() === true && isset($content['uuid']) === true) {
$content['uuid'] = null;
}

// merge the translation with the new data
$translation->update($content, true);
}
Expand Down Expand Up @@ -567,7 +579,11 @@ public function toString(string $template = null, array $data = [], string|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;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Data/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ abstract public static function encode($data): string;
public static function read(string $file): array
{
$contents = F::read($file);

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);
Expand Down
4 changes: 2 additions & 2 deletions src/Filesystem/F.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,14 @@ public static function niceSize(
public static function read(string $file): string|false
{
if (
is_file($file) !== true &&
is_readable($file) !== true &&
Str::startsWith($file, 'https://') !== true &&
Str::startsWith($file, 'http://') !== true
) {
return false;
}

return @file_get_contents($file);
return file_get_contents($file);
}

/**
Expand Down
57 changes: 42 additions & 15 deletions src/Uuid/ModelUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,11 @@ public function id(): string
return $id;
}

// generate ID and write to content file
// generate a new ID (to be saved in the content file)
$id = static::generate();

// make sure Kirby has the required permissions
// for the update action
$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])
// );
// store the new UUID
$this->storeId($id);

// update the Uri object
$this->uri->host($id);
Expand All @@ -91,7 +80,45 @@ public function id(): string
*/
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');
}

/**
Expand Down
Loading

0 comments on commit 04ef75b

Please sign in to comment.