]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/DBClean.php
Merge pull request #8494 from annando/ap-fix-comments
[friendica.git] / src / Worker / DBClean.php
index 60f0e64c427c2da4ad669cfab7af73556cc5c3b3..0316b9ebf6ebdef744938dac6ce698f63c0f6321 100644 (file)
@@ -1,16 +1,34 @@
 <?php
 /**
- * @file src/Worker/DBClean.php
- * The script is called from time to time to clean the database entries and remove orphaned data.
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @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\Worker;
 
-use Friendica\Core\Config;
 use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\DI;
 
+/**
+ * The script is called from time to time to clean the database entries and remove orphaned data.
+ */
 class DBClean {
        public static function execute($stage = 0) {
 
@@ -80,7 +98,7 @@ class DBClean {
                        $last_id = DI::config()->get('system', 'dbclean-last-id-1', 0);
 
                        Logger::log("Deleting old global item entries from item table without user copy. Last ID: ".$last_id);
-                       $r = DBA::p("SELECT `id` FROM `item` WHERE `uid` = 0 AND
+                       $r = DBA::p("SELECT `id`, `guid` FROM `item` WHERE `uid` = 0 AND
                                                NOT EXISTS (SELECT `guid` FROM `item` AS `i` WHERE `item`.`guid` = `i`.`guid` AND `i`.`uid` != 0) AND
                                                `received` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `id` >= ?
                                        ORDER BY `id` LIMIT ?", $days_unclaimed, $last_id, $limit);
@@ -89,6 +107,7 @@ class DBClean {
                                Logger::log("found global item orphans: ".$count);
                                while ($orphan = DBA::fetch($r)) {
                                        $last_id = $orphan["id"];
+                                       Logger::info('Delete global orphan item', ['id' => $orphan['id'], 'guid' => $orphan['guid']]);
                                        DBA::delete('item', ['id' => $orphan["id"]]);
                                }
                                Worker::add(PRIORITY_MEDIUM, 'DBClean', 1, $last_id);
@@ -103,7 +122,7 @@ class DBClean {
                        $last_id = DI::config()->get('system', 'dbclean-last-id-2', 0);
 
                        Logger::log("Deleting items without parents. Last ID: ".$last_id);
-                       $r = DBA::p("SELECT `id` FROM `item`
+                       $r = DBA::p("SELECT `id`, `guid` FROM `item`
                                        WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`)
                                        AND `id` >= ? ORDER BY `id` LIMIT ?", $last_id, $limit);
                        $count = DBA::numRows($r);
@@ -111,6 +130,7 @@ class DBClean {
                                Logger::log("found item orphans without parents: ".$count);
                                while ($orphan = DBA::fetch($r)) {
                                        $last_id = $orphan["id"];
+                                       Logger::info('Delete orphan item', ['id' => $orphan['id'], 'guid' => $orphan['guid']]);
                                        DBA::delete('item', ['id' => $orphan["id"]]);
                                }
                                Worker::add(PRIORITY_MEDIUM, 'DBClean', 2, $last_id);
@@ -299,7 +319,7 @@ class DBClean {
                        $till_id = DI::config()->get('system', 'dbclean-last-id-8', 0);
 
                        Logger::log("Deleting old global item entries from expired threads from ID ".$last_id." to ID ".$till_id);
-                       $r = DBA::p("SELECT `id` FROM `item` WHERE `uid` = 0 AND
+                       $r = DBA::p("SELECT `id`, `guid` FROM `item` WHERE `uid` = 0 AND
                                                NOT EXISTS (SELECT `guid` FROM `item` AS `i` WHERE `item`.`guid` = `i`.`guid` AND `i`.`uid` != 0) AND
                                                `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY AND `id` >= ? AND `id` <= ?
                                        ORDER BY `id` LIMIT ?", $last_id, $till_id, $limit);
@@ -308,6 +328,7 @@ class DBClean {
                                Logger::log("found global item entries from expired threads: ".$count);
                                while ($orphan = DBA::fetch($r)) {
                                        $last_id = $orphan["id"];
+                                       Logger::info('Delete expired thread item', ['id' => $orphan['id'], 'guid' => $orphan['guid']]);
                                        DBA::delete('item', ['id' => $orphan["id"]]);
                                }
                                Worker::add(PRIORITY_MEDIUM, 'DBClean', 9, $last_id);