use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\System;
+use Friendica\Core\StorageManager;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Object\Image;
$params = ["order" => ["scale" => true]];
$photo = self::selectFirst([], $conditions, $params);
- if ($photo === false) {
- return self::createPhotoForSystemResource("images/nosign.jpg");
- }
+
return $photo;
}
/**
- * @brief Check if photo with given resource id exists
+ * @brief Check if photo with given conditions exists
*
- * @param string $resourceid Resource ID of the photo
+ * @param array $conditions Array of extra conditions
*
* @return boolean
*/
- public static function exists($resourceid)
+ public static function exists(array $conditions)
{
- return DBA::count("photo", ["resource-id" => $resourceid]) > 0;
+ return DBA::exists("photo", $conditions);
}
+
/**
* @brief Get Image object for given row id. null if row id does not exist
*
- * @param integer $id Row id
+ * @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
*
* @return \Friendica\Object\Image
*/
- public static function getImageForPhoto($photo)
+ public static function getImageForPhoto(array $photo)
{
$data = "";
if ($photo["backend-class"] == "") {
$backend_ref = (string)$existing_photo["backend-ref"];
$backend_class = (string)$existing_photo["backend-class"];
} else {
- $backend_class = Config::get("storage", "class", "");
+ $backend_class = StorageManager::getBackend();
}
if ($backend_class === "") {
$data = $Image->asString();
return $r;
}
- public static function delete(array $conditions, $options = [])
+
+ /**
+ * @brief Delete info from table and data from storage
+ *
+ * @param array $conditions Field condition(s)
+ * @param array $options Options array, Optional
+ *
+ * @return boolean
+ *
+ * @see \Friendica\Database\DBA::delete
+ */
+ public static function delete(array $conditions, array $options = [])
{
// get photo to delete data info
$photos = self::select(["backend-class","backend-ref"], $conditions);
-
+
foreach($photos as $photo) {
$backend_class = (string)$photo["backend-class"];
if ($backend_class !== "") {
$fields["data"] = $img->asString();
}
}
+ $fields['updated'] = DateTimeFormat::utcNow();
}
- $fields['updated'] = DateTimeFormat::utcNow();
+ $fields['edited'] = DateTimeFormat::utcNow();
- return DBA::update("photo", $fields, $conditions);
+ return DBA::update("photo", $fields, $conditions, $old_fields);
}
/**