Skip to content
Snippets Groups Projects
Commit 7c462d05 authored by Chris Leppanen's avatar Chris Leppanen
Browse files

Issue #1074520 by ccheu: Commit #783098 not included in 7.x-2.0-alpha3.

parent 88777976
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ files[] = tests/feeds_mapper_date.test ...@@ -17,6 +17,7 @@ files[] = tests/feeds_mapper_date.test
files[] = tests/feeds_mapper_field.test files[] = tests/feeds_mapper_field.test
files[] = tests/feeds_mapper_file.test files[] = tests/feeds_mapper_file.test
files[] = tests/feeds_mapper_path.test files[] = tests/feeds_mapper_path.test
files[] = tests/feeds_mapper_profile.test
files[] = tests/feeds_mapper.test files[] = tests/feeds_mapper.test
files[] = tests/feeds_mapper_config.test files[] = tests/feeds_mapper_config.test
files[] = tests/feeds_fetcher_file.test files[] = tests/feeds_fetcher_file.test
......
...@@ -43,14 +43,13 @@ function feeds_hook_info() { ...@@ -43,14 +43,13 @@ function feeds_hook_info() {
function feeds_cron() { function feeds_cron() {
if ($importers = feeds_reschedule()) { if ($importers = feeds_reschedule()) {
foreach ($importers as $id) { foreach ($importers as $id) {
feeds_importer($id)->schedule();
$rows = db_query("SELECT feed_nid FROM {feeds_source} WHERE id = :id", array(':id' => $id)); $rows = db_query("SELECT feed_nid FROM {feeds_source} WHERE id = :id", array(':id' => $id));
foreach ($rows as $row) { foreach ($rows as $row) {
feeds_source($id, $row->feed_nid)->schedule(); feeds_source($id, $row->feed_nid)->schedule();
} }
} }
feeds_reschedule(FALSE);
} }
// Expire old log entries. // Expire old log entries.
db_delete('feeds_log') db_delete('feeds_log')
->condition('request_time', REQUEST_TIME - 604800, '<') ->condition('request_time', REQUEST_TIME - 604800, '<')
...@@ -190,31 +189,37 @@ function feeds_batch($method, $importer_id, $feed_nid = 0, &$context) { ...@@ -190,31 +189,37 @@ function feeds_batch($method, $importer_id, $feed_nid = 0, &$context) {
} }
} }
/** /**
* Reschedule one or all importers. * Reschedules an importer's sources.
* *
* @param $importer_id * The importers designated to be rescheduled wil have their sources
* If TRUE, all importers will be rescheduled, if FALSE, no importers will * rescheduled on the next cron run.
* be rescheduled, if an importer id, only importer of that id will be *
* rescheduled. * @param string $importer_id
* * (Optional) If an importer id, that importer will be added to the list
* @return * for rescheduling. If NULL, the list of importers will be reset.
* TRUE if all importers need rescheduling. FALSE if no rescheduling is *
* required. An array of importers that need rescheduling. * @return array
*/ * The list of importers that need to have their sources rescheduled.
function feeds_reschedule($importer_id = NULL) { *
$reschedule = variable_get('feeds_reschedule', FALSE); * @see feeds_cron()
if ($importer_id === TRUE || $importer_id === FALSE) { */
$reschedule = $importer_id; function feeds_reschedule($importer_id = NULL) {
}
elseif (is_string($importer_id) && $reschedule !== TRUE) { // Get a list of importers.
$reschedule = is_array($reschedule) ? $reschedule : array(); $reschedule = variable_get('feeds_reschedule', array());
$reschedule[$importer_id] = $importer_id;
// We are adding one to the list.
if ($importer_id) {
$reschedule[] = $importer_id;
$reschedule = array_unique($reschedule);
variable_set('feeds_reschedule', $reschedule);
} }
variable_set('feeds_reschedule', $reschedule);
if ($reschedule === TRUE) { else {
return feeds_enabled_importers(); variable_del('feeds_reschedule');
} }
return $reschedule; return $reschedule;
} }
......
...@@ -95,6 +95,7 @@ class FeedsImporter extends FeedsConfigurable { ...@@ -95,6 +95,7 @@ class FeedsImporter extends FeedsConfigurable {
else { else {
JobScheduler::get('feeds_importer_expire')->remove($job); JobScheduler::get('feeds_importer_expire')->remove($job);
} }
debug($job);
} }
/** /**
...@@ -126,13 +127,20 @@ class FeedsImporter extends FeedsConfigurable { ...@@ -126,13 +127,20 @@ class FeedsImporter extends FeedsConfigurable {
if ($config = db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $this->id))->fetchField()) { if ($config = db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $this->id))->fetchField()) {
drupal_write_record('feeds_importer', $save, 'id'); drupal_write_record('feeds_importer', $save, 'id');
// Only rebuild menu if content_type has changed. Don't worry about // Only rebuild menu if content_type has changed. Don't worry about
// rebuilding menus when creating a new importer since it will default // rebuilding menus when creating a new importer since it will default
// to the standalone page. // to the standalone page.
$config = unserialize($config); $config = unserialize($config);
if ($config['content_type'] != $save->config['content_type']) { if ($config['content_type'] != $save->config['content_type']) {
variable_set('menu_rebuild_needed', TRUE); variable_set('menu_rebuild_needed', TRUE);
} }
// Reschedule this importer's sources if the import period changed.
if ($config['import_period'] != $save->config['import_period']) {
feeds_reschedule($this->id);
}
} }
else { else {
drupal_write_record('feeds_importer', $save); drupal_write_record('feeds_importer', $save);
...@@ -168,6 +176,7 @@ class FeedsImporter extends FeedsConfigurable { ...@@ -168,6 +176,7 @@ class FeedsImporter extends FeedsConfigurable {
); );
if ($this->export_type & EXPORT_IN_CODE) { if ($this->export_type & EXPORT_IN_CODE) {
feeds_reschedule($this->id); feeds_reschedule($this->id);
$this->schedule();
} }
else { else {
JobScheduler::get('feeds_importer_expire')->remove($job); JobScheduler::get('feeds_importer_expire')->remove($job);
...@@ -310,16 +319,6 @@ class FeedsImporter extends FeedsConfigurable { ...@@ -310,16 +319,6 @@ class FeedsImporter extends FeedsConfigurable {
); );
return $form; return $form;
} }
/**
* Reschedule if import period changes.
*/
public function configFormSubmit(&$values) {
if ($this->config['import_period'] != $values['import_period']) {
feeds_reschedule($this->id);
}
parent::configFormSubmit($values);
}
} }
/** /**
......
<?php
/**
* @file
* On behalf implementation of Feeds mapping API for user profiles.
*/
/**
* Implements hook_feeds_processor_target_alter().
*/
function profile_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
if ($entity_type != 'user') {
return;
}
$categories = profile_user_categories();
foreach ($categories as $category) {
foreach (_profile_get_fields($category['name']) as $record) {
$targets[$record->name] = array(
'name' => t('Profile: @name', array('@name' => $record->title)),
'description' => t('Profile: @name', array('@name' => $record->title)),
'callback' => 'profile_feeds_set_target',
);
}
}
}
/**
* Set the user profile target after import.
*/
function profile_feeds_set_target($source, $entity, $target, $value, $mapping) {
$entity->$target = $value;
}
name,mail,color,letter
magna,auctor@tortor.com,red,alpha
rhoncus,rhoncus@habitasse.org,blue,beta
<?php
/**
* @file
* Test suite for profile mapper mappers/profile.inc.
*/
/**
* Class for testing Feeds profile mapper.
*/
class FeedsMapperProfileTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
'name' => 'Mapper: Profile',
'description' => 'Test Feeds Mapper support for profile fields.',
'group' => 'Feeds',
);
}
function setUp() {
// Call parent setup with required modules.
parent::setUp(array('profile'));
}
/**
* Basic test loading a doulbe entry CSV file.
*/
function test() {
// Create profile fields.
$edit = array(
'category' => 'test',
'title' => 'color',
'name' => 'profile_textfield_test',
'register' => 1,
);
$name = $this->drupalPost('admin/config/people/profile/add/textfield', $edit, t('Save field'));
$edit = array(
'category' => 'test',
'title' => 'letter',
'name' => 'profile_select_test',
'options' => 'alpha' . "\n" . 'beta' . "\n" . 'gamma',
'register' => 1,
);
$name = $this->drupalPost('admin/config/people/profile/add/selection', $edit, t('Save field'));
// Create an importer.
$this->createImporterConfiguration('Profile import', 'profile_import');
// Set and configure plugins.
$this->setPlugin('profile_import', 'FeedsFileFetcher');
$this->setPlugin('profile_import', 'FeedsCSVParser');
$this->setPlugin('profile_import', 'FeedsUserProcessor');
// Go to mapping page and create a couple of mappings.
$mappings = array(
'0' => array(
'source' => 'name',
'target' => 'name',
'unique' => 0,
),
'1' => array(
'source' => 'mail',
'target' => 'mail',
'unique' => 1,
),
'2' => array(
'source' => 'color',
'target' => 'profile_textfield_test',
),
'3' => array(
'source' => 'letter',
'target' => 'profile_select_test',
),
);
$this->addMappings('profile_import', $mappings);
// Change some of the basic configuration.
$edit = array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
);
$this->drupalPost('admin/structure/feeds/profile_import/settings', $edit, 'Save');
// Import CSV file.
$this->importFile('profile_import', $this->absolutePath() .'/tests/feeds/profile.csv');
$this->assertText('Created 2 users.');
// Check the two imported users.
$this->drupalGet('admin/people');
$this->assertText('magna');
$this->assertText('rhoncus');
$account = user_load_by_name('magna');
$this->assertEqual($account->profile_textfield_test, 'red', 'User profile_textfield_test is correct');
$this->assertEqual($account->profile_select_test, 'alpha', 'User profile_select_test is correct');
$account = user_load_by_name('rhoncus');
$this->assertEqual($account->profile_textfield_test, 'blue', 'User profile_textfield_test is correct');
$this->assertEqual($account->profile_select_test, 'beta', 'User profile_select_test is correct');
}
}
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