Done TODO: delete all subject file type for a media on delete
This commit is contained in:
parent
914ab4c5f9
commit
ae30f926bb
2 changed files with 33 additions and 26 deletions
|
|
@ -155,7 +155,7 @@ class MediaController extends Controller
|
|||
$user = auth()->user();
|
||||
|
||||
/** @var \App\Models\Dossier|null */
|
||||
$dossier = Dossier::where('id', $request->folder)->first();
|
||||
$dossier = Dossier::where('id', $request->folder)->first();
|
||||
|
||||
$response = [];
|
||||
$filters = (object)collect($request->filters)->all();
|
||||
|
|
@ -985,25 +985,22 @@ class MediaController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
// TODO: \array_undot( herre
|
||||
$tmpFilters = [
|
||||
[
|
||||
'bool' => [
|
||||
'should' => [
|
||||
[
|
||||
'bool' => [
|
||||
'must' => $mustLib
|
||||
]
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'must' => $mustArt
|
||||
]
|
||||
$tmpFilters = [[
|
||||
'bool' => [
|
||||
'should' => [
|
||||
[
|
||||
'bool' => [
|
||||
'must' => $mustLib
|
||||
]
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'must' => $mustArt
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
]];
|
||||
} else {
|
||||
// * Search auto
|
||||
$tmpFilters = [
|
||||
|
|
|
|||
|
|
@ -526,8 +526,8 @@ class Media extends Model
|
|||
|
||||
/**
|
||||
* Delete files on path
|
||||
*
|
||||
* @return void
|
||||
* @throws \RuntimeException If the media does not have a subject.
|
||||
*/
|
||||
public function deleteFilesOnAllPath()
|
||||
{
|
||||
|
|
@ -536,7 +536,19 @@ class Media extends Model
|
|||
$storage->delete($this->relative_path);
|
||||
$storage->delete($this->thumb_relative_path);
|
||||
$storage->delete($this->preview_relative_path);
|
||||
// TODO: Add delete forl all sujet formats.
|
||||
if (!$this->sujet) {
|
||||
throw new \RuntimeException('This medias does not have any subject wich is forbidden');
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
||||
$storage = Storage::disk('media');
|
||||
|
||||
$this->sujet->formats->map(function (Format $format) use ($storage) {
|
||||
$filePath = "{$this->folder}/{$this->uid}_{$format->libelle}.{$format->extension}";
|
||||
if ($storage->exists($filePath)) {
|
||||
$storage->delete($filePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -612,13 +624,11 @@ class Media extends Model
|
|||
/** @var \Illuminate\Support\Collection<\App\Models\Format> $formats */
|
||||
$formats = optional($this->sujet)->formats ?? collect();
|
||||
|
||||
foreach ($formats as $format) {
|
||||
$targetWidth = \floatval($format->largeur);
|
||||
if (\floatval($format->hauteur) == 0) {
|
||||
$targetHeight = \floatval(floor(($this->hauteur * $format->largeur) / $this->largeur));
|
||||
} else {
|
||||
$targetHeight = \floatval($format->hauteur);
|
||||
}
|
||||
$formats->map(function (Format $format) use ($storage, $im) {
|
||||
$targetWidth = \floatval($format->largeur);
|
||||
$targetHeight = \floatval($format->hauteur) == 0 ?
|
||||
\floatval(floor(($this->hauteur * $format->largeur) / $this->largeur)) :
|
||||
\floatval($format->hauteur);
|
||||
|
||||
$im->setImageFormat($format->extension);
|
||||
if ($this->largeur >= $targetWidth || $this->hauteur >= $targetHeight) {
|
||||
|
|
@ -628,7 +638,7 @@ class Media extends Model
|
|||
"{$this->folder}/{$this->uid}_{$format->libelle}.{$format->extension}",
|
||||
$im->getImageBlob()
|
||||
);
|
||||
}
|
||||
});
|
||||
$im->destroy();
|
||||
unset($im);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue