Skip to content
Snippets Groups Projects
Commit 68de746c authored by Alex Barth's avatar Alex Barth
Browse files

#753426 Monkey Master, andrewlevine, alex_b: Partial update of nodes.

parent ebaf53fc
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
Feeds 6.x 1.X XXXX
------------------
- #753426 Monkey Master, andrewlevine, alex_b: Partial update of nodes.
- #840626 alevine, alex_b: Support using same mapping target multiple times.
- #624464 lyricnz, alex_b: Fix to "support tabs as delimiters".
- #840350 lyricnz: (Optionally) Transliterate enclosure filenames to provide
......
......@@ -9,6 +9,11 @@
// Create or delete FEEDS_NODE_BATCH_SIZE at a time.
define('FEEDS_NODE_BATCH_SIZE', 50);
// Updating mode for existing nodes.
define('FEEDS_NODE_SKIP_EXISTING', 0);
define('FEEDS_NODE_REPLACE_EXISTING', 1);
define('FEEDS_NODE_UPDATE_EXISTING', 2);
/**
* Creates nodes from feed items.
*/
......@@ -25,7 +30,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
while ($item = $batch->shiftItem()) {
// Create/update if item does not exist or update existing is enabled.
if (!($nid = $this->existingItemId($item, $source)) || $this->config['update_existing']) {
if (!($nid = $this->existingItemId($item, $source)) || ($this->config['update_existing'] != FEEDS_NODE_SKIP_EXISTING)) {
$node = $this->buildNode($nid, $source->feed_nid);
// Only proceed if item has actually changed.
......@@ -142,7 +147,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
$type = isset($types['story']) ? 'story' : key($types);
return array(
'content_type' => $type,
'update_existing' => 0,
'update_existing' => FEEDS_NODE_SKIP_EXISTING,
'expire' => FEEDS_EXPIRE_NEVER,
'mappings' => array(),
'author' => 0,
......@@ -179,9 +184,14 @@ class FeedsNodeProcessor extends FeedsProcessor {
'#default_value' => $this->config['expire'],
);
$form['update_existing'] = array(
'#type' => 'checkbox',
'#type' => 'radios',
'#title' => t('Update existing items'),
'#description' => t('Check if existing items should be updated from the feed.'),
'#description' => t('Choose how existing items should be updated from the feed.'),
'#options' => array(
FEEDS_NODE_SKIP_EXISTING => 'Do not update existing item nodes',
FEEDS_NODE_REPLACE_EXISTING => 'Replace existing item nodes',
FEEDS_NODE_UPDATE_EXISTING => 'Update existing item nodes (slower than replacing them)',
),
'#default_value' => $this->config['update_existing'],
);
return $form;
......@@ -291,21 +301,31 @@ class FeedsNodeProcessor extends FeedsProcessor {
*/
protected function buildNode($nid, $feed_nid) {
$node = new stdClass();
if (!empty($nid)) {
$node->nid = $nid;
$node->vid = db_result(db_query("SELECT vid FROM {node} WHERE nid = %d", $nid));
if (empty($nid)) {
$node->created = FEEDS_REQUEST_TIME;
$populate = TRUE;
}
else {
$node->created = FEEDS_REQUEST_TIME;
if ($this->config['update_existing'] == FEEDS_NODE_UPDATE_EXISTING) {
$node = node_load($nid, NULL, TRUE);
}
else {
$node->nid = $nid;
$node->vid = db_result(db_query("SELECT vid FROM {node} WHERE nid = %d", $nid));
$populate = TRUE;
}
}
if ($populate) {
$node->type = $this->config['content_type'];
$node->changed = FEEDS_REQUEST_TIME;
$node->feeds_node_item = new stdClass();
$node->feeds_node_item->id = $this->id;
$node->feeds_node_item->imported = FEEDS_REQUEST_TIME;
$node->feeds_node_item->feed_nid = $feed_nid;
$node->feeds_node_item->url = '';
$node->feeds_node_item->guid = '';
}
$node->type = $this->config['content_type'];
$node->changed = FEEDS_REQUEST_TIME;
$node->feeds_node_item = new stdClass();
$node->feeds_node_item->id = $this->id;
$node->feeds_node_item->imported = FEEDS_REQUEST_TIME;
$node->feeds_node_item->feed_nid = $feed_nid;
$node->feeds_node_item->url = '';
$node->feeds_node_item->guid = '';
static $included;
if (!$included) {
module_load_include('inc', 'node', 'node.pages');
......@@ -315,7 +335,9 @@ class FeedsNodeProcessor extends FeedsProcessor {
// Populate properties that are set by node_object_prepare().
$node->log = 'Created/updated by FeedsNodeProcessor';
$node->uid = $this->config['author'];
if ($populate) {
$node->uid = $this->config['author'];
}
return $node;
}
......
......@@ -144,8 +144,8 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Enable update existing and import updated feed file.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => TRUE));
// Enable replace existing and import updated feed file.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1));
$feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed_changes.rss2';
$this->editFeedNode($nid, $feed_url);
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
......@@ -185,6 +185,15 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid WHERE n.uid = %d", $author->uid));
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Set to update existing, remove authorship of above nodes and import again.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 2));
db_query("UPDATE {node} n JOIN {feeds_node_item} fi ON n.nid = fi.nid SET n.uid = 0, fi.hash=''");
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->drupalGet('node');
$this->assertNoPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/');
$count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid WHERE n.uid = %d", $author->uid));
$this->assertEqual($count, 0, 'Accurate number of items in database.');
// Login with new user with only access content permissions.
$this->drupalLogin(
$this->drupalCreateUser()
......@@ -289,8 +298,8 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Enable update existing and import updated feed file.
$this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => TRUE));
// Enable replace existing and import updated feed file.
$this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => 1));
$feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_changes.rss2';
$this->importURL('syndication_standalone', $feed_url);
$this->assertText('Updated 2 Story nodes.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment