diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8ed8d14a7305bfd4c6cdf5832ed1804112d31f29..a67b46e22f1170eb48370ce2a96dbc74f2fba971 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXXXX ---------------------------------- +- #652180 ronald_istos, rjbrown99, et. al.: Assign author of imported nodes. - #783098 elliotttf: Introduce hook_feeds_user_processor_targets_alter(), mapper for user profile fields. diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc index 56e67365c94455b9a7c016a56ec6ad7524f59733..da4079801d4b655b92af317c638dd467ff778894 100644 --- a/plugins/FeedsNodeProcessor.inc +++ b/plugins/FeedsNodeProcessor.inc @@ -60,7 +60,7 @@ class FeedsNodeProcessor extends FeedsProcessor { // Populate properties that are set by node_object_prepare(). $node->log = 'Created/updated by FeedsNodeProcessor'; - $node->uid = 0; + $node->uid = $this->config['author']; // Map and save nodes. If errors occur don't stop but report them. try { @@ -172,6 +172,7 @@ class FeedsNodeProcessor extends FeedsProcessor { 'update_existing' => 0, 'expire' => FEEDS_EXPIRE_NEVER, 'mappings' => array(), + 'author' => 0, ); } @@ -188,6 +189,14 @@ class FeedsNodeProcessor extends FeedsProcessor { '#options' => $types, '#default_value' => $this->config['content_type'], ); + $author = user_load(array('uid' => $this->config['author'])); + $form['author'] = array( + '#type' => 'textfield', + '#title' => t('Author'), + '#description' => t('Author to be assigned to created nodes - leave empty to assign "anonymous".'), + '#autocomplete_path' => 'user/autocomplete', + '#default_value' => empty($author->name) ? 'anonymous' : check_plain($author->name), + ); $period = drupal_map_assoc(array(FEEDS_EXPIRE_NEVER, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 604800 * 4, 604800 * 12, 604800 * 24, 31536000), 'feeds_format_expire'); $form['expire'] = array( '#type' => 'select', @@ -205,6 +214,18 @@ class FeedsNodeProcessor extends FeedsProcessor { return $form; } + /** + * Override parent::configFormValidate(). + */ + public function configFormValidate(&$values) { + if ($author = user_load(array('name' => $values['author']))) { + $values['author'] = $author->uid; + } + else { + $values['author'] = 0; + } + } + /** * Override setTargetElement to operate on a target item that is a node. */ diff --git a/tests/feeds.test b/tests/feeds.test index 68a77a8e25afb6ed041b5151812483d301e074b7..28f337a7079163948dc4f26a57cf8b4b286c829c 100644 --- a/tests/feeds.test +++ b/tests/feeds.test @@ -100,6 +100,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { // Assert accuracy of aggregated information. $this->drupalGet('node'); + $this->assertPattern('/<span class="submitted">(.*?)Anonymous<\/span>/'); $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates'); $this->assertText('Tue, 10/06/2009'); $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal'); @@ -172,12 +173,16 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); $this->assertEqual($count, 0, 'Accurate number of items in database.'); - // Import again, we should find new content. + // Change author, import again. + $author = $this->drupalCreateUser(); + $this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $author->name)); $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); $this->assertText('Created 10 Story nodes.'); - // Assert DB status, there should be 10 again. - $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}")); + // Assert author. + $this->drupalGet('node'); + $this->assertPattern('/<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, 10, 'Accurate number of items in database.'); // Login with new user with only access content permissions.