]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Media.php
Merge branch '2021.03-rc' into copyright-2021
[friendica.git] / src / Model / Post / Media.php
index 1a9d4a83ea47c54876521bf61a95209490d74ed9..5dc5a0daa241ef8bc3df99e327cca313d98aa43b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,6 +23,7 @@ namespace Friendica\Model\Post;
 
 use Friendica\Core\Logger;
 use Friendica\Core\System;
+use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Util\Images;
@@ -72,20 +73,36 @@ class Media
 
                // We are storing as fast as possible to avoid duplicated network requests
                // when fetching additional information for pictures and other content.
-               $result = DBA::insert('post-media', $media, true);
+               $result = DBA::insert('post-media', $media, Database::INSERT_UPDATE);
                Logger::info('Stored media', ['result' => $result, 'media' => $media, 'callstack' => System::callstack()]);
                $stored = $media;
 
                $media = self::fetchAdditionalData($media);
 
                if (array_diff_assoc($media, $stored)) {
-                       $result = DBA::insert('post-media', $media, true);
+                       $result = DBA::insert('post-media', $media, Database::INSERT_UPDATE);
                        Logger::info('Updated media', ['result' => $result, 'media' => $media]);
                } else {
                        Logger::info('Nothing to update', ['media' => $media]);
                }
        }
 
+       /**
+        * Copy attachments from one uri-id to another
+        *
+        * @param integer $from_uri_id
+        * @param integer $to_uri_id
+        * @return void
+        */
+       public static function copy(int $from_uri_id, int $to_uri_id)
+       {
+               $attachments = self::getByURIId($from_uri_id);
+               foreach ($attachments as $attachment) {
+                       $attachment['uri-id'] = $to_uri_id;
+                       self::insert($attachment);
+               }
+       }
+
        /**
         * Creates the "[attach]" element from the given attributes
         *