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