示例#1
0
 /**
  *
  * Delete all not published revisions that are older than X days.
  * @param int $days
  */
 public static function removeOldRevisions($days)
 {
     //
     // 1) Dynamic Widgets (including revisions)
     // Dynamic widgets have an associated revision.
     // That revision's creation time and publication
     // state indicates if a widget should be removed
     // or not from corresponding db table 'ip_widget'.
     //
     $table = ipTable('revision');
     $sql = "\n            SELECT `revisionId` FROM {$table}\n            WHERE (" . ipDb()->sqlMinAge('createdAt', $days * 24, 'HOUR') . ") AND `isPublished` = 0\n        ";
     $revisionList = ipDb()->fetchColumn($sql);
     foreach ($revisionList as $revisionId) {
         \Ip\Internal\Content\Service::removeRevision($revisionId);
     }
     //
     // 2) Static Widgets (from static blocks only!)
     // Static widgets are presisted with revisionId=0.
     // Therefore, we've to make the time check on widget's
     // 'createdAt' column combined with 'isDeleted=1' flag
     // and 'revisionId=0' indicating widget's removal state.
     //
     $table = ipTable('widget');
     $sql = $sql = "\n            SELECT `id` FROM {$table}\n            WHERE (" . ipDb()->sqlMinAge('createdAt', $days * 24, 'HOUR') . ") \n            AND `revisionId` = 0 AND `isDeleted` = 1 AND `deletedAt` IS NOT NULL\n        ";
     $staticWidgetList = ipDb()->fetchColumn($sql);
     foreach ($staticWidgetList as $staticWidgetId) {
         \Ip\Internal\Content\Service::removeWidget($staticWidgetId);
     }
 }