diff --git a/uc_store/includes/ca.inc b/uc_store/includes/ca.inc deleted file mode 100644 index 98d228f3..00000000 --- a/uc_store/includes/ca.inc +++ /dev/null @@ -1,553 +0,0 @@ -ca_trigger == 'calculate_taxes') { - return ca_extract_conditions($predicate, $predicate->pid); - } - elseif (strpos($predicate->ca_trigger, 'get_quote_from_') === 0) { - return ca_extract_conditions($predicate, $predicate->ca_trigger); - } - - $rule = rules_reaction_rule(); - if (is_numeric($predicate->pid)) { - $rule->name = $predicate->ca_trigger . '_' . $predicate->pid; - } - else { - $rule->name = $predicate->pid; - } - $rule->label = $predicate->title; - $rule->active = (bool) $predicate->status; - $rule->event($predicate->ca_trigger); - - ca_add_conditions($rule, $predicate->conditions['#conditions']); - ca_add_actions($rule, $predicate->actions); - - $rule->save(); -} - -/** - * Saves the conditions of the predicate as a separate component. - * - * @param $predicate - * An object row from {ca_predicates}. - * @param $name - * The name to give the Rules component. - */ -function ca_extract_conditions($predicate, $name) { - $component = rules_and(array('order' => array('uc_order', 'label' => t('Order')))); - $component->name = $name; - $component->label = t('@title conditions', array('@title' => $predicate->title)); - - // CA predicates always have an AND at the root level. - ca_add_conditions($component, $predicate->conditions['#conditions']); - - $component->save(); -} - -/** - * Reads a predicate's conditions array and add them to a component. - * - * @param &$component - * A RulesConditionContainer or a Rule to receive conditions. - * @param $conditions - * A predicate's array of conditions. - */ -function ca_add_conditions(&$component, $conditions) { - foreach ($conditions as $condition) { - // Handle condition containers. - if (isset($condition['#conditions'])) { - switch ($condition['#operator']) { - case 'AND': - $sub_tree = rules_and(); - break; - - case 'OR': - $sub_tree = rules_or(); - break; - } - - // Recurse. - ca_add_conditions($sub_tree, $condition['#conditions']); - - if ($sub_tree->getIterator()->hasChildren()) { - $component->condition($sub_tree); - } - } - // Handle individual conditions. - else { - // Handle certain conditions as a generic "data_is" condition. - $map = ca_data_map(); - if (isset($map[$condition['#name']])) { - $name = 'data_is'; - } - else { - $name = $condition['#name']; - } - - $settings = array(); - // The argument maps are like data selectors pointing to event variables. - foreach ($condition['#argument_map'] as $key => $value) { - if ($name == 'data_is') { - $settings['data:select'] = $map[$condition['#name']]['data']; - } - // Special case: parameter changed, but doesn't use 'data_is'. - elseif ($name == 'uc_attribute_ordered_product_option' && $key == 'order') { - $settings['product:select'] = $value; - } - else { - $key .= ':select'; - $settings[$key] = $value; - } - } - - $negate = FALSE; - foreach ($condition['#settings'] as $key => $value) { - // Save negation for later. - if ($key == 'negate') { - $negate = TRUE; - continue; - } - - if ($condition['#name'] == 'ca_condition_date' && $key == 'date') { - $settings['date'] = $settings['date']['year'] . '/' . $settings['date']['month'] . '/' . $settings['date']['day']; - } - else { - $settings[$key] = $value; - } - } - - if ($name == 'data_is') { - $settings['#info'] = $map[$condition['#name']]['#info']; - - // data_is doesn't handle multiple values. Use a condition container. - if (count($settings[$map[$condition['#name']]['value']]) > 1) { - if (isset($map[$condition['#name']]['op']) && $settings[$map[$condition['#name']]['op']] == 'AND') { - $rules_condition = rules_and(); - } - else { - $rules_condition = rules_or(); - } - - foreach ($settings[$map[$condition['#name']]['value']] as $value) { - $rules_condition->condition('data_is', array('data:select' => $settings['data:select'], 'op' => 'contains', 'value' => $value, '#info' => $settings['#info'])); - } - } - elseif (is_array($settings[$map[$condition['#name']]['value']])) { - $rules_condition = rules_condition('data_is', array('data:select' => $settings['data:select'], 'op' => 'contains', 'value' => $settings[$map[$condition['#name']]['value']], '#info' => $settings['#info'])); - } - else { - // Translate operator settings. - if (isset($map[$condition['#name']]['op'])) { - switch ($settings[$map[$condition['#name']]['op']]) { - case 'before': - case 'less': - $ops = '<'; - break; - - case 'less_equal': - $ops = array('<', '=='); - break; - - case 'only': - case 'equal': - $ops = '=='; - break; - - case 'not': - $negate = !$negate; - $settings['operator'] = '=='; - break; - - case 'after': - case 'greater': - $ops = '>'; - break; - - case 'greater_equal': - $ops = array('>', '=='); - break; - - case 'begins': - case 'contains': - case 'ends': - $settings['operator'] = 'contains'; - break; - - case 'yes': - $settings['operator'] = '=='; - $settings['value'] = TRUE; - break; - - case 'no': - $settings['operator'] = '=='; - $settings['value'] = FALSE; - break; - } - - if ($condition['#name'] == 'node_field_comparison') { - switch ($settings['field']) { - case 'nid': - case 'vid': - case 'uid': - $type = 'integer'; - break; - - case 'type': - case 'title': - $type = 'text'; - break; - - case 'status': - case 'promote': - case 'sticky': - $type = 'boolean'; - break; - } - - $settings = array( - 'data:select' => array_shift($settings) . ':' . $settings['field'], - 'op' => $settings['operator'], - 'value' => $settings['value'], - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => $type, - ), - ), - ), - ); - } - - // data_is only provides <, =, and > for numeric data. Use two - // separate conditions for <= and >= cases. - if (is_array($ops)) { - $data_condition = data_or(); - foreach ($ops as $op) { - $data_condition->condition('data_is', array('data:select' => $settings['data:select'], 'op' => $op, 'value' => $settings[$map[$condition['#name']]['value']], '#info' => $settings['#info'])); - } - - $rules_condition = rules_condition($data_condition); - } - else { - $rules_condition = rules_condition('data_is', array('data:select' => $settings['data:select'], 'op' => $ops, 'value' => $settings[$map[$condition['#name']]['value']], '#info' => $settings['#info'])); - } - } - // Standard data_is check that 'data' is equal to 'value'. - else { - $rules_condition = rules_condition('data_is', array('data:select' => $settings['data:select'], 'value' => $settings[$map[$condition['#name']]['value']], '#info' => $settings['#info'])); - } - } - } - else { - if ($name == 'ca_condition_custom_php') { - $name = 'php_eval'; - $settings = array('code' => $settings['php']); - } - - $rules_condition = rules_condition($name, $settings); - } - - if ($negate) { - $rules_condition->negate(); - } - - $component->condition($rules_condition); - } - } -} - -/** - * Reads a predicate's actions array and add them to a Rule. - * - * @param Rule &$rule - * The configuration to receive actions. - * @param $actions - * The predicate's actions array. - */ -function ca_add_actions(&$rule, $actions) { - foreach ($actions as $action) { - $settings = array(); - // The argument maps are like data selectors pointing to event variables. - foreach ($action['#argument_map'] as $key => $value) { - $key .= ':select'; - $settings[$key] = $value; - } - - foreach ($action['#settings'] as $key => $value) { - $settings[$key] = $value; - } - - switch ($action['#name']) { - case 'ca_backdrop_set_message': - $name = 'backdrop_message'; - $settings = array( - 'message' => $settings['message_text'], - 'error' => $settings['message_type'] == 'error', - ); - break; - - case 'ca_action_custom_php': - $name = 'php_eval'; - $settings = array('code' => $settings['php']); - break; - - default: - $name = $action['#name']; - break; - } - $rule->action($name, $settings); - } -} - -/** - * Maps obsolete conditions to correct settings for 'data_is'. - */ -function ca_data_map() { - return array( - 'ca_condition_date' => array( - // @todo: use the correct selector - 'data' => 'system:date', - 'op' => 'operator', - 'value' => 'date', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'date', - ), - ), - ), - ), - 'ca_condition_user_roles' => array( - 'data' => 'user:roles', - 'value' => 'roles', - 'op' => 'operator', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'entity_plus_metadata_user_roles', - ), - ), - ), - ), - 'node_field_comparison' => array( - 'data' => '*', - 'op' => 'operator', - 'value' => 'value', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => '*', - ), - ), - ), - ), - 'uc_cart_condition_product_class' => array( - 'data' => 'product:type', - 'value' => 'class', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'node_type_get_names', - ), - ), - ), - ), - 'uc_quote_condition_product_shipping_type' => array( - 'data' => 'product:shipping-type', - 'value' => 'type', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - 'options list' => 'uc_quote_shipping_type_options', - ), - ), - ), - ), - 'uc_order_condition_payment_method' => array( - 'data' => 'order:payment-method', - 'value' => 'payment_method', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - ), - ), - ), - ), - 'uc_order_status_condition' => array( - 'data' => 'order:order-status', - 'value' => 'order_status', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - 'options list' => 'uc_order_status_list', - ), - ), - ), - ), - 'uc_order_condition_total' => array( - 'data' => 'order:order-total', - 'value' => 'order_total_value', - 'op' => 'order_total_comparison', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'decimal', - ), - ), - ), - ), - 'uc_order_condition_delivery_postal_code' => array( - 'data' => 'order:delivery-address:postal-code', - 'value' => 'pattern', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - ), - ), - ), - ), - 'uc_order_condition_delivery_zone' => array( - 'data' => 'order:delivery-address:zone', - 'value' => 'zones', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'uc_zone_option_list', - ), - ), - ), - ), - 'uc_order_condition_delivery_country' => array( - 'data' => 'order:delivery-address:country', - 'value' => 'countries', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'uc_country_option_list', - ), - ), - ), - ), - 'uc_order_condition_billing_postal_code' => array( - 'data' => 'order:billing-address:postal-code', - 'value' => 'pattern', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - ), - ), - ), - ), - 'uc_order_condition_billing_zone' => array( - 'data' => 'order:billing-address:zone', - 'value' => 'zones', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'uc_zone_option_list', - ), - ), - ), - ), - 'uc_order_condition_billing_country' => array( - 'data' => 'order:billing-address:country', - 'value' => 'countries', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'uc_country_option_list', - ), - ), - ), - ), - 'uc_order_condition_user_name' => array( - 'data' => 'user:name', - 'value' => 'name', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - ), - ), - ), - ), - 'uc_order_condition_user_email' => array( - 'data' => 'user:mail', - 'value' => 'mail', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - ), - ), - ), - ), - 'uc_order_condition_user_created' => array( - 'data' => 'user:created', - 'value' => 'created', - 'op' => 'operator', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'date', - ), - ), - ), - ), - 'uc_order_condition_user_login' => array( - 'data' => 'user:login', - 'value' => 'login', - 'op' => 'operator', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'date', - ), - ), - ), - ), - 'uc_order_condition_user_language' => array( - 'data' => 'user:language', - 'value' => 'language', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'text', - ), - ), - ), - ), - 'uc_order_condition_user_roles' => array( - 'data' => 'user:roles', - 'value' => 'roles', - 'op' => 'operator', - '#info' => array( - 'parameter' => array( - 'value' => array( - 'type' => 'list', - 'options list' => 'entity_plus_metadata_user_roles', - ), - ), - ), - ), - ); -} diff --git a/uc_store/includes/coder_review_uc3x.inc b/uc_store/includes/coder_review_uc3x.inc deleted file mode 100644 index 8802ad18..00000000 --- a/uc_store/includes/coder_review_uc3x.inc +++ /dev/null @@ -1,122 +0,0 @@ - 7.x upgrades. - */ - -/** - * Warns about namespace and function name changes. - */ -function coder_review_uc3x_reviews() { - $rules = array( - // Ubercart hook names were namespaced. - array( - '#type' => 'regex', - '#value' => '(? 'all', - '#never' => 'function theme', - '#warning_callback' => '_coder_review_uc3x_hook_warning', - ), - // Private functions were moved into uc_ namespace. - array( - '#type' => 'regex', - // (? '\b(? 'all', - '#warning_callback' => '_coder_review_uc3x_function_warning', - ), - // Theme functions were namespaced. - array( - '#type' => 'regex', - '#value' => 'theme\([\'"](address_pane|cart_review_table|summary_overview)[\'"]', - '#warning_callback' => '_coder_review_uc3x_function_warning', - ), - // TAPIr table ids were namespaced. - array( - '#type' => 'regex', - '#value' => '(? 'allphp', - '#warning_callback' => '_coder_review_uc3x_function_warning', - ), - // uc_payment_process() is now uc_payment_process_payment(). - array( - '#type' => 'regex', - '#value' => '\buc_payment_process\s*\(', - '#warning' => 'uc_payment_process() is now uc_payment_process_payment() because of hook_process().', - ), - // uc_add_js() was removed, use backdrop_add_js() instead. - array( - '#type' => 'grep', - '#value' => 'uc_add_js(', - '#warning' => 'uc_add_js() has been removed. Use backdrop_add_js() instead.', - ), - // First argument to uc_product_get_models() and hook_uc_product_models() - // changed from $node to $nid. - array( - '#type' => 'regex', - '#value' => '(\buc_product_get_models|\B_uc_product_models)\s*\(', - '#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.', - ), - // Checkout and order pane callback arguments changed. - array( - '#type' => 'regex', - '#value' => 'pane.*\(\$op,\s*&?\$(arg1|order)(,\s*&?\$arg2)?', - '#never' => '\(\$op,\s*&?\$order,\s*&?\$form\s*=\s*NULL,\s*&\$form_state\s*=\s*NULL\)', - '#warning' => 'Checkout and order pane callbacks take the arguments ($op, $order, &$form = NULL, &$form_state = NULL).', - ), - // uc_price() removed. - array( - '#type' => 'grep', - '#value' => 'uc_price(', - '#warning' => 'The function uc_price() was removed.', - ), - // hook_uc_price_handler() removed. - array( - '#type' => 'regex', - '#value' => '\B_uc_price_handler\(', - '#warning' => 'hook_uc_price_handler() was removed.', - '#severity' => 'normal', - ), - // theme_uc_price() has only one argument. - array( - '#type' => 'regex', - '#value' => 'theme\s*\(\s*[\'"]uc_price[\'"]\s*,[^,]+,', - '#warning' => 'theme_uc_price() takes only one argument: "price", which is a float.', - ), - // Specify the allowed arguments to theme_uc_product_price() before it is ported. - array( - '#type' => 'regex', - '#value' => 'theme\s*\(\s*[\'"]uc_product_price[\'"]\s*,[^,]+,', - '#not' => '[\'"]#price', - '#warning' => 'theme_uc_product_price() takes a render element with a "#value" and optional "#title" and "#attributes".', - ), - // uc_order_load_line_items() has only one argument. - array( - '#type' => 'regex', - '#value' => 'uc_order_load_line_items\([^,]+,', - '#warning' => 'uc_order_load_line_items() takes only one argument, the order object. Both stored and calculated line items are returned at once.', - ), - ); - - $review = array( - '#title' => t('Converting Ubercart 2.x modules to 3.x'), - '#rules' => $rules, - '#severity' => 'critical', - ); - - return array('ubercart3x' => $review); -} - -function _coder_review_uc3x_hook_warning() { - return array( - '#warning' => 'Ubercart hooks have been namespaced with "uc_" in the front.', - '#link' => 'http://drupal.org/node/510382', - ); -} - -function _coder_review_uc3x_function_warning() { - return array( - '#warning' => 'Ubercart private functions, theme functions, and TAPIr table ids have been namespaced with "uc_" in the front.', - '#link' => 'http://drupal.org/node/750784', - ); -} diff --git a/uc_store/uc_store.module b/uc_store/uc_store.module index 3e3ef7e0..611d479e 100644 --- a/uc_store/uc_store.module +++ b/uc_store/uc_store.module @@ -679,30 +679,6 @@ function uc_store_block_info() { return $blocks; } -/** - * Implements hook_reviews(). - * - * Provides code reviews for coder_review.module. - */ -function uc_store_reviews() { - $coder_reviews = array(); - $path = backdrop_get_path('module', 'uc_store') . '/includes'; - $files = backdrop_system_listing('/coder_review_.*\.inc$/', $path, 'filepath', 0); - - foreach ($files as $file) { - require_once BACKDROP_ROOT . '/' . $file->uri; - - $function = $file->name . '_reviews'; - if (function_exists($function)) { - if ($review = call_user_func($function)) { - $coder_reviews = array_merge($coder_reviews, $review); - } - } - } - - return $coder_reviews; -} - /** * Returns the default store footer options. */