+ } elseif ($stage == 10) {
+ $last_id = Config::get('system', 'dbclean-last-id-10', 0);
+ $days = intval(Config::get('system', 'dbclean_expire_conversation', 90));
+
+ logger("Deleting old conversations. Last created: ".$last_id);
+ $r = DBA::p("SELECT `received`, `item-uri` FROM `conversation`
+ WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY
+ ORDER BY `received` LIMIT ?", $days, $limit);
+ $count = DBA::numRows($r);
+ if ($count > 0) {
+ logger("found old conversations: ".$count);
+ while ($orphan = DBA::fetch($r)) {
+ $last_id = $orphan["received"];
+ DBA::delete('conversation', ['item-uri' => $orphan["item-uri"]]);
+ }
+ Worker::add(PRIORITY_MEDIUM, 'DBClean', 10, $last_id);
+ } else {
+ logger("No old conversations found");
+ }
+ DBA::close($r);
+ logger("Done deleting ".$count." conversations. Last created: ".$last_id);