function user_patterns_prepare in Patterns 7
Same name and namespace in other branches
- 7.2 patterns_components/components/user.inc \user_patterns_prepare()
Implements hook_patterns_prepare() for the user module.
File
- patterns_components/
components/ user.inc, line 130
Code
function user_patterns_prepare($action, $tag, &$data) {
$status = PATTERNS_SUCCESS;
$msg = t('Execution successful');
if ($tag == 'user') {
if (!isset($data['name'])) {
if (!isset($data['uid'])) {
$status = PATTERNS_ERR;
$msg = t('Cannot create/modify user. Missing name and uid.');
}
// Retrieve the username name from the db
$data['name'] = db_select('users', 'u')
->fields('u', array(
'name',
))
->condition('u.uid', $data['uid'])
->execute()
->fetchField();
}
else {
if (!isset($data['uid'])) {
$data['uid'] = db_select('users', 'u')
->fields('u', array(
'uid',
))
->condition('u.name', $data['name'])
->execute()
->fetchField();
}
}
// @TODO: Check if we are overriding the password
if (isset($data['password'])) {
$data['pass'] = array(
'pass1' => $data['password'],
'pass2' => $data['password'],
);
unset($data['password']);
}
if (isset($data['timezone'])) {
/* TODO: this needs work and verification
if (in_array($data['timezone'], array('0', '+0', '-0', '0000', '-0000'))) {
$data['timezone'] = '+0000';
}
if (!empty($data['timezone']) && preg_match('/(\+|-)([0][0-9]|[1][01])(00|30|45)/', $data['timezone'], $parts)) {
$seconds = $parts[2] * 3600 + $parts[3] * 60;
$sign = $parts[1] == '+' ? '' : '-';
$data['timezone'] = $sign . $seconds;
}
*/
}
else {
// Default timezone is Europe/Berlin.
$data['timezone'] = 'Europe/Berlin';
}
}
elseif ($tag == 'role') {
/* if (isset($data['value'])) {
$data['name'] = $data['value'];
unset($data['value']);
} */
}
elseif ($tag == 'permission') {
if (isset($data['role']) && !isset($data['rid'])) {
$data['rid'] = $data['role'];
}
unset($data['role']);
}
return patterns_results($status, $msg);
}