Merge pull request #10108 from annando/issue-10105

Issue 10105: Use legacy photo data field if used
This commit is contained in:
Tobias Diekershoff 2021-04-01 07:35:10 +02:00 committed by GitHub
commit 33eac7c420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -159,8 +159,12 @@ class Attach
*/ */
public static function getData($item) public static function getData($item)
{ {
if (!empty($item['data'])) {
return $item['data'];
}
$backendClass = DI::storageManager()->getByName($item['backend-class'] ?? ''); $backendClass = DI::storageManager()->getByName($item['backend-class'] ?? '');
if ($backendClass === null) { if (empty($backendClass)) {
// legacy data storage in 'data' column // legacy data storage in 'data' column
$i = self::selectFirst(['data'], ['id' => $item['id']]); $i = self::selectFirst(['data'], ['id' => $item['id']]);
if ($i === false) { if ($i === false) {
@ -275,7 +279,7 @@ class Attach
foreach($items as $item) { foreach($items as $item) {
$backend_class = DI::storageManager()->getByName($item['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
if ($backend_class !== null) { if (!empty($backend_class)) {
$fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? ''); $fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
} else { } else {
$fields['data'] = $img->asString(); $fields['data'] = $img->asString();
@ -307,7 +311,7 @@ class Attach
foreach($items as $item) { foreach($items as $item) {
$backend_class = DI::storageManager()->getByName($item['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
if ($backend_class !== null) { if (!empty($backend_class)) {
$backend_class->delete($item['backend-ref'] ?? ''); $backend_class->delete($item['backend-ref'] ?? '');
} }
} }

View File

@ -188,8 +188,12 @@ class Photo
*/ */
public static function getImageDataForPhoto(array $photo) public static function getImageDataForPhoto(array $photo)
{ {
if (!empty($photo['data'])) {
return $photo['data'];
}
$backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? ''); $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
if ($backendClass === null) { if (empty($backendClass)) {
// legacy data storage in "data" column // legacy data storage in "data" column
$i = self::selectFirst(['data'], ['id' => $photo['id']]); $i = self::selectFirst(['data'], ['id' => $photo['id']]);
if ($i === false) { if ($i === false) {
@ -308,7 +312,7 @@ class Photo
$storage = DI::storage(); $storage = DI::storage();
} }
if ($storage === null) { if (empty($storage)) {
$data = $Image->asString(); $data = $Image->asString();
} else { } else {
$backend_ref = $storage->put($Image->asString(), $backend_ref); $backend_ref = $storage->put($Image->asString(), $backend_ref);
@ -368,7 +372,7 @@ class Photo
while ($photo = DBA::fetch($photos)) { while ($photo = DBA::fetch($photos)) {
$backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
if ($backend_class !== null) { if (!empty($backend_class)) {
if ($backend_class->delete($photo["backend-ref"] ?? '')) { if ($backend_class->delete($photo["backend-ref"] ?? '')) {
// Delete the photos after they had been deleted successfully // Delete the photos after they had been deleted successfully
DBA::delete("photo", ['id' => $photo['id']]); DBA::delete("photo", ['id' => $photo['id']]);
@ -402,7 +406,7 @@ class Photo
foreach($photos as $photo) { foreach($photos as $photo) {
$backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
if ($backend_class !== null) { if (!empty($backend_class)) {
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']); $fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
} else { } else {
$fields["data"] = $img->asString(); $fields["data"] = $img->asString();