function rules_modules_enabled

Implements hook_modules_enabled().

File

./rules.module, line 1520

Code

function rules_modules_enabled($modules) {
    // Re-enable Rules configurations that are dirty, because they require one of
    // the enabled the modules.
    $query = db_select('rules_dependencies', 'rd');
    $query->join('rules_config', 'rc', 'rd.id = rc.id');
    $query->fields('rd', array(
        'id',
    ))
        ->condition('rd.module', $modules, 'IN')
        ->condition('rc.dirty', 1);
    $ids = $query->execute()
        ->fetchCol();
    // If there are some configurations that might work again, re-check all dirty
    // configurations as others might work again too, e.g. consider a rule that is
    // dirty because it requires a dirty component.
    if ($ids) {
        $rules_configs = rules_config_load_multiple(FALSE, array(
            'dirty' => 1,
        ));
        foreach ($rules_configs as $rules_config) {
            try {
                $rules_config->integrityCheck();
                // If no exceptions were thrown we can set the configuration back to OK.
                db_update('rules_config')->fields(array(
                    'dirty' => 0,
                ))
                    ->condition('id', $rules_config->id)
                    ->execute();
                if ($rules_config->active) {
                    drupal_set_message(t('All dependencies for the Rules configuration %config are met again, so it has been re-activated.', array(
                        '%config' => $rules_config->label(),
                    )));
                }
            } catch (RulesIntegrityException $e) {
                // The rule is still dirty, so do nothing.
            }
        }
    }
    rules_clear_cache();
}