mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
blog MDL-25341 added removal of deleted external blog posts
This commit is contained in:
parent
cc52e53dd1
commit
50ff50daaa
19
blog/lib.php
19
blog/lib.php
@ -137,7 +137,8 @@ function blog_remove_associations_for_course($courseid) {
|
||||
|
||||
/**
|
||||
* Given a record in the {blog_external} table, checks the blog's URL
|
||||
* for new entries not yet copied into Moodle.
|
||||
* for new entries not yet copied into Moodle.
|
||||
* Also attempts to identify and remove deleted blog entries
|
||||
*
|
||||
* @param object $externalblog
|
||||
* @return boolean False if the Feed is invalid
|
||||
@ -164,7 +165,9 @@ function blog_sync_external_entries($externalblog) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//used to identify blog posts that have been deleted from the source feed
|
||||
$oldesttimestamp = null;
|
||||
$uniquehashes = array();
|
||||
|
||||
foreach ($rss->get_items() as $entry) {
|
||||
// If filtertags are defined, use them to filter the entries by RSS category
|
||||
@ -185,6 +188,8 @@ function blog_sync_external_entries($externalblog) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$uniquehashes[] = $entry->get_permalink();
|
||||
|
||||
$newentry = new stdClass();
|
||||
$newentry->userid = $externalblog->userid;
|
||||
@ -249,6 +254,18 @@ function blog_sync_external_entries($externalblog) {
|
||||
$DB->update_record('post', $newentry);
|
||||
}
|
||||
}
|
||||
|
||||
//Look at the posts we have in the database to check if any of them have been deleted from the feed.
|
||||
//Only checking posts within the time frame returned by the rss feed. Older items may have been deleted or
|
||||
//may just not be returned anymore. We cant tell the difference so we leave older posts alone.
|
||||
$dbposts = $DB->get_records_select('post', 'created > :ts', array('ts'=>$oldesttimestamp), '', 'id, uniquehash');
|
||||
$todelete = array();
|
||||
foreach($dbposts as $dbpost) {
|
||||
if (!in_array($dbpost->uniquehash,$uniquehashes)) {
|
||||
$todelete[] = $dbpost->id;
|
||||
}
|
||||
}
|
||||
$DB->delete_records_list('post', 'id', $todelete);
|
||||
|
||||
$DB->update_record('blog_external', array('id' => $externalblog->id, 'timefetched' => mktime()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user