]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Attach.php
BBCode - fixed syntax error
[friendica.git] / src / Model / Attach.php
index bfd5199bd5778fb211e01a587ae6fd0e37ab3c17..7efb56f95a03a87fcd38dc5823aa73b5de2a5883 100644 (file)
@@ -11,6 +11,8 @@ use Friendica\Core\System;
 use Friendica\Core\StorageManager;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
+use Friendica\Model\Storage\IStorage;
+use Friendica\Object\Image;
 use Friendica\Util\Security;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Mimetype;
@@ -175,7 +177,7 @@ class Attach extends BaseObject
         * @return boolean/integer Row id on success, False on errors
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '')
+       public static function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '')
        {
                if ($filetype === '') {
                        $filetype = Mimetype::getContentType($filename);
@@ -185,6 +187,7 @@ class Attach extends BaseObject
                        $filesize = strlen($data);
                }
 
+               /** @var IStorage $backend_class */
                $backend_class = StorageManager::getBackend();
                $backend_ref = '';
                if ($backend_class !== '') {
@@ -257,18 +260,19 @@ class Attach extends BaseObject
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @see   \Friendica\Database\DBA::update
         */
-       public static function update($fields, $conditions, $img = null, array $old_fields = [])
+       public static function update($fields, $conditions, Image $img = null, array $old_fields = [])
        {
-               if (!is_null($data)) {
+               if (!is_null($img)) {
                        // get items to update
                        $items = self::select(['backend-class','backend-ref'], $conditions);
 
                        foreach($items as $item) {
+                               /** @var IStorage $backend_class */
                                $backend_class = (string)$item['backend-class'];
                                if ($backend_class !== '') {
                                        $fields['backend-ref'] = $backend_class::put($img->asString(), $item['backend-ref']);
                                } else {
-                                       $fields['data'] = $data;
+                                       $fields['data'] = $img->asString();
                                }
                        }
                }
@@ -296,6 +300,7 @@ class Attach extends BaseObject
                $items = self::select(['backend-class','backend-ref'], $conditions);
 
                foreach($items as $item) {
+                       /** @var IStorage $backend_class */
                        $backend_class = (string)$item['backend-class'];
                        if ($backend_class !== '') {
                                $backend_class::delete($item['backend-ref']);