function coder_upgrade_upgrade_call_file_scan_directory_alter in Coder 7
Same name and namespace in other branches
- 7.2 coder_upgrade/conversions/call.inc \coder_upgrade_upgrade_call_file_scan_directory_alter()
Implements hook_upgrade_call_file_scan_directory_alter().
File
- coder_upgrade/
conversions/ call.inc, line 1411 - Provides conversion routines applied to function calls.
Code
function coder_upgrade_upgrade_call_file_scan_directory_alter(&$node, &$reader) {
// DONE (IN PROGRESS)
cdp(__FUNCTION__);
// Create helper objects.
$editor = PGPEditor::getInstance();
// Get the function call object.
$item =& $node->data;
// Process function call.
$name =& $item->name;
/*
* TODO Default values will not harm anything if they are in the $options
* array. However, if the mask and nomask parameters are variables, then they
* need to be changed to preg format. Also, the key values need to change in
* the function call and the variables that reference the file objects.
*/
// Save the depth parameter.
$depth = $item
->getParameter(7);
$item
->deleteParameter(7);
if ($item->parameters
->count() > 1) {
// Change mask from ereg to preg style.
// Part of http://drupal.org/node/224333#preg_match
$mask = $item
->getParameter(1);
$operand = $mask
->getElement();
if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING) {
// Parameter is a string.
$mask = coder_upgrade_ereg_to_preg($item
->printParameter(1));
$editor
->setParameter($item, 1, $mask);
}
elseif ($operand instanceof PGPOperand && $operand
->findNode('type') == T_VARIABLE) {
// Parameter is a variable.
$variable = $operand
->findNode('value');
// Get the parent = statement (i.e. node) this function call is part of.
$parent = $item->parent;
// $parent = &$item->parent;
// Get the statement list the parent is part of.
$statement = $parent->container
->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
if ($statement) {
$operand2 =& $statement->values
->getElement()
->findNode('operand', 'backward');
// TODO A pattern here - this is the same code as above but executed on a different object.
if (is_array($operand2) && $operand2['type'] == T_CONSTANT_ENCAPSED_STRING) {
$operand2['value'] = coder_upgrade_ereg_to_preg($operand2['value']);
$mask = $operand2['value'];
}
else {
clp("ERROR: Could not find a string to change in " . __FUNCTION__);
}
}
}
else {
clp("ERROR: Could not find a string to change in " . __FUNCTION__);
}
}
if ($item->parameters
->count() > 2) {
// Change nomask from array to preg style.
// http://drupal.org/node/224333#file_scan_directory_nomask
$nomask = $item
->getParameter(2);
$operand = $nomask
->getElement();
if ($operand instanceof PGPArray) {
// Parameter is an array.
$nomask = coder_upgrade_array_to_preg($operand);
$editor
->setParameter($item, 2, $nomask);
}
elseif ($operand instanceof PGPOperand && $operand
->findNode('type') == T_VARIABLE) {
// Parameter is a variable.
$variable = $operand
->findNode('value');
// Get the parent = statement (i.e. node) this function call is part of.
$parent = $item->parent;
// $parent = &$item->parent;
// Get the statement list the parent is part of.
$statement = $parent->container
->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
if ($statement) {
$operand2 =& $statement->values
->getElement()
->findNode('operand', 'backward');
// TODO A pattern here - this is the same code as above but executed on a different object.
if ($operand2 instanceof PGPArray) {
$nomask = coder_upgrade_array_to_preg($operand2);
$operand2 = array(
'type' => T_CONSTANT_ENCAPSED_STRING,
'value' => $nomask,
);
}
else {
clp("ERROR: Could not find a string to change in " . __FUNCTION__);
}
}
}
else {
clp("ERROR: Could not find a string to change in " . __FUNCTION__);
}
}
if ($item->parameters
->count() > 5) {
// Change key values.
// http://drupal.org/node/224333#file_scan_directory_property_names
$operand = $item
->getParameter(5)
->getElement();
if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING) {
// Parameter is a string.
$key = coder_upgrade_file_key($item
->printParameter(5));
$editor
->setParameter($item, 5, $key);
}
elseif ($operand instanceof PGPOperand && $operand
->findNode('type') == T_VARIABLE) {
// Parameter is a variable.
$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.
// TODO Add a comment if unable to make the change. This applies to all routines!!!
}
// http://drupal.org/node/224333#file_scan_directory_array_itize
// Arrayitize the parameters.
$keys = array(
'nomask',
'callback',
'recurse',
'key',
'min_depth',
);
$defaults = array(
/*"array('.', '..', 'CVS')"*/
"'/(\\.\\.?|CVS)\$/'",
'0',
'TRUE',
/*"'filename'"*/
"'uri'",
0,
);
$string = $editor
->arrayitize($item, 2, $keys, $defaults);
if (is_object($depth) || $string != 'array()') {
$temp = $editor
->expressionToStatement($string);
$temp
->getElement(0)->multiline = 0;
$item
->setParameter(2, $temp);
}
if (is_object($depth)) {
$item
->setParameter(3, $depth);
}
// TODO Could regex for '->filename' and change to '->filepath'???
// See http://drupal.org/files/issues/file_scan_directory-1.patch
}