mirror of
https://github.com/koel/koel
synced 2024-11-28 06:50:27 +00:00
35 lines
617 B
PHP
35 lines
617 B
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Models\Album;
|
|
use Illuminate\Log\Logger;
|
|
use Throwable;
|
|
|
|
class AlbumObserver
|
|
{
|
|
private Logger $logger;
|
|
|
|
public function __construct(Logger $logger)
|
|
{
|
|
$this->logger = $logger;
|
|
}
|
|
|
|
public function deleted(Album $album): void
|
|
{
|
|
$this->deleteAlbumCover($album);
|
|
}
|
|
|
|
private function deleteAlbumCover(Album $album): void
|
|
{
|
|
if (!$album->has_cover) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
unlink($album->cover_path);
|
|
} catch (Throwable $e) {
|
|
$this->logger->error($e);
|
|
}
|
|
}
|
|
}
|