6 * Function call conversion routine file for the coder_upgrade module.
7 * These routines upgrade function calls using the grammar parser.
9 * The functions in this conversion routine file correspond to topics in the
10 * category roadmap at http://drupal.org/node/394070 that are marked with a
11 * green check mark in the Upgrade column.
13 * Copyright 2009-10 by Jim Berry ("solotandem", http://drupal.org/user/240748)
17 * The upgrades to these functions are documented at the following urls.
20 * http://drupal.org/node/224333#absolute_includes
21 * http://drupal.org/node/224333#registry
22 * http://drupal.org/node/224333#drupal_set_session (REVERTED)
23 * http://drupal.org/node/224333#time
24 * http://drupal.org/node/224333#rebuild_functions
25 * http://drupal.org/node/224333#drupal_uninstall_modules
26 * http://drupal.org/node/224333#module_implements_not_module_list
27 * http://drupal.org/node/224333#drupal_http_request_parameters
28 * http://drupal.org/node/224333#system_get_module_data
29 * http://drupal.org/node/224333#static_variable_api (NOT IN THIS FUNCTION)
30 * http://drupal.org/node/224333#drupal_set_html_head
31 * http://drupal.org/node/224333#php_eval
32 * http://drupal.org/node/224333#http_header_functions
33 * http://drupal.org/node/224333#drupal_set_content
34 * http://drupal.org/node/224333#time_limit
35 * http://drupal.org/node/224333#drupal_set_header_renamed
39 * http://drupal.org/node/224333#schema_ret
43 * http://drupal.org/node/224333#comment_load (DUP Comments)
44 * http://drupal.org/node/224333#menu_tree_data
48 * http://drupal.org/node/224333#comment_load
49 * http://drupal.org/node/224333#comment_validate_removed
50 * http://drupal.org/node/224333#comment_node_url
53 * Input Sanitization and Input Formats
54 * http://drupal.org/node/224333#check_markup_params
55 * http://drupal.org/node/224333#drupal_set_title
56 * http://drupal.org/node/224333#hook_filter_info (NOT IN THIS FUNCTION)
57 * http://drupal.org/node/224333#filter_formats_parameters
61 * http://drupal.org/node/224333#taxonomy_get_tree
62 * http://drupal.org/node/224333#taxonomy_crud
66 * http://drupal.org/node/224333#drupal_add_js_options
67 * http://drupal.org/node/224333#drupal_add_js_weight (Included with above)
68 * http://drupal.org/node/224333#rename-drupal-to-js
72 * http://drupal.org/node/224333#drupal_add_js_options (DUP Javascript)
73 * http://drupal.org/node/224333#drupal_add_css_weight (Should have a DUP in Javascript)
77 * http://drupal.org/node/224333#rebuild_functions (DUP System)
78 * http://drupal.org/node/224333#theme_page
79 * http://drupal.org/node/224333#theme_changes
80 * http://drupal.org/node/224333#placeholder
81 * http://drupal.org/node/224333#theme_pager
82 * http://drupal.org/node/224333#theme_username
86 * http://drupal.org/node/224333#drupal_execute_drupal_form_submit
90 * http://drupal.org/node/224333#file_scan_directory_array_itize
91 * http://drupal.org/node/224333#file_scan_directory_nomask
92 * http://drupal.org/node/224333#file_set_status
93 * http://drupal.org/node/224333#preg_match
94 * http://drupal.org/node/224333#file_scan_directory_property_names
98 * http://drupal.org/node/224333#user_cancel (ALSO in convert_functions)
99 * http://drupal.org/node/224333#user_authenticate
103 * http://drupal.org/node/224333#node_type_base (ALSO in convert_functions)
104 * http://drupal.org/node/224333#node_invoke_nodeapi
105 * http://drupal.org/node/224333#node_type_get_functions
109 * http://drupal.org/node/224333#locale_context
113 * http://drupal.org/node/224333#book_toc_parameters
114 * http://drupal.org/node/224333#referer_uri
115 * http://drupal.org/node/224333#drupal_clone
116 * http://drupal.org/node/224333#actions_synchronize
117 * http://drupal.org/node/224333#url_is_external
118 * http://drupal.org/node/224333#drupal_valid_path
119 * http://drupal.org/node/224333#format_date
120 * http://drupal.org/node/224333#url_query_parameter
124 * Implements hook_upgrade_call_alter().
126 function coder_upgrade_upgrade_call_alter(&$item, &$reader, $name) { // NEEDS WORK
127 // Create helper objects.
128 $editor = PGPEditor
::getInstance();
130 // Process function call.
131 // $name = &$item->name;
135 // includes/database.pgsql.inc Add a new field to a table.
137 // includes/database.pgsql.inc Add an index.
138 case
'db_add_primary_key':
139 // includes/database.pgsql.inc Add a primary key.
140 case
'db_add_unique_key':
141 // includes/database.pgsql.inc Add a unique key.
142 case
'db_change_field':
143 // includes/database.pgsql.inc Change a field definition.
144 case
'db_create_table':
145 // includes/database.inc Create a new table from a Drupal table definition.
146 case
'db_create_table_sql':
147 // includes/database.pgsql.inc Generate SQL to create a new table from a Drupal schema definition.
148 case
'db_drop_field':
149 // includes/database.pgsql.inc Drop a field.
150 case
'db_drop_index':
151 // includes/database.pgsql.inc Drop an index.
152 case
'db_drop_primary_key':
153 // includes/database.pgsql.inc Drop the primary key.
154 case
'db_drop_table':
155 // includes/database.pgsql.inc Drop a table.
156 case
'db_drop_unique_key':
157 // includes/database.pgsql.inc Drop a unique key.
158 case
'db_field_names':
159 // includes/database.inc Return an array of field names from an array of key/index column specifiers.
160 case
'db_field_set_default':
161 // includes/database.pgsql.inc Set the default value for a field.
162 case
'db_field_set_no_default':
163 // includes/database.pgsql.inc Set a field to have no default value.
164 case
'db_rename_table':
165 // includes/database.pgsql.inc Rename a table.
166 $item->deleteParameter();
170 * See http://drupal.org/node/224333#update_sql
171 * Search for assignments to and return statements with the $ret parameter
172 * used in these db_operation function calls.
174 * These could be moved to the install file although it may be possible to
175 * call them in other files.
183 // These are included by $reader in function call list.
184 // Use with http://drupal.org/node/224333#absolute_includes
185 coder_upgrade_convert_require($item, $reader);
195 * Implements hook_upgrade_call_actions_synchronize_alter().
197 function coder_upgrade_upgrade_call_actions_synchronize_alter(&$item, &$reader) { // DONE
198 // Create helper objects.
199 $editor = PGPEditor
::getInstance();
201 // Process function call.
202 $name = &$item->name
;
203 $count = $item->parameters
->count();
205 $item->deleteParameter();
210 * Implements hook_upgrade_call_book_toc_alter().
212 function coder_upgrade_upgrade_call_book_toc_alter(&$item, &$reader) { // DONE
213 // Create helper objects.
214 $editor = PGPEditor
::getInstance();
216 // Process function call.
217 $name = &$item->name
;
218 // Adjust parameters.
219 $count = $item->parameters
->count();
222 $p1 = $item->getParameter(1);
223 $p2 = $item->getParameter(2);
224 $item->setParameter(1, $p2);
225 $item->setParameter(2, $p1);
227 // Remove default parameter.
229 $value = $item->printParameter(2);
230 cdp("value = $value");
231 if ($value == 'array()') {
232 $item->deleteParameter(2);
238 * Implements hook_upgrade_call_check_markup_alter().
240 function coder_upgrade_upgrade_call_check_markup_alter(&$item, &$reader) { // DONE
241 // Create helper objects.
242 $editor = PGPEditor
::getInstance();
244 // Process function call.
245 $name = &$item->name
;
246 if ($item->parameters
->count() > 2) {
247 $editor->insertParameter($item, 2, '$langcode = \'\' /* TODO Set this variable. */');
252 * Implements hook_upgrade_call__comment_load_alter().
254 function coder_upgrade_upgrade_call__comment_load_alter(&$item, &$reader) { // DONE
255 // Create helper objects.
256 $editor = PGPEditor
::getInstance();
258 // Process function call.
259 $name = &$item->name
;
260 $name['value'] = 'comment_load';
261 // TODO The %_comment wildcard change to %comment in hook_menu. (See coder_upgrade.other_regex.inc.)
265 * Implements hook_upgrade_call_comment_node_url_alter().
267 function coder_upgrade_upgrade_call_comment_node_url_alter(&$item, &$reader) { // DONE
268 // Create helper objects.
269 $editor = PGPEditor
::getInstance();
271 // Process function call.
272 $name = &$item->name
;
273 $parent = $item->parent
;
274 $temp = $editor->statementsToText($parent);
275 $from = '@comment_node_url()@';
276 $to = "'comment/' . \$comment->cid";
277 $temp = preg_replace($from, $to, $temp);
278 $temp = $editor->textToStatements($temp);
279 $parent->data
= $temp->getElement(0);
283 * Implements hook_upgrade_call_comment_validate_alter().
285 function coder_upgrade_upgrade_call_comment_validate_alter(&$item, &$reader) { // DONE
286 // Create helper objects.
287 $editor = PGPEditor
::getInstance();
289 // Process function call.
290 $name = &$item->name
;
291 $name['value'] = 'comment_form_validate';
292 $editor->setParameters($item, array('$form', '$form_state /* TODO Set these variables. */'));
296 * Implements hook_upgrade_call_db_add_field_alter().
298 function coder_upgrade_upgrade_call_db_add_field_alter(&$item, &$reader) { // NEEDS WORK
299 // Create helper objects.
300 $editor = PGPEditor::getInstance();
302 // Process function call.
303 $name = &$item->name;
304 // includes/database.pgsql.inc Add a new field to a table.
305 $item->deleteParameter();
309 * See http://drupal.org/node/224333#update_sql
310 * Search for assignments to and return statements with the $ret parameter
311 * used in these db_operation function calls.
313 * These could be moved to the install file although it may be possible to
314 * call them in other files.
319 * Implements hook_upgrade_call_db_add_index_alter().
321 function coder_upgrade_upgrade_call_db_add_index_alter(&$item, &$reader) { // DONE
322 // Create helper objects.
323 $editor = PGPEditor::getInstance();
325 // Process function call.
326 $name = &$item->name;
327 // includes/database.pgsql.inc Add an index.
328 $item->deleteParameter();
332 * Implements hook_upgrade_call_db_add_primary_key_alter().
334 function coder_upgrade_upgrade_call_db_add_primary_key_alter(&$item, &$reader) { // DONE
335 // Create helper objects.
336 $editor = PGPEditor::getInstance();
338 // Process function call.
339 $name = &$item->name;
340 // includes/database.pgsql.inc Add a primary key.
341 $item->deleteParameter();
345 * Implements hook_upgrade_call_db_add_unique_key_alter().
347 function coder_upgrade_upgrade_call_db_add_unique_key_alter(&$item, &$reader) { // DONE
348 // Create helper objects.
349 $editor = PGPEditor::getInstance();
351 // Process function call.
352 $name = &$item->name;
353 // includes/database.pgsql.inc Add a unique key.
354 $item->deleteParameter();
358 * Implements hook_upgrade_call_db_change_field_alter().
360 function coder_upgrade_upgrade_call_db_change_field_alter(&$item, &$reader) { // DONE
361 // Create helper objects.
362 $editor = PGPEditor::getInstance();
364 // Process function call.
365 $name = &$item->name;
366 // includes/database.pgsql.inc Change a field definition.
367 $item->deleteParameter();
371 * Implements hook_upgrade_call_db_create_table_alter().
373 function coder_upgrade_upgrade_call_db_create_table_alter(&$item, &$reader) { // DONE
374 // Create helper objects.
375 $editor = PGPEditor::getInstance();
377 // Process function call.
378 $name = &$item->name;
379 // includes/database.inc Create a new table from a Drupal table definition.
380 $item->deleteParameter();
384 * Implements hook_upgrade_call_db_create_table_sql_alter().
386 function coder_upgrade_upgrade_call_db_create_table_sql_alter(&$item, &$reader) { // DONE
387 // Create helper objects.
388 $editor = PGPEditor::getInstance();
390 // Process function call.
391 $name = &$item->name;
392 // includes/database.pgsql.inc Generate SQL to create a new table from a Drupal schema definition.
393 $item->deleteParameter();
397 * Implements hook_upgrade_call_db_drop_field_alter().
399 function coder_upgrade_upgrade_call_db_drop_field_alter(&$item, &$reader) { // DONE
400 // Create helper objects.
401 $editor = PGPEditor::getInstance();
403 // Process function call.
404 $name = &$item->name;
405 // includes/database.pgsql.inc Drop a field.
406 $item->deleteParameter();
410 * Implements hook_upgrade_call_db_drop_index_alter().
412 function coder_upgrade_upgrade_call_db_drop_index_alter(&$item, &$reader) { // DONE
413 // Create helper objects.
414 $editor = PGPEditor::getInstance();
416 // Process function call.
417 $name = &$item->name;
418 // includes/database.pgsql.inc Drop an index.
419 $item->deleteParameter();
423 * Implements hook_upgrade_call_db_drop_primary_key_alter().
425 function coder_upgrade_upgrade_call_db_drop_primary_key_alter(&$item, &$reader) { // DONE
426 // Create helper objects.
427 $editor = PGPEditor::getInstance();
429 // Process function call.
430 $name = &$item->name;
431 // includes/database.pgsql.inc Drop the primary key.
432 $item->deleteParameter();
436 * Implements hook_upgrade_call_db_drop_table_alter().
438 function coder_upgrade_upgrade_call_db_drop_table_alter(&$item, &$reader) { // DONE
439 // Create helper objects.
440 $editor = PGPEditor::getInstance();
442 // Process function call.
443 $name = &$item->name;
444 // includes/database.pgsql.inc Drop a table.
445 $item->deleteParameter();
449 * Implements hook_upgrade_call_db_drop_unique_key_alter().
451 function coder_upgrade_upgrade_call_db_drop_unique_key_alter(&$item, &$reader) { // DONE
452 // Create helper objects.
453 $editor = PGPEditor::getInstance();
455 // Process function call.
456 $name = &$item->name;
457 // includes/database.pgsql.inc Drop a unique key.
458 $item->deleteParameter();
462 * Implements hook_upgrade_call_db_field_names_alter().
464 function coder_upgrade_upgrade_call_db_field_names_alter(&$item, &$reader) { // DONE
465 // Create helper objects.
466 $editor = PGPEditor::getInstance();
468 // Process function call.
469 $name = &$item->name;
470 // includes/database.inc Return an array of field names from an array of key/index column specifiers.
471 $item->deleteParameter();
475 * Implements hook_upgrade_call_db_field_set_default_alter().
477 function coder_upgrade_upgrade_call_db_field_set_default_alter(&$item, &$reader) { // DONE
478 // Create helper objects.
479 $editor = PGPEditor::getInstance();
481 // Process function call.
482 $name = &$item->name;
483 // includes/database.pgsql.inc Set the default value for a field.
484 $item->deleteParameter();
488 * Implements hook_upgrade_call_db_field_set_no_default_alter().
490 function coder_upgrade_upgrade_call_db_field_set_no_default_alter(&$item, &$reader) { // DONE
491 // Create helper objects.
492 $editor = PGPEditor::getInstance();
494 // Process function call.
495 $name = &$item->name;
496 // includes/database.pgsql.inc Set a field to have no default value.
497 $item->deleteParameter();
501 * Implements hook_upgrade_call_db_rename_table_alter().
503 function coder_upgrade_upgrade_call_db_rename_table_alter(&$item, &$reader) { // DONE
504 // Create helper objects.
505 $editor = PGPEditor::getInstance();
507 // Process function call.
508 $name = &$item->name;
509 // includes/database.pgsql.inc Rename a table.
510 $item->deleteParameter();
514 * Implements hook_upgrade_call_drupal_add_css_alter().
516 function coder_upgrade_upgrade_call_drupal_add_css_alter(&$item, &$reader) { // DONE (UPDATED)
517 // Create helper objects.
518 $editor = PGPEditor
::getInstance();
520 // Process function call.
521 $name = &$item->name
;
522 // A similar comment to that in 'drupal_add_js' below applies here.
523 cdp($item->parameters
->print_r());
525 $count = $item->parameters
->count();
530 $type = trim($item->printParameter(1), "'\"");
531 if ($type == 'module') {
532 $item->deleteParameter(1);
537 // Insert a new weight parameter.
538 $type = trim($item->printParameter(1), "'\"");
539 $weight = coder_upgrade_css_weight($type);
540 $editor->insertParameter($item, 2, "$weight");
542 // Arrayitize the parameters.
543 $keys = array('type', 'weight', 'media', 'preprocess');
544 $defaults = array("'module'", 'CSS_DEFAULT', "'all'", 'TRUE');
545 $string = $editor->arrayitize($item, 1, $keys, $defaults);
546 $string = preg_replace('@[\'"]theme[\'"]@', "'file'", $string); // Could be deleted.
548 if ($string != 'array()') {
549 $temp = $editor->expressionToStatement($string);
550 $temp->getElement(0)->multiline
= 0;
551 cdp($temp->print_r());
552 $item->setParameter(1, $temp);
557 * Returns the new css weight parameter.
559 * @param string $type
562 function coder_upgrade_css_weight($type) {
565 return 'CSS_DEFAULT';
571 return 'CSS_DEFAULT';
576 * Implements hook_upgrade_call_drupal_add_js_alter().
578 function coder_upgrade_upgrade_call_drupal_add_js_alter(&$item, &$reader) { // DONE (UPDATED)
579 // Create helper objects.
580 $editor = PGPEditor
::getInstance();
582 // Process function call.
583 $name = &$item->name
;
586 * drupal_add_js('misc/collapse.js', 'core', 'header', FALSE, TRUE, TRUE);
588 * drupal_add_js('misc/collapse.js', array('type' => 'file', 'weight' => JS_LIBRARY));
589 * which is correct, although the function will also accept
590 * drupal_add_js('misc/collapse.js', array('weight' => JS_LIBRARY));
591 * The example begs the question why someone would have included all
592 * the default parameters.
594 * A type of 'core', 'module' or 'theme' all convert to 'file' which is
595 * the new default. The weight parameter then corresponds to the old type.
597 cdp($item->parameters
->print_r());
599 $count = $item->parameters
->count();
604 $type = trim($item->printParameter(1), "'\"");
605 if ($type == 'module') {
606 // if (in_array($type, array('module', ''))) {
607 $item->deleteParameter(1);
610 elseif (in_array($type, array('core', 'theme'))) {
611 // Add a default value for the scope parameter (removed below).
612 $editor->insertParameter($item, 2, "'header'");
616 // Insert a new weight parameter.
617 $type = trim($item->printParameter(1), "'\"");
618 $weight = coder_upgrade_js_weight($type);
619 $editor->insertParameter($item, 3, "$weight");
621 // Arrayitize the parameters.
622 $keys = array('type', 'scope', 'weight', 'defer', 'cache', 'preprocess');
623 $defaults = array("'module'", "'header'", 'JS_DEFAULT', 'FALSE', 'TRUE', 'TRUE');
624 $string = $editor->arrayitize($item, 1, $keys, $defaults);
625 $string = preg_replace('@[\'"](core|theme)[\'"]@', "'file'", $string); // Could be deleted.
627 if ($string != 'array()') {
628 $temp = $editor->expressionToStatement($string);
629 $temp->getElement(0)->multiline
= 0;
630 cdp($temp->print_r());
631 $item->setParameter(1, $temp);
636 * Returns the new js weight parameter.
638 * @param string $type
641 function coder_upgrade_js_weight($type) {
658 * Implements hook_upgrade_call_drupal_clone_alter().
660 function coder_upgrade_upgrade_call_drupal_clone_alter(&$item, &$reader) { // DONE
661 // Create helper objects.
662 $editor = PGPEditor
::getInstance();
664 // Process function call.
665 $name = &$item->name
;
666 $name['value'] = 'clone';
671 * Implements hook_upgrade_call_drupal_eval_alter().
673 function coder_upgrade_upgrade_call_drupal_eval_alter(&$item, &$reader) { // DONE
674 // Create helper objects.
675 $editor = PGPEditor
::getInstance();
677 // Process function call.
678 $name = &$item->name
;
680 * Examine the statement containing the function call.
681 * Wrap the containing statement in an "if (module_exists('php'))" block.
682 * The function call may be the containing statement.
685 // Set the name of the function call.
686 $name['value'] = 'php_eval';
688 // Get the parent = statement (i.e. node) this function call is part of.
689 $parent = $item->parent
;
690 $temp = $editor->statementsToText($parent);
691 $temp = $editor->textToStatements("if (module_exists('php')) {\n\t$temp\n}");
692 $parent->data
= $temp->getElement(0);
696 * Implements hook_upgrade_call_drupal_execute_alter().
698 function coder_upgrade_upgrade_call_drupal_execute_alter(&$item, &$reader) { // DONE
699 // Create helper objects.
700 $editor = PGPEditor
::getInstance();
702 // Process function call.
703 $name = &$item->name
;
704 $name['value'] = 'drupal_form_submit';
709 * Implements hook_upgrade_call_drupal_get_content_alter().
711 function coder_upgrade_upgrade_call_drupal_get_content_alter(&$item, &$reader) { // DONE
712 // Create helper objects.
713 $editor = PGPEditor
::getInstance();
715 // Process function call.
716 $name = &$item->name
;
717 $name['value'] = 'drupal_get_region_content';
721 * Implements hook_upgrade_call_drupal_get_headers_alter().
723 function coder_upgrade_upgrade_call_drupal_get_headers_alter(&$item, &$reader) { // DONE
724 // Create helper objects.
725 $editor = PGPEditor
::getInstance();
727 // Process function call.
728 $name = &$item->name
;
729 // $name['value'] = 'drupal_get_header'; // Overwritten by following change.
730 // http://drupal.org/node/224333#drupal_set_header_renamed
731 $name['value'] = 'drupal_get_http_header';
735 * Implements hook_upgrade_call_drupal_http_request_alter().
737 function coder_upgrade_upgrade_call_drupal_http_request_alter(&$item, &$reader) { // DONE
738 // Create helper objects.
739 $editor = PGPEditor
::getInstance();
741 // Process function call.
742 $name = &$item->name
;
743 cdp($item->parameters
->print_r());
745 $count = $item->parameters
->count();
750 $keys = array('headers', 'method', 'data', 'max_redirects');
751 $defaults = array('xxx_YYY_zzz', "'GET'", 'NULL', 3);
752 $string = $editor->arrayitize($item, 1, $keys, $defaults);
754 $temp = $editor->expressionToStatement($string);
755 $temp->getElement(0)->multiline
= 0;
756 cdp($temp->print_r());
757 $item->setParameter(1, $temp);
761 * Implements hook_upgrade_call_drupal_json_alter().
763 function coder_upgrade_upgrade_call_drupal_json_alter(&$item, &$reader) { // DONE
764 // Create helper objects.
765 $editor = PGPEditor
::getInstance();
767 // Process function call.
768 $name = &$item->name
;
769 $name['value'] = 'drupal_json_output';
773 * Implements hook_upgrade_call_drupal_rebuild_code_registry_alter().
775 function coder_upgrade_upgrade_call_drupal_rebuild_code_registry_alter(&$item, &$reader) { // DONE
776 // Create helper objects.
777 $editor = PGPEditor
::getInstance();
779 // Process function call.
780 $name = &$item->name
;
781 $name['value'] = 'registry_rebuild';
785 * Implements hook_upgrade_call_drupal_rebuild_theme_registry_alter().
787 function coder_upgrade_upgrade_call_drupal_rebuild_theme_registry_alter(&$item, &$reader) { // DONE
788 // Create helper objects.
789 $editor = PGPEditor
::getInstance();
791 // Process function call.
792 $name = &$item->name
;
793 $name['value'] = 'drupal_theme_rebuild';
797 * Implements hook_upgrade_call_drupal_set_content_alter().
799 function coder_upgrade_upgrade_call_drupal_set_content_alter(&$item, &$reader) { // DONE
800 // Create helper objects.
801 $editor = PGPEditor
::getInstance();
803 // Process function call.
804 $name = &$item->name
;
805 $name['value'] = 'drupal_add_region_content';
809 * Implements hook_upgrade_call_drupal_set_header_alter().
811 function coder_upgrade_upgrade_call_drupal_set_header_alter(&$item, &$reader) { // DONE
812 // Create helper objects.
813 $editor = PGPEditor
::getInstance();
815 // Process function call.
816 $name = &$item->name
;
817 // http://drupal.org/node/224333#drupal_set_header_renamed
818 $name['value'] = 'drupal_add_http_header';
819 // TODO the hook_file_download() changes. Use parser on the entire function.
820 $temp = $item->printParameters();
821 if (strpos($temp, 'Content-Type:') !== FALSE
) {
822 $temp = explode(':', $temp);
823 foreach ($temp as
$key => $string) {
824 $temp[$key] = "'" .
trim($string, "' ") .
"'";
826 $editor->setParameters($item, $temp);
828 elseif (strpos($temp, "\$_SERVER['SERVER_PROTOCOL']") !== FALSE
||
829 strpos($temp, '\$_SERVER["SERVER_PROTOCOL"]') !== FALSE
) {
830 $from = '@\$_SERVER\[(\'|")SERVER_PROTOCOL(\'|")\]\s*\.\s*(\'|")\s*(.*?)(\'|")@';
832 $temp = preg_replace($from, $to, $temp);
833 $editor->setParameters($item, array($temp));
838 * Implements hook_upgrade_call_drupal_set_html_head_alter().
840 function coder_upgrade_upgrade_call_drupal_set_html_head_alter(&$item, &$reader) { // DONE (UPDATED)
841 // Create helper objects.
842 $editor = PGPEditor
::getInstance();
844 // Process function call.
845 $name = &$item->name
;
846 $name['value'] = 'drupal_add_html_head';
848 $count = $item->parameters
->count();
850 $key = '$key = NULL /* TODO Set this variable. */';
851 // Insert new required parameter when first parameter is set.
852 $editor->insertParameter($item, 1, $key);
857 * Implements hook_upgrade_call_drupal_set_title_alter().
859 function coder_upgrade_upgrade_call_drupal_set_title_alter(&$item, &$reader) { // DONE
860 // Create helper objects.
861 $editor = PGPEditor
::getInstance();
863 // Process function call.
864 $name = &$item->name
;
865 $temp = $item->printParameters();
868 if (strpos($temp, 'check_plain') !== FALSE
) {
869 // TODO Could check for isset, count of parameters, etc.???
870 // check_plain could be part of an expression (e.g. concatenation).
871 $temp = $item->getParameter(0);
872 $temp = $temp->getElement(0);
873 cdp("Printing the first ");
874 cdp($temp->print_r());
875 $editor->setParameter($item, 0, $temp->printParameter(0));
876 cdp($item->print_r());
879 $parameters = &$item->parameters
;
880 if ($call = & $parameters->search('PGPFunctionCall', 'name', 'value', 't')) {
881 $temp = $call->toString();
883 if (preg_match('#(\'|")@\w+(\'|")\s*=>\s*#', $temp)) {
884 $editor->setParameter($item, 1, 'PASS_THROUGH');
885 cdp($item->print_r(0, $item));
891 * Implements hook_upgrade_call_drupal_system_listing_alter().
893 function coder_upgrade_upgrade_call_drupal_system_listing_alter(&$item, &$reader) { // DONE (Revise like file_scan_directory)
894 // Create helper objects.
895 $editor = PGPEditor
::getInstance();
897 // Process function call.
898 $name = &$item->name
;
899 $temp = $item->printParameter(0);
900 // Check for type == T_CONSTANT_ENCAPSED_STRING
901 // Check for a '/' in the mask and use a different mask or delimit the '/' with '\/'.
902 if ($temp[0] == "'") {
903 $editor->setParameter($item, 0, "'/" .
substr($temp, 1, -1) .
"/'");
905 elseif ($temp[0] == '"') {
906 $editor->setParameter($item, 0, '"/' .
substr($temp, 1, -1) .
'/"');
908 // else if type == T_VARIABLE, find the $mask used in the call and examine its value.
912 * Implements hook_upgrade_call_drupal_to_js_alter().
914 function coder_upgrade_upgrade_call_drupal_to_js_alter(&$item, &$reader) { // DONE
915 // Create helper objects.
916 $editor = PGPEditor
::getInstance();
918 // Process function call.
919 $name = &$item->name
;
920 $name['value'] = 'drupal_json_encode';
924 * Implements hook_upgrade_call_drupal_uninstall_module_alter().
926 function coder_upgrade_upgrade_call_drupal_uninstall_module_alter(&$item, &$reader) { // DONE
927 // Create helper objects.
928 $editor = PGPEditor
::getInstance();
930 // Process function call.
931 $name = &$item->name
;
932 $name['value'] = 'drupal_uninstall_modules';
933 $temp = $item->printParameters();
934 $editor->setParameters($item, array('array(' .
$temp .
')'));
938 * Implements hook_upgrade_call_file_scan_directory_alter().
940 function coder_upgrade_upgrade_call_file_scan_directory_alter(&$item, &$reader) { // DONE (IN PROGRESS)
942 // Create helper objects.
943 $editor = PGPEditor
::getInstance();
945 // Process function call.
946 $name = &$item->name
;
949 * TODO Default values will not harm anything if they are in the $options
950 * array. However, if the mask and nomask parameters are variables, then they
951 * need to be changed to preg format. Also, the key values need to change in
952 * the function call and the variables that reference the file objects.
955 // Save the depth parameter.
956 $depth = $item->getParameter(7);
957 $item->deleteParameter(7);
959 if ($item->parameters
->count() > 1) {
960 // Change mask from ereg to preg style.
961 // Part of http://drupal.org/node/224333#preg_match
962 $mask = $item->getParameter(1);
963 $operand = $mask->getElement();
964 if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING
) {
965 // Parameter is a string.
966 $mask = coder_upgrade_ereg_to_preg($item->printParameter(1));
967 $editor->setParameter($item, 1, $mask);
969 elseif (is_a($operand, 'PGPOperand') && $operand->findNode('type') == T_VARIABLE
) {
970 // Parameter is a variable.
971 $variable = $operand->findNode('value');
972 // Get the parent = statement (i.e. node) this function call is part of.
973 $parent = $item->parent
; // $parent = &$item->parent;
974 // Get the statement list the parent is part of.
975 $statement = $parent->container
->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
977 $operand2 = &$statement->values
->getElement()->findNode('operand', 'backward');
978 // TODO A pattern here - this is the same code as above but executed on a different object.
979 if (is_array($operand2) && $operand2['type'] == T_CONSTANT_ENCAPSED_STRING
) {
980 $operand2['value'] = coder_upgrade_ereg_to_preg($operand2['value']);
981 $mask = $operand2['value'];
984 clp("ERROR: Could not find a string to change in " . __FUNCTION__
);
989 clp("ERROR: Could not find a string to change in " . __FUNCTION__
);
993 if ($item->parameters
->count() > 2) {
994 // Change nomask from array to preg style.
995 // http://drupal.org/node/224333#file_scan_directory_nomask
996 $nomask = $item->getParameter(2);
997 $operand = $nomask->getElement();
998 if (is_a($operand, 'PGPArray')) {
999 // Parameter is an array.
1000 $nomask = coder_upgrade_array_to_preg($operand);
1001 $editor->setParameter($item, 2, $nomask);
1003 elseif (is_a($operand, 'PGPOperand') && $operand->findNode('type') == T_VARIABLE
) {
1004 // Parameter is a variable.
1005 $variable = $operand->findNode('value');
1006 // Get the parent = statement (i.e. node) this function call is part of.
1007 $parent = $item->parent
; // $parent = &$item->parent;
1008 // Get the statement list the parent is part of.
1009 $statement = $parent->container
->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
1011 $operand2 = &$statement->values
->getElement()->findNode('operand', 'backward');
1012 // TODO A pattern here - this is the same code as above but executed on a different object.
1013 if (is_a($operand2, 'PGPArray')) {
1014 $nomask = coder_upgrade_array_to_preg($operand2);
1015 $operand2 = array('type' => T_CONSTANT_ENCAPSED_STRING
, 'value' => $nomask);
1018 clp("ERROR: Could not find a string to change in " . __FUNCTION__
);
1023 clp("ERROR: Could not find a string to change in " . __FUNCTION__
);
1027 if ($item->parameters
->count() > 5) {
1028 // Change key values.
1029 // http://drupal.org/node/224333#file_scan_directory_property_names
1030 $operand = $item->getParameter(5)->getElement();
1031 if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING
) {
1032 // Parameter is a string.
1033 $key = coder_upgrade_file_key($item->printParameter(5));
1034 $editor->setParameter($item, 5, $key);
1036 elseif (is_a($operand, 'PGPOperand') && $operand->findNode('type') == T_VARIABLE
) {
1037 // Parameter is a variable.
1038 $variable = $operand->findNode('value');
1039 $parent = $item->parent
;
1040 $statement = $parent->container
->searchBackward('PGPAssignment', 'values', 0, $variable, $parent);
1043 // Edge case: the parameter could have a comment.
1044 // Make a general function to clean the parameter of comments and whitespace so we can truly evaluate it.
1045 // TODO Add a comment if unable to make the change. This applies to all routines!!!
1048 // http://drupal.org/node/224333#file_scan_directory_array_itize
1049 // Arrayitize the parameters.
1050 $keys = array('nomask', 'callback', 'recurse', 'key', 'min_depth');
1051 $defaults = array(/*"array('.', '..', 'CVS')"*/ "'/(\.\.?|CVS)$/'", '0', 'TRUE', /*"'filename'"*/"'uri'", 0);
1052 $string = $editor->arrayitize($item, 2, $keys, $defaults);
1054 if (is_object($depth) || $string != 'array()') {
1055 $temp = $editor->expressionToStatement($string);
1056 $temp->getElement(0)->multiline
= 0;
1057 $item->setParameter(2, $temp);
1059 if (is_object($depth)) {
1060 $item->setParameter(7, $depth);
1063 // TODO Could regex for '->filename' and change to '->filepath'???
1064 // See http://drupal.org/files/issues/file_scan_directory-1.patch
1068 * Returns the new file key parameter.
1070 * @param string $key
1073 function coder_upgrade_file_key($key) {
1079 return "'filename'";
1090 * Converts an ereg string to a preg string.
1092 * @param string $string
1095 function coder_upgrade_ereg_to_preg($string) {
1097 // Check for type == T_CONSTANT_ENCAPSED_STRING
1098 // Check for a '/' in the mask and use a different mask or delimit the '/' with '\/'.
1099 $delimiters = array('/', '@', '#', '%', '~', ''); // TODO Are these all legal?
1100 foreach ($delimiters as
$delimiter) {
1101 if (strpos($string, $delimiter) === FALSE
) {
1107 clp('ERROR: Could not find a suitable delimiter for the regular exprssion');
1109 $string = str_replace('/', '\/', $string);
1112 $quote = $string[0];
1113 return $quote .
$delimiter .
substr($string, 1, -1) .
$delimiter .
$quote;
1117 * Returns a preg string for the nomask parameter.
1119 * @param PGPOperand $nomask
1122 function coder_upgrade_array_to_preg($operand) {
1124 $defaults = array('.', '..', 'CVS');
1125 $current = $operand->values
->first();
1126 while ($current->next != NULL
) {
1127 if ($current->type
== 'value') {
1128 $values[] = trim($current->data
->toString(), "'\"");
1130 $current = $current->next;
1132 $defaults = array_diff($defaults, $values);
1133 if (empty($defaults)) {
1134 return "'/(\.\.?|CVS)$/'";
1137 foreach ($values as
$value) {
1138 $strings[] .
= str_replace('.', '\.', $value);
1140 return "'/(" .
implode('|', $strings) .
")/'";
1144 * Implements hook_upgrade_call_file_set_status_alter().
1146 function coder_upgrade_upgrade_call_file_set_status_alter(&$item, &$reader) { // DONE
1147 // Create helper objects.
1148 $editor = PGPEditor
::getInstance();
1150 // Process function call.
1151 $name = &$item->name
;
1153 if ($item->parameters
->count() == 2) {
1154 $p0 = $item->printParameter(0);
1155 $p1 = $item->printParameter(1);
1157 // Insert statement.
1158 $temp = $editor->textToStatements("{$p0}->status &= $p1");
1159 $parent = $item->parent
;
1160 $parent->container
->insertBefore($parent, $temp->getElement(0));
1162 // Change statement.
1164 $to = "$p0 = file_save($p0)";
1165 $temp = str_replace($from, $to, $temp2);
1166 $temp = $editor->textToStatements($temp);
1167 $parent->data
= $temp->getElement(0);
1172 * Implements hook_upgrade_call_filter_formats_alter().
1174 function coder_upgrade_upgrade_call_filter_formats_alter(&$item, &$reader) { // DONE (UPDATED)
1175 // Create helper objects.
1176 $editor = PGPEditor
::getInstance();
1178 // Process function call.
1179 $name = &$item->name
;
1180 cdp('filter_formats');
1182 * If call has a parameter, then change it to $user and add global statement.
1183 * If no parameter, then this still implies current user in D6.
1184 * Set the existing assignment variable to itself at $index.
1185 * Ex: $formats = filter_formats($index);
1188 * $formats = filter_formats($user);
1189 * $formats = $formats[$index];
1191 $index = $item->printParameter(0);
1192 cdp("index = '$index'");
1193 $p0 = $editor->expressionToStatement('$user');
1194 $item->setParameter(0, $p0);
1196 // Get the parent = statement (i.e. node) this function call is part of.
1197 $parent = &$item->parent
;
1198 // Get the statement list the parent is part of.
1199 $container = &$parent->container
;
1200 // Insert a statement.
1201 $statement = $editor->textToStatements("global \$user;")->getElement(0);
1202 $container->insertBefore($parent, $statement, 'global');
1204 // Insert a statement.
1205 $assignment = $parent->data
;
1206 $assign_variable = $assignment->values
->getElement()->getElement()->toString();
1207 cdp($parent->data
->print_r());
1208 $statement = $editor->textToStatements("$assign_variable = $assign_variable\[$index\];")->getElement(0);
1209 $container->insertAfter($parent, $statement, 'assignment');
1214 * Implements hook_upgrade_call_format_date_alter().
1216 function coder_upgrade_upgrade_call_format_date_alter(&$item, &$reader) {
1217 // Create helper objects.
1218 $editor = PGPEditor
::getInstance();
1220 // Change date types
1221 $date_type = $item->printParameter(1);
1222 $date_type = trim($date_type, "'\"");
1223 switch ($date_type) {
1225 $editor->setParameter($item, 1, "'short'");
1228 $editor->setParameter($item, 1, "'long'");
1234 * Implements hook_upgrade_call_format_plural_alter().
1236 function coder_upgrade_upgrade_call_format_plural_alter(&$item, &$reader) { // DONE
1237 // Create helper objects.
1238 $editor = PGPEditor
::getInstance();
1240 // Process function call.
1241 $name = &$item->name
;
1242 $count = $item->parameters
->count();
1247 $keys = array('langcode');
1248 $defaults = array("'XXX_YYY'");
1249 $string = $editor->arrayitize($item, 4, $keys, $defaults);
1251 $temp = $editor->expressionToStatement($string);
1252 $temp->getElement(0)->multiline
= 0;
1253 cdp($temp->print_r());
1254 $item->setParameter(4, $temp);
1258 * Implements hook_upgrade_call_function_exists_alter().
1260 function coder_upgrade_upgrade_call_function_exists_alter(&$item, &$reader) { // DONE
1261 // Create helper objects.
1262 $editor = PGPEditor
::getInstance();
1264 // Process function call.
1265 $name = &$item->name
;
1266 // Change was reverted.
1267 // $name['value'] = 'drupal_function_exists';
1271 * Implements hook_upgrade_call_menu_path_is_external_alter().
1273 function coder_upgrade_upgrade_call_menu_path_is_external_alter(&$item, &$reader) { // DONE
1274 // Create helper objects.
1275 $editor = PGPEditor
::getInstance();
1277 // Process function call.
1278 $name = &$item->name
;
1279 $name['value'] = 'url_is_external';
1283 * Implements hook_upgrade_call_menu_tree_data().
1285 function coder_upgrade_upgrade_call_menu_tree_data_alter(&$item, &$reader) {
1286 // Create helper objects.
1287 $editor = PGPEditor
::getInstance();
1289 // Function now expects an array of links, rather than a query resource.
1290 $p1 = $item->getParameter()->getElement();
1291 if (!is_object($p1)) {
1295 elseif (get_class($p1) == 'PGPOperand') {
1296 $resource = $p1->toString();
1298 elseif (get_class($p1) == 'PGPFunctionCall') {
1299 $resource = '$result';
1300 $statement = $editor->textToStatements('$result = '.
$p1->toString())->getElement(0);
1301 $item->insertStatementBefore($statement);
1303 // Insert statements.
1304 $statement = $editor->textToStatements('$list = array()')->getElement(0);
1305 $item->insertStatementBefore($statement);
1306 $statement = $editor->textToStatements("foreach ({$resource} as \$item) {\n\t\$list[] = \$item;\n}")->getElement(0);
1307 $item->insertStatementBefore($statement);
1308 $editor->setParameter($item, 0, '$list');
1312 * Implements hook_upgrade_call_menu_valid_path_alter().
1314 function coder_upgrade_upgrade_call_menu_valid_path_alter(&$item, &$reader) { // DONE
1315 // Create helper objects.
1316 $editor = PGPEditor
::getInstance();
1318 // Process function call.
1319 $name = &$item->name
; // NOT DONE
1320 $name['value'] = 'drupal_valid_path';
1321 // cdp($item->parameters->print_r());
1322 $count = $item->parameters
->count();
1324 $editor->setParameter($item, 0, "'' /* TODO Please pass a menu path */");
1327 coder_upgrade_convert_menu_valid_path($item, $reader, $editor);
1331 * Implements hook_upgrade_call_module_invoke_alter().
1333 function coder_upgrade_upgrade_call_module_invoke_alter(&$item, &$reader) { // DONE
1334 // Create helper objects.
1335 $editor = PGPEditor
::getInstance();
1337 // Process function call.
1338 $name = &$item->name
;
1339 // http://drupal.org/node/224333#taxonomy_get_tree
1340 $depth = '$max_depth = NULL /* TODO Set this variable. */';
1341 $count = $item->parameters
->count();
1342 // Confirm this call relates to our topic.
1344 $p0 = $item->printParameter(0);
1345 $p1 = $item->printParameter(1);
1346 if ($p0 != "'taxonomy'" || $p1 != "'get_tree'") {
1347 cdp("FAILED to relate");
1352 // Adjust parameters.
1355 $p4 = $item->getParameter(4);
1356 $p5 = $item->getParameter(5);
1357 $item->setParameter(4, $p5);
1358 $item->setParameter(5, $p4);
1360 elseif ($count > 4) {
1361 // Insert parameter due to change in parameter order.
1362 $editor->insertParameter($item, 4, $depth);
1363 $count = $item->parameters
->count();
1366 $defaults = array(array('NULL', $depth), '-1');
1367 $string = $editor->removeDefaults($item, 4, $defaults);
1371 * Implements hook_upgrade_call_module_list_alter().
1373 function coder_upgrade_upgrade_call_module_list_alter(&$item, &$reader) { // DONE
1374 // Create helper objects.
1375 $editor = PGPEditor
::getInstance();
1377 // Process function call.
1378 $name = &$item->name
;
1379 $name['value'] = 'module_implements';
1380 $editor->setParameters($item, array('$hook /* TODO Set this variable. */'));
1384 * Implements hook_upgrade_call_module_rebuild_cache_alter().
1386 function coder_upgrade_upgrade_call_module_rebuild_cache_alter(&$item, &$reader) { // DONE
1387 // Create helper objects.
1388 $editor = PGPEditor
::getInstance();
1390 // Process function call.
1391 $name = &$item->name
;
1392 $name['value'] = 'system_rebuild_module_data';
1396 * Implements hook_upgrade_call_node_get_types_alter().
1398 function coder_upgrade_upgrade_call_node_get_types_alter(&$item, &$reader) { // DONE
1399 // Create helper objects.
1400 $editor = PGPEditor
::getInstance();
1402 if ($item->parameterCount() && !$item->getParameter()->isType(T_CONSTANT_ENCAPSED_STRING
)) {
1403 // Add TODO comment.
1404 $item->insertStatementBefore($editor->commentToStatement('// TODO Please change this function call to node_type_get_$op based on the value of the $op variable.'));
1408 $op = $item->printParameter(0);
1409 $node = $item->printParameter(1);
1410 $reset = $item->printParameter(2);
1412 // node_get_types($op) is now node_type_get_$op.
1413 $op = trim($op, "'\"");
1414 $op = $op ?
$op : 'types';
1416 $item->parameters
->clear();
1423 if (strtoupper($node) == 'NULL' || $node == '') {
1424 $node = $node == '' ?
'$node' : $node;
1425 $todo = ' /* TODO The $node parameter should not be null. Please declare and initialize a $node parameter. */';
1427 $editor->setParameter($item, 0, $node .
$todo);
1431 $name = &$item->name
;
1432 $name['value'] = 'node_type_get_'.
$op;
1434 // node_type_clear() (to clear the static cache) is now a separate function.
1435 if ($reset && $reset != 'FALSE') {
1436 $statement = $editor->textToStatements("node_types_clear();")->getElement(0);
1437 $item->insertStatementBefore($statement);
1441 * Implements hook_upgrade_call_node_invoke_nodeapi_alter().
1443 function coder_upgrade_upgrade_call_node_invoke_nodeapi_alter(&$item, &$reader) { // DONE
1444 // Create helper objects.
1445 $editor = PGPEditor
::getInstance();
1447 // Process function call.
1448 $name = &$item->name
;
1449 $name['value'] = 'module_invoke_all';
1451 if ($item->parameterCount() < 2) {
1452 $item->insertStatementBefore($editor->commentToStatement('// TODO The $hook parameter should not be null. Please declare and initialize a $hook parameter.'));
1453 $editor->insertParameter($item, 0, 'node_ . $hook /* TODO Set this variable. */');
1457 $op = $item->getParameter(1);
1458 $p2 = $item->printParameter(2);
1459 $p3 = $item->printParameter(3);
1461 $item->deleteParameter(3);
1462 $item->deleteParameter(2);
1463 $item->deleteParameter(1);
1465 if ($op->isType(T_CONSTANT_ENCAPSED_STRING
)) {
1466 $operation = trim($op->toString(), "'\"");
1467 switch ($operation) {
1475 // This operation hook becomes node_x
1478 case
'prepare translation':
1479 case
'search result':
1480 case
'update index':
1481 // This operation hook becomes node_x_x
1482 $operation = str_replace(" ", "_", $operation);
1486 // This operation hook becomes node_build_alter
1487 $operation = 'build_alter';
1490 case
'delete revision':
1491 // This operation hook becomes node_revision_delete
1492 $operation = 'revision_delete';
1496 // This operation hook becomes node_view with $view_mode = 'print'
1497 $operation = 'view';
1502 // This operation hook becomes node_view with $view_mode = 'rss'
1503 $operation = 'view';
1508 // This operation hook becomes node_view with $view_mode = 'full' by default
1509 if ($p2 && !in_array(strtolower($p2), array('null', 'false'))) {
1512 elseif ($p3 && !in_array(strtolower($p3), array('null', 'false'))) {
1518 cdp("ERROR: Invalid case value");
1521 $p0 = "'node_" .
$operation .
"'";
1524 $p0 = "'node_' . ".
$op->toString();
1525 // Let's assume $p2 is valid.
1526 // $p2 .= $p2 ? " /* TODO: Set this parameter based on the " . $op->toString() . " hook */" : '';
1529 $editor->insertParameter($item, 0, $p0);
1531 $editor->setParameter($item, 2, $p2);
1536 * Implements hook_upgrade_call__node_type_set_defaults_alter().
1538 function coder_upgrade_upgrade_call__node_type_set_defaults_alter(&$item, &$reader) { // DONE
1539 // Create helper objects.
1540 $editor = PGPEditor
::getInstance();
1542 // Process function call.
1543 $name = &$item->name
;
1544 // http://drupal.org/node/224333#node_type_base
1545 $name['value'] = 'node_type_set_defaults';
1549 * Implements hook_upgrade_call_referer_uri_alter().
1551 function coder_upgrade_upgrade_call_referer_uri_alter(&$item, &$reader) { // DONE
1552 // Create helper objects.
1553 $editor = PGPEditor
::getInstance();
1555 // Process function call.
1556 $name = &$item->name
;
1557 $expression = $editor->expressionToStatement("\$_SERVER['HTTP_REFERER']");
1558 $item = $expression->getElement(0);
1562 * Updates require() and its siblings.
1564 function coder_upgrade_convert_require(&$item, &$reader) { // DONE
1566 // Create helper objects.
1567 $editor = PGPEditor
::getInstance();
1569 // These language elements are included by $reader in function call list.
1570 // Use with http://drupal.org/node/224333#absolute_includes
1572 // Eliminate parentheses (if any).
1573 $item->noparens
= 1;
1575 // Get first parameter.
1576 $p0 = $item->getParameter();
1577 $operand = $p0->getElement();
1578 if (is_a($operand, 'PGPOperand') && $operand->findNode('type') == T_STRING
&& $operand->findNode('value') == 'DRUPAL_ROOT') {
1579 // Nothing to change.
1580 cdp('leaving the routine');
1583 if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING
) {
1584 if (strpos($operand['value'], "'./'") === 0) { // if ($operand['value'][0] == '.') {
1586 // Remove './' from the beginning of the string.
1587 $operand['value'] = str_replace('./', '', $operand['value']);
1588 cdp('value = '.
$operand['value']);
1589 if ($operand['value'] == "''" || $operand['value'] == '""') {
1590 cdp('deleteElement');
1591 $p0->deleteElement();
1592 $p0->deleteElement(); // This should be a concatenation operator.
1596 // Prepend DRUPAL_ROOT before existing expression.
1597 $editor->setParameter($item, 0, "DRUPAL_ROOT . '/' . " .
$p0->toString());
1601 * Implements hook_upgrade_call_set_time_limit_alter().
1603 function coder_upgrade_upgrade_call_set_time_limit_alter(&$item, &$reader) { // DONE
1604 // Create helper objects.
1605 $editor = PGPEditor
::getInstance();
1607 // Process function call.
1608 $name = &$item->name
;
1609 $name['value'] = 'drupal_set_time_limit';
1613 * Implements hook_upgrade_call_system_theme_data_alter().
1615 function coder_upgrade_upgrade_call_system_theme_data_alter(&$item, &$reader) { // DONE
1616 // Create helper objects.
1617 $editor = PGPEditor
::getInstance();
1619 // Process function call.
1620 $name = &$item->name
;
1621 $name['value'] = 'system_rebuild_theme_data';
1625 * Implements hook_upgrade_call_t_alter().
1627 function coder_upgrade_upgrade_call_t_alter(&$item, &$reader) { // DONE
1628 // Create helper objects.
1629 $editor = PGPEditor
::getInstance();
1631 // Process function call.
1632 $name = &$item->name
;
1633 $count = $item->parameters
->count();
1638 $keys = array('langcode');
1639 $defaults = array("'XXX_YYY'");
1640 $string = $editor->arrayitize($item, 2, $keys, $defaults);
1642 $temp = $editor->expressionToStatement($string);
1643 $temp->getElement(0)->multiline
= 0;
1644 cdp($temp->print_r());
1645 $item->setParameter(2, $temp);
1649 * Implements hook_upgrade_call_taxonomy_del_term_alter().
1651 function coder_upgrade_upgrade_call_taxonomy_del_term_alter(&$item, &$reader) { // DONE
1652 // Create helper objects.
1653 $editor = PGPEditor
::getInstance();
1655 // Process function call.
1656 $name = &$item->name
;
1657 $name['value'] = 'taxonomy_term_delete';
1661 * Implements hook_upgrade_call_taxonomy_del_vocabulary_alter().
1663 function coder_upgrade_upgrade_call_taxonomy_del_vocabulary_alter(&$item, &$reader) { // DONE
1664 // Create helper objects.
1665 $editor = PGPEditor
::getInstance();
1667 // Process function call.
1668 $name = &$item->name
;
1669 $name['value'] = 'taxonomy_vocabulary_delete';
1673 * Implements hook_upgrade_call_taxonomy_get_term_alter().
1675 function coder_upgrade_upgrade_call_taxonomy_get_term_alter(&$item, &$reader) { // DONE
1676 // Create helper objects.
1677 $editor = PGPEditor
::getInstance();
1679 // Process function call.
1680 $name = &$item->name
;
1681 $name['value'] = 'taxonomy_term_load';
1685 * Implements hook_upgrade_call_taxonomy_get_tree_alter().
1687 function coder_upgrade_upgrade_call_taxonomy_get_tree_alter(&$item, &$reader) { // DONE
1688 // Create helper objects.
1689 $editor = PGPEditor
::getInstance();
1691 // Process function call.
1692 $name = &$item->name
;
1693 $depth = '$max_depth = NULL /* TODO Set this variable. */';
1694 $count = $item->parameters
->count();
1695 // Adjust parameters.
1698 $p2 = $item->getParameter(2);
1699 $p3 = $item->getParameter(3);
1700 $item->setParameter(2, $p3);
1701 $item->setParameter(3, $p2);
1703 elseif ($count > 2) {
1704 // Insert parameter due to change in parameter order.
1705 $editor->insertParameter($item, 2, $depth);
1706 $count = $item->parameters
->count();
1709 $defaults = array(array('NULL', $depth), '-1');
1710 $string = $editor->removeDefaults($item, 2, $defaults);
1714 * Implements hook_upgrade_call_taxonomy_save_term_alter().
1716 function coder_upgrade_upgrade_call_taxonomy_save_term_alter(&$item, &$reader) { // DONE
1717 // Create helper objects.
1718 $editor = PGPEditor
::getInstance();
1720 // Process function call.
1721 $name = &$item->name
;
1722 $name['value'] = 'taxonomy_term_save';
1723 $temp = $item->printParameters();
1724 $editor->setParameters($item, array('$term /* TODO Term object replaces array ' .
$temp .
' */)'));
1728 * Implements hook_upgrade_call_taxonomy_save_vocabulary_alter().
1730 function coder_upgrade_upgrade_call_taxonomy_save_vocabulary_alter(&$item, &$reader) { // DONE
1731 // Create helper objects.
1732 $editor = PGPEditor
::getInstance();
1734 // Process function call.
1735 $name = &$item->name
;
1736 $name['value'] = 'taxonomy_vocabulary_save';
1737 $temp = $item->printParameters();
1738 $editor->setParameters($item, array('$vocabulary /* TODO Vocabulary object replaces array ' .
$temp .
' */)'));
1742 * Implements hook_upgrade_call_theme_alter().
1744 function coder_upgrade_upgrade_call_theme_alter(&$item, &$reader) { // DONE
1745 global $upgrade_theme_registry;
1747 // Create helper objects.
1748 $editor = PGPEditor
::getInstance();
1750 // Process function call.
1751 $name = &$item->name
;
1753 $p0 = $item->getParameter();
1754 if (!$p0->isType(T_CONSTANT_ENCAPSED_STRING
)) {
1755 // TODO Look for the assignment to the theme hook (a variable or expression).
1756 $item->insertStatementBefore($editor->commentToStatement('// TODO Please change this theme call to use an associative array for the $variables parameter.'));
1760 // Process changes to specific themes.
1761 $theme = trim($item->printParameter(), "'\"");
1762 // http://drupal.org/node/224333#theme_page
1763 if ($theme == 'page') { // DONE
1764 $item->insertStatementBefore($editor->commentToStatement('// TODO Please change this theme call as discussed at http://drupal.org/node/224333#theme_page.'));
1765 // Get the statement (i.e. node) this function call is part of.
1766 $parent = &$item->parent
;
1767 // Comment out the statement.
1768 $text = $parent->data
->toString();
1769 $parent->data
= $editor->textToStatements('// ' .
$text)->getElement();
1772 // http://drupal.org/node/224333##theme_pager
1773 // Limit parameter has been removed.
1774 if ($theme == 'pager') { // DONE
1775 $item->deleteParameter(2); // Does nothing if no third parameter.
1777 // http://drupal.org/node/224333#placeholder
1778 // theme('placeholder') has been replaced by drupal_placeholder().
1779 if ($theme == 'placeholder') { // DONE
1780 $item->deleteParameter();
1781 $name['value'] = 'drupal_placeholder';
1784 // http://drupal.org/node/224333#theme_username
1785 // theme('username') parameters have changed.
1786 // Note: this is automatically handled below.
1787 // if ($theme == 'username') { // DONE
1788 // $p1 = $item->printParameter(1);
1789 // $p1 = "array('account' => $p1)";
1790 // $editor->setParameter($item, 1, $p1);
1795 * http://drupal.org/node/224333#theme_changes
1797 * In module pre-processing, create a global variable to hold the array of
1798 * theme registrations for all core files (including disabled modules). Add
1799 * to this array the theme entries for the current module. Find the current
1800 * theme call in the global list to get the names of its parameters.
1801 * Array-itize the parameters.
1803 * See drupal_common_theme() in common.inc and hook_theme in the core modules.
1805 * See http://drupal.org/files/issues/theme-wip-572618-83.patch
1808 $theme = trim($item->printParameter(0), "'\"");
1809 if (!isset($upgrade_theme_registry[$theme])) {
1810 clp("ERROR: Theme entry for '$theme' not found in theme registry or hook_theme");
1811 $item->insertStatementBefore($editor->commentToStatement('// TODO Please change this theme call to use an associative array for the $variables parameter.'));
1814 $hook = $upgrade_theme_registry[$theme];
1816 if (isset($hook['variables'])) {
1817 $count = $item->parameterCount();
1818 // TODO Incorporate default value elimination into this.
1819 if ($count == 1 /*|| $count - 1 != count($hook['variables'])*/) {
1820 // This theme call is missing some or all of the variables parameters.
1821 $item->insertStatementBefore($editor->commentToStatement('// TODO Please change this theme call to use an associative array for the $variables parameter.'));
1824 $defaults = array_fill(0, $count - 1, "'XXX_YYY'");
1825 $string = $editor->arrayitize($item, 1, array_keys($hook['variables']), $defaults);
1827 $temp = $editor->expressionToStatement($string);
1828 $temp->getElement(0)->multiline
= 0;
1829 $item->setParameter(1, $temp);
1834 * Implements hook_upgrade_call_time_alter().
1836 function coder_upgrade_upgrade_call_time_alter(&$item, &$reader) { // DONE
1837 // Create helper objects.
1838 $editor = PGPEditor
::getInstance();
1840 // Process function call.
1841 $name = &$item->name
;
1842 $expression = $editor->expressionToStatement('REQUEST_TIME');
1843 cdp($expression->print_r());
1844 $item = $expression->getElement(0);
1848 * Implements hook_upgrade_call_url_alter().
1850 function coder_upgrade_upgrade_call_url_alter(&$item, &$reader) {
1851 // Create helper objects.
1852 $editor = PGPEditor
::getInstance();
1854 if ($item->parameterCount() < 2) {
1859 // Convert query string into an array
1860 $p1 = $item->getParameter(1)->getElement();
1861 if (!is_object($p1) || !$p1->isType(/*'PGPArray'*/ T_ARRAY
)) {
1862 // Add TODO comment.
1863 $item->insertStatementBefore($editor->commentToStatement('// TODO The second parameter to this function call should be an array.'));
1867 if ($query = &$p1->findValue('query')) {
1868 if ($query->isType(T_CONSTANT_ENCAPSED_STRING
)) {
1869 parse_str(trim($query->first()->data
['value'], "'\""), $query_str);
1870 // TODO This leaves an inline array expression with a trailing comma.
1871 $query = $editor->expressionToStatement(str_replace(array("\n", " "), '', var_export($query_str, TRUE
)));
1877 * Implements hook_upgrade_call_user_authenticate_alter().
1879 function coder_upgrade_upgrade_call_user_authenticate_alter(&$item, &$reader) { // DONE
1880 // Create helper objects.
1881 $editor = PGPEditor
::getInstance();
1883 // Process function call.
1884 $name = &$item->name
;
1885 $count = $item->parameters
->count();
1887 $editor->setParameters($item, array('$name', '$password /* TODO Set these variables */'));
1893 * - parameter is an array expression: extract values to use as new
1895 * - parameter is a variable expression (not an array): assume the
1896 * variable has name and pass as elements
1899 $p0 = $item->getParameter();
1900 $operand = $p0->getElement();
1901 $class = get_class($operand);
1902 if ($class == 'PGPOperand') {
1903 // Get the variable name used as the parameter.
1904 $parameter = $item->printParameter();
1905 // Make variable assignments referring to two new parameters.
1906 $assign1 = $editor->textToStatements('$name = ' .
$parameter .
"['name']; // TODO Set these variables");
1907 $assign2 = $editor->textToStatements('$password = ' .
$parameter .
"['pass'];")->getElement(0);
1908 cdp($assign1->print_r());
1909 // Insert the assignments before this statement.
1910 // Get the statement (i.e. node) this function call is part of.
1911 $parent = &$item->parent
;
1912 // Get the statement list the parent is part of.
1913 $container = &$parent->container
;
1914 // Insert statements.
1915 $container->insertListBefore($parent, $assign1, 'assignment');
1916 $container->insertBefore($parent, $assign2, 'assignment');
1917 // Set the parameters on this function call.
1918 $editor->setParameters($item, array('$name', '$password'));
1920 elseif ($class == 'PGPArray') {
1921 $name = $operand->findValue("'name'")->toString();
1922 $password = $operand->findValue("'pass'")->toString();
1923 // Set the parameters on this function call.
1924 $editor->setParameters($item, array($name, $password));
1929 * Implements hook_upgrade_call_user_delete_alter().
1931 function coder_upgrade_upgrade_call_user_delete_alter(&$item, &$reader) { // DONE
1932 // Create helper objects.
1933 $editor = PGPEditor
::getInstance();
1935 // Process function call.
1936 $name = &$item->name
;
1937 $name['value'] = 'user_cancel';
1938 $editor->setParameter($item, 2, "\$method = 'user_cancel_block' /* TODO Set this variable */");
1942 * Updates menu_valid_path().
1944 * Copied from hook_node_info() change.
1947 * In general, there are 3 typical cases (or code styles):
1948 * Case 1: passes variable directly.
1949 * if (!menu_valid_path(array('link_path' => $expression))) { ... }
1951 * Case 2: makes one assignment to array variable; passes variable.
1952 * $item = array('link_path' => $expression);
1953 * if (!menu_valid_path($item)) { ... }
1955 * Case 3: makes multiple assignments to array variable; passes variable.
1956 * $item['link_path'] = $expression1;
1957 * $item['link_title'] = $expression2;
1958 * if (!menu_valid_path($item)) { ... }
1960 * [The inner array to modify is 3 levels deep in the first 2 cases, but only
1961 * 2 levels deep in the third. In the first 2 cases, we can loop on the key1
1962 * arrays. In the third, the loop is on assignment statements.]
1964 function coder_upgrade_convert_menu_valid_path(&$item, &$reader, &$editor) { // DONE
1965 cdp("inside " . __FUNCTION__
);
1967 $operand = $item->getParameter()->getElement();
1968 cdp($operand->print_r());
1970 // Examine the type of the operand in the parameter.
1971 if (get_class($operand) == 'PGPArray') {
1972 // Use case 1 - passes variable directly.
1973 cdp("Case 1: passes variable directly");
1974 coder_upgrade_callback_menu_valid_path($item, $operand);
1976 elseif (get_class($operand) == 'PGPOperand') {
1977 $p0 = $operand->toString();
1978 if ($operand->count() > 2) {
1979 // Use case 4 - passes more complex variable directly. (NOT HANDLED)
1980 // The operand passed is more complex than a variable name. It might
1981 // be an expression like $item['xx'] or $item->xx.
1982 clp("ERROR: Variable expression $p0 passed as parameter in menu_valid_path");
1983 $editor->setParameter($item, 0, "$p0 /* TODO Please pass a menu path directly */");
1986 if ($operand->getElement(0) != T_VARIABLE
) {
1987 clp("ERROR: Parameter $p0 is not a variable in menu_valid_path");
1991 $variable = $operand->getElement(1);
1992 cdp("variable = $variable");
1994 // Get the statement (i.e. node) this function call is part of.
1995 $parent = &$item->parent
;
1996 // Get the statement list the parent is part of.
1997 $container = &$parent->container
;
1998 // Search the container for assignment to the variable.
2001 * Loop on body statements until we find an assignment to the parameter
2002 * variable. Loop in reverse from the parent statement to find the last
2003 * setting of the variable.
2006 $parameter_variable = $operand->toString();
2009 $current = $parent->previous
;
2010 while ($current->previous
!= NULL
) {
2011 if (is_object($current->data
) && $current->data
->type
== T_ASSIGNMENT
) {
2012 $assignment = $current->data
;
2013 $assign_variable = $assignment->values
->getElement()->getElement()->toString();
2014 if ($parameter_variable == $assign_variable) {
2015 // Use case 2: makes one assignment to array variable; pass variable.
2016 cdp("Case 2: Assignment variable matches parameter variable");
2017 $value1 = $assignment->values
->getElement();
2018 $array1 = $value1->getElement($value1->count() - 1);
2019 coder_upgrade_callback_menu_valid_path($item, $array1);
2023 elseif (strpos($assign_variable, $parameter_variable) !== FALSE
&& strpos($assign_variable, 'link_path') !== FALSE
) {
2024 // Use case 3: makes multiple assignments to array variable; pass variable.
2025 cdp("Case 3: Assignment variable includes parameter variable");
2026 $value1 = $assignment->values
->getElement();
2027 $value2 = $value1->getElement($value1->count() - 1);
2028 // Make an expression object to use as function call parameter.
2029 $expression = new
PGPExpression();
2030 $expression->insertLast($value2, 'operand');
2031 $item->setParameter(0, $value2);
2032 cdp($item->toString());
2037 $current = $current->previous
;
2040 clp("ERROR: Assignment statement to parameter variable not found in menu_valid_path");
2047 * Changes function call parameter.
2049 * @param PGPFunctionCall $item
2050 * @param PGPArray $operand
2052 function coder_upgrade_callback_menu_valid_path(&$item, &$operand) { // DONE
2053 cdp("inside " . __FUNCTION__
);
2054 // TODO This key value could also be in double quotes.
2055 $value = $operand->findValue("'link_path'");
2056 cdp($value->print_r());
2057 $item->setParameter(0, $value);
2058 cdp($item->toString());