function coder_upgrade_insert_dbtng_statement in Coder 7.2
Same name and namespace in other branches
- 7 coder_upgrade/conversions/db.inc \coder_upgrade_insert_dbtng_statement()
Inserts (or replaces) D6 database API call with D7 call.
Parameters
PGPNode $node: The node containing the function call object to be replaced.
array $new: The array of strings of the new database API call.
Return value
unknown_type
1 call to coder_upgrade_insert_dbtng_statement()
- coder_upgrade_parse_query_string in coder_upgrade/
conversions/ db.inc - Replaces D6 database API call with D7 equivalent.
File
- coder_upgrade/
conversions/ db.inc, line 535 - Provides conversion routines applied to database API function calls and hooks.
Code
function coder_upgrade_insert_dbtng_statement(&$node, $new) {
cdp(__FUNCTION__);
// Create helper objects.
$editor = PGPEditor::getInstance();
// Get the function call object.
$item =& $node->data;
// Create the expression text to be inserted.
// TODO Handle the indentation of the output string in the toString() routine.
$new = implode("\n", $new);
$new = str_replace("\t", ' ', $new);
if ($new == 'NULL') {
clp("ERROR: Could not parse the SQL string");
$comment = '// TODO Please convert this statement to the D7 database API syntax.';
}
else {
$comment = '// TODO Please review the conversion of this statement to the D7 database API syntax.';
}
// Insert a comment before the statement containing the function call.
$item
->insertStatementBefore($editor
->commentToStatement($comment));
// Insert a multiline-safe comment with the original function call.
$string = str_replace(array(
'/*',
'*/',
), '', $item
->toString());
$item
->insertStatementBefore($editor
->commentToStatement("/* {$string} */"));
// Create a new DBTNG expression (of chained operations).
$temp = $editor
->expressionToStatement($new);
// Insert the expression in the containing statement before the function call.
$node->container
->insertListBefore($node, $temp);
// Delete the function call.
// NOTE: This is an example of deleting a function call reference.
$node->container
->delete($node);
// NOTE: If the replacement was another function call, then we could write:
// $temp->parent = $item->parent;
// $item = $temp;
}