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

#652180 ronald_istos, rjbrown99, et. al.: Assign author of imported nodes.

parent dd9ef226
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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.
*/
......
......@@ -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 &amp; 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.
......
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