You are here

function rules_config_update_dirty_flag in Rules 7.2

Ensures the configuration's 'dirty' flag is up to date by running an integrity check.

Parameters

bool $update: (optional) Whether the dirty flag is also updated in the database if necessary. Defaults to TRUE.

8 calls to rules_config_update_dirty_flag()
RulesEvaluationException::__construct in includes/rules.core.inc
Constructor.
RulesEventSet::rebuildEventCache in includes/rules.plugins.inc
Rebuilds the event cache.
RulesPlugin::save in includes/rules.core.inc
Saves the configuration to the database.
RulesPluginUI::buildContent in ui/ui.core.inc
Implements RulesPluginUIInterface.
rules_admin_settings_integrity_check_submit in rules_admin/rules_admin.inc
Form submit callback to check the integrity of all configurations.

... See full list

2 string references to 'rules_config_update_dirty_flag'
RulesPlugin::save in includes/rules.core.inc
Saves the configuration to the database.
rules_clear_cache in ./rules.module
Clears the rule set cache.

File

./rules.module, line 956
Rules engine module.

Code

function rules_config_update_dirty_flag($rules_config, $update = TRUE) {

  // Keep a log of already check configurations to avoid repetitive checks on
  // often used components.
  // @see rules_element_invoke_component_validate()
  $checked =& drupal_static(__FUNCTION__, array());
  if (!empty($checked[$rules_config->name])) {
    return;
  }
  $checked[$rules_config->name] = TRUE;
  $was_dirty = !empty($rules_config->dirty);
  try {

    // First set the rule to dirty, so any repetitive checks give green light
    // for this configuration.
    $rules_config->dirty = FALSE;
    $rules_config
      ->integrityCheck();
    if ($was_dirty) {
      $variables = array(
        '%label' => $rules_config
          ->label(),
        '%name' => $rules_config->name,
        '@plugin' => $rules_config
          ->plugin(),
      );
      watchdog('rules', 'The @plugin %label (%name) was marked dirty, but passes the integrity check now and is active again.', $variables, WATCHDOG_INFO);
    }
  } catch (RulesIntegrityException $e) {
    $rules_config->dirty = TRUE;
    if (!$was_dirty) {
      $variables = array(
        '%label' => $rules_config
          ->label(),
        '%name' => $rules_config->name,
        '!message' => $e
          ->getMessage(),
        '@plugin' => $rules_config
          ->plugin(),
      );
      watchdog('rules', 'The @plugin %label (%name) fails the integrity check and cannot be executed. Error: !message', $variables, WATCHDOG_ERROR);
    }
  }

  // Save the updated dirty flag to the database.
  if ($was_dirty != $rules_config->dirty) {
    db_update('rules_config')
      ->fields(array(
      'dirty' => (int) $rules_config->dirty,
    ))
      ->condition('id', $rules_config->id)
      ->execute();
  }
}