This commit is contained in:
isUnknown 2025-04-30 14:43:38 +02:00
parent 6804a4c9b7
commit 7815c8b49a
3 changed files with 32 additions and 10 deletions

View file

@ -2,6 +2,12 @@
return [
'debug' => true,
'cache' => [
'pages' => [
'active' => true
],
'api' => true
],
'smartypants' => true,
'locale' => 'fr_FR.utf-8',
'date' => [
@ -34,5 +40,6 @@ return [
'hooks' => [
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
'page.delete:before' => require_once(__DIR__ . '/hooks/delete-steps.php'),
'page.update:after' => require_once(__DIR__ . '/hooks/regenerate-project-steps-cache.php')
],
];

View file

@ -0,0 +1,7 @@
<?php
return function($newPage, $oldPage) {
if ($newPage->template() == 'project' || $newPage->parents()->findBy('template', 'project')) {
$newPage->getSteps();
}
};

View file

@ -4,19 +4,27 @@ use adrienpayet\notifications\NotificationsPage;
class ProjectPage extends NotificationsPage {
public function getSteps() {
$steps = [];
$apiCache = kirby()->cache('api');
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
foreach ($this->children() as $child) {
try {
$steps[] = $this->createStep($child);
} catch (\Throwable $th) {
//throw $th;
if ($stepsData === null) {
$steps = [];
foreach ($this->children() as $child) {
try {
$steps[] = $this->createStep($child);
} catch (\Throwable $th) {
//throw $th;
}
}
usort($steps, fn($a, $b) => $a['index'] <=> $b['index']);
$apiCache->set($this->slug() . '_' . 'steps', $steps);
return $steps;
} else {
return $stepsData;
}
usort($steps, fn($a, $b) => $a['index'] <=> $b['index']);
return $steps;
}
private function createStep($child) {