Skip to content

Commit

Permalink
blog MDL-25341 made external blog syncronization not delete all previ…
Browse files Browse the repository at this point in the history
…ously retreieved blog posts
  • Loading branch information
andyjdavis committed Dec 16, 2010
1 parent 88e5c58 commit 9829e3d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions blog/lib.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ function blog_sync_external_entries($externalblog) {
$DB->update_record('blog_external', $externalblog);
}

// Delete all blog entries associated with this external blog
blog_delete_external_entries($externalblog);

$rss = new moodle_simplepie($externalblog->url);

if (empty($rss->data)) {
Expand Down Expand Up @@ -196,15 +193,21 @@ function blog_sync_external_entries($externalblog) {
$newentry->format = FORMAT_HTML;
$newentry->subject = $entry->get_title();
$newentry->summary = $entry->get_description();

//used to decide whether to insert or update
//uses enty permalink plus creation date if available
$existingpostconditions = array('uniquehash'=>$entry->get_permalink());

//our DB doesnt allow null creation or modified timestamps so check the external blog didnt supply one
//our DB doesnt allow null creation or modified timestamps so check the external blog supplied one
$entrydate = $entry->get_date('U');
if (empty($entrydate)) {
$newentry->created = time();
$newentry->lastmodified = time();
} else {
$newentry->created = $entrydate;
$newentry->lastmodified = $entrydate;

$existingpostconditions['created'] = $entrydate;
}

$textlib = textlib_get_instance();
Expand All @@ -216,11 +219,17 @@ function blog_sync_external_entries($externalblog) {
continue;
}

$id = $DB->insert_record('post', $newentry);
$postid = $DB->get_field('post', 'id', $existingpostconditions);
if ($postid===false) {
$id = $DB->insert_record('post', $newentry);

// Set tags
if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) {
tag_set('post', $id, $tags);
// Set tags
if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) {
tag_set('post', $id, $tags);
}
} else {
$newentry->id = $postid;
$id = $DB->update_record('post', $newentry);
}
}

Expand Down

0 comments on commit 9829e3d

Please sign in to comment.