function advagg_mod_init

nittany7 advagg_mod.module advagg_mod_init()
cis7 advagg_mod.module advagg_mod_init()
mooc7 advagg_mod.module advagg_mod_init()

Implement hook_init().

File

modules/contrib/advagg/advagg_mod/advagg_mod.module, line 44
Advanced aggregation modifier module.

Code

function advagg_mod_init() {
  // Return if unified_multisite_dir is not set.
  $dir = rtrim(variable_get('advagg_mod_unified_multisite_dir', ''), '/');
  if (empty($dir) || !file_exists($dir) || !is_dir($dir)) {
    return;
  }

  $counter_filename = $dir . '/' . ADVAGG_SPACE . 'advagg_global_counter';
  $local_counter = advagg_get_global_counter();
  if (!file_exists($counter_filename)) {
    module_load_include('inc', 'advagg', 'advagg.missing');
    advagg_save_data($counter_filename, $local_counter);
  }
  else {
    $shared_counter = (int) file_get_contents($counter_filename);

    if ($shared_counter == $local_counter) {
      // Counters are the same, return.
      return;
    }
    elseif ($shared_counter < $local_counter) {
      // Local counter is higher, update saved file and return.
      module_load_include('inc', 'advagg', 'advagg.missing');
      advagg_save_data($counter_filename, $local_counter, TRUE);
      return;
    }
    elseif ($shared_counter > $local_counter) {
      // Shared counter is higher, update local copy and return.
      variable_set('advagg_global_counter', $shared_counter);
      return;
    }
  }
}