coder_upgrade.call.inc: Implement #theme_page; coder_upgrade.function.inc: Refactor...
[project/coder.git] / coder_upgrade / conversions / coder_upgrade.call.inc
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Function call conversion routine file for the coder_upgrade module.
7 * These routines upgrade function calls using the grammar parser.
8 *
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.
12 *
13 * Copyright 2009-10 by Jim Berry ("solotandem", http://drupal.org/user/240748)
14 */
15
16 /**
17 * The upgrades to these functions are documented at the following urls.
18 *
19 * System
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
36 *
37 *
38 * Database
39 * http://drupal.org/node/224333#schema_ret
40 *
41 *
42 * Menu
43 * http://drupal.org/node/224333#comment_load (DUP Comments)
44 * http://drupal.org/node/224333#menu_tree_data
45 *
46 *
47 * Comments
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
51 *
52 *
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
58 *
59 *
60 * Taxonomy
61 * http://drupal.org/node/224333#taxonomy_get_tree
62 * http://drupal.org/node/224333#taxonomy_crud
63 *
64 *
65 * Javascript
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
69 *
70 *
71 * CSS
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)
74 *
75 *
76 * Theming
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
83 *
84 *
85 * Form API
86 * http://drupal.org/node/224333#drupal_execute_drupal_form_submit
87 *
88 *
89 * File API
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
95 *
96 *
97 * User API
98 * http://drupal.org/node/224333#user_cancel (ALSO in convert_functions)
99 * http://drupal.org/node/224333#user_authenticate
100 *
101 *
102 * Node API
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
106 *
107 *
108 * Multi-lingual
109 * http://drupal.org/node/224333#locale_context
110 *
111 *
112 * Miscellaneous
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
121 */
122
123 /**
124 * Implements hook_upgrade_call_alter().
125 */
126 function coder_upgrade_upgrade_call_alter(&$item, &$reader, $name) { // NEEDS WORK
127 // Create helper objects.
128 $editor = PGPEditor::getInstance();
129
130 // Process function call.
131 // $name = &$item->name;
132
133 switch ($name) {
134 case 'db_add_field':
135 // includes/database.pgsql.inc Add a new field to a table.
136 case 'db_add_index':
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();
167
168 /*
169 * TODO
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.
173 *
174 * These could be moved to the install file although it may be possible to
175 * call them in other files.
176 */
177 break;
178
179 case 'require':
180 case 'require_once':
181 case 'include':
182 case 'include_once':
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);
186 break;
187
188 default:
189 ;
190 break;
191 }
192 }
193
194 /**
195 * Implements hook_upgrade_call_actions_synchronize_alter().
196 */
197 function coder_upgrade_upgrade_call_actions_synchronize_alter(&$item, &$reader) { // DONE
198 // Create helper objects.
199 $editor = PGPEditor::getInstance();
200
201 // Process function call.
202 $name = &$item->name;
203 $count = $item->parameters->count();
204 if ($count > 0) {
205 $item->deleteParameter();
206 }
207 }
208
209 /**
210 * Implements hook_upgrade_call_book_toc_alter().
211 */
212 function coder_upgrade_upgrade_call_book_toc_alter(&$item, &$reader) { // DONE
213 // Create helper objects.
214 $editor = PGPEditor::getInstance();
215
216 // Process function call.
217 $name = &$item->name;
218 // Adjust parameters.
219 $count = $item->parameters->count();
220 if ($count > 2) {
221 // Switch places.
222 $p1 = $item->getParameter(1);
223 $p2 = $item->getParameter(2);
224 $item->setParameter(1, $p2);
225 $item->setParameter(2, $p1);
226 }
227 // Remove default parameter.
228 if ($count == 3) {
229 $value = $item->printParameter(2);
230 cdp("value = $value");
231 if ($value == 'array()') {
232 $item->deleteParameter(2);
233 }
234 }
235 }
236
237 /**
238 * Implements hook_upgrade_call_check_markup_alter().
239 */
240 function coder_upgrade_upgrade_call_check_markup_alter(&$item, &$reader) { // DONE
241 // Create helper objects.
242 $editor = PGPEditor::getInstance();
243
244 // Process function call.
245 $name = &$item->name;
246 if ($item->parameters->count() > 2) {
247 $editor->insertParameter($item, 2, '$langcode = \'\' /* TODO Set this variable. */');
248 }
249 }
250
251 /**
252 * Implements hook_upgrade_call__comment_load_alter().
253 */
254 function coder_upgrade_upgrade_call__comment_load_alter(&$item, &$reader) { // DONE
255 // Create helper objects.
256 $editor = PGPEditor::getInstance();
257
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.)
262 }
263
264 /**
265 * Implements hook_upgrade_call_comment_node_url_alter().
266 */
267 function coder_upgrade_upgrade_call_comment_node_url_alter(&$item, &$reader) { // DONE
268 // Create helper objects.
269 $editor = PGPEditor::getInstance();
270
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);
280 }
281
282 /**
283 * Implements hook_upgrade_call_comment_validate_alter().
284 */
285 function coder_upgrade_upgrade_call_comment_validate_alter(&$item, &$reader) { // DONE
286 // Create helper objects.
287 $editor = PGPEditor::getInstance();
288
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. */'));
293 }
294
295 /**
296 * Implements hook_upgrade_call_db_add_field_alter().
297 *//*
298 function coder_upgrade_upgrade_call_db_add_field_alter(&$item, &$reader) { // NEEDS WORK
299 // Create helper objects.
300 $editor = PGPEditor::getInstance();
301
302 // Process function call.
303 $name = &$item->name;
304 // includes/database.pgsql.inc Add a new field to a table.
305 $item->deleteParameter();
306
307 /*
308 * TODO
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.
312 *
313 * These could be moved to the install file although it may be possible to
314 * call them in other files.
315 *//*
316 }*/
317
318 /**
319 * Implements hook_upgrade_call_db_add_index_alter().
320 *//*
321 function coder_upgrade_upgrade_call_db_add_index_alter(&$item, &$reader) { // DONE
322 // Create helper objects.
323 $editor = PGPEditor::getInstance();
324
325 // Process function call.
326 $name = &$item->name;
327 // includes/database.pgsql.inc Add an index.
328 $item->deleteParameter();
329 }*/
330
331 /**
332 * Implements hook_upgrade_call_db_add_primary_key_alter().
333 *//*
334 function coder_upgrade_upgrade_call_db_add_primary_key_alter(&$item, &$reader) { // DONE
335 // Create helper objects.
336 $editor = PGPEditor::getInstance();
337
338 // Process function call.
339 $name = &$item->name;
340 // includes/database.pgsql.inc Add a primary key.
341 $item->deleteParameter();
342 }*/
343
344 /**
345 * Implements hook_upgrade_call_db_add_unique_key_alter().
346 *//*
347 function coder_upgrade_upgrade_call_db_add_unique_key_alter(&$item, &$reader) { // DONE
348 // Create helper objects.
349 $editor = PGPEditor::getInstance();
350
351 // Process function call.
352 $name = &$item->name;
353 // includes/database.pgsql.inc Add a unique key.
354 $item->deleteParameter();
355 }*/
356
357 /**
358 * Implements hook_upgrade_call_db_change_field_alter().
359 *//*
360 function coder_upgrade_upgrade_call_db_change_field_alter(&$item, &$reader) { // DONE
361 // Create helper objects.
362 $editor = PGPEditor::getInstance();
363
364 // Process function call.
365 $name = &$item->name;
366 // includes/database.pgsql.inc Change a field definition.
367 $item->deleteParameter();
368 }*/
369
370 /**
371 * Implements hook_upgrade_call_db_create_table_alter().
372 *//*
373 function coder_upgrade_upgrade_call_db_create_table_alter(&$item, &$reader) { // DONE
374 // Create helper objects.
375 $editor = PGPEditor::getInstance();
376
377 // Process function call.
378 $name = &$item->name;
379 // includes/database.inc Create a new table from a Drupal table definition.
380 $item->deleteParameter();
381 }*/
382
383 /**
384 * Implements hook_upgrade_call_db_create_table_sql_alter().
385 *//*
386 function coder_upgrade_upgrade_call_db_create_table_sql_alter(&$item, &$reader) { // DONE
387 // Create helper objects.
388 $editor = PGPEditor::getInstance();
389
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();
394 }*/
395
396 /**
397 * Implements hook_upgrade_call_db_drop_field_alter().
398 *//*
399 function coder_upgrade_upgrade_call_db_drop_field_alter(&$item, &$reader) { // DONE
400 // Create helper objects.
401 $editor = PGPEditor::getInstance();
402
403 // Process function call.
404 $name = &$item->name;
405 // includes/database.pgsql.inc Drop a field.
406 $item->deleteParameter();
407 }*/
408
409 /**
410 * Implements hook_upgrade_call_db_drop_index_alter().
411 *//*
412 function coder_upgrade_upgrade_call_db_drop_index_alter(&$item, &$reader) { // DONE
413 // Create helper objects.
414 $editor = PGPEditor::getInstance();
415
416 // Process function call.
417 $name = &$item->name;
418 // includes/database.pgsql.inc Drop an index.
419 $item->deleteParameter();
420 }*/
421
422 /**
423 * Implements hook_upgrade_call_db_drop_primary_key_alter().
424 *//*
425 function coder_upgrade_upgrade_call_db_drop_primary_key_alter(&$item, &$reader) { // DONE
426 // Create helper objects.
427 $editor = PGPEditor::getInstance();
428
429 // Process function call.
430 $name = &$item->name;
431 // includes/database.pgsql.inc Drop the primary key.
432 $item->deleteParameter();
433 }*/
434
435 /**
436 * Implements hook_upgrade_call_db_drop_table_alter().
437 *//*
438 function coder_upgrade_upgrade_call_db_drop_table_alter(&$item, &$reader) { // DONE
439 // Create helper objects.
440 $editor = PGPEditor::getInstance();
441
442 // Process function call.
443 $name = &$item->name;
444 // includes/database.pgsql.inc Drop a table.
445 $item->deleteParameter();
446 }*/
447
448 /**
449 * Implements hook_upgrade_call_db_drop_unique_key_alter().
450 *//*
451 function coder_upgrade_upgrade_call_db_drop_unique_key_alter(&$item, &$reader) { // DONE
452 // Create helper objects.
453 $editor = PGPEditor::getInstance();
454
455 // Process function call.
456 $name = &$item->name;
457 // includes/database.pgsql.inc Drop a unique key.
458 $item->deleteParameter();
459 }*/
460
461 /**
462 * Implements hook_upgrade_call_db_field_names_alter().
463 *//*
464 function coder_upgrade_upgrade_call_db_field_names_alter(&$item, &$reader) { // DONE
465 // Create helper objects.
466 $editor = PGPEditor::getInstance();
467
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();
472 }*/
473
474 /**
475 * Implements hook_upgrade_call_db_field_set_default_alter().
476 *//*
477 function coder_upgrade_upgrade_call_db_field_set_default_alter(&$item, &$reader) { // DONE
478 // Create helper objects.
479 $editor = PGPEditor::getInstance();
480
481 // Process function call.
482 $name = &$item->name;
483 // includes/database.pgsql.inc Set the default value for a field.
484 $item->deleteParameter();
485 }*/
486
487 /**
488 * Implements hook_upgrade_call_db_field_set_no_default_alter().
489 *//*
490 function coder_upgrade_upgrade_call_db_field_set_no_default_alter(&$item, &$reader) { // DONE
491 // Create helper objects.
492 $editor = PGPEditor::getInstance();
493
494 // Process function call.
495 $name = &$item->name;
496 // includes/database.pgsql.inc Set a field to have no default value.
497 $item->deleteParameter();
498 }*/
499
500 /**
501 * Implements hook_upgrade_call_db_rename_table_alter().
502 *//*
503 function coder_upgrade_upgrade_call_db_rename_table_alter(&$item, &$reader) { // DONE
504 // Create helper objects.
505 $editor = PGPEditor::getInstance();
506
507 // Process function call.
508 $name = &$item->name;
509 // includes/database.pgsql.inc Rename a table.
510 $item->deleteParameter();
511 }*/
512
513 /**
514 * Implements hook_upgrade_call_drupal_add_css_alter().
515 */
516 function coder_upgrade_upgrade_call_drupal_add_css_alter(&$item, &$reader) { // DONE (UPDATED)
517 // Create helper objects.
518 $editor = PGPEditor::getInstance();
519
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());
524
525 $count = $item->parameters->count();
526 if ($count == 1) {
527 return;
528 }
529 if ($count == 2) {
530 $type = trim($item->printParameter(1), "'\"");
531 if ($type == 'module') {
532 $item->deleteParameter(1);
533 return;
534 }
535 }
536
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");
541
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.
547
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);
553 }
554 }
555
556 /**
557 * Returns the new css weight parameter.
558 *
559 * @param string $type
560 * @return string
561 */
562 function coder_upgrade_css_weight($type) {
563 switch ($type) {
564 case 'module':
565 return 'CSS_DEFAULT';
566
567 case 'theme':
568 return 'CSS_THEME';
569
570 default:
571 return 'CSS_DEFAULT';
572 }
573 }
574
575 /**
576 * Implements hook_upgrade_call_drupal_add_js_alter().
577 */
578 function coder_upgrade_upgrade_call_drupal_add_js_alter(&$item, &$reader) { // DONE (UPDATED)
579 // Create helper objects.
580 $editor = PGPEditor::getInstance();
581
582 // Process function call.
583 $name = &$item->name;
584 /*
585 * With
586 * drupal_add_js('misc/collapse.js', 'core', 'header', FALSE, TRUE, TRUE);
587 * we will output
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.
593 *
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.
596 */
597 cdp($item->parameters->print_r());
598
599 $count = $item->parameters->count();
600 if ($count == 1) {
601 return;
602 }
603 if ($count == 2) {
604 $type = trim($item->printParameter(1), "'\"");
605 if ($type == 'module') {
606 // if (in_array($type, array('module', ''))) {
607 $item->deleteParameter(1);
608 return;
609 }
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'");
613 }
614 }
615
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");
620
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.
626
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);
632 }
633 }
634
635 /**
636 * Returns the new js weight parameter.
637 *
638 * @param string $type
639 * @return string
640 */
641 function coder_upgrade_js_weight($type) {
642 switch ($type) {
643 case 'core':
644 return 'JS_LIBRARY';
645
646 case 'module':
647 return 'JS_DEFAULT';
648
649 case 'theme':
650 return 'JS_THEME';
651
652 default:
653 return 'JS_DEFAULT';
654 }
655 }
656
657 /**
658 * Implements hook_upgrade_call_drupal_clone_alter().
659 */
660 function coder_upgrade_upgrade_call_drupal_clone_alter(&$item, &$reader) { // DONE
661 // Create helper objects.
662 $editor = PGPEditor::getInstance();
663
664 // Process function call.
665 $name = &$item->name;
666 $name['value'] = 'clone';
667 $item->noparens = 1;
668 }
669
670 /**
671 * Implements hook_upgrade_call_drupal_eval_alter().
672 */
673 function coder_upgrade_upgrade_call_drupal_eval_alter(&$item, &$reader) { // DONE
674 // Create helper objects.
675 $editor = PGPEditor::getInstance();
676
677 // Process function call.
678 $name = &$item->name;
679 /*
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.
683 */
684
685 // Set the name of the function call.
686 $name['value'] = 'php_eval';
687
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);
693 }
694
695 /**
696 * Implements hook_upgrade_call_drupal_execute_alter().
697 */
698 function coder_upgrade_upgrade_call_drupal_execute_alter(&$item, &$reader) { // DONE
699 // Create helper objects.
700 $editor = PGPEditor::getInstance();
701
702 // Process function call.
703 $name = &$item->name;
704 $name['value'] = 'drupal_form_submit';
705 }
706
707
708 /**
709 * Implements hook_upgrade_call_drupal_get_content_alter().
710 */
711 function coder_upgrade_upgrade_call_drupal_get_content_alter(&$item, &$reader) { // DONE
712 // Create helper objects.
713 $editor = PGPEditor::getInstance();
714
715 // Process function call.
716 $name = &$item->name;
717 $name['value'] = 'drupal_get_region_content';
718 }
719
720 /**
721 * Implements hook_upgrade_call_drupal_get_headers_alter().
722 */
723 function coder_upgrade_upgrade_call_drupal_get_headers_alter(&$item, &$reader) { // DONE
724 // Create helper objects.
725 $editor = PGPEditor::getInstance();
726
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';
732 }
733
734 /**
735 * Implements hook_upgrade_call_drupal_http_request_alter().
736 */
737 function coder_upgrade_upgrade_call_drupal_http_request_alter(&$item, &$reader) { // DONE
738 // Create helper objects.
739 $editor = PGPEditor::getInstance();
740
741 // Process function call.
742 $name = &$item->name;
743 cdp($item->parameters->print_r());
744
745 $count = $item->parameters->count();
746 if ($count == 1) {
747 return;
748 }
749
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);
753
754 $temp = $editor->expressionToStatement($string);
755 $temp->getElement(0)->multiline = 0;
756 cdp($temp->print_r());
757 $item->setParameter(1, $temp);
758 }
759
760 /**
761 * Implements hook_upgrade_call_drupal_json_alter().
762 */
763 function coder_upgrade_upgrade_call_drupal_json_alter(&$item, &$reader) { // DONE
764 // Create helper objects.
765 $editor = PGPEditor::getInstance();
766
767 // Process function call.
768 $name = &$item->name;
769 $name['value'] = 'drupal_json_output';
770 }
771
772 /**
773 * Implements hook_upgrade_call_drupal_rebuild_code_registry_alter().
774 */
775 function coder_upgrade_upgrade_call_drupal_rebuild_code_registry_alter(&$item, &$reader) { // DONE
776 // Create helper objects.
777 $editor = PGPEditor::getInstance();
778
779 // Process function call.
780 $name = &$item->name;
781 $name['value'] = 'registry_rebuild';
782 }
783
784 /**
785 * Implements hook_upgrade_call_drupal_rebuild_theme_registry_alter().
786 */
787 function coder_upgrade_upgrade_call_drupal_rebuild_theme_registry_alter(&$item, &$reader) { // DONE
788 // Create helper objects.
789 $editor = PGPEditor::getInstance();
790
791 // Process function call.
792 $name = &$item->name;
793 $name['value'] = 'drupal_theme_rebuild';
794 }
795
796 /**
797 * Implements hook_upgrade_call_drupal_set_content_alter().
798 */
799 function coder_upgrade_upgrade_call_drupal_set_content_alter(&$item, &$reader) { // DONE
800 // Create helper objects.
801 $editor = PGPEditor::getInstance();
802
803 // Process function call.
804 $name = &$item->name;
805 $name['value'] = 'drupal_add_region_content';
806 }
807
808 /**
809 * Implements hook_upgrade_call_drupal_set_header_alter().
810 */
811 function coder_upgrade_upgrade_call_drupal_set_header_alter(&$item, &$reader) { // DONE
812 // Create helper objects.
813 $editor = PGPEditor::getInstance();
814
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, "' ") . "'";
825 }
826 $editor->setParameters($item, $temp);
827 }
828 elseif (strpos($temp, "\$_SERVER['SERVER_PROTOCOL']") !== FALSE ||
829 strpos($temp, '\$_SERVER["SERVER_PROTOCOL"]') !== FALSE) {
830 $from = '@\$_SERVER\[(\'|")SERVER_PROTOCOL(\'|")\]\s*\.\s*(\'|")\s*(.*?)(\'|")@';
831 $to = "$3$4$3";
832 $temp = preg_replace($from, $to, $temp);
833 $editor->setParameters($item, array($temp));
834 }
835 }
836
837 /**
838 * Implements hook_upgrade_call_drupal_set_html_head_alter().
839 */
840 function coder_upgrade_upgrade_call_drupal_set_html_head_alter(&$item, &$reader) { // DONE (UPDATED)
841 // Create helper objects.
842 $editor = PGPEditor::getInstance();
843
844 // Process function call.
845 $name = &$item->name;
846 $name['value'] = 'drupal_add_html_head';
847
848 $count = $item->parameters->count();
849 if ($count == 1) {
850 $key = '$key = NULL /* TODO Set this variable. */';
851 // Insert new required parameter when first parameter is set.
852 $editor->insertParameter($item, 1, $key);
853 }
854 }
855
856 /**
857 * Implements hook_upgrade_call_drupal_set_title_alter().
858 */
859 function coder_upgrade_upgrade_call_drupal_set_title_alter(&$item, &$reader) { // DONE
860 // Create helper objects.
861 $editor = PGPEditor::getInstance();
862
863 // Process function call.
864 $name = &$item->name;
865 $temp = $item->printParameters();
866 cdp("temp = $temp");
867
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());
877 return;
878 }
879 $parameters = &$item->parameters;
880 if ($call = & $parameters->search('PGPFunctionCall', 'name', 'value', 't')) {
881 $temp = $call->toString();
882 cdp("temp = $temp");
883 if (preg_match('#(\'|")@\w+(\'|")\s*=>\s*#', $temp)) {
884 $editor->setParameter($item, 1, 'PASS_THROUGH');
885 cdp($item->print_r(0, $item));
886 }
887 }
888 }
889
890 /**
891 * Implements hook_upgrade_call_drupal_system_listing_alter().
892 */
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();
896
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) . "/'");
904 }
905 elseif ($temp[0] == '"') {
906 $editor->setParameter($item, 0, '"/' . substr($temp, 1, -1) . '/"');
907 }
908 // else if type == T_VARIABLE, find the $mask used in the call and examine its value.
909 }
910
911 /**
912 * Implements hook_upgrade_call_drupal_to_js_alter().
913 */
914 function coder_upgrade_upgrade_call_drupal_to_js_alter(&$item, &$reader) { // DONE
915 // Create helper objects.
916 $editor = PGPEditor::getInstance();
917
918 // Process function call.
919 $name = &$item->name;
920 $name['value'] = 'drupal_json_encode';
921 }
922
923 /**
924 * Implements hook_upgrade_call_drupal_uninstall_module_alter().
925 */
926 function coder_upgrade_upgrade_call_drupal_uninstall_module_alter(&$item, &$reader) { // DONE
927 // Create helper objects.
928 $editor = PGPEditor::getInstance();
929
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 . ')'));
935 }
936
937 /**
938 * Implements hook_upgrade_call_file_scan_directory_alter().
939 */
940 function coder_upgrade_upgrade_call_file_scan_directory_alter(&$item, &$reader) { // DONE (IN PROGRESS)
941 cdp(__FUNCTION__);
942 // Create helper objects.
943 $editor = PGPEditor::getInstance();
944
945 // Process function call.
946 $name = &$item->name;
947
948 /*
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.
953 */
954
955 // Save the depth parameter.
956 $depth = $item->getParameter(7);
957 $item->deleteParameter(7);
958
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);
968 }
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);
976 if ($statement) {
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'];
982 }
983 else {
984 clp("ERROR: Could not find a string to change in " . __FUNCTION__);
985 }
986 }
987 }
988 else {
989 clp("ERROR: Could not find a string to change in " . __FUNCTION__);
990 }
991 }
992
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);
1002 }
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);
1010 if ($statement) {
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);
1016 }
1017 else {
1018 clp("ERROR: Could not find a string to change in " . __FUNCTION__);
1019 }
1020 }
1021 }
1022 else {
1023 clp("ERROR: Could not find a string to change in " . __FUNCTION__);
1024 }
1025 }
1026
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);
1035 }
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);
1041
1042 }
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!!!
1046 }
1047
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);
1053
1054 if (is_object($depth) || $string != 'array()') {
1055 $temp = $editor->expressionToStatement($string);
1056 $temp->getElement(0)->multiline = 0;
1057 $item->setParameter(2, $temp);
1058 }
1059 if (is_object($depth)) {
1060 $item->setParameter(7, $depth);
1061 }
1062
1063 // TODO Could regex for '->filename' and change to '->filepath'???
1064 // See http://drupal.org/files/issues/file_scan_directory-1.patch
1065 }
1066
1067 /**
1068 * Returns the new file key parameter.
1069 *
1070 * @param string $key
1071 * @return string
1072 */
1073 function coder_upgrade_file_key($key) {
1074 switch ($key) {
1075 case "'filename'":
1076 return "'uri'";
1077
1078 case "'basename'":
1079 return "'filename'";
1080
1081 case "'name'":
1082 return "'name'";
1083
1084 default:
1085 return "'uri'";
1086 }
1087 }
1088
1089 /**
1090 * Converts an ereg string to a preg string.
1091 *
1092 * @param string $string
1093 * @return string
1094 */
1095 function coder_upgrade_ereg_to_preg($string) {
1096 cdp(__FUNCTION__);
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) {
1102 break;
1103 }
1104 }
1105
1106 if (!$delimiter) {
1107 clp('ERROR: Could not find a suitable delimiter for the regular exprssion');
1108 $delimiter = '/';
1109 $string = str_replace('/', '\/', $string);
1110 }
1111
1112 $quote = $string[0];
1113 return $quote . $delimiter . substr($string, 1, -1) . $delimiter . $quote;
1114 }
1115
1116 /**
1117 * Returns a preg string for the nomask parameter.
1118 *
1119 * @param PGPOperand $nomask
1120 * @return string
1121 */
1122 function coder_upgrade_array_to_preg($operand) {
1123 cdp(__FUNCTION__);
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(), "'\"");
1129 }
1130 $current = $current->next;
1131 }
1132 $defaults = array_diff($defaults, $values);
1133 if (empty($defaults)) {
1134 return "'/(\.\.?|CVS)$/'";
1135 }
1136 $strings = array();
1137 foreach ($values as $value) {
1138 $strings[] .= str_replace('.', '\.', $value);
1139 }
1140 return "'/(" . implode('|', $strings) . ")/'";
1141 }
1142
1143 /**
1144 * Implements hook_upgrade_call_file_set_status_alter().
1145 */
1146 function coder_upgrade_upgrade_call_file_set_status_alter(&$item, &$reader) { // DONE
1147 // Create helper objects.
1148 $editor = PGPEditor::getInstance();
1149
1150 // Process function call.
1151 $name = &$item->name;
1152
1153 if ($item->parameters->count() == 2) {
1154 $p0 = $item->printParameter(0);
1155 $p1 = $item->printParameter(1);
1156
1157 // Insert statement.
1158 $temp = $editor->textToStatements("{$p0}->status &= $p1");
1159 $parent = $item->parent;
1160 $parent->container->insertBefore($parent, $temp->getElement(0));
1161
1162 // Change statement.
1163 $from = $temp1;
1164 $to = "$p0 = file_save($p0)";
1165 $temp = str_replace($from, $to, $temp2);
1166 $temp = $editor->textToStatements($temp);
1167 $parent->data = $temp->getElement(0);
1168 }
1169 }
1170
1171 /**
1172 * Implements hook_upgrade_call_filter_formats_alter().
1173 */
1174 function coder_upgrade_upgrade_call_filter_formats_alter(&$item, &$reader) { // DONE (UPDATED)
1175 // Create helper objects.
1176 $editor = PGPEditor::getInstance();
1177
1178 // Process function call.
1179 $name = &$item->name;
1180 cdp('filter_formats');
1181 /*
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);
1186 * becomes
1187 * global $user;
1188 * $formats = filter_formats($user);
1189 * $formats = $formats[$index];
1190 */
1191 $index = $item->printParameter(0);
1192 cdp("index = '$index'");
1193 $p0 = $editor->expressionToStatement('$user');
1194 $item->setParameter(0, $p0);
1195
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');
1203 if ($index) {
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');
1210 }
1211 }
1212
1213 /**
1214 * Implements hook_upgrade_call_format_date_alter().
1215 */
1216 function coder_upgrade_upgrade_call_format_date_alter(&$item, &$reader) {
1217 // Create helper objects.
1218 $editor = PGPEditor::getInstance();
1219
1220 // Change date types
1221 $date_type = $item->printParameter(1);
1222 $date_type = trim($date_type, "'\"");
1223 switch ($date_type) {
1224 case 'small';
1225 $editor->setParameter($item, 1, "'short'");
1226 break;
1227 case 'large':
1228 $editor->setParameter($item, 1, "'long'");
1229 break;
1230 }
1231 }
1232
1233 /**
1234 * Implements hook_upgrade_call_format_plural_alter().
1235 */
1236 function coder_upgrade_upgrade_call_format_plural_alter(&$item, &$reader) { // DONE
1237 // Create helper objects.
1238 $editor = PGPEditor::getInstance();
1239
1240 // Process function call.
1241 $name = &$item->name;
1242 $count = $item->parameters->count();
1243 if ($count < 5) {
1244 return;
1245 }
1246
1247 $keys = array('langcode');
1248 $defaults = array("'XXX_YYY'");
1249 $string = $editor->arrayitize($item, 4, $keys, $defaults);
1250
1251 $temp = $editor->expressionToStatement($string);
1252 $temp->getElement(0)->multiline = 0;
1253 cdp($temp->print_r());
1254 $item->setParameter(4, $temp);
1255 }
1256
1257 /**
1258 * Implements hook_upgrade_call_function_exists_alter().
1259 */
1260 function coder_upgrade_upgrade_call_function_exists_alter(&$item, &$reader) { // DONE
1261 // Create helper objects.
1262 $editor = PGPEditor::getInstance();
1263
1264 // Process function call.
1265 $name = &$item->name;
1266 // Change was reverted.
1267 // $name['value'] = 'drupal_function_exists';
1268 }
1269
1270 /**
1271 * Implements hook_upgrade_call_menu_path_is_external_alter().
1272 */
1273 function coder_upgrade_upgrade_call_menu_path_is_external_alter(&$item, &$reader) { // DONE
1274 // Create helper objects.
1275 $editor = PGPEditor::getInstance();
1276
1277 // Process function call.
1278 $name = &$item->name;
1279 $name['value'] = 'url_is_external';
1280 }
1281
1282 /**
1283 * Implements hook_upgrade_call_menu_tree_data().
1284 */
1285 function coder_upgrade_upgrade_call_menu_tree_data_alter(&$item, &$reader) {
1286 // Create helper objects.
1287 $editor = PGPEditor::getInstance();
1288
1289 // Function now expects an array of links, rather than a query resource.
1290 $p1 = $item->getParameter()->getElement();
1291 if (!is_object($p1)) {
1292 // TODO
1293 return;
1294 }
1295 elseif (get_class($p1) == 'PGPOperand') {
1296 $resource = $p1->toString();
1297 }
1298 elseif (get_class($p1) == 'PGPFunctionCall') {
1299 $resource = '$result';
1300 $statement = $editor->textToStatements('$result = '. $p1->toString())->getElement(0);
1301 $item->insertStatementBefore($statement);
1302 }
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');
1309 }
1310
1311 /**
1312 * Implements hook_upgrade_call_menu_valid_path_alter().
1313 */
1314 function coder_upgrade_upgrade_call_menu_valid_path_alter(&$item, &$reader) { // DONE
1315 // Create helper objects.
1316 $editor = PGPEditor::getInstance();
1317
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();
1323 if (!$count) {
1324 $editor->setParameter($item, 0, "'' /* TODO Please pass a menu path */");
1325 return;
1326 }
1327 coder_upgrade_convert_menu_valid_path($item, $reader, $editor);
1328 }
1329
1330 /**
1331 * Implements hook_upgrade_call_module_invoke_alter().
1332 */
1333 function coder_upgrade_upgrade_call_module_invoke_alter(&$item, &$reader) { // DONE
1334 // Create helper objects.
1335 $editor = PGPEditor::getInstance();
1336
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.
1343 if ($count > 2) {
1344 $p0 = $item->printParameter(0);
1345 $p1 = $item->printParameter(1);
1346 if ($p0 != "'taxonomy'" || $p1 != "'get_tree'") {
1347 cdp("FAILED to relate");
1348 return;
1349 }
1350 }
1351
1352 // Adjust parameters.
1353 if ($count > 5) {
1354 // Switch places.
1355 $p4 = $item->getParameter(4);
1356 $p5 = $item->getParameter(5);
1357 $item->setParameter(4, $p5);
1358 $item->setParameter(5, $p4);
1359 }
1360 elseif ($count > 4) {
1361 // Insert parameter due to change in parameter order.
1362 $editor->insertParameter($item, 4, $depth);
1363 $count = $item->parameters->count();
1364 }
1365
1366 $defaults = array(array('NULL', $depth), '-1');
1367 $string = $editor->removeDefaults($item, 4, $defaults);
1368 }
1369
1370 /**
1371 * Implements hook_upgrade_call_module_list_alter().
1372 */
1373 function coder_upgrade_upgrade_call_module_list_alter(&$item, &$reader) { // DONE
1374 // Create helper objects.
1375 $editor = PGPEditor::getInstance();
1376
1377 // Process function call.
1378 $name = &$item->name;
1379 $name['value'] = 'module_implements';
1380 $editor->setParameters($item, array('$hook /* TODO Set this variable. */'));
1381 }
1382
1383 /**
1384 * Implements hook_upgrade_call_module_rebuild_cache_alter().
1385 */
1386 function coder_upgrade_upgrade_call_module_rebuild_cache_alter(&$item, &$reader) { // DONE
1387 // Create helper objects.
1388 $editor = PGPEditor::getInstance();
1389
1390 // Process function call.
1391 $name = &$item->name;
1392 $name['value'] = 'system_rebuild_module_data';
1393 }
1394
1395 /**
1396 * Implements hook_upgrade_call_node_get_types_alter().
1397 */
1398 function coder_upgrade_upgrade_call_node_get_types_alter(&$item, &$reader) { // DONE
1399 // Create helper objects.
1400 $editor = PGPEditor::getInstance();
1401
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.'));
1405 return;
1406 }
1407
1408 $op = $item->printParameter(0);
1409 $node = $item->printParameter(1);
1410 $reset = $item->printParameter(2);
1411
1412 // node_get_types($op) is now node_type_get_$op.
1413 $op = trim($op, "'\"");
1414 $op = $op ? $op : 'types';
1415
1416 $item->parameters->clear();
1417 switch ($op) {
1418 case 'module':
1419 $op = 'base';
1420 case 'name':
1421 case 'type':
1422 $todo = '';
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. */';
1426 }
1427 $editor->setParameter($item, 0, $node . $todo);
1428 break;
1429 }
1430
1431 $name = &$item->name;
1432 $name['value'] = 'node_type_get_'. $op;
1433
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);
1438 }
1439 }
1440 /**
1441 * Implements hook_upgrade_call_node_invoke_nodeapi_alter().
1442 */
1443 function coder_upgrade_upgrade_call_node_invoke_nodeapi_alter(&$item, &$reader) { // DONE
1444 // Create helper objects.
1445 $editor = PGPEditor::getInstance();
1446
1447 // Process function call.
1448 $name = &$item->name;
1449 $name['value'] = 'module_invoke_all';
1450
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. */');
1454 return;
1455 }
1456
1457 $op = $item->getParameter(1);
1458 $p2 = $item->printParameter(2);
1459 $p3 = $item->printParameter(3);
1460
1461 $item->deleteParameter(3);
1462 $item->deleteParameter(2);
1463 $item->deleteParameter(1);
1464
1465 if ($op->isType(T_CONSTANT_ENCAPSED_STRING)) {
1466 $operation = trim($op->toString(), "'\"");
1467 switch ($operation) {
1468 case 'delete':
1469 case 'insert':
1470 case 'load':
1471 case 'prepare':
1472 case 'presave':
1473 case 'update':
1474 case 'validate':
1475 // This operation hook becomes node_x
1476 break;
1477
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);
1483 break;
1484
1485 case 'alter':
1486 // This operation hook becomes node_build_alter
1487 $operation = 'build_alter';
1488 break;
1489
1490 case 'delete revision':
1491 // This operation hook becomes node_revision_delete
1492 $operation = 'revision_delete';
1493 break;
1494
1495 case 'print':
1496 // This operation hook becomes node_view with $view_mode = 'print'
1497 $operation = 'view';
1498 $p2 = "'print'";
1499 break;
1500
1501 case 'rss item':
1502 // This operation hook becomes node_view with $view_mode = 'rss'
1503 $operation = 'view';
1504 $p2 = "'rss'";
1505 break;
1506
1507 case 'view':
1508 // This operation hook becomes node_view with $view_mode = 'full' by default
1509 if ($p2 && !in_array(strtolower($p2), array('null', 'false'))) {
1510 $p2 = "'teaser'";
1511 }
1512 elseif ($p3 && !in_array(strtolower($p3), array('null', 'false'))) {
1513 $p2 = "'full'";
1514 }
1515 break;
1516
1517 default:
1518 cdp("ERROR: Invalid case value");
1519 return;
1520 }
1521 $p0 = "'node_" . $operation . "'";
1522 }
1523 else {
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 */" : '';
1527 }
1528
1529 $editor->insertParameter($item, 0, $p0);
1530 if ($p2) {
1531 $editor->setParameter($item, 2, $p2);
1532 }
1533 }
1534
1535 /**
1536 * Implements hook_upgrade_call__node_type_set_defaults_alter().
1537 */
1538 function coder_upgrade_upgrade_call__node_type_set_defaults_alter(&$item, &$reader) { // DONE
1539 // Create helper objects.
1540 $editor = PGPEditor::getInstance();
1541
1542 // Process function call.
1543 $name = &$item->name;
1544 // http://drupal.org/node/224333#node_type_base
1545 $name['value'] = 'node_type_set_defaults';
1546 }
1547
1548 /**
1549 * Implements hook_upgrade_call_referer_uri_alter().
1550 */
1551 function coder_upgrade_upgrade_call_referer_uri_alter(&$item, &$reader) { // DONE
1552 // Create helper objects.
1553 $editor = PGPEditor::getInstance();
1554
1555 // Process function call.
1556 $name = &$item->name;
1557 $expression = $editor->expressionToStatement("\$_SERVER['HTTP_REFERER']");
1558 $item = $expression->getElement(0);
1559 }
1560
1561 /**
1562 * Updates require() and its siblings.
1563 */
1564 function coder_upgrade_convert_require(&$item, &$reader) { // DONE
1565 cdp(__FUNCTION__);
1566 // Create helper objects.
1567 $editor = PGPEditor::getInstance();
1568
1569 // These language elements are included by $reader in function call list.
1570 // Use with http://drupal.org/node/224333#absolute_includes
1571
1572 // Eliminate parentheses (if any).
1573 $item->noparens = 1;
1574
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');
1581 return;
1582 }
1583 if (is_array($operand) && $operand['type'] == T_CONSTANT_ENCAPSED_STRING) {
1584 if (strpos($operand['value'], "'./'") === 0) { // if ($operand['value'][0] == '.') {
1585 cdp('found ./');
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.
1593 }
1594 }
1595 }
1596 // Prepend DRUPAL_ROOT before existing expression.
1597 $editor->setParameter($item, 0, "DRUPAL_ROOT . '/' . " . $p0->toString());
1598 }
1599
1600 /**
1601 * Implements hook_upgrade_call_set_time_limit_alter().
1602 */
1603 function coder_upgrade_upgrade_call_set_time_limit_alter(&$item, &$reader) { // DONE
1604 // Create helper objects.
1605 $editor = PGPEditor::getInstance();
1606
1607 // Process function call.
1608 $name = &$item->name;
1609 $name['value'] = 'drupal_set_time_limit';
1610 }
1611
1612 /**
1613 * Implements hook_upgrade_call_system_theme_data_alter().
1614 */
1615 function coder_upgrade_upgrade_call_system_theme_data_alter(&$item, &$reader) { // DONE
1616 // Create helper objects.
1617 $editor = PGPEditor::getInstance();
1618
1619 // Process function call.
1620 $name = &$item->name;
1621 $name['value'] = 'system_rebuild_theme_data';
1622 }
1623
1624 /**
1625 * Implements hook_upgrade_call_t_alter().
1626 */
1627 function coder_upgrade_upgrade_call_t_alter(&$item, &$reader) { // DONE
1628 // Create helper objects.
1629 $editor = PGPEditor::getInstance();
1630
1631 // Process function call.
1632 $name = &$item->name;
1633 $count = $item->parameters->count();
1634 if ($count < 3) {
1635 return;
1636 }
1637
1638 $keys = array('langcode');
1639 $defaults = array("'XXX_YYY'");
1640 $string = $editor->arrayitize($item, 2, $keys, $defaults);
1641
1642 $temp = $editor->expressionToStatement($string);
1643 $temp->getElement(0)->multiline = 0;
1644 cdp($temp->print_r());
1645 $item->setParameter(2, $temp);
1646 }
1647
1648 /**
1649 * Implements hook_upgrade_call_taxonomy_del_term_alter().
1650 */
1651 function coder_upgrade_upgrade_call_taxonomy_del_term_alter(&$item, &$reader) { // DONE
1652 // Create helper objects.
1653 $editor = PGPEditor::getInstance();
1654
1655 // Process function call.
1656 $name = &$item->name;
1657 $name['value'] = 'taxonomy_term_delete';
1658 }
1659
1660 /**
1661 * Implements hook_upgrade_call_taxonomy_del_vocabulary_alter().
1662 */
1663 function coder_upgrade_upgrade_call_taxonomy_del_vocabulary_alter(&$item, &$reader) { // DONE
1664 // Create helper objects.
1665 $editor = PGPEditor::getInstance();
1666
1667 // Process function call.
1668 $name = &$item->name;
1669 $name['value'] = 'taxonomy_vocabulary_delete';
1670 }
1671
1672 /**
1673 * Implements hook_upgrade_call_taxonomy_get_term_alter().
1674 */
1675 function coder_upgrade_upgrade_call_taxonomy_get_term_alter(&$item, &$reader) { // DONE
1676 // Create helper objects.
1677 $editor = PGPEditor::getInstance();
1678
1679 // Process function call.
1680 $name = &$item->name;
1681 $name['value'] = 'taxonomy_term_load';
1682 }
1683
1684 /**
1685 * Implements hook_upgrade_call_taxonomy_get_tree_alter().
1686 */
1687 function coder_upgrade_upgrade_call_taxonomy_get_tree_alter(&$item, &$reader) { // DONE
1688 // Create helper objects.
1689 $editor = PGPEditor::getInstance();
1690
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.
1696 if ($count > 3) {
1697 // Switch places.
1698 $p2 = $item->getParameter(2);
1699 $p3 = $item->getParameter(3);
1700 $item->setParameter(2, $p3);
1701 $item->setParameter(3, $p2);
1702 }
1703 elseif ($count > 2) {
1704 // Insert parameter due to change in parameter order.
1705 $editor->insertParameter($item, 2, $depth);
1706 $count = $item->parameters->count();
1707 }
1708
1709 $defaults = array(array('NULL', $depth), '-1');
1710 $string = $editor->removeDefaults($item, 2, $defaults);
1711 }
1712
1713 /**
1714 * Implements hook_upgrade_call_taxonomy_save_term_alter().
1715 */
1716 function coder_upgrade_upgrade_call_taxonomy_save_term_alter(&$item, &$reader) { // DONE
1717 // Create helper objects.
1718 $editor = PGPEditor::getInstance();
1719
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 . ' */)'));
1725 }
1726
1727 /**
1728 * Implements hook_upgrade_call_taxonomy_save_vocabulary_alter().
1729 */
1730 function coder_upgrade_upgrade_call_taxonomy_save_vocabulary_alter(&$item, &$reader) { // DONE
1731 // Create helper objects.
1732 $editor = PGPEditor::getInstance();
1733
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 . ' */)'));
1739 }
1740
1741 /**
1742 * Implements hook_upgrade_call_theme_alter().
1743 */
1744 function coder_upgrade_upgrade_call_theme_alter(&$item, &$reader) { // DONE
1745 global $upgrade_theme_registry;
1746
1747 // Create helper objects.
1748 $editor = PGPEditor::getInstance();
1749
1750 // Process function call.
1751 $name = &$item->name;
1752
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.'));
1757 return;
1758 }
1759
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();
1770 return;
1771 }
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.
1776 }
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';
1782 return;
1783 }
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);
1791 // return;
1792 // }
1793
1794 /*
1795 * http://drupal.org/node/224333#theme_changes
1796 *
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.
1802 *
1803 * See drupal_common_theme() in common.inc and hook_theme in the core modules.
1804 *
1805 * See http://drupal.org/files/issues/theme-wip-572618-83.patch
1806 */
1807
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.'));
1812 return;
1813 }
1814 $hook = $upgrade_theme_registry[$theme];
1815
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.'));
1822 return;
1823 }
1824 $defaults = array_fill(0, $count - 1, "'XXX_YYY'");
1825 $string = $editor->arrayitize($item, 1, array_keys($hook['variables']), $defaults);
1826
1827 $temp = $editor->expressionToStatement($string);
1828 $temp->getElement(0)->multiline = 0;
1829 $item->setParameter(1, $temp);
1830 }
1831 }
1832
1833 /**
1834 * Implements hook_upgrade_call_time_alter().
1835 */
1836 function coder_upgrade_upgrade_call_time_alter(&$item, &$reader) { // DONE
1837 // Create helper objects.
1838 $editor = PGPEditor::getInstance();
1839
1840 // Process function call.
1841 $name = &$item->name;
1842 $expression = $editor->expressionToStatement('REQUEST_TIME');
1843 cdp($expression->print_r());
1844 $item = $expression->getElement(0);
1845 }
1846
1847 /**
1848 * Implements hook_upgrade_call_url_alter().
1849 */
1850 function coder_upgrade_upgrade_call_url_alter(&$item, &$reader) {
1851 // Create helper objects.
1852 $editor = PGPEditor::getInstance();
1853
1854 if ($item->parameterCount() < 2) {
1855 // Nothing to do.
1856 return;
1857 }
1858
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.'));
1864 return;
1865 }
1866
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)));
1872 }
1873 }
1874 }
1875
1876 /**
1877 * Implements hook_upgrade_call_user_authenticate_alter().
1878 */
1879 function coder_upgrade_upgrade_call_user_authenticate_alter(&$item, &$reader) { // DONE
1880 // Create helper objects.
1881 $editor = PGPEditor::getInstance();
1882
1883 // Process function call.
1884 $name = &$item->name;
1885 $count = $item->parameters->count();
1886 if ($count == 0) {
1887 $editor->setParameters($item, array('$name', '$password /* TODO Set these variables */'));
1888 return;
1889 }
1890
1891 /*
1892 * Two cases:
1893 * - parameter is an array expression: extract values to use as new
1894 * parameters
1895 * - parameter is a variable expression (not an array): assume the
1896 * variable has name and pass as elements
1897 */
1898
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'));
1919 }
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));
1925 }
1926 }
1927
1928 /**
1929 * Implements hook_upgrade_call_user_delete_alter().
1930 */
1931 function coder_upgrade_upgrade_call_user_delete_alter(&$item, &$reader) { // DONE
1932 // Create helper objects.
1933 $editor = PGPEditor::getInstance();
1934
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 */");
1939 }
1940
1941 /**
1942 * Updates menu_valid_path().
1943 *
1944 * Copied from hook_node_info() change.
1945 *
1946 * NOTE
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))) { ... }
1950 *
1951 * Case 2: makes one assignment to array variable; passes variable.
1952 * $item = array('link_path' => $expression);
1953 * if (!menu_valid_path($item)) { ... }
1954 *
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)) { ... }
1959 *
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.]
1963 */
1964 function coder_upgrade_convert_menu_valid_path(&$item, &$reader, &$editor) { // DONE
1965 cdp("inside " . __FUNCTION__);
1966
1967 $operand = $item->getParameter()->getElement();
1968 cdp($operand->print_r());
1969
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);
1975 }
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 */");
1984 return;
1985 }
1986 if ($operand->getElement(0) != T_VARIABLE) {
1987 clp("ERROR: Parameter $p0 is not a variable in menu_valid_path");
1988 return;
1989 }
1990
1991 $variable = $operand->getElement(1);
1992 cdp("variable = $variable");
1993
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.
1999
2000 /*
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.
2004 */
2005
2006 $parameter_variable = $operand->toString();
2007 $count = 0;
2008
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);
2020 // $count++;
2021 return;
2022 }
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());
2033 // $count++;
2034 return;
2035 }
2036 }
2037 $current = $current->previous;
2038 }
2039 if (!$count) {
2040 clp("ERROR: Assignment statement to parameter variable not found in menu_valid_path");
2041 return;
2042 }
2043 }
2044 }
2045
2046 /**
2047 * Changes function call parameter.
2048 *
2049 * @param PGPFunctionCall $item
2050 * @param PGPArray $operand
2051 */
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());
2059 }