You are here

function coder_upgrade_extract_operations in Coder 7

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

Extracts operations from conditions and replaces the conditions with TRUE.

Parameters

PGPList $conditions: A list of conditions to an if block.

string $op: A string of the hook operation.

Return value

array Array of operations referenced in the if block.

3 calls to coder_upgrade_extract_operations()
coder_upgrade_convert_link in coder_upgrade/conversions/function.inc
Updates hook_link().
coder_upgrade_convert_op in coder_upgrade/conversions/other.inc
Initiates the transformation of $op hook to a new hook_$op style function.
coder_upgrade_convert_op in coder_upgrade/conversions/tool.inc
Initiates the transformation of a hook($op) to a new hook_$op style function.

File

coder_upgrade/conversions/other.inc, line 1451
Other conversion routine file for the coder_upgrade module.

Code

function coder_upgrade_extract_operations(&$conditions, $op) {
  cdp("inside " . __FUNCTION__);
  $operations = array();

  /*
   * A condition may consist of at most two operands separated by an operator.
   */
  if (is_a($conditions, 'PGPList')) {

    // Iterate over the conditions of the condition list.
    $current = $conditions
      ->first();
    while ($current->next != NULL) {
      $type = $current->type;
      if ($type == 'condition') {

        // Get the condition object of the current node.
        $condition =& $current->data;

        // Iterate over elements of the condition expression.
        $found = FALSE;
        $current2 = $condition
          ->first();
        while ($current2->next != NULL) {
          if ($current2->type == 'operand') {

            // Get the operand (object or array) of the current node.
            $element =& $current2->data;

            // Inspect the element looking for $op.
            if (is_a($element, 'PGPOperand')) {

              // Inspect the operand looking for $op.
              $text = $element
                ->toString();
              if (strpos($text, $op) !== FALSE) {
                $found = TRUE;
              }
              else {
                $operation = $element
                  ->toString();
              }
            }
            elseif (is_array($element)) {

              // This should have type = T_CONSTANT_ENCAPSED_STRING.
              $operation = $element['value'];
            }
          }

          // An interesting effect takes place with an & on the next line.
          $current2 = $current2->next;
        }
        if ($found) {

          // Replace condition with TRUE so the logic remains the same.
          $condition
            ->clear();
          $data = array(
            'type' => T_STRING,
            'value' => 'TRUE',
          );
          $condition
            ->insertLast($data, 'operand');

          // Add operation to list.
          $operations[] = trim($operation, "'\"");
        }
      }
      $current = $current->next;
    }
  }
  return $operations;
}