use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Model\Storage\ExternalResource;
+use Friendica\Model\Storage\ReferenceStorageException;
+use Friendica\Model\Storage\StorageException;
use Friendica\Model\Storage\SystemResource;
use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat;
* @return \Friendica\Object\Image
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
+ * @throws StorageException
*/
public static function getImageDataForPhoto(array $photo)
{
$data = $i['data'];
} else {
$backendRef = $photo['backend-ref'] ?? '';
- $data = $backendClass->get($backendRef);
+ try {
+ $data = $backendClass->get($backendRef);
+ } catch (ReferenceStorageException $referenceStorageException) {
+ DI::logger()->debug('No data found for photo', ['photo' => $photo, 'exception' => $referenceStorageException]);
+ return null;
+ }
}
return $data;
}
if (DBA::isResult($existing_photo)) {
$backend_ref = (string)$existing_photo["backend-ref"];
- $storage = DI::storageManager()->getByName($existing_photo["backend-class"] ?? '');
+ $storage = DI::storageManager()->getSelectableStorageByName($existing_photo["backend-class"] ?? '');
} else {
$storage = DI::storage();
}
$photos = DBA::select('photo', ['id', 'backend-class', 'backend-ref'], $conditions);
while ($photo = DBA::fetch($photos)) {
- $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
+ $backend_class = DI::storageManager()->getSelectableStorageByName($photo['backend-class'] ?? '');
if (!empty($backend_class)) {
- if ($backend_class->delete($photo["backend-ref"] ?? '')) {
+ try {
+ $backend_class->delete($item['backend-ref'] ?? '');
// Delete the photos after they had been deleted successfully
DBA::delete("photo", ['id' => $photo['id']]);
+ } catch (ReferenceStorageException $referenceStorageException) {
+ DI::logger()->debug('phot doesn\'t exist.', ['conditions' => $conditions, 'exception' => $referenceStorageException]);
}
}
}
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
foreach($photos as $photo) {
- $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
+ $backend_class = DI::storageManager()->getSelectableStorageByName($photo['backend-class'] ?? '');
if (!empty($backend_class)) {
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
} else {
* @throws \Exception
*/
public static function isLocal($name)
+ {
+ return (bool)self::getIdForName($name);
+ }
+
+ /**
+ * Return the id of a local photo
+ *
+ * @param string $name Picture link
+ * @return int
+ */
+ public static function getIdForName($name)
{
$data = self::getResourceData($name);
if (empty($data)) {
- return false;
+ return 0;
}
- return DBA::exists('photo', ['resource-id' => $data['guid'], 'scale' => $data['scale']]);
+ $photo = DBA::selectFirst('photo', ['id'], ['resource-id' => $data['guid'], 'scale' => $data['scale']]);
+ if (!empty($photo['id'])) {
+ return $photo['id'];
+ }
+ return 0;
}
/**