+ return $r;
+ }
+
+ /**
+ * Store new file metadata in db and binary in default backend from existing file
+ *
+ * @param $src
+ * @param $uid
+ * @param string $filename
+ * @param string $allow_cid
+ * @param string $allow_gid
+ * @param string $deny_cid
+ * @param string $deny_gid
+ * @return boolean True on success
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function storeFile($src, $uid, $filename = '', $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '')
+ {
+ if ($filename === '') {
+ $filename = basename($src);
+ }
+
+ $data = @file_get_contents($src);
+
+ return self::store($data, $uid, $filename, '', null, $allow_cid, $allow_gid, $deny_cid, $deny_gid);
+ }
+
+
+ /**
+ * Update an attached file
+ *
+ * @param array $fields Contains the fields that are updated
+ * @param array $conditions Condition array with the key values
+ * @param Image $img Image data to update. Optional, default null.
+ * @param array|boolean $old_fields Array with the old field values that are about to be replaced (true = update on duplicate)
+ *
+ * @return boolean Was the update successful?
+ *
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @see \Friendica\Database\DBA::update
+ */
+ public static function update($fields, $conditions, Image $img = null, array $old_fields = [])
+ {
+ if (!is_null($img)) {
+ // get items to update
+ $items = self::selectToArray(['backend-class','backend-ref'], $conditions);
+
+ foreach($items as $item) {
+ $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
+ if ($backend_class !== null) {
+ $fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
+ } else {
+ $fields['data'] = $img->asString();
+ }
+ }
+ }
+
+ $fields['edited'] = DateTimeFormat::utcNow();
+
+ return DBA::update('attach', $fields, $conditions, $old_fields);
+ }
+
+
+ /**
+ * Delete info from table and data from storage
+ *
+ * @param array $conditions Field condition(s)
+ * @param array $options Options array, Optional
+ *
+ * @return boolean
+ *
+ * @throws \Exception
+ * @see \Friendica\Database\DBA::delete
+ */
+ public static function delete(array $conditions, array $options = [])
+ {
+ // get items to delete data info
+ $items = self::selectToArray(['backend-class','backend-ref'], $conditions);
+
+ foreach($items as $item) {
+ $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
+ if ($backend_class !== null) {
+ $backend_class->delete($item['backend-ref'] ?? '');
+ }
+ }
+
+ return DBA::delete('attach', $conditions, $options);