koel/app/Observers/AlbumObserver.php

36 lines
610 B
PHP
Raw Normal View History

2018-08-29 07:58:46 +00:00
<?php
namespace App\Observers;
use App\Models\Album;
2018-08-31 13:47:15 +00:00
use Illuminate\Log\Logger;
2020-12-22 20:11:22 +00:00
use Throwable;
2018-08-29 07:58:46 +00:00
class AlbumObserver
{
2018-08-31 13:47:15 +00:00
private $logger;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
2018-08-29 07:58:46 +00:00
public function deleted(Album $album): void
2018-10-19 14:33:04 +00:00
{
$this->deleteAlbumCover($album);
}
private function deleteAlbumCover(Album $album): void
2018-08-29 07:58:46 +00:00
{
if (!$album->has_cover) {
return;
}
try {
unlink($album->cover_path);
2020-12-22 20:11:22 +00:00
} catch (Throwable $e) {
2018-08-31 13:47:15 +00:00
$this->logger->error($e);
2018-08-29 07:58:46 +00:00
}
}
}