From: nupplaPhil Date: Mon, 6 Jan 2020 21:07:23 +0000 (+0100) Subject: fix Photo model X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1bce3fd0f1aa6b32139ae7a6ff7027254e97a3d0;p=friendica.git fix Photo model --- diff --git a/src/Model/Photo.php b/src/Model/Photo.php index f8f50824bd..8df06565bc 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -173,26 +173,24 @@ class Photo */ public static function getImageForPhoto(array $photo) { - $data = ""; - - if ($photo["backend-class"] == "") { + if (empty($photo['backend-class'])) { // legacy data storage in "data" column - $i = self::selectFirst(["data"], ["id" => $photo["id"]]); + $i = self::selectFirst(['data'], ['id' => $photo['id']]); if ($i === false) { return null; } - $data = $i["data"]; + $data = $i['data']; } else { - $backendClass = $photo["backend-class"]; - $backendRef = $photo["backend-ref"]; - $data = $backendClass::get($backendRef); + $backendClass = DI::facStorage()->getByName($photo['backend-class'] ?? ''); + $backendRef = $photo['backend-ref'] ?? ''; + $data = $backendClass->get($backendRef); } - if ($data === "") { + if (empty($data)) { return null; } - return new Image($data, $photo["type"]); + return new Image($data, $photo['type']); } /** @@ -223,11 +221,11 @@ class Photo $fields = self::getFields(); $values = array_fill(0, count($fields), ""); - $photo = array_combine($fields, $values); - $photo["backend-class"] = SystemResource::NAME; - $photo["backend-ref"] = $filename; - $photo["type"] = $mimetype; - $photo["cacheable"] = false; + $photo = array_combine($fields, $values); + $photo['backend-class'] = SystemResource::NAME; + $photo['backend-ref'] = $filename; + $photo['type'] = $mimetype; + $photo['cacheable'] = false; return $photo; } @@ -340,10 +338,9 @@ class Photo $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions); foreach($photos as $photo) { - /** @var IStorage $backend_class */ - $backend_class = (string)$photo["backend-class"]; - if ($backend_class !== "") { - $backend_class::delete($photo["backend-ref"]); + $backend_class = DI::facStorage()->getByName($photo['backend-class'] ?? ''); + if ($backend_class !== null) { + $backend_class->delete($photo["backend-ref"] ?? ''); } } @@ -370,10 +367,9 @@ class Photo $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions); foreach($photos as $photo) { - /** @var IStorage $backend_class */ - $backend_class = (string)$photo["backend-class"]; - if ($backend_class !== "") { - $fields["backend-ref"] = $backend_class::put($img->asString(), $photo["backend-ref"]); + $backend_class = DI::facStorage()->getByName($photo['backend-class'] ?? ''); + if ($backend_class !== null) { + $fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']); } else { $fields["data"] = $img->asString(); }