/**
  * Delete all expired items.
  */
 public function execute()
 {
     global $DB;
     // Check if the category bin is disabled or there is no expiry time.
     $lifetime = get_config('tool_recyclebin', 'categorybinexpiry');
     if (!\tool_recyclebin\category_bin::is_enabled() || $lifetime <= 0) {
         return true;
     }
     // Get the items we can delete.
     $items = $DB->get_recordset_select('tool_recyclebin_category', 'timecreated <= :timecreated', array('timecreated' => time() - $lifetime));
     foreach ($items as $item) {
         mtrace("[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...");
         $bin = new \tool_recyclebin\category_bin($item->categoryid);
         $bin->delete_item($item);
     }
     $items->close();
     return true;
 }
Beispiel #2
0
/**
 * Hook called before we delete a course.
 *
 * @param \stdClass $course The course record.
 */
function tool_recyclebin_pre_course_delete($course)
{
    // Delete all the items in the course recycle bin, regardless if it enabled or not.
    // It may have been enabled, then disabled later on, so may still have content.
    $coursebin = new \tool_recyclebin\course_bin($course->id);
    $coursebin->delete_all_items();
    if (\tool_recyclebin\category_bin::is_enabled()) {
        $categorybin = new \tool_recyclebin\category_bin($course->category);
        $categorybin->store_item($course);
    }
}
Beispiel #3
0
/**
 * Hook called before we delete a course.
 *
 * @param \stdClass $course The course record.
 */
function tool_recyclebin_pre_course_delete($course)
{
    // It is possible that the course deletion which triggered this hook
    // was from an in progress course restore. In that case we do not want
    // it in the recycle bin.
    if (isset($course->deletesource) && $course->deletesource == 'restore') {
        return;
    }
    // Delete all the items in the course recycle bin, regardless if it enabled or not.
    // It may have been enabled, then disabled later on, so may still have content.
    $coursebin = new \tool_recyclebin\course_bin($course->id);
    $coursebin->delete_all_items();
    if (\tool_recyclebin\category_bin::is_enabled()) {
        $categorybin = new \tool_recyclebin\category_bin($course->category);
        $categorybin->store_item($course);
    }
}