From f07115aec24833a1caab09b9078939c8e03c33d7 Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Fri, 26 Apr 2024 23:26:55 +0200 Subject: [PATCH] Allow to "touch" a bundle --- app/Classes/Bundle.php | 13 ++++++---- app/Console/Commands/Bundle/Touch.php | 34 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 app/Console/Commands/Bundle/Touch.php diff --git a/app/Classes/Bundle.php b/app/Classes/Bundle.php index e5e98cb..5587f84 100644 --- a/app/Classes/Bundle.php +++ b/app/Classes/Bundle.php @@ -182,8 +182,7 @@ public function save(): void || $this->saveMetadata() || $this->saveMarkdown() ) { - $this->metadata()->set('lastModified', now()->toIso8601String()); - $this->saveMetadata(); + $this->touch(); } } @@ -199,13 +198,19 @@ public function repair(): void $this->save(); } - public function render() + public function touch() + { + $this->metadata()->set('lastModified', now()->toIso8601String()); + $this->saveMetadata(); + } + + public function render(bool $ignoreCache = false) { $lastModified = Carbon::parse($this->metadata()->get('lastModified', '1970-01-02')); $lastRendered = Carbon::parse($this->metadata()->get('lastRendered', '1970-01-01')); $cacheKey = sprintf('render_%s', Str::slug($this->getPath())); - if ($lastRendered->gt($lastModified) && Cache::has($cacheKey)) { + if ($lastRendered->gt($lastModified) && Cache::has($cacheKey) && !$ignoreCache) { return Cache::get($cacheKey); } diff --git a/app/Console/Commands/Bundle/Touch.php b/app/Console/Commands/Bundle/Touch.php new file mode 100644 index 0000000..754e3c1 --- /dev/null +++ b/app/Console/Commands/Bundle/Touch.php @@ -0,0 +1,34 @@ +argument('path'), Storage::disk(env('CONTENT_DISK'))); + + $bundle->touch(); + } +}