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;
use Exception;
2018-08-31 13:47:15 +00:00
use Illuminate\Log\Logger;
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);
} catch (Exception $e) {
2018-08-31 13:47:15 +00:00
$this->logger->error($e);
2018-08-29 07:58:46 +00:00
}
}
}