Skip to content

Commit 6371e9c

Browse files
committed
🐛 $field->toFilesTurbo() did not resolve properly
1 parent ab41334 commit 6371e9c

File tree

4 files changed

+57
-36
lines changed

4 files changed

+57
-36
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby-turbo",
33
"type": "kirby-plugin",
4-
"version": "5.1.0",
4+
"version": "5.1.1",
55
"description": "Speed up Kirby with caching",
66
"license": "proprietary",
77
"authors": [

composer.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
use Bnomei\TurboStopwatch;
1818
use Bnomei\TurboUuidCache;
1919
use Kirby\Cms\App;
20+
use Kirby\Cms\File;
2021
use Kirby\Cms\Files;
2122
use Kirby\Cms\Page;
2223
use Kirby\Cms\Pages;
2324
use Kirby\Content\Field;
2425
use Kirby\Filesystem\F;
2526
use Kirby\Http\Route;
27+
use Kirby\Toolkit\A;
2628

2729
@include_once __DIR__.'/vendor/autoload.php';
2830

@@ -286,26 +288,45 @@ function tubs(array|string $key, Closure $closure): mixed
286288
},
287289
],
288290
'fieldMethods' => [
291+
'toFileTurbo' => function (Field $field): ?File {
292+
return $field->toFilesTurbo()->first();
293+
},
289294
'toFilesTurbo' => function (Field $field): Files {
290295
if (kirby()->option('cache.uuid.type') === 'turbo-uuid') {
291-
$ids = [];
292-
foreach ($field->yaml() as $uuid) { // @phpstan-ignore-line
293-
$uuid = 'file/'.substr($uuid, 7, 2).'/'.substr($uuid, 9);
294-
$ids[] = kirby()->cache('uuid')->get($uuid);
296+
$files = [];
297+
$pages = [];
298+
$cache = kirby()->cache('uuid');
299+
foreach ($field->yaml() as $fileKey) { // @phpstan-ignore-line
300+
$fileKey = 'file/'.substr($fileKey, 7, 2).'/'.substr($fileKey, 9);
301+
if ($data =$cache->get($fileKey)) {
302+
$parentUuid = is_array($data) ? A::get($data, 'parent') : null;
303+
if (! $parentUuid) {
304+
continue;
305+
}
306+
$parentKey = 'page/'.substr($parentUuid, 7, 2).'/'.substr($parentUuid, 9);
307+
if ($parentId =$cache->get($parentKey)) {
308+
$pages[$parentId] = A::get($pages, $parentId, kirby()->page($parentId));
309+
$files[] = $pages[$parentId]?->file(A::get($data, 'filename'));
310+
}
311+
}
295312
}
296313

297-
return new Files(array_filter($ids));
314+
return new Files(array_filter($files));
298315
}
299316

300317
// default
301318
return $field->toFiles(); // @phpstan-ignore-line
302319
},
320+
'toPageTurbo' => function (Field $field): ?Page {
321+
return $field->toPagesTurbo()->first();
322+
},
303323
'toPagesTurbo' => function (Field $field): Pages {
304324
if (kirby()->option('cache.uuid.type') === 'turbo-uuid') {
305325
$ids = [];
326+
$cache = kirby()->cache('uuid');
306327
foreach ($field->yaml() as $uuid) { // @phpstan-ignore-line
307-
$uuid = 'page/'.substr($uuid, 7, 2).'/'.substr($uuid, 9);
308-
$ids[] = kirby()->cache('uuid')->get($uuid);
328+
$key = 'page/'.substr($uuid, 7, 2).'/'.substr($uuid, 9);
329+
$ids[] = $cache->get($key);
309330
}
310331

311332
return new Pages(array_filter($ids));

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'bnomei/kirby-turbo',
4-
'pretty_version' => '5.1.0',
5-
'version' => '5.1.0.0',
4+
'pretty_version' => '5.1.1',
5+
'version' => '5.1.1.0',
66
'reference' => null,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -11,8 +11,8 @@
1111
),
1212
'versions' => array(
1313
'bnomei/kirby-turbo' => array(
14-
'pretty_version' => '5.1.0',
15-
'version' => '5.1.0.0',
14+
'pretty_version' => '5.1.1',
15+
'version' => '5.1.1.0',
1616
'reference' => null,
1717
'type' => 'kirby-plugin',
1818
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)