You are here

function coder_upgrade_upgrade_call_node_load_alter in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/conversions/call.inc \coder_upgrade_upgrade_call_node_load_alter()

Implements hook_upgrade_call_node_load_alter().

File

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

Code

function coder_upgrade_upgrade_call_node_load_alter(&$node, &$reader) {

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

  // Get the function call object.
  $item =& $node->data;

  // First parameter no longer an array, so we need to use node_load_multiple().
  $p0 = $item
    ->getParameter()
    ->getElement();
  if (is_object($p0) && get_class($p0) == 'PGPArray') {
    if ($nid = $p0
      ->findValue('nid')) {
      $item
        ->setParameter(0, $nid);
    }
    else {
      $name =& $item->name;
      $name = 'node_load_multiple';
      if ($item
        ->parameterCount() > 1) {

        // Add vid to conditions array if present
        // TODO Would it work to have passed nid and vid as params in D6?
        // If so, then we should allow for this.
        $key = $editor
          ->expressionToStatement("'vid'");

        // TODO Add an API function to insert array item with or w/o key.
        $p0->values
          ->insertLast($key, 'key');
        $assign = '=>';
        $p0->values
          ->insertLast($assign, 'assign');

        //      $value = $editor->expressionToStatement($item->printParameter(1));
        $p0->values
          ->insertLast($item
          ->getParameter(1), 'value');
        $p0->count++;
        cdp($p0);

        //      $p1 = $item->printParameter(1); // TODO What if this has an assignment?
        $item
          ->deleteParameter(1);
        $editor
          ->insertParameter($item, 0, 'array()');
      }

      // TODO Maybe use array_shift to get the first node?
      $item
        ->insertStatementBefore($editor
        ->commentToStatement('// TODO node_load_multiple returns an array of nodes, rather than a single node'));
    }
  }
}