]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/History.php
Merge pull request #11728 from nupplaphil/feat/split_db_definitions
[friendica.git] / src / Model / Post / History.php
index e889ccf20559b0344e308fb22646ee26cb3de59e..e7699e20c9b0b0f580b8965fea6b6757ab2b5653 100644 (file)
@@ -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) {