Skip to content

Commit

Permalink
MDL-42467 mod_data: added code to delete cached RSS feeds when databa…
Browse files Browse the repository at this point in the history
…se or glossary entries are deleted
  • Loading branch information
andyjdavis committed Jun 26, 2014
1 parent 9663e6f commit 5636246
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
9 changes: 8 additions & 1 deletion mod/data/lib.php
Expand Up @@ -3671,7 +3671,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) {
Expand All @@ -3685,6 +3685,13 @@ function data_delete_record($recordid, $data, $courseid, $cmid) {
$DB->delete_records('data_records', array('id'=>$deleterecord->id));

add_to_log($courseid, 'data', 'record delete', "view.php?id=$cmid", $data->id, $cmid);

// Delete cached RSS feeds.
if (!empty($CFG->enablerssfeeds)) {
require_once($CFG->dirroot.'/mod/data/rsslib.php');
data_rss_delete_file($data);
}

return true;
}
}
Expand Down
12 changes: 12 additions & 0 deletions mod/data/rsslib.php
Expand Up @@ -177,3 +177,15 @@ function data_rss_newstuff($data, $time) {
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);
}

7 changes: 7 additions & 0 deletions mod/glossary/deleteentry.php
Expand Up @@ -114,6 +114,13 @@
}

add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id,$cm->id);

// Delete cached RSS feeds.
if (!empty($CFG->enablerssfeeds)) {
require_once($CFG->dirroot.'/mod/glossary/rsslib.php');
glossary_rss_delete_file($glossary);
}

redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook");

} else { // the operation has not been confirmed yet so ask the user to do so
Expand Down
12 changes: 11 additions & 1 deletion mod/glossary/rsslib.php
Expand Up @@ -196,4 +196,14 @@ function glossary_rss_newstuff($glossary, $time) {
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);
}

0 comments on commit 5636246

Please sign in to comment.