You are here

function coder_upgrade_convert_update_N in Coder 7

Same name in this branch
  1. 7 coder_upgrade/conversions/other.inc \coder_upgrade_convert_update_N()
  2. 7 coder_upgrade/conversions/function.inc \coder_upgrade_convert_update_N()
Same name and namespace in other branches
  1. 7.2 coder_upgrade/conversions/other.inc \coder_upgrade_convert_update_N()
  2. 7.2 coder_upgrade/conversions/function.inc \coder_upgrade_convert_update_N()

Updates hook_update_N().

Check hook_update_N for a Doxygen style comment. Update hooks now return strings or throw exceptions.

@todo These hooks do not need to carry over from one version to the next. So we could simply delete the hook or its body. For those inclined to keep these hooks, we can modify the return statement (if any) to conform to D7.

Parameters

PGPNode $node: A node object containing a PGPClass (or function) item.

2 calls to coder_upgrade_convert_update_N()
coder_upgrade_callback_functions in coder_upgrade/conversions/other.inc
Callback routine for function changes using grammar parser.
coder_upgrade_upgrade_hook_update_N_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_update_N_alter().

File

coder_upgrade/conversions/function.inc, line 1274
Provides conversion routines applied to functions (or hooks).

Code

function coder_upgrade_convert_update_N(&$node) {
  cdp("inside " . __FUNCTION__);

  // Changes: update_php, update_sql
  $item =& $node->data;
  $editor = PGPEditor::getInstance();

  // Get the function body.
  $body =& $item->body;

  // Find return statement.
  // find() only looks at statements in the list, while search() recurses through inner lists.
  if (!($return = $body
    ->search('PGPFunctionCall', 'name', 'value', 'return', FALSE, 'backward'))) {

    // if (!($return = $body->find(T_RETURN, 'reverse'))) {
    //    clp("ERROR: return statement not found in hook_update_N");
    //    $body->insertFirst($editor->commentToStatement($msg), 'comment');
    return;
  }
  else {

    // Strip inline comment delimiter tokens from the parameter.
    $string = str_replace(array(
      '/*',
      '*/',
    ), '', $return
      ->getParameter()
      ->toString());

    // $string = $return->getParameter()->stripComments()->toString();
    // To use PGPList->insertListBefore() need the node of $return.
    //    $statement = $editor->textToStatements("// hook_update_N() no longer returns a \$ret array.\n//Instead, it should return nothing or a translated string to be displayed to the user indicating that the update ran successfully.\nSee http://drupal.org/node/224333#update_sql.");
    $statement = $editor
      ->commentToStatement("// hook_update_N() no longer returns a \$ret array. Instead, return ");
    $return
      ->insertStatementBefore($statement);
    $statement = $editor
      ->commentToStatement("// nothing or a translated string indicating the update ran successfully.");
    $return
      ->insertStatementBefore($statement);
    $statement = $editor
      ->commentToStatement("// See http://drupal.org/node/224333#update_sql.");
    $return
      ->insertStatementBefore($statement);

    // Replace the return() operand with t().
    $editor
      ->setParameter($return, 0, "t('TODO Add a descriptive string here to show in the UI.') /* {$string} */");
  }
}