Is there a way to programmatically configure interval? I would like to enable the module and then directly set my own interval, without using the admin, as rules_ui is not activated on my site.

Comments

amateescu’s picture

Title: Programmatically configure interval? » Document how to configure the interval programatically
Category: support » task

That's a good question :) You can override the default by using hook_default_rules_configuration_alter().

I guess that should be documented in a README.txt. Do you think you have the time to write a patch for it?

jgalletta’s picture

I'm currently struggling with the hook to understand how to properly alter the interval, once I'll figure out how to do I'll write something about it.

jgalletta’s picture

Ok so I can't find a way to alter the action if the hook_default_rules_configuration_alter.
I can add a new action but not remove or modify an existing one...

And when I try to override the entire rule configuration, I have duplicates in the database.
Am I missing something obvious?

EDIT:
I managed to get what I want with this code, but it's ugly:

/**
 * Implements hook_default_rules_configuration_alter
 */
function commerce_data_default_rules_configuration_alter(&$configs) {
  if (isset($configs['commerce_cart_expiration_delete_expired_carts'])) {
    foreach ($configs['commerce_cart_expiration_delete_expired_carts']->actions() as $action) {
      $action->settings['interval'] = 199999;
    }
  }
}
amateescu’s picture

It's not that ugly.. and that's actually the only way to do it, but you also need to check the name of the action that you're altering. Something like this:

function MODULE_NAME_default_rules_configuration_alter(&$configs) {
  if (isset($configs['commerce_cart_expiration_delete_expired_carts'])) {
    foreach ($configs['commerce_cart_expiration_delete_expired_carts']->actions() as $action) {
      if ($action->getElementName() == 'commerce_cart_expiration_delete_orders') {
        $action->settings['interval'] = 3600;
      }
    }
  }
}
jgalletta’s picture

Hey,

I wrote a README.txt and created the patch to add it to the module.
Please tell me if you want to do some changes on it.

jgalletta’s picture

Component: Code » Documentation
Status: Active » Needs review

Change issue status.

amateescu’s picture

Status: Needs review » Fixed

I basically rewrote the file and committed it to 7.x-1.x. Thanks for starting it :)

http://drupalcode.org/sandbox/amateescu/1454320.git/commit/5521f28

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Collins405’s picture

Version: » 7.x-1.4
Issue summary: View changes

I cant get this to work, Ive added the code from the readme, and ive added it to my_module.rules_defaults.inc but it wont affect the interval, can anyone help?