From 393ccc057c40238edc3d057956a4f345a405e474 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:06:56 +0200 Subject: [PATCH 01/17] Accept a VersionId instance in the ::from method --- src/Content/VersionId.php | 6 +++++- tests/Content/VersionIdTest.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Content/VersionId.php b/src/Content/VersionId.php index 3c35a27fe9..6d8f7eb5ef 100644 --- a/src/Content/VersionId.php +++ b/src/Content/VersionId.php @@ -79,8 +79,12 @@ public static function default(ModelWithContent $model): static /** * Creates a VersionId instance from a simple string value */ - public static function from(string $value): static + public static function from(self|string $value): static { + if ($value instanceof static) { + return $value; + } + return new static($value); } diff --git a/tests/Content/VersionIdTest.php b/tests/Content/VersionIdTest.php index 43d274e003..6a165e32c6 100644 --- a/tests/Content/VersionIdTest.php +++ b/tests/Content/VersionIdTest.php @@ -59,10 +59,19 @@ public function testDefault() * @covers ::from * @covers ::value */ - public function testFrom() + public function testFromString() { $version = VersionId::from('published'); + $this->assertSame('published', $version->value()); + } + /** + * @covers ::from + * @covers ::value + */ + public function testFromInstance() + { + $version = VersionId::from(VersionId::published()); $this->assertSame('published', $version->value()); } From eb14d8d3e64d5733bc0ab6257ab5ccaf1353a644 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:08:39 +0200 Subject: [PATCH 02/17] New ModelWithContent::version() method --- src/Cms/ModelWithContent.php | 13 +++++++++++++ tests/Cms/Models/ModelWithContentTest.php | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 7c817b9afa..3f3e9dcf91 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -7,6 +7,7 @@ use Kirby\Content\ContentStorage; use Kirby\Content\ContentTranslation; use Kirby\Content\PlainTextContentStorageHandler; +use Kirby\Content\Version; use Kirby\Content\VersionId; use Kirby\Exception\InvalidArgumentException; use Kirby\Exception\NotFoundException; @@ -730,6 +731,18 @@ public function uuid(): Uuid|null return Uuid::for($this); } + /** + * Returns a content version instance + * @since 5.0.0 + */ + public function version(VersionId|string $versionId): Version + { + return new Version( + model: $this, + id: VersionId::from($versionId) + ); + } + /** * Low level data writer method * to store the given data on disk or anywhere else diff --git a/tests/Cms/Models/ModelWithContentTest.php b/tests/Cms/Models/ModelWithContentTest.php index 94b1107224..82a5e83f46 100644 --- a/tests/Cms/Models/ModelWithContentTest.php +++ b/tests/Cms/Models/ModelWithContentTest.php @@ -3,6 +3,7 @@ namespace Kirby\Cms; use Closure; +use Kirby\Content\Version; use Kirby\Exception\InvalidArgumentException; use Kirby\Panel\Page as PanelPage; use Kirby\Uuid\PageUuid; @@ -443,4 +444,13 @@ public function testUuid() $model = new Page(['slug' => 'foo']); $this->assertInstanceOf(PageUuid::class, $model->uuid()); } + + public function testVersion() + { + $model = new Site(); + $this->assertInstanceOf(Version::class, $model->version('published')); + + $model = new Page(['slug' => 'foo']); + $this->assertInstanceOf(Version::class, $model->version('published')); + } } From e17c4d4cbb205e11fb9b78a264505fc346fda2c8 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:16:07 +0200 Subject: [PATCH 03/17] Use ModelWithContent::version in ModelWithContent::writeContent --- src/Cms/ModelWithContent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 3f3e9dcf91..2586d60a59 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -755,10 +755,10 @@ public function writeContent(array $data, string|null $languageCode = null): boo try { // we can only update if the version already exists - $this->storage()->update($id, $languageCode, $data); + $this->version($id)->update($data, $languageCode ?? 'default'); } catch (NotFoundException) { // otherwise create a new version - $this->storage()->create($id, $languageCode, $data); + $this->version($id)->create($data, $languageCode ?? 'default'); } return true; From 65d1405829ec6334a324218e83dbb61cb203f920 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:17:41 +0200 Subject: [PATCH 04/17] Use ModelWithContent::version in ModelWithContent::readContent --- src/Cms/ModelWithContent.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 2586d60a59..be851726aa 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -419,10 +419,7 @@ public function query( public function readContent(string|null $languageCode = null): array { try { - return $this->storage()->read( - VersionId::default($this), - $languageCode - ); + return $this->version(VersionId::default($this))->read($languageCode ?? 'default'); } catch (NotFoundException) { // only if the content file really does not exist, it's ok // to return empty content. Otherwise this could lead to From 518cf84439adb0e27793e2474e745a8d1d38e31e Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:18:51 +0200 Subject: [PATCH 05/17] Use ModelWithContent::version in ModelWithContent::convertTo --- src/Cms/ModelWithContent.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index be851726aa..152dbaec9e 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -202,10 +202,7 @@ protected function convertTo(string $blueprint): static $content = $this->content($code)->convertTo($blueprint); // delete the old text file - $this->storage()->delete( - $identifier, - $code - ); + $this->version($identifier)->delete($code); // save to re-create the translation content file // with the converted/updated content @@ -229,7 +226,7 @@ protected function convertTo(string $blueprint): static $content = $this->content()->convertTo($blueprint); // delete the old text file - $this->storage()->delete($identifier, 'default'); + $this->version($identifier)->delete('default'); return $new->save($content); } From dfe9b044f49497738fb58f64ccf11af7c50729bd Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:23:30 +0200 Subject: [PATCH 06/17] Use File::version() in File::modifiedContent() --- src/Cms/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cms/File.php b/src/Cms/File.php index 43ef18479a..3800916dfe 100644 --- a/src/Cms/File.php +++ b/src/Cms/File.php @@ -426,7 +426,7 @@ public function modified( */ protected function modifiedContent(string|null $languageCode = null): int { - return $this->storage()->modified(VersionId::published(), $languageCode) ?? 0; + return $this->version(VersionId::published())->modified($languageCode ?? 'default') ?? 0; } /** From fa8555c04abf291c47f62681d9a8317e8e04426d Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:31:18 +0200 Subject: [PATCH 07/17] Use version method instead of direct storage access wherever possible --- src/Cms/Page.php | 5 ++--- src/Cms/User.php | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Cms/Page.php b/src/Cms/Page.php index 28fd385eef..757c2ae55e 100644 --- a/src/Cms/Page.php +++ b/src/Cms/Page.php @@ -830,9 +830,8 @@ public function modified( string|null $handler = null, string|null $languageCode = null ): int|string|false|null { - $modified = $this->storage()->modified( - VersionId::default($this), - $languageCode + $modified = $this->version(VersionId::default($this))->modified( + $languageCode ?? 'current' ); if ($modified === null) { diff --git a/src/Cms/User.php b/src/Cms/User.php index c226633d5d..90cd6aca7e 100644 --- a/src/Cms/User.php +++ b/src/Cms/User.php @@ -208,10 +208,7 @@ public function email(): string|null */ public function exists(): bool { - return $this->storage()->exists( - VersionId::published(), - 'default' - ); + return $this->version(VersionId::published())->exists('default'); } /** @@ -473,7 +470,7 @@ public function modified( string|null $handler = null, string|null $languageCode = null ): int|string|false { - $modifiedContent = $this->storage()->modified(VersionId::published(), $languageCode); + $modifiedContent = $this->version(VersionId::published())->modified($languageCode ?? 'current'); $modifiedIndex = F::modified($this->root() . '/index.php'); $modifiedTotal = max([$modifiedContent, $modifiedIndex]); From 9499e8dcf26f7ab6d7256a24f0a24f959fcec6bd Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:37:23 +0200 Subject: [PATCH 08/17] Use Site::version in System class to get the correct content file --- src/Cms/System.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Cms/System.php b/src/Cms/System.php index 55ccee0f84..2603adb37c 100644 --- a/src/Cms/System.php +++ b/src/Cms/System.php @@ -76,10 +76,7 @@ public function exposedFileUrl(string $folder): string|null switch ($folder) { case 'content': - return $url . '/' . basename($this->app->site()->storage()->contentFile( - VersionId::published(), - 'default' - )); + return $url . '/' . basename($this->app->site()->version(VersionId::published())->contentFile()); case 'git': return $url . '/config'; case 'kirby': From 03a7d1a7651e912c986de6a41ef74400145e914a Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:39:25 +0200 Subject: [PATCH 09/17] Fix ContentTranslation::contentFile by using ::version --- src/Content/ContentTranslation.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Content/ContentTranslation.php b/src/Content/ContentTranslation.php index ee3eed2a76..39c2764098 100644 --- a/src/Content/ContentTranslation.php +++ b/src/Content/ContentTranslation.php @@ -85,10 +85,7 @@ public function content(): array */ public function contentFile(): string { - return $this->contentFile = $this->parent->storage()->contentFile( - VersionId::default($this->parent), - $this->code - ); + return $this->contentFile = $this->parent->version(VersionId::default($this->parent))->contentFile($this->code); } /** From 012cc042d56b560f394c6cc68c67bd9c9a979457 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:42:35 +0200 Subject: [PATCH 10/17] Use class name instead of keywords --- src/Content/VersionId.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/VersionId.php b/src/Content/VersionId.php index 6d8f7eb5ef..62b2c5be47 100644 --- a/src/Content/VersionId.php +++ b/src/Content/VersionId.php @@ -79,9 +79,9 @@ public static function default(ModelWithContent $model): static /** * Creates a VersionId instance from a simple string value */ - public static function from(self|string $value): static + public static function from(VersionId|string $value): static { - if ($value instanceof static) { + if ($value instanceof VersionId) { return $value; } From e72666433db125d8491c9d81b351a1765e894b48 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Wed, 5 Jun 2024 12:21:13 +0200 Subject: [PATCH 11/17] Fall back to the default model version in ::version --- src/Cms/ModelWithContent.php | 4 ++-- tests/Cms/Models/ModelWithContentTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 152dbaec9e..0e32e79864 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -729,11 +729,11 @@ public function uuid(): Uuid|null * Returns a content version instance * @since 5.0.0 */ - public function version(VersionId|string $versionId): Version + public function version(VersionId|string|null $versionId = null): Version { return new Version( model: $this, - id: VersionId::from($versionId) + id: VersionId::from($versionId ?? VersionId::default($this)) ); } diff --git a/tests/Cms/Models/ModelWithContentTest.php b/tests/Cms/Models/ModelWithContentTest.php index 82a5e83f46..00249c2fdc 100644 --- a/tests/Cms/Models/ModelWithContentTest.php +++ b/tests/Cms/Models/ModelWithContentTest.php @@ -449,8 +449,21 @@ public function testVersion() { $model = new Site(); $this->assertInstanceOf(Version::class, $model->version('published')); + $this->assertSame('published', $model->version()->id()->value()); $model = new Page(['slug' => 'foo']); $this->assertInstanceOf(Version::class, $model->version('published')); + $this->assertSame('published', $model->version()->id()->value()); + } + + public function testVersionFallback() + { + $model = new Page(['slug' => 'foo']); + $this->assertInstanceOf(Version::class, $model->version()); + $this->assertSame('published', $model->version()->id()->value()); + + $model = new Page(['slug' => 'foo', 'isDraft' => true]); + $this->assertInstanceOf(Version::class, $model->version()); + $this->assertSame('changes', $model->version()->id()->value()); } } From 2398f30ea292ba39dd4ca1a0e488c6dac3fab78d Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Wed, 5 Jun 2024 12:25:53 +0200 Subject: [PATCH 12/17] Simplify code after new default version id fallback in ::version --- src/Cms/ModelWithContent.php | 10 ++++++---- src/Cms/Page.php | 2 +- src/Content/ContentTranslation.php | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 0e32e79864..d05edea4c0 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -416,7 +416,7 @@ public function query( public function readContent(string|null $languageCode = null): array { try { - return $this->version(VersionId::default($this))->read($languageCode ?? 'default'); + return $this->version()->read($languageCode ?? 'default'); } catch (NotFoundException) { // only if the content file really does not exist, it's ok // to return empty content. Otherwise this could lead to @@ -745,14 +745,16 @@ public function version(VersionId|string|null $versionId = null): Version public function writeContent(array $data, string|null $languageCode = null): bool { $data = $this->contentFileData($data, $languageCode); - $id = VersionId::default($this); + + // update the default language, unless a specific language is passed + $languageCode ??= 'default'; try { // we can only update if the version already exists - $this->version($id)->update($data, $languageCode ?? 'default'); + $this->version()->update($data, $languageCode); } catch (NotFoundException) { // otherwise create a new version - $this->version($id)->create($data, $languageCode ?? 'default'); + $this->version()->create($data, $languageCode); } return true; diff --git a/src/Cms/Page.php b/src/Cms/Page.php index 757c2ae55e..bc1a64b3c8 100644 --- a/src/Cms/Page.php +++ b/src/Cms/Page.php @@ -830,7 +830,7 @@ public function modified( string|null $handler = null, string|null $languageCode = null ): int|string|false|null { - $modified = $this->version(VersionId::default($this))->modified( + $modified = $this->version()->modified( $languageCode ?? 'current' ); diff --git a/src/Content/ContentTranslation.php b/src/Content/ContentTranslation.php index 39c2764098..5d74e6b4f0 100644 --- a/src/Content/ContentTranslation.php +++ b/src/Content/ContentTranslation.php @@ -85,7 +85,7 @@ public function content(): array */ public function contentFile(): string { - return $this->contentFile = $this->parent->version(VersionId::default($this->parent))->contentFile($this->code); + return $this->contentFile = $this->parent->version()->contentFile($this->code); } /** From 04c431387c3a1d706fbcd02f0ce301e849a06941 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 May 2024 16:53:56 +0200 Subject: [PATCH 13/17] Refactor unit tests to use the new version method --- tests/Cms/Files/FileActionsTest.php | 36 ++++++++++++++--------------- tests/Cms/Pages/PageActionsTest.php | 20 ++++++++-------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/Cms/Files/FileActionsTest.php b/tests/Cms/Files/FileActionsTest.php index 8bc1b81716..f08d8b2326 100644 --- a/tests/Cms/Files/FileActionsTest.php +++ b/tests/Cms/Files/FileActionsTest.php @@ -104,19 +104,19 @@ public function testChangeName(File $file) // create an empty dummy file F::write($file->root(), ''); // ...and an empty content file for it - F::write($file->storage()->contentFile(VersionId::published(), 'default'), ''); + F::write($file->version(VersionId::published())->contentFile('default'), ''); $this->assertFileExists($file->root()); - $this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileExists($file->version(VersionId::published())->contentFile('default')); $result = $file->changeName('test'); $this->assertNotSame($file->root(), $result->root()); $this->assertSame('test.csv', $result->filename()); $this->assertFileExists($result->root()); - $this->assertFileExists($result->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileExists($result->version(VersionId::published())->contentFile('default')); $this->assertFileDoesNotExist($file->root()); - $this->assertFileDoesNotExist($file->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileDoesNotExist($file->version(VersionId::published())->contentFile('default')); } public static function fileProviderMultiLang(): array @@ -140,20 +140,20 @@ public function testChangeNameMultiLang(File $file) // create an empty dummy file F::write($file->root(), ''); // ...and empty content files for it - F::write($file->storage()->contentFile(VersionId::published(), 'en'), ''); - F::write($file->storage()->contentFile(VersionId::published(), 'de'), ''); + F::write($file->version(VersionId::published())->contentFile('en'), ''); + F::write($file->version(VersionId::published())->contentFile('de'), ''); $this->assertFileExists($file->root()); - $this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'en')); - $this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'de')); + $this->assertFileExists($file->version(VersionId::published())->contentFile('en')); + $this->assertFileExists($file->version(VersionId::published())->contentFile('de')); $result = $file->changeName('test'); $this->assertNotEquals($file->root(), $result->root()); $this->assertSame('test.csv', $result->filename()); $this->assertFileExists($result->root()); - $this->assertFileExists($result->storage()->contentFile(VersionId::published(), 'en')); - $this->assertFileExists($result->storage()->contentFile(VersionId::published(), 'de')); + $this->assertFileExists($result->version(VersionId::published())->contentFile('en')); + $this->assertFileExists($result->version(VersionId::published())->contentFile('de')); } public function testChangeTemplate() @@ -375,9 +375,9 @@ public function testChangeTemplateMultilang() $this->assertNull($modified->caption()->value()); $this->assertSame('Das ist der Text', $modified->text()->value()); - $this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'en')); - $this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'de')); - $this->assertFileDoesNotExist($modified->storage()->contentFile(VersionId::published(), 'fr')); + $this->assertFileExists($modified->version(VersionId::published())->contentFile('en')); + $this->assertFileExists($modified->version(VersionId::published())->contentFile('de')); + $this->assertFileDoesNotExist($modified->version(VersionId::published())->contentFile('fr')); } public function testChangeTemplateDefault() @@ -753,17 +753,17 @@ public function testDelete(File $file) // create an empty dummy file F::write($file->root(), ''); // ...and an empty content file for it - F::write($file->storage()->contentFile(VersionId::published(), 'default'), ''); + F::write($file->version(VersionId::published())->contentFile('default'), ''); $this->assertFileExists($file->root()); - $this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileExists($file->version(VersionId::published())->contentFile('default')); $result = $file->delete(); $this->assertTrue($result); $this->assertFileDoesNotExist($file->root()); - $this->assertFileDoesNotExist($file->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileDoesNotExist($file->version(VersionId::published())->contentFile('default')); } /** @@ -873,11 +873,11 @@ public function testSave($file) F::write($file->root(), ''); $this->assertFileExists($file->root()); - $this->assertFileDoesNotExist($file->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileDoesNotExist($file->version(VersionId::published())->contentFile('default')); $file = $file->clone(['content' => ['caption' => 'save']])->save(); - $this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'default')); + $this->assertFileExists($file->version(VersionId::published())->contentFile('default')); } /** diff --git a/tests/Cms/Pages/PageActionsTest.php b/tests/Cms/Pages/PageActionsTest.php index 1f13c98223..5199602c72 100644 --- a/tests/Cms/Pages/PageActionsTest.php +++ b/tests/Cms/Pages/PageActionsTest.php @@ -422,9 +422,9 @@ public function testChangeTemplateMultilang() $this->assertSame('article', $modified->intendedTemplate()->name()); $this->assertSame(2, $calls); - $this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'en')); - $this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'de')); - $this->assertFileDoesNotExist($modified->storage()->contentFile(VersionId::published(), 'fr')); + $this->assertFileExists($modified->version(VersionId::published())->contentFile('en')); + $this->assertFileExists($modified->version(VersionId::published())->contentFile('de')); + $this->assertFileDoesNotExist($modified->version(VersionId::published())->contentFile('fr')); $this->assertNull($modified->caption()->value()); $this->assertSame('Text', $modified->text()->value()); $this->assertNull($modified->content('de')->get('caption')->value()); @@ -889,15 +889,15 @@ public function testDuplicateMultiLang() 'parent' => $page, 'code' => 'en', ]); - $this->assertFileExists($page->storage()->contentFile(VersionId::changes(), 'en')); + $this->assertFileExists($page->version(VersionId::changes())->contentFile('en')); $drafts = $app->site()->drafts(); $childrenAndDrafts = $app->site()->childrenAndDrafts(); $copy = $page->duplicate('test-copy'); - $this->assertFileExists($copy->storage()->contentFile(VersionId::changes(), 'en')); - $this->assertFileDoesNotExist($copy->storage()->contentFile(VersionId::changes(), 'de')); + $this->assertFileExists($copy->version(VersionId::changes())->contentFile('en')); + $this->assertFileDoesNotExist($copy->version(VersionId::changes())->contentFile('de')); $this->assertIsPage($page, $drafts->find('test')); $this->assertIsPage($page, $childrenAndDrafts->find('test')); @@ -929,8 +929,8 @@ public function testDuplicateMultiLangSlug() 'slug' => 'test-de' ], 'de'); - $this->assertFileExists($page->storage()->contentFile(VersionId::changes(), 'en')); - $this->assertFileExists($page->storage()->contentFile(VersionId::changes(), 'de')); + $this->assertFileExists($page->version(VersionId::changes())->contentFile('en')); + $this->assertFileExists($page->version(VersionId::changes())->contentFile('de')); $this->assertSame('test', $page->slug()); $this->assertSame('test-de', $page->slug('de')); @@ -1044,8 +1044,8 @@ public function testDuplicateChildrenMultiLang() $copy = $page->duplicate('test-copy', ['children' => true]); - $this->assertFileExists($copy->storage()->contentFile(VersionId::changes(), 'en')); - $this->assertFileDoesNotExist($copy->storage()->contentFile(VersionId::changes(), 'de')); + $this->assertFileExists($copy->version(VersionId::changes())->contentFile('en')); + $this->assertFileDoesNotExist($copy->version(VersionId::changes())->contentFile('de')); $this->assertNotSame($page->uuid()->id(), $copy->uuid()->id()); From 0626fea78b59ef58a38184c59c51c2dccdfa297c Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Wed, 5 Jun 2024 12:33:02 +0200 Subject: [PATCH 14/17] Fix CS issue --- src/Cms/Page.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Cms/Page.php b/src/Cms/Page.php index bc1a64b3c8..361ad341c6 100644 --- a/src/Cms/Page.php +++ b/src/Cms/Page.php @@ -4,7 +4,6 @@ use Closure; use Kirby\Content\Field; -use Kirby\Content\VersionId; use Kirby\Exception\Exception; use Kirby\Exception\InvalidArgumentException; use Kirby\Exception\NotFoundException; From 2bb72865cdeaa10656e41c5836b82a3571aef8eb Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Mon, 17 Jun 2024 11:02:40 +0200 Subject: [PATCH 15/17] Keep unit test more specific Co-authored-by: Lukas Bestle --- tests/Cms/Models/ModelWithContentTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Cms/Models/ModelWithContentTest.php b/tests/Cms/Models/ModelWithContentTest.php index 00249c2fdc..3b694c411d 100644 --- a/tests/Cms/Models/ModelWithContentTest.php +++ b/tests/Cms/Models/ModelWithContentTest.php @@ -449,11 +449,11 @@ public function testVersion() { $model = new Site(); $this->assertInstanceOf(Version::class, $model->version('published')); - $this->assertSame('published', $model->version()->id()->value()); + $this->assertSame('published', $model->version('published')->id()->value()); $model = new Page(['slug' => 'foo']); $this->assertInstanceOf(Version::class, $model->version('published')); - $this->assertSame('published', $model->version()->id()->value()); + $this->assertSame('published', $model->version('published')->id()->value()); } public function testVersionFallback() From 5ed897ef13a84072de8c28cc94ab9b70dce0c974 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Mon, 17 Jun 2024 11:06:10 +0200 Subject: [PATCH 16/17] Use the current language in File::modifiedContent --- src/Cms/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cms/File.php b/src/Cms/File.php index 3800916dfe..0c21e79c64 100644 --- a/src/Cms/File.php +++ b/src/Cms/File.php @@ -426,7 +426,7 @@ public function modified( */ protected function modifiedContent(string|null $languageCode = null): int { - return $this->version(VersionId::published())->modified($languageCode ?? 'default') ?? 0; + return $this->version(VersionId::published())->modified($languageCode ?? 'current') ?? 0; } /** From ed425c1ed9b273b7ca154c7607fa5c391e51ef2c Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Mon, 17 Jun 2024 11:09:04 +0200 Subject: [PATCH 17/17] Test passing a VersionId instance --- tests/Cms/Models/ModelWithContentTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Cms/Models/ModelWithContentTest.php b/tests/Cms/Models/ModelWithContentTest.php index 3b694c411d..48312cc38c 100644 --- a/tests/Cms/Models/ModelWithContentTest.php +++ b/tests/Cms/Models/ModelWithContentTest.php @@ -4,6 +4,7 @@ use Closure; use Kirby\Content\Version; +use Kirby\Content\VersionId; use Kirby\Exception\InvalidArgumentException; use Kirby\Panel\Page as PanelPage; use Kirby\Uuid\PageUuid; @@ -450,10 +451,12 @@ public function testVersion() $model = new Site(); $this->assertInstanceOf(Version::class, $model->version('published')); $this->assertSame('published', $model->version('published')->id()->value()); + $this->assertSame('published', $model->version(VersionId::published())->id()->value()); $model = new Page(['slug' => 'foo']); $this->assertInstanceOf(Version::class, $model->version('published')); $this->assertSame('published', $model->version('published')->id()->value()); + $this->assertSame('published', $model->version(VersionId::published())->id()->value()); } public function testVersionFallback()