coder_review_uc3x.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * @file
  4. * Implements Coder Upgrade functionality for Ubercart 6.x -> 7.x upgrades.
  5. */
  6. /**
  7. * Warns about namespace and function name changes.
  8. */
  9. function coder_review_uc3x_reviews() {
  10. $rules = array(
  11. // Ubercart hook names were namespaced.
  12. array(
  13. '#type' => 'regex',
  14. '#value' => '(?<!uc)_(add_to_cart|add_to_cart_data|calculate_tax|cart_display|(?<!update_)cart_item|cart_pane|checkout_pane|download_authorize|file_action|file_transfer_alter|line_item|line_item_alter|line_item_data_alter|order|order_actions|order_pane|order_product|order_product_alter|order_state|payment_method|payment_gagteway|product_class|product_description|product_description_alter|product_feature|product_types|shipment|shipping_type|shipping_method|store_status|update_cart_item)\s*\(',
  15. '#source' => 'all',
  16. '#never' => 'function theme',
  17. '#warning_callback' => '_coder_review_uc3x_hook_warning',
  18. ),
  19. // Private functions were moved into uc_ namespace.
  20. array(
  21. '#type' => 'regex',
  22. // (?<![(|]) prevents this very line from generating a warning.
  23. '#value' => '\b(?<![(|])(_2checkout_post_url|_call_order_pane_byref|_checkout_pane_(data|list)|_country_import_(include|list)|_get_order_screen_titles|_line_item_(data|list)|_order_pane_(data|list)|_parse_cs_avs_code|_parse_cs_cvv_code|_parse_cs_reason_code|_payment_gateway_(data|list)|_payment_method_(data|list)|_save_cc_data_to_order|_store_footer_options|summarize_(checkbox|child_form_pages|element|form|null)|_total_sort|_valid_card_(expiration|issue|number|start)|_valid_cvv)\b',
  24. '#source' => 'all',
  25. '#warning_callback' => '_coder_review_uc3x_function_warning',
  26. ),
  27. // Theme functions were namespaced.
  28. array(
  29. '#type' => 'regex',
  30. '#value' => 'theme\([\'"](address_pane|cart_review_table|summary_overview)[\'"]',
  31. '#warning_callback' => '_coder_review_uc3x_function_warning',
  32. ),
  33. // TAPIr table ids were namespaced.
  34. array(
  35. '#type' => 'regex',
  36. '#value' => '(?<!uc_)op_((admin|order)_comments|products)_(customer|edit|view)_table',
  37. '#source' => 'allphp',
  38. '#warning_callback' => '_coder_review_uc3x_function_warning',
  39. ),
  40. // uc_payment_process() is now uc_payment_process_payment().
  41. array(
  42. '#type' => 'regex',
  43. '#value' => '\buc_payment_process\s*\(',
  44. '#warning' => 'uc_payment_process() is now uc_payment_process_payment() because of hook_process().',
  45. ),
  46. // uc_add_js() was removed, use drupal_add_js() instead.
  47. array(
  48. '#type' => 'grep',
  49. '#value' => 'uc_add_js(',
  50. '#warning' => 'uc_add_js() has been removed. Use drupal_add_js() instead.',
  51. ),
  52. // First argument to uc_product_get_models() and hook_uc_product_models()
  53. // changed from $node to $nid.
  54. array(
  55. '#type' => 'regex',
  56. '#value' => '(\buc_product_get_models|\B_uc_product_models)\s*\(',
  57. '#warning' => 'First argument to uc_product_get_models() and hook_uc_product_models() has changed - it is now an integer node id instead of a node object.',
  58. ),
  59. // Checkout and order pane callback arguments changed.
  60. array(
  61. '#type' => 'regex',
  62. '#value' => 'pane.*\(\$op,\s*&?\$(arg1|order)(,\s*&?\$arg2)?',
  63. '#never' => '\(\$op,\s*&?\$order,\s*&?\$form\s*=\s*NULL,\s*&\$form_state\s*=\s*NULL\)',
  64. '#warning' => 'Checkout and order pane callbacks take the arguments ($op, $order, &$form = NULL, &$form_state = NULL).',
  65. ),
  66. // uc_price() removed.
  67. array(
  68. '#type' => 'grep',
  69. '#value' => 'uc_price(',
  70. '#warning' => 'The function uc_price() was removed.',
  71. ),
  72. // hook_uc_price_handler() removed.
  73. array(
  74. '#type' => 'regex',
  75. '#value' => '\B_uc_price_handler\(',
  76. '#warning' => 'hook_uc_price_handler() was removed.',
  77. '#severity' => 'normal',
  78. ),
  79. // theme_uc_price() has only one argument.
  80. array(
  81. '#type' => 'regex',
  82. '#value' => 'theme\s*\(\s*[\'"]uc_price[\'"]\s*,[^,]+,',
  83. '#warning' => 'theme_uc_price() takes only one argument: "price", which is a float.',
  84. ),
  85. // Specify the allowed arguments to theme_uc_product_price() before it is ported.
  86. array(
  87. '#type' => 'regex',
  88. '#value' => 'theme\s*\(\s*[\'"]uc_product_price[\'"]\s*,[^,]+,',
  89. '#not' => '[\'"]#price',
  90. '#warning' => 'theme_uc_product_price() takes a render element with a "#value" and optional "#title" and "#attributes".'
  91. ),
  92. // uc_order_load_line_items() has only one argument.
  93. array(
  94. '#type' => 'regex',
  95. '#value' => 'uc_order_load_line_items\([^,]+,',
  96. '#warning' => 'uc_order_load_line_items() takes only one argument, the order object. Both stored and calculated line items are returned at once.',
  97. ),
  98. );
  99. $review = array(
  100. '#title' => t('Converting Ubercart 2.x modules to 3.x'),
  101. '#rules' => $rules,
  102. '#severity' => 'critical',
  103. );
  104. return array('ubercart3x' => $review);
  105. }
  106. function _coder_review_uc3x_hook_warning() {
  107. return array(
  108. '#warning' => 'Ubercart hooks have been namespaced with "uc_" in the front.',
  109. '#link' => 'http://drupal.org/node/510382',
  110. );
  111. }
  112. function _coder_review_uc3x_function_warning() {
  113. return array(
  114. '#warning' => 'Ubercart private functions, theme functions, and TAPIr table ids have been namespaced with "uc_" in the front.',
  115. '#link' => 'http://drupal.org/node/750784',
  116. );
  117. }