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

Break out building of object into its own method.

parent a38c3985
No related branches found
No related tags found
No related merge requests found
...@@ -26,45 +26,16 @@ class FeedsNodeProcessor extends FeedsProcessor { ...@@ -26,45 +26,16 @@ class FeedsNodeProcessor extends FeedsProcessor {
// Create/update if item does not exist or update existing is enabled. // 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']) {
$node = $this->buildNode($nid, $source->feed_nid);
$node = new stdClass(); // Only proceed if item has actually changed.
$hash = $this->hash($item); $hash = $this->hash($item);
if (!empty($nid) && $hash == $this->getHash($nid)) {
// If updating check whether item actually has changed and if so, continue;
// retrieve its nid and vid.
if (!empty($nid)) {
if ($hash == $this->getHash($nid)) {
continue;
}
$node->nid = $nid;
$node->vid = db_result(db_query("SELECT vid FROM {node} WHERE nid = %d", $nid));
} }
else {
$node->created = FEEDS_REQUEST_TIME;
}
// Populate and prepare node object.
$node->type = $this->config['content_type'];
$node->changed = FEEDS_REQUEST_TIME;
$node->feeds_node_item = new stdClass();
$node->feeds_node_item->hash = $hash; $node->feeds_node_item->hash = $hash;
$node->feeds_node_item->id = $this->id;
$node->feeds_node_item->imported = FEEDS_REQUEST_TIME;
$node->feeds_node_item->feed_nid = $source->feed_nid;
$node->feeds_node_item->url = '';
$node->feeds_node_item->guid = '';
static $included;
if (!$included) {
module_load_include('inc', 'node', 'node.pages');
$included = TRUE;
}
node_object_prepare($node);
// Populate properties that are set by node_object_prepare().
$node->log = 'Created/updated by FeedsNodeProcessor';
$node->uid = $this->config['author'];
// Map and save nodes. If errors occur don't stop but report them. // Map and save node. If errors occur don't stop but report them.
try { try {
$this->map($item, $node); $this->map($item, $node);
node_save($node); node_save($node);
...@@ -317,6 +288,39 @@ class FeedsNodeProcessor extends FeedsProcessor { ...@@ -317,6 +288,39 @@ class FeedsNodeProcessor extends FeedsProcessor {
return 0; return 0;
} }
/**
* Creates a new node object in memory and returns it.
*/
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));
}
else {
$node->created = FEEDS_REQUEST_TIME;
}
$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');
$included = TRUE;
}
node_object_prepare($node);
// Populate properties that are set by node_object_prepare().
$node->log = 'Created/updated by FeedsNodeProcessor';
$node->uid = $this->config['author'];
return $node;
}
/** /**
* Create MD5 hash of $item array. * Create MD5 hash of $item array.
* @return Always returns a hash, even with empty, NULL, FALSE: * @return Always returns a hash, even with empty, NULL, FALSE:
......
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