You are here

function coder_upgrade_convert_user_load in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/conversions/call.inc \coder_upgrade_convert_user_load()
1 call to coder_upgrade_convert_user_load()
coder_upgrade_upgrade_call_user_load_alter in coder_upgrade/conversions/call.inc
Implements hook_upgrade_call_user_load_alter().

File

coder_upgrade/conversions/call.inc, line 2778
Provides conversion routines applied to function calls.

Code

function coder_upgrade_convert_user_load(&$item, &$operand, $is_parameter = TRUE) {

  // DONE
  // Create helper objects.
  $editor = PGPEditor::getInstance();

  // TODO We need an isType() that is not a class method.
  if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING) {

    // Value is a string. (Assume it is an integer.)
    //    $uid = trim($operand['value'], "'\"");
    //    $operand = $editor->expressionToStatement("array($uid)");
    return FALSE;

    // return $is_parameter ? $operand : FALSE;
  }
  elseif (is_array($operand)) {

    // Unexpected.
  }
  elseif (is_object($operand) && $operand
    ->isType(T_ARRAY)) {
    $array =& $operand;
    if ($uid = $array
      ->findValue('uid')) {

      // Array contains a value for key = 'uid'
      $array
        ->deleteKey('uid');
      if ($array->count) {

        // If other conditions, then need to use user_load_multiple.
        $p0 = $editor
          ->expressionToStatement("array(" . $uid
          ->toString() . ")");
        $item->name['value'] = 'user_load_multiple';
      }
      else {

        // Stay with user_load.
        $p0 = $editor
          ->expressionToStatement($uid
          ->toString());
      }
    }
    else {

      // Create empty array for $uids parameter.
      $p0 = $editor
        ->expressionToStatement('array()');
      $item->name['value'] = 'user_load_multiple';
    }
    return $p0;
  }
  elseif (is_object($operand)) {

    // Unexpected.
  }
  else {

    // Value is a number.
    //    $uid = trim($operand, "'\"");
    //    $operand = $editor->expressionToStatement("array($uid)");
    return FALSE;

    // return $is_parameter ? $operand : FALSE;
  }
  return FALSE;
}