2021-09-06 02:31:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Aweos\Resizer\Classes;
|
|
|
|
|
2021-09-09 19:18:41 +02:00
|
|
|
use Aweos\Resizer\Lib\MediaPath;
|
2021-09-06 02:31:27 +02:00
|
|
|
use Storage;
|
|
|
|
|
|
|
|
class FileObserver
|
|
|
|
{
|
|
|
|
|
2021-09-09 19:18:41 +02:00
|
|
|
public function delete(MediaPath $path): void
|
2021-09-06 02:31:27 +02:00
|
|
|
{
|
2021-09-09 19:18:41 +02:00
|
|
|
foreach ($path->versions() as $version) {
|
|
|
|
Storage::delete($version->get('path'));
|
|
|
|
}
|
2021-09-06 02:31:27 +02:00
|
|
|
|
2021-09-09 19:18:41 +02:00
|
|
|
if (empty(Storage::files($path->versionsDirPath()))) {
|
|
|
|
Storage::deleteDirectory($path->versionsDirPath());
|
2021-09-06 02:31:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 19:18:41 +02:00
|
|
|
public function rename(MediaPath $old, MediaPath $new): void
|
2021-09-06 02:31:27 +02:00
|
|
|
{
|
2021-09-09 19:18:41 +02:00
|
|
|
foreach ($old->versions() as $version) {
|
|
|
|
Storage::move(
|
|
|
|
$version->get('path'),
|
|
|
|
$new->versionsDirPath().'/'.$new->filename().$version->get('size').$version->get('ext')
|
|
|
|
);
|
2021-09-06 02:31:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|