]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Attach.php
Fix: The "extid" field wasn't updated
[friendica.git] / src / Model / Attach.php
index fc0ebb8e2c869398c915fadd3c6075477d1716c6..6182727c9762ad85d63c6365941bc8636129c5aa 100644 (file)
@@ -1,9 +1,24 @@
 <?php
-
 /**
- * @file src/Model/Attach.php
- * @brief This file contains the Attach class for database interface
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Model;
 
 use Friendica\Core\System;
@@ -13,7 +28,7 @@ use Friendica\DI;
 use Friendica\Object\Image;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Mimetype;
-use Friendica\Util\Security;
+use Friendica\Security\Security;
 
 /**
  * Class to handle attach dabatase table
@@ -22,7 +37,7 @@ class Attach
 {
 
        /**
-        * @brief Return a list of fields that are associated with the attach table
+        * Return a list of fields that are associated with the attach table
         *
         * @return array field list
         * @throws \Exception
@@ -36,7 +51,7 @@ class Attach
        }
 
        /**
-        * @brief Select rows from the attach table and return them as array
+        * Select rows from the attach table and return them as array
         *
         * @param array $fields     Array of selected fields, empty for all
         * @param array $conditions Array of fields for conditions
@@ -57,7 +72,7 @@ class Attach
        }
 
        /**
-        * @brief Retrieve a single record from the attach table
+        * Retrieve a single record from the attach table
         *
         * @param array $fields     Array of selected fields, empty for all
         * @param array $conditions Array of fields for conditions
@@ -78,7 +93,7 @@ class Attach
        }
 
        /**
-        * @brief Check if attachment with given conditions exists
+        * Check if attachment with given conditions exists
         *
         * @param array $conditions Array of extra conditions
         *
@@ -91,7 +106,7 @@ class Attach
        }
 
        /**
-        * @brief Retrive a single record given the ID
+        * Retrive a single record given the ID
         *
         * @param int $id Row id of the record
         *
@@ -106,7 +121,7 @@ class Attach
        }
 
        /**
-        * @brief Retrive a single record given the ID
+        * Retrive a single record given the ID
         *
         * @param int $id Row id of the record
         *
@@ -135,7 +150,7 @@ class Attach
        }
 
        /**
-        * @brief Get file data for given row id. null if row id does not exist
+        * Get file data for given row id. null if row id does not exist
         *
         * @param array $item Attachment data. Needs at least 'id', 'backend-class', 'backend-ref'
         *
@@ -144,8 +159,12 @@ class Attach
         */
        public static function getData($item)
        {
-               $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
-               if ($backendClass === null) {
+               if (!empty($item['data'])) {
+                       return $item['data'];
+               }
+
+               $backendClass = DI::storageManager()->getByName($item['backend-class'] ?? '');
+               if (empty($backendClass)) {
                        // legacy data storage in 'data' column
                        $i = self::selectFirst(['data'], ['id' => $item['id']]);
                        if ($i === false) {
@@ -159,7 +178,7 @@ class Attach
        }
 
        /**
-        * @brief Store new file metadata in db and binary in default backend
+        * Store new file metadata in db and binary in default backend
         *
         * @param string  $data      Binary data
         * @param integer $uid       User ID
@@ -215,7 +234,7 @@ class Attach
        }
 
        /**
-        * @brief Store new file metadata in db and binary in default backend from existing file
+        * Store new file metadata in db and binary in default backend from existing file
         *
         * @param        $src
         * @param        $uid
@@ -240,7 +259,7 @@ class Attach
 
 
        /**
-        * @brief Update an attached file
+        * Update an attached file
         *
         * @param array         $fields     Contains the fields that are updated
         * @param array         $conditions Condition array with the key values
@@ -260,7 +279,7 @@ class Attach
 
                        foreach($items as $item) {
                                $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
-                               if ($backend_class !== null) {
+                               if (!empty($backend_class)) {
                                        $fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
                                } else {
                                        $fields['data'] = $img->asString();
@@ -275,7 +294,7 @@ class Attach
 
 
        /**
-        * @brief Delete info from table and data from storage
+        * Delete info from table and data from storage
         *
         * @param array $conditions Field condition(s)
         * @param array $options    Options array, Optional
@@ -292,7 +311,7 @@ class Attach
 
                foreach($items as $item) {
                        $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
-                       if ($backend_class !== null) {
+                       if (!empty($backend_class)) {
                                $backend_class->delete($item['backend-ref'] ?? '');
                        }
                }