Skip to content
Snippets Groups Projects
Commit 44b9e9be authored by git's avatar git Committed by MegaChriz
Browse files

Issue #2655470 by alan-ps, Louis Delacretaz: Added a timezone target to the user processor.

parent b35a9fee
No related branches found
No related tags found
No related merge requests found
......@@ -104,6 +104,11 @@ class FeedsUserProcessor extends FeedsProcessor {
if (empty($account->name) || empty($account->mail) || !valid_email_address($account->mail)) {
throw new FeedsValidationException(t('User name missing or email not valid.'));
}
// Timezone validation.
if (!empty($account->timezone) && !array_key_exists($account->timezone, system_time_zones())) {
throw new FeedsValidationException(t("Failed importing '@name'. User's timezone is not valid.", array('@name' => $account->name)));
}
}
/**
......@@ -237,6 +242,10 @@ class FeedsUserProcessor extends FeedsProcessor {
$this->rolesListSetTarget($source, $target_user, $target_element, $value, $mapping);
break;
case 'timezone':
$target_user->timezone = $value;
break;
default:
parent::setTargetElement($source, $target_user, $target_element, $value);
break;
......@@ -277,6 +286,10 @@ class FeedsUserProcessor extends FeedsProcessor {
'name' => t('User language'),
'description' => t('Default language for the user.'),
),
'timezone' => array(
'name' => t('Timezone'),
'description' => t('The timezone identifier, like UTC or Europe/Lisbon.'),
),
'roles_list' => array(
'name' => t('User roles'),
'description' => t('User roles provided as role names in comma separated list.'),
......
name,mail,since,password,password_md5,password_sha512
Morticia,morticia@example.com,1244347500,mort,e0108a7eb91670308fff8179a4785453,$S$DfuNE4ur7Jq8xVoJURGm8oMIYunKd366KQUE6akc3EXW/ym9ghpq
Fester,fester@example.com,1241865600,fest,c8cce3815094f01f0ab774fd4f7a77d4,$S$DjJPqmjlWTIen0nQrG3a.vA71Vc0DqCpKuB.g9zmBMnGzIV6JxqH
Gomez,gomez@example.com,1228572000,gome,8a5346b9a510f1f698ab0062b71201ac,$S$Dv.EtHlTfnrxuWGLbe3cf31mD9MF6.4u2Z46M2o2dMGgQGzi7m/5
Wednesday,wednesdayexample.com,1228347137,wedn,fefb673afaf531dbd78771976a150dc8,$S$DdPzksGh/c8UukipWagAhTzaqUp/eNHVPiC.x6URBQyA503Z41PI
Pugsley,pugsley@example,1228260225,pugs,09189568a8ee4d0addf53d2f6e4847cd,$S$D1oUihjrYXr.4iesN8Sfw1rVRLdo188v0NRGgcNR/V09oIyYPYmZ
name,mail,since,password,password_md5,password_sha512,timezone
Morticia,morticia@example.com,1244347500,mort,e0108a7eb91670308fff8179a4785453,$S$DfuNE4ur7Jq8xVoJURGm8oMIYunKd366KQUE6akc3EXW/ym9ghpq,UTC
Fester,fester@example.com,1241865600,fest,c8cce3815094f01f0ab774fd4f7a77d4,$S$DjJPqmjlWTIen0nQrG3a.vA71Vc0DqCpKuB.g9zmBMnGzIV6JxqH,
Gomez,gomez@example.com,1228572000,gome,8a5346b9a510f1f698ab0062b71201ac,$S$Dv.EtHlTfnrxuWGLbe3cf31mD9MF6.4u2Z46M2o2dMGgQGzi7m/5,utc
Wednesday,wednesdayexample.com,1228347137,wedn,fefb673afaf531dbd78771976a150dc8,$S$DdPzksGh/c8UukipWagAhTzaqUp/eNHVPiC.x6URBQyA503Z41PI,America/New_York
Pugsley,pugsley@example,1228260225,pugs,09189568a8ee4d0addf53d2f6e4847cd,$S$D1oUihjrYXr.4iesN8Sfw1rVRLdo188v0NRGgcNR/V09oIyYPYmZ,Europe/Lisbon
......@@ -756,6 +756,48 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase {
$this->feedsLoginUser('Gomez', 'gome');
}
/**
* Tests mapping to timezone.
*/
public function testTimezoneTarget() {
// Set to update existing users.
$this->setSettings('user_import', 'FeedsUserProcessor', array('update_existing' => FEEDS_UPDATE_EXISTING));
// Add mapping to timezone.
$this->addMappings('user_import', array(
4 => array(
'source' => 'timezone',
'target' => 'timezone',
),
));
// Create an account for Fester, to ensure that the timezone can be emptied.
user_save(drupal_anonymous_user(), array(
'name' => 'Fester',
'mail' => 'fester@example.com',
'pass' => 'fest',
'status' => 1,
'timezone' => 'Europe/Lisbon',
));
// Import CSV file.
$this->importFile('user_import', $this->absolutePath() . '/tests/feeds/users.csv');
// Assert that Morticia got the UTC timezone.
$account = user_load_by_name('Morticia');
$this->assertEqual('UTC', $account->timezone, 'Morticia has the UTC timezone.');
// Assert that Fester did not get any timezone.
$account = user_load_by_name('Fester');
$this->assertFalse($account->timezone, 'Fester does not have any timezone');
// Assert that Gomez doesn't exist after import and appropriate message is
// displayed.
$account = user_load_by_name('Gomez');
$this->assertFalse($account, "Gomez doesn't exist after import.");
$this->assertText("Failed importing 'Gomez'. User's timezone is not valid.");
}
/**
* Log in an imported user.
*
......
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