You are here

function user_patterns_prepare in Patterns 7.2

Same name and namespace in other branches
  1. 7 patterns_components/components/user.inc \user_patterns_prepare()

Implements hook_patterns_prepare() for the user module.

File

patterns_components/components/user.inc, line 203

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'],
      );
    }
    else {

      //Load the fake att but with empty values, so it can be executed with no changes
      $data['pass'] = '';
    }
  }
  elseif ($tag == 'role') {

    /* if (isset($data['value'])) {
         $data['name'] = $data['value'];
         unset($data['value']);
       } */
  }
  return patterns_results($status, $msg);
}