Added tools to repair and check last modification time
This commit is contained in:
parent
e09fc2faa1
commit
5799ec3281
|
@ -7,6 +7,7 @@
|
||||||
use App\Classes\Traits\ManagesMetadata;
|
use App\Classes\Traits\ManagesMetadata;
|
||||||
use App\Contracts\Bundles;
|
use App\Contracts\Bundles;
|
||||||
use App\Services\BundleRenderers\Facades\BundleRenderer;
|
use App\Services\BundleRenderers\Facades\BundleRenderer;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
@ -111,6 +112,7 @@ public function save(): void
|
||||||
public function repair(): void
|
public function repair(): void
|
||||||
{
|
{
|
||||||
$this->load();
|
$this->load();
|
||||||
|
$this->repairCover();
|
||||||
$this->lintMarkdown();
|
$this->lintMarkdown();
|
||||||
$this->repairAttachments();
|
$this->repairAttachments();
|
||||||
$this->save();
|
$this->save();
|
||||||
|
@ -140,6 +142,13 @@ public function render()
|
||||||
return $renderer->render();
|
return $renderer->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function renderCard()
|
||||||
|
{
|
||||||
|
$renderer = BundleRenderer::getBundleRendererFor($this);
|
||||||
|
|
||||||
|
return $renderer->renderCard();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of bundles in the specified path
|
* Return a list of bundles in the specified path
|
||||||
*/
|
*/
|
||||||
|
@ -167,6 +176,47 @@ public static function findBundles(FilesystemAdapter $disk, ?string $path = '/',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the most recent modification date of this bundle and all
|
||||||
|
* sub-bundles
|
||||||
|
*/
|
||||||
|
public function lastModified(): ?Carbon
|
||||||
|
{
|
||||||
|
$dates = $this->disk
|
||||||
|
->listContents($this->getPath(), true)
|
||||||
|
->map(fn (StorageAttributes $attributes) => $attributes->lastModified())
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$latestTime = 0;
|
||||||
|
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
if ($date > $latestTime) {
|
||||||
|
$latestTime = $date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $latestTime == 0 ? null : Carbon::parse($latestTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function repairCover()
|
||||||
|
{
|
||||||
|
$cover = $this->metadata()->get('cover');
|
||||||
|
|
||||||
|
if (empty($cover)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($cover)) {
|
||||||
|
$path = $cover['url'];
|
||||||
|
|
||||||
|
foreach ($this->attachments(AttachmentsManager::Images)->manager()->get('files') as $ref => $data) {
|
||||||
|
if (Str::endsWith($data['filename'], $path)) {
|
||||||
|
$this->metadata()->set('cover', $ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a normalized representation of bundle's path
|
* Return a normalized representation of bundle's path
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user