You are here

function coder_upgrade_convert_install in Coder 7

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

Updates hook_install() or hook_uninstall().

Database schema (un)installed automatically.

Parameters

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

3 calls to coder_upgrade_convert_install()
coder_upgrade_callback_functions in coder_upgrade/conversions/other.inc
Callback routine for function changes using grammar parser.
coder_upgrade_upgrade_hook_install_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_install_alter().
coder_upgrade_upgrade_hook_uninstall_alter in coder_upgrade/conversions/function.inc
Implements hook_upgrade_hook_uninstall_alter().

File

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

Code

function coder_upgrade_convert_install($node) {
  cdp("inside " . __FUNCTION__);
  $item =& $node->data;

  // Get body statements.
  $body =& $item->body;
  $editor = PGPEditor::getInstance();

  /*
   * In 6.x, drupal_install_schema() has a return value, but not in 7.x.
   * The code below asssumes the return value is not utilized. Otherwise,
   * set the variable to array.
   *
   * @todo If there is a likelihood of multiple calls to these functions, then
   * use $body->searchCallback().
   */
  foreach (array(
    'drupal_install_schema',
    'drupal_uninstall_schema',
  ) as $function) {
    if ($call_node = $body
      ->search('PGPFunctionCall', 'name', 'value', $function, TRUE)) {

      // Get the function call object.
      $call = $call_node->data;

      // Insert a comment before the statement containing the function call.
      $statement = $editor
        ->commentToStatement("// TODO The drupal_(un)install_schema functions are called automatically in D7.");
      $call
        ->insertStatementBefore($statement);

      // Get the expression containing the function call.
      $container = $call_node->container;
      if ($container
        ->countType('operand') > 1) {

        // The function call is part of a larger expression.
        // Insert nodes to comment out the function call and replace it with default return value.
        $statement = $editor
          ->expressionToStatement('array()/*' . $call
          ->toString() . '*/');
        $container
          ->insertListBefore($call_node, $statement);

        // Delete the function call node.
        $container
          ->delete($call_node);
      }
      else {

        // The function call is the sole expression on this statement.
        // Comment out the statement.
        $call->parent->data = $editor
          ->commentToStatement($call
          ->toString());
      }
    }
  }
}