Skip to content
Snippets Groups Projects
Commit 4a90d0d2 authored by Jim Berry's avatar Jim Berry
Browse files

coder_upgrade.db.inc: Disable db_query routine untill it is more robust;...

coder_upgrade.db.inc: Disable db_query routine untill it is more robust; coder_upgrade.call.inc: Implement #user_load_multiple; coder_upgrade.function.inc: Refactor coder_upgrade_convert_return pattern to loop on conditional statements.
parent 5bd7fa24
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,14 @@
coder_upgrade 7.x-1.x, 2009-xx-xx (development version)
---------------------------------
- Changes (2010-03-11):
* coder_upgrade.db.inc
* - disable db_query routine untill it is more robust
* coder_upgrade.call.inc
* - implement #user_load_multiple
* coder_upgrade.function.inc
* - refactor coder_upgrade_convert_return pattern to loop on conditional statements
- Changes (2010-03-10):
* coder_upgrade.call.inc
* - implement #theme_page
......
......@@ -96,6 +96,7 @@
*
* User API
* http://drupal.org/node/224333#user_cancel (ALSO in convert_functions)
* http://drupal.org/node/224333#user_load_multiple
* http://drupal.org/node/224333#user_authenticate
*
*
......@@ -1038,7 +1039,6 @@ function coder_upgrade_upgrade_call_file_scan_directory_alter(&$item, &$reader)
$variable = $operand->findNode('value');
$parent = $item->parent;
$statement = $parent->container->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
}
// Edge case: the parameter could have a comment.
// Make a general function to clean the parameter of comments and whitespace so we can truly evaluate it.
......@@ -1938,6 +1938,121 @@ function coder_upgrade_upgrade_call_user_delete_alter(&$item, &$reader) { // DON
$editor->setParameter($item, 2, "\$method = 'user_cancel_block' /* TODO Set this variable */");
}
/**
* Implements hook_upgrade_call_user_load_alter().
*/
function coder_upgrade_upgrade_call_user_load_alter(&$item, &$reader) { // DONE
// Create helper objects.
$editor = PGPEditor::getInstance();
// Process function call.
$name = &$item->name;
$name['value'] = 'user_load_multiple';
if (!$item->parameterCount()) {
// No parameters is an acceptable default.
return;
}
/*
* Steps
* - parameter may be a value, array, or variable (with a preceding assignment)
* - value: wrap in an array
* - array
* - extract 'uid' element
* - leave remaining items as $conditions in new function
* - variable: apply above to the assignment value
*/
if ($item->getParameter()->isType(T_VARIABLE)) {
// Parameter is a variable.
$variable = $item->getParameter()->getElement()->findNode('value');
$parent = $item->parent;
// TODO This single search won't find multiple assignments to array variable.
$statement = $parent->container->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
if ($statement) {
$operand = &$statement->values->getElement()->findNode('operand', 'backward');
$p0 = coder_upgrade_convert_user_load($item, $operand, FALSE);
}
}
else {
$operand = &$item->getParameter()->getElement();
$p0 = coder_upgrade_convert_user_load($item, $operand);
if ($item->getParameter()->isType(T_ARRAY)) {
// Parameter is an array.
$array = $item->getParameter()->getElement();
if (!$array->count) {
$item->deleteParameter();
}
}
}
if ($p0) {
$item->insertParameter(0, $p0);
}
}
function coder_upgrade_convert_user_load(&$item, &$operand, $is_parameter = TRUE) { // DONE
// Create helper objects.
$editor = PGPEditor::getInstance();
// TODO We need an isType() that is not a class method.
if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING) {
// Value is a string. (Assume it is an integer.)
$uid = trim($operand['value'], "'\"");
$operand = $editor->expressionToStatement("array($uid)");
return FALSE; // return $is_parameter ? $operand : FALSE;
}
elseif (is_array($operand)) {
// Unexpected.
}
elseif (is_object($operand) && $operand->isType(T_ARRAY)) {
$array = &$operand;
if ($uid = $array->findValue('uid')) {
// Array contains a value for key = 'uid'
$p0 = $editor->expressionToStatement("array(" . $uid->toString() . ")");
$array->deleteKey('uid');
}
else {
// Create empty array for $uids parameter.
$p0 = $editor->expressionToStatement('array()');
}
return $p0;
}
elseif (is_object($operand)) {
// Unexpected.
}
else {
// Value is a number.
$uid = trim($operand, "'\"");
$operand = $editor->expressionToStatement("array($uid)");
return FALSE; // return $is_parameter ? $operand : FALSE;
}
return FALSE;
}
/**
* Implements hook_upgrade_call_variable_get_alter().
*/
function coder_upgrade_upgrade_call_variable_get_alter(&$item, &$reader) { // (OMIT)
// Create helper objects.
$editor = PGPEditor::getInstance();
// Process function call.
$name = &$item->name;
}
/**
* Implements hook_upgrade_call_variable_set_alter().
*/
function coder_upgrade_upgrade_call_variable_set_alter(&$item, &$reader) { // (OMIT)
// Create helper objects.
$editor = PGPEditor::getInstance();
// Process function call.
$name = &$item->name;
}
/**
* Updates menu_valid_path().
*
......
......@@ -26,6 +26,9 @@
* @param PGPFunctionCall $item
*/
function coder_upgrade_upgrade_call_db_query_alter(&$item, &$reader) {
// Disable this routine until it is improved.
return;
// Create helper objects.
$editor = PGPEditor::getInstance();
......
......@@ -1019,9 +1019,10 @@ function coder_upgrade_convert_op(&$node, $callback, $op_index) {
// SWITCH condition.
$current = $body->first();
while ($current->next != NULL) {
$found = FALSE;
$statement = &$current->data;
if (is_object($statement)) {
cdp($statement->print_r());
cdp($statement);
}
if (is_a($statement, 'PGPConditional')) {
// cdp("inside PGPConditional check");
......@@ -1035,6 +1036,7 @@ function coder_upgrade_convert_op(&$node, $callback, $op_index) {
$operand = $condition->toString();
// If the condition variable matches the $op variable, then go to work.
if ($op == $operand) {
$found = TRUE;
$cases = $statement->body;
$node->traverse($cases, $callback);
}
......@@ -1051,6 +1053,7 @@ function coder_upgrade_convert_op(&$node, $callback, $op_index) {
$operations = coder_upgrade_extract_operations($statement->conditions, $op);
// Loop on the extracted operations.
foreach ($operations as $operation) {
$found = TRUE;
// Change a T_ELSEIF to a T_IF in the new hook function.
$statement->type = T_IF; // If it isn't already.
$block = new stdClass();
......@@ -1061,13 +1064,24 @@ function coder_upgrade_convert_op(&$node, $callback, $op_index) {
}
}
}
elseif (is_array($statement) && $statement['type'] == T_WHITESPACE) {
// Remove whitespace.
$found = TRUE;
}
// Move to next node.
$current = &$current->next;
if ($found) {
// Get the statement list the switch statement (or if block) node is part of.
$container = &$current->container;
$container->delete($current->previous);
}
}
if ($body->count()) {
$editor = PGPEditor::getInstance();
// TODO Insert comment indicating the block was not changed.
$body->insertFirst($editor->commentToStatement('// TODO Remaining code in this function needs to be moved to the appropriate new hook function.')/*, 'comment'*/);
}
}
/**
* Extracts operations from conditions and replaces the conditions with TRUE.
......@@ -1198,7 +1212,7 @@ function coder_upgrade_callback_block($node, $case_node, $operation = '') {
// http://drupal.org/node/224333#block_deltas_renamed
// Change numeric block keys to strings
$editor = new PGPEditor();
$editor = PGPEditor::getInstance();
$body = &$case_node->data->body;
$text = $body->toString();
$search = array(
......@@ -1215,7 +1229,7 @@ function coder_upgrade_callback_block($node, $case_node, $operation = '') {
$text = preg_replace($search, $replace, $text, -1, $count);
if ($count) {
$body = $editor->textToStatements($text);
$body->insertFirst($editor->commentToStatement('// TODO Rename block deltas (e.g. delta-0) to readable strings.', 'comment'));
$body->insertFirst($editor->commentToStatement('// TODO Rename block deltas (e.g. delta-0) to readable strings.'), 'comment');
}
// Create the new hook function.
......@@ -1612,7 +1626,7 @@ function coder_upgrade_op_to_hook($node, $case_node, $hook, $parameters) {
* arrays. In the third, the loop is on assignment statements.
*
*/
function coder_upgrade_convert_return(&$node, $hook, $callback = '') { // (OMIT)
function coder_upgrade_convert_return(&$node, $hook, $callback = '') { // DONE
cdp("inside " . __FUNCTION__);
$editor = PGPEditor::getInstance();
$msg = '// TODO The array elements in this hook function need to be changed.';
......@@ -1624,7 +1638,7 @@ function coder_upgrade_convert_return(&$node, $hook, $callback = '') { // (OMIT)
if (!($return = $body->find(T_RETURN, 'reverse'))) {
clp("ERROR: return statement not found in hook_$hook");
$body->insertFirst($editor->commentToStatement($msg, 'comment'));
$body->insertFirst($editor->commentToStatement($msg), 'comment');
return;
}
......@@ -1648,8 +1662,29 @@ function coder_upgrade_convert_return(&$node, $hook, $callback = '') { // (OMIT)
$return_variable = $operand->toString();
$count = 0;
coder_upgrade_convert_return_loop($body->first(), $count, $return_variable, $hook, $callback);
if (!$count) {
clp("ERROR: assignment statement to return variable not found in hook_$hook");
$body->insertFirst($editor->commentToStatement($msg), 'comment');
return;
}
}
else {
clp("ERROR: operand of return statement is not an array or variable in hook_$hook");
$body->insertFirst($editor->commentToStatement($msg), 'comment');
}
}
$current = $body->first();
function coder_upgrade_convert_return_loop(&$node, &$count, $return_variable, $hook, $callback = '') { // NOT DONE
cdp("inside " . __FUNCTION__);
/*
* Loop on body statements until we find an assignment to the return variable.
* The assignment could be to an array element like $info['node_type_name'] = array(...).
* Or directly to the variable like $info = array('node_type_name' = array(...)).
*/
$current = $node;
while ($current->next != NULL) {
if (is_object($current->data) && $current->data->type == T_ASSIGNMENT) { // if ($current->data->isType(T_ASSIGNMENT)) {
$assignment = $current->data;
......@@ -1688,17 +1723,10 @@ function coder_upgrade_convert_return(&$node, $hook, $callback = '') { // (OMIT)
$count++;
}
}
$current = $current->next;
}
if (!$count) {
clp("ERROR: assignment statement to return variable not found in hook_$hook");
$body->insertFirst($editor->commentToStatement($msg, 'comment'));
return;
elseif (is_a($current->data, 'PGPConditional')) {
coder_upgrade_convert_return_loop($current->data->body->first(), $count, $return_variable, $hook, $callback);
}
}
else {
clp("ERROR: operand of return statement is not an array or variable in hook_$hook");
$body->insertFirst($editor->commentToStatement($msg, 'comment'));
$current = $current->next;
}
}
......@@ -1710,7 +1738,7 @@ function coder_upgrade_convert_return(&$node, $hook, $callback = '') { // (OMIT)
*
* @param PGPArray $array1
*/
function coder_upgrade_callback_return_case1(&$array1, $hook, $callback = '') { // (OMIT)
function coder_upgrade_callback_return_case1(&$array1, $hook, $callback = '') { // DONE
cdp("inside " . __FUNCTION__);
// The keys of this array are the node types.
......@@ -1751,7 +1779,7 @@ function coder_upgrade_callback_return_case1(&$array1, $hook, $callback = '') {
*
* @param PGPArray $array2
*/
function coder_upgrade_callback_return_case3(&$array2, $hook, $callback = '') { // (OMIT)
function coder_upgrade_callback_return_case3(&$array2, $hook, $callback = '') { // DONE
cdp("inside " . __FUNCTION__);
$callback = $callback == '' ? "coder_upgrade_callback_$hook" : $callback;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment