This commit is contained in:
parent
6804a4c9b7
commit
7815c8b49a
3 changed files with 32 additions and 10 deletions
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
|
'cache' => [
|
||||||
|
'pages' => [
|
||||||
|
'active' => true
|
||||||
|
],
|
||||||
|
'api' => true
|
||||||
|
],
|
||||||
'smartypants' => true,
|
'smartypants' => true,
|
||||||
'locale' => 'fr_FR.utf-8',
|
'locale' => 'fr_FR.utf-8',
|
||||||
'date' => [
|
'date' => [
|
||||||
|
|
@ -34,5 +40,6 @@ return [
|
||||||
'hooks' => [
|
'hooks' => [
|
||||||
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
||||||
'page.delete:before' => require_once(__DIR__ . '/hooks/delete-steps.php'),
|
'page.delete:before' => require_once(__DIR__ . '/hooks/delete-steps.php'),
|
||||||
|
'page.update:after' => require_once(__DIR__ . '/hooks/regenerate-project-steps-cache.php')
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return function($newPage, $oldPage) {
|
||||||
|
if ($newPage->template() == 'project' || $newPage->parents()->findBy('template', 'project')) {
|
||||||
|
$newPage->getSteps();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -4,19 +4,27 @@ use adrienpayet\notifications\NotificationsPage;
|
||||||
|
|
||||||
class ProjectPage extends NotificationsPage {
|
class ProjectPage extends NotificationsPage {
|
||||||
public function getSteps() {
|
public function getSteps() {
|
||||||
$steps = [];
|
$apiCache = kirby()->cache('api');
|
||||||
|
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
|
||||||
|
|
||||||
foreach ($this->children() as $child) {
|
if ($stepsData === null) {
|
||||||
try {
|
$steps = [];
|
||||||
$steps[] = $this->createStep($child);
|
|
||||||
} catch (\Throwable $th) {
|
foreach ($this->children() as $child) {
|
||||||
//throw $th;
|
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) {
|
private function createStep($child) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue