1
0

Allow to "touch" a bundle

This commit is contained in:
Richard Dern 2024-04-26 23:26:55 +02:00
parent f66aa12053
commit f07115aec2
2 changed files with 43 additions and 4 deletions

View File

@ -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);
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class Touch extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bundle:touch { path : Path to the bundle }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update a bundle "lastModified" metadata';
/**
* Execute the console command.
*/
public function handle()
{
$bundle = new Bundle($this->argument('path'), Storage::disk(env('CONTENT_DISK')));
$bundle->touch();
}
}