]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/ExpirePosts.php
Ward againt contact_id = 0 in UpdateContact worker
[friendica.git] / src / Worker / ExpirePosts.php
index d1aa98d05dbac91318965a517f67996c805fa7f5..a2ef33f330e74a4397e1e16f027878074545a233 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -53,10 +53,10 @@ class ExpirePosts
                }
 
                // Set the expiry for origin posta
-               Worker::add(PRIORITY_LOW, 'Expire');
+               Worker::add(Worker::PRIORITY_LOW, 'Expire');
 
                // update nodeinfo data after everything is cleaned up
-               Worker::add(PRIORITY_LOW, 'NodeInfo');
+               Worker::add(Worker::PRIORITY_LOW, 'NodeInfo');
        }
 
        /**
@@ -68,7 +68,7 @@ class ExpirePosts
        {
                Logger::notice('Delete expired posts');
                // physically remove anything that has been deleted for more than two months
-               $condition = ["`gravity` = ? AND `deleted` AND `changed` < ?", GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')];
+               $condition = ["`gravity` = ? AND `deleted` AND `changed` < ?", Item::GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')];
                $rows = Post::select(['guid', 'uri-id', 'uid'],  $condition);
                while ($row = Post::fetch($rows)) {
                        Logger::info('Delete expired item', ['uri-id' => $row['uri-id'], 'guid' => $row['guid']]);
@@ -122,7 +122,7 @@ class ExpirePosts
                $rows = 0;
                $userposts = DBA::select('post-user', [], ["`uri-id` not in (select `uri-id` from `post`)"]);
                while ($fields = DBA::fetch($userposts)) {
-                       $post_fields = DBStructure::getFieldsForTable('post', $fields);
+                       $post_fields = DI::dbaDefinition()->truncateFieldsForTable('post', $fields);
                        DBA::insert('post', $post_fields, Database::INSERT_IGNORE);
                        $rows++;
                }
@@ -134,9 +134,9 @@ class ExpirePosts
                }
 
                $rows = 0;
-               $userposts = DBA::select('post-user', [], ["`gravity` = ? AND `uri-id` not in (select `uri-id` from `post-thread`)", GRAVITY_PARENT]);
+               $userposts = DBA::select('post-user', [], ["`gravity` = ? AND `uri-id` not in (select `uri-id` from `post-thread`)", Item::GRAVITY_PARENT]);
                while ($fields = DBA::fetch($userposts)) {
-                       $post_fields = DBStructure::getFieldsForTable('post-thread', $fields);
+                       $post_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread', $fields);
                        $post_fields['commented'] = $post_fields['changed'] = $post_fields['created'];
                        DBA::insert('post-thread', $post_fields, Database::INSERT_IGNORE);
                        $rows++;
@@ -149,9 +149,9 @@ class ExpirePosts
                }
 
                $rows = 0;
-               $userposts = DBA::select('post-user', [], ["`gravity` = ? AND `id` not in (select `post-user-id` from `post-thread-user`)", GRAVITY_PARENT]);
+               $userposts = DBA::select('post-user', [], ["`gravity` = ? AND `id` not in (select `post-user-id` from `post-thread-user`)", Item::GRAVITY_PARENT]);
                while ($fields = DBA::fetch($userposts)) {
-                       $post_fields = DBStructure::getFieldsForTable('post-thread-user', $fields);
+                       $post_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $fields);
                        $post_fields['commented'] = $post_fields['changed'] = $post_fields['created'];
                        DBA::insert('post-thread-user', $post_fields, Database::INSERT_IGNORE);
                        $rows++;
@@ -183,12 +183,16 @@ class ExpirePosts
                        AND NOT EXISTS(SELECT `parent-uri-id` FROM `post-user` WHERE `parent-uri-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `thr-parent-id` FROM `post-user` WHERE `thr-parent-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `external-id` FROM `post-user` WHERE `external-id` = `item-uri`.`id`)
+                       AND NOT EXISTS(SELECT `conversation-id` FROM `post-thread` WHERE `conversation-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `uri-id` FROM `mail` WHERE `uri-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `uri-id` FROM `event` WHERE `uri-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `uri-id` FROM `user-contact` WHERE `uri-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `uri-id` FROM `contact` WHERE `uri-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `uri-id` FROM `apcontact` WHERE `uri-id` = `item-uri`.`id`)
-                       AND NOT EXISTS(SELECT `uri-id` FROM `fcontact` WHERE `uri-id` = `item-uri`.`id`)
+                       AND NOT EXISTS(SELECT `uri-id` FROM `diaspora-contact` WHERE `uri-id` = `item-uri`.`id`)
+                       AND NOT EXISTS(SELECT `uri-id` FROM `inbox-status` WHERE `uri-id` = `item-uri`.`id`)
+                       AND NOT EXISTS(SELECT `uri-id` FROM `post-delivery` WHERE `uri-id` = `item-uri`.`id`)
+                       AND NOT EXISTS(SELECT `uri-id` FROM `post-delivery` WHERE `inbox-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `parent-uri-id` FROM `mail` WHERE `parent-uri-id` = `item-uri`.`id`)
                        AND NOT EXISTS(SELECT `thr-parent-id` FROM `mail` WHERE `thr-parent-id` = `item-uri`.`id`)", $item['uri-id']]);
 
@@ -225,9 +229,11 @@ class ExpirePosts
                        $uris = DBA::select('item-uri', ['id'], ["`id` IN
                                (SELECT `uri-id` FROM `post-thread` WHERE `received` < ?
                                        AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-thread-user`
-                                               WHERE (`mention` OR `starred` OR `wall` OR `pinned`) AND `uri-id` = `post-thread`.`uri-id`)
+                                               WHERE (`mention` OR `starred` OR `wall`) AND `uri-id` = `post-thread`.`uri-id`)
                                        AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-category`
                                                WHERE `uri-id` = `post-thread`.`uri-id`)
+                                       AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-collection`
+                                               WHERE `uri-id` = `post-thread`.`uri-id`)
                                        AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-media`
                                                WHERE `uri-id` = `post-thread`.`uri-id`)
                                        AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` INNER JOIN `contact` ON `contact`.`id` = `contact-id` AND `notify_new_posts`
@@ -258,7 +264,7 @@ class ExpirePosts
                                                AND `i`.`parent-uri-id` = `post-user`.`uri-id`)
                                        AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` = ?
                                                AND `i`.`parent-uri-id` = `post-user`.`uri-id` AND `i`.`received` > ?))",
-                               GRAVITY_PARENT, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days'), 0, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days')]);
+                               Item::GRAVITY_PARENT, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days'), 0, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days')]);
 
                        Logger::notice('Start deleting unclaimed public items');
                        $affected_count = 0;