Allow to "touch" a bundle
This commit is contained in:
parent
f66aa12053
commit
f07115aec2
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
34
app/Console/Commands/Bundle/Touch.php
Normal file
34
app/Console/Commands/Bundle/Touch.php
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user