MDL-42467 mod_data: added code to delete cached RSS feeds when database or glossary...
authorAndrew Davis <andrew@moodle.com>
Fri, 20 Jun 2014 04:58:48 +0000 (12:58 +0800)
committerAndrew Davis <andrew@moodle.com>
Wed, 25 Jun 2014 00:48:16 +0000 (08:48 +0800)
mod/data/lib.php
mod/data/rsslib.php
mod/glossary/deleteentry.php
mod/glossary/rsslib.php

index f3bb8f2..2edddbf 100644 (file)
@@ -3704,7 +3704,7 @@ function data_user_can_delete_preset($context, $preset) {
  * @return bool True if the record deleted, false if not.
  */
 function data_delete_record($recordid, $data, $courseid, $cmid) {
-    global $DB;
+    global $DB, $CFG;
 
     if ($deleterecord = $DB->get_record('data_records', array('id' => $recordid))) {
         if ($deleterecord->dataid == $data->id) {
@@ -3717,6 +3717,12 @@ function data_delete_record($recordid, $data, $courseid, $cmid) {
                 $DB->delete_records('data_content', array('recordid'=>$deleterecord->id));
                 $DB->delete_records('data_records', array('id'=>$deleterecord->id));
 
+                // Delete cached RSS feeds.
+                if (!empty($CFG->enablerssfeeds)) {
+                    require_once($CFG->dirroot.'/mod/data/rsslib.php');
+                    data_rss_delete_file($data);
+                }
+
                 // Trigger an event for deleting this record.
                 $event = \mod_data\event\record_deleted::create(array(
                     'objectid' => $deleterecord->id,
index 1c3b3e6..823239f 100644 (file)
         return ($recs && !empty($recs));
     }
 
+    /**
+     * Given a database object, deletes all cached RSS files associated with it.
+     *
+     * @param stdClass $data
+     */
+    function data_rss_delete_file($data) {
+        global $CFG;
+        require_once("$CFG->libdir/rsslib.php");
+
+        rss_delete_file('mod_data', $data);
+    }
+
index 7f5b64d..f50a56d 100644 (file)
@@ -114,6 +114,12 @@ if ($confirm and confirm_sesskey()) { // the operation was confirmed.
         $rm->delete_ratings($delopt);
     }
 
+    // Delete cached RSS feeds.
+    if (!empty($CFG->enablerssfeeds)) {
+        require_once($CFG->dirroot.'/mod/glossary/rsslib.php');
+        glossary_rss_delete_file($glossary);
+    }
+
     $event = \mod_glossary\event\entry_deleted::create(array(
         'context' => $context,
         'objectid' => $origentry->id,
index 66b2ffc..f322b8b 100644 (file)
         return ($recs && !empty($recs));
     }
 
-
+    /**
+      * Given a glossary object, deletes all cached RSS files associated with it.
+      *
+      * @param stdClass $glossary
+      */
+    function glossary_rss_delete_file($glossary) {
+        global $CFG;
+        require_once("$CFG->libdir/rsslib.php");
+
+        rss_delete_file('mod_glossary', $glossary);
+    }