]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/History.php
Merge pull request #13230 from annando/warnings
[friendica.git] / src / Model / Post / History.php
index e889ccf20559b0344e308fb22646ee26cb3de59e..8a373b3cd3ed86a77e944f0bed2ba1dfc4df54b0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -24,7 +24,7 @@ namespace Friendica\Model\Post;
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\Database\Database;
-use Friendica\Database\DBStructure;
+use Friendica\DI;
 use Friendica\Model\Post;
 
 class History
@@ -37,16 +37,22 @@ class History
         */
        public static function add(int $uri_id, array $item)
        {
-               $allfields = DBStructure::definition('', false);
-               $fields = array_keys($allfields['post-history']['fields']);
+               $allfields = DI::dbaDefinition()->getAll();
+               $fields    = array_keys($allfields['post-history']['fields']);
 
                $post = Post::selectFirstPost($fields, ['uri-id' => $uri_id]);
                if (empty($post)) {
+                       Logger::warning('Post not found', ['uri-id' => $uri_id]);
                        return;
                }
 
-               $update = false;
-               $changed = DBStructure::getFieldsForTable('post-history', $item);
+               if ($item['edited'] <= $post['edited']) {
+                       Logger::info('New edit date is not newer than the old one', ['uri-id' => $uri_id, 'old' => $post['edited'], 'new' => $item['edited']]);
+                       return;
+               }
+
+               $update  = false;
+               $changed = DI::dbaDefinition()->truncateFieldsForTable('post-history', $item);
                unset($changed['uri-id']);
                unset($changed['edited']);
                foreach ($changed as $field => $content) {