update image data from bank working

This commit is contained in:
isUnknown 2024-10-15 15:29:02 +02:00
parent 4f808ba017
commit 0e656e1920
5 changed files with 44 additions and 13 deletions

View file

@ -1,8 +1,8 @@
Description: test Description: nouvelle description
---- ----
Tags: DA globale Tags:
---- ----
@ -10,7 +10,7 @@ Sort: 7
---- ----
Uuid: cWXe3yDs2zcLLiQE Uuid: PbMGJPIjFYxbbyhq
---- ----

View file

@ -14,7 +14,10 @@ Description:
---- ----
Clientbriefimages: - file://cWXe3yDs2zcLLiQE Clientbriefimages:
- file://PbMGJPIjFYxbbyhq
- file://STF67mX6eGsLsOGh
---- ----

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

View file

@ -0,0 +1,17 @@
Description: test 2
----
Tags:
----
Sort: 8
----
Uuid: STF67mX6eGsLsOGh
----
Template: image

View file

@ -29,17 +29,30 @@ return [
foreach ($data['imageUris'] as $imageUri) { foreach ($data['imageUris'] as $imageUri) {
$imageData = json_decode($imageUri, true); $imageData = json_decode($imageUri, true);
$source = page('materials')->file($imageData['uuid']); $existingFile = $page->file($imageData['name']);
$source = null;
if (!$existingFile) {
try {
$source = page('materials')->file($imageData['uuid'])->copy($page);
} catch (\Throwable $th) {
$alerts[$source->name()] = $th->getMessage();
}
} else {
$allFiles = array_filter($allFiles, function ($uuid) use ($existingFile) {
return $uuid != $existingFile->uuid();
});
$source = $existingFile;
}
try { try {
$copiedFile = $source->copy($page); $updatedFile = $source->update([
$updatedFile = $copiedFile->update([
'description' => $imageData['description'], 'description' => $imageData['description'],
'tags' => $imageData['tags'], 'tags' => $imageData['tags'],
]); ]);
$allFiles[] = $updatedFile->uuid();
$allFiles[] = (string) $copiedFile->uuid(); } catch (\Throwable $th) {
} catch (Exception $e) { $alert[$source->name()] = $th->getMessage();
$alerts[$source->name()] = $e->getMessage();
} }
} }
} }
@ -106,8 +119,6 @@ return [
'clientBriefImages' => $allFiles 'clientBriefImages' => $allFiles
]); ]);
} }
throw new Exception(json_encode($allFiles), 1);
$images = []; $images = [];