diff --git a/modules/customer/commerce_customer.install b/modules/customer/commerce_customer.install index 7789259..bedb5f8 100644 --- a/modules/customer/commerce_customer.install +++ b/modules/customer/commerce_customer.install @@ -176,6 +176,58 @@ function commerce_customer_field_schema($field) { } /** + * Implements hook_install(). + */ +function commerce_customer_install() { + commerce_customer_configure_customer_types(); +} + +/** + * Implements hook_modules_installed(). + */ +function commerce_customer_modules_installed($modules) { + commerce_customer_configure_customer_fields($modules); +} + +/** + * Implements hook_modules_disabled(). + */ +function commerce_customer_modules_disabled($modules) { + // Loop through all the disabled modules. + foreach ($modules as $module) { + // If the module implements hook_commerce_customer_profile_type_info()... + if (module_hook($module, 'commerce_customer_profile_type_info')) { + $profile_types = module_invoke($module, 'commerce_customer_profile_type_info'); + + // Disable any profiles of the types disabled. + $query = db_update('commerce_customer_profile') + ->fields(array('status' => 0)) + ->condition('type', array_keys($profile_types), 'IN') + ->execute(); + + // Ensure each profile's current revision is also disabled. + $query = db_update('commerce_customer_profile_revision') + ->fields(array('status' => 0)) + ->where('revision_id IN (SELECT revision_id FROM {commerce_customer_profile} WHERE type IN (:profile_types))', array(':profile_types' => array_keys($profile_types))) + ->execute(); + + // Loop through and disable customer profile reference fields that may + // correspond to the disabled profile types. + foreach ($profile_types as $type => $profile_type) { + foreach (field_read_fields(array('type' => 'commerce_customer_profile_reference')) as $field_name => $field) { + // If this field references profiles of the disabled type... + if ($field['settings']['profile_type'] == $type) { + // Set it to inactive and save it. + $field['active'] = 0; + field_update_field($field); + } + } + } + } + } +} + +/** * Implements hook_uninstall(). */ function commerce_customer_uninstall() { diff --git a/modules/customer/commerce_customer.module b/modules/customer/commerce_customer.module index ac37929..289723c 100644 --- a/modules/customer/commerce_customer.module +++ b/modules/customer/commerce_customer.module @@ -121,21 +121,7 @@ function commerce_customer_hook_info() { } /** - * Implements hook_enable(). - */ -function commerce_customer_enable() { - commerce_customer_configure_customer_types(); -} - -/** - * Implements hook_modules_enabled(). - */ -function commerce_customer_modules_enabled($modules) { - commerce_customer_configure_customer_fields($modules); -} - -/** - * Configures customer profile types defined by enabled modules. + * Configures customer profile types defined by installed modules. */ function commerce_customer_configure_customer_types() { foreach (commerce_customer_profile_types() as $type => $profile_type) { @@ -202,7 +188,7 @@ function commerce_customer_configure_customer_profile_type($profile_type) { } /** - * Configures fields referencing customer profile types defined by enabled + * Configures fields referencing customer profile types defined by installed * modules and configures the fields on those profile types if necessary. * * @param $modules @@ -245,44 +231,6 @@ function commerce_customer_configure_customer_fields($modules = NULL) { } /** - * Implements hook_modules_disabled(). - */ -function commerce_customer_modules_disabled($modules) { - // Loop through all the disabled modules. - foreach ($modules as $module) { - // If the module implements hook_commerce_customer_profile_type_info()... - if (module_hook($module, 'commerce_customer_profile_type_info')) { - $profile_types = module_invoke($module, 'commerce_customer_profile_type_info'); - - // Disable any profiles of the types disabled. - $query = db_update('commerce_customer_profile') - ->fields(array('status' => 0)) - ->condition('type', array_keys($profile_types), 'IN') - ->execute(); - - // Ensure each profile's current revision is also disabled. - $query = db_update('commerce_customer_profile_revision') - ->fields(array('status' => 0)) - ->where('revision_id IN (SELECT revision_id FROM {commerce_customer_profile} WHERE type IN (:profile_types))', array(':profile_types' => array_keys($profile_types))) - ->execute(); - - // Loop through and disable customer profile reference fields that may - // correspond to the disabled profile types. - foreach ($profile_types as $type => $profile_type) { - foreach (field_read_fields(array('type' => 'commerce_customer_profile_reference')) as $field_name => $field) { - // If this field references profiles of the disabled type... - if ($field['settings']['profile_type'] == $type) { - // Set it to inactive and save it. - $field['active'] = 0; - field_update_field($field); - } - } - } - } - } -} - -/** * Implements hook_views_api(). */ function commerce_customer_views_api() { diff --git a/modules/line_item/commerce_line_item.install b/modules/line_item/commerce_line_item.install index 5226efe..743f994 100644 --- a/modules/line_item/commerce_line_item.install +++ b/modules/line_item/commerce_line_item.install @@ -105,6 +105,20 @@ function commerce_line_item_field_schema($field) { } /** + * Implements hook_install(). + */ +function commerce_line_item_install() { + commerce_line_item_configure_line_item_types(); +} + +/** + * Implements hook_modules_installed(). + */ +function commerce_line_item_modules_installed($modules) { + commerce_line_item_configure_line_item_fields($modules); +} + +/** * Implements hook_uninstall(). */ function commerce_line_item_uninstall() { diff --git a/modules/line_item/commerce_line_item.module b/modules/line_item/commerce_line_item.module index 18033a6..2f38ae7 100644 --- a/modules/line_item/commerce_line_item.module +++ b/modules/line_item/commerce_line_item.module @@ -234,21 +234,7 @@ function commerce_line_item_views_api() { } /** - * Implements hook_enable(). - */ -function commerce_line_item_enable() { - commerce_line_item_configure_line_item_types(); -} - -/** - * Implements hook_modules_enabled(). - */ -function commerce_line_item_modules_enabled($modules) { - commerce_line_item_configure_line_item_fields($modules); -} - -/** - * Configures line item types defined by enabled modules. + * Configures line item types defined by installed modules. */ function commerce_line_item_configure_line_item_types() { foreach (commerce_line_item_types() as $line_item_type) { @@ -279,7 +265,7 @@ function commerce_line_item_configure_line_item_type($line_item_type) { } /** - * Configures line item types defined by other modules that are enabled after + * Configures line item types defined by other modules that are installed after * the Line Item module. * * @param $modules diff --git a/modules/order/commerce_order.install b/modules/order/commerce_order.install index d29bb23..d91986f 100644 --- a/modules/order/commerce_order.install +++ b/modules/order/commerce_order.install @@ -188,6 +188,20 @@ function commerce_order_schema() { } /** + * Implements hook_install(). + */ +function commerce_order_install() { + commerce_order_configure_order_type(); +} + +/** + * Implements hook_modules_installed(). + */ +function commerce_order_modules_installed($modules) { + commerce_order_configure_order_fields($modules); +} + +/** * Implements hook_uninstall(). */ function commerce_order_uninstall() { diff --git a/modules/order/commerce_order.module b/modules/order/commerce_order.module index 962d038..273841d 100644 --- a/modules/order/commerce_order.module +++ b/modules/order/commerce_order.module @@ -125,20 +125,6 @@ function commerce_order_hook_info() { } /** - * Implements hook_enable(). - */ -function commerce_order_enable() { - commerce_order_configure_order_type(); -} - -/** - * Implements hook_modules_enabled(). - */ -function commerce_order_modules_enabled($modules) { - commerce_order_configure_order_fields($modules); -} - -/** * Ensures the line item field is present on the default order bundle. */ function commerce_order_configure_order_type($type = 'commerce_order') { @@ -265,8 +251,8 @@ function commerce_order_configure_customer_profile_type($customer_profile_type, /** * Configures the customer profile reference fields attached to the default - * order type when modules defining customer profile types are enabeld after the - * Order module. + * order type when modules defining customer profile types are installed after + * the Order module. * * @param $modules * An array of module names whose customer profile reference fields should be diff --git a/modules/payment/commerce_payment.install b/modules/payment/commerce_payment.install index dd36c11..6bb2da2 100644 --- a/modules/payment/commerce_payment.install +++ b/modules/payment/commerce_payment.install @@ -5,7 +5,6 @@ * Installation functions for Drupal Commerce Payment. */ - /** * Implements hook_schema(). */ @@ -253,6 +252,45 @@ function commerce_payment_schema() { } /** + * Implements hook_modules_enabled(). + */ +function commerce_payment_modules_enabled($modules) { + _commerce_payment_default_rules_reset($modules); +} + +/** + * Implements hook_modules_disabled(). + */ +function commerce_payment_modules_disabled($modules) { + _commerce_payment_default_rules_reset($modules); +} + +/** + * Resets default Rules if necessary when modules are enabled or disabled. + * + * @param $modules + * An array of module names that have been enabled or disabled. + */ +function _commerce_payment_default_rules_reset($modules) { + $reset_default_rules = FALSE; + + // Look for any module defining a new payment method. + foreach ($modules as $module) { + if (function_exists($module . '_commerce_payment_method_info')) { + $reset_default_rules = TRUE; + } + } + + // If we found a module defining a new payment method, we need to rebuild the + // default Rules especially for this module so the default payment method Rule + // will appear properly for this module. + if ($reset_default_rules) { + entity_defaults_rebuild(); + rules_clear_cache(TRUE); + } +} + +/** * Add an index to the commerce_payment_transaction_revision table on transaction_id. */ function commerce_payment_update_7100() { diff --git a/modules/payment/commerce_payment.module b/modules/payment/commerce_payment.module index e45354c..ac51a1d 100644 --- a/modules/payment/commerce_payment.module +++ b/modules/payment/commerce_payment.module @@ -235,38 +235,6 @@ function template_preprocess_commerce_payment_totals(&$variables) { } /** - * Implements hook_modules_enabled(). - */ -function commerce_payment_modules_enabled($modules) { - _commerce_payment_default_rules_reset($modules); -} - -/** - * Resets default Rules if necessary when modules are enabled or disabled. - * - * @param $modules - * An array of module names that have been enabled or disabled. - */ -function _commerce_payment_default_rules_reset($modules) { - $reset_default_rules = FALSE; - - // Look for any module defining a new payment method. - foreach ($modules as $module) { - if (function_exists($module . '_commerce_payment_method_info')) { - $reset_default_rules = TRUE; - } - } - - // If we found a module defining a new payment method, we need to rebuild the - // default Rules especially for this module so the default payment method Rule - // will appear properly for this module. - if ($reset_default_rules) { - entity_defaults_rebuild(); - rules_clear_cache(TRUE); - } -} - -/** * Implements hook_commerce_checkout_page_info(). */ function commerce_payment_commerce_checkout_page_info() { diff --git a/modules/product/commerce_product.install b/modules/product/commerce_product.install index de1559f..88e1652 100644 --- a/modules/product/commerce_product.install +++ b/modules/product/commerce_product.install @@ -187,6 +187,20 @@ function commerce_product_schema() { } /** + * Implements hook_install(). + */ +function commerce_product_install() { + commerce_product_configure_product_types(); +} + +/** + * Implements hook_modules_installed(). + */ +function commerce_product_modules_installed($modules) { + commerce_product_configure_product_fields($modules); +} + +/** * Implements hook_uninstall(). */ function commerce_product_uninstall() { diff --git a/modules/product/commerce_product.module b/modules/product/commerce_product.module index b5c0958..93d9472 100644 --- a/modules/product/commerce_product.module +++ b/modules/product/commerce_product.module @@ -289,21 +289,7 @@ function commerce_product_permission() { } /** - * Implements hook_enable(). - */ -function commerce_product_enable() { - commerce_product_configure_product_types(); -} - -/** - * Implements hook_modules_enabled(). - */ -function commerce_product_modules_enabled($modules) { - commerce_product_configure_product_fields($modules); -} - -/** - * Configure the product types defined by enabled modules. + * Configure the product types defined by installed modules. */ function commerce_product_configure_product_types() { foreach (commerce_product_types() as $type => $product_type) {