You are here

function advagg_enable in Advanced CSS/JS Aggregation 7.2

Same name and namespace in other branches
  1. 6 advagg.install \advagg_enable()
  2. 7 advagg.install \advagg_enable()

Implements hook_enable().

File

./advagg.install, line 44
Handles Advanced Aggregation installation and upgrade tasks.

Code

function advagg_enable() {

  // Make sure the advagg_get_root_files_dir() function is available.
  drupal_load('module', 'advagg');

  // Make sure permissions for dirs are correct. Needed if installed via drush.
  list($css_path, $js_path) = advagg_get_root_files_dir();
  $stat_public = stat('public://');
  $stat_css = stat($css_path[0]);
  $stat_js = stat($js_path[0]);
  if (isset($stat_public['uid'])) {
    if (isset($stat_css['uid']) && $stat_public['uid'] != $stat_css['uid']) {
      @chown($css_path[0], $stat_public['uid']);
    }
    if (isset($stat_js['uid']) && $stat_public['uid'] != $stat_js['uid']) {
      @chown($stat_js[0], $stat_public['uid']);
    }
  }
  if (isset($stat_public['gid'])) {
    if (isset($stat_css['gid']) && $stat_public['gid'] != $stat_css['gid']) {
      @chgrp($css_path[0], $stat_public['gid']);
    }
    if (isset($stat_js['uid']) && $stat_public['gid'] != $stat_js['gid']) {
      @chgrp($stat_js[0], $stat_public['gid']);
    }
  }
  if (drupal_is_cli()) {

    // Remove advagg and public dirs if empty and running from command line.
    list($css_path, $js_path) = advagg_get_root_files_dir();
    $files = file_scan_directory($css_path[1], '/.*/');
    if (empty($files)) {
      rmdir($css_path[1]);
    }
    $files = file_scan_directory($js_path[1], '/.*/');
    if (empty($files)) {
      rmdir($js_path[1]);
    }
    $files = file_scan_directory('public://', '/.*/');
    if (empty($files)) {
      rmdir('public://');
    }
  }

  // Make sure the advagg_flush_all_cache_bins() function is available.
  module_load_include('inc', 'advagg', 'advagg');
  module_load_include('inc', 'advagg', 'advagg.cache');

  // Flush caches.
  advagg_flush_all_cache_bins();

  // Flush menu cache on shutdown.
  register_shutdown_function('menu_rebuild');

  // Set the advagg_needs_update variable if this is a major version update.
  if (!db_table_exists('advagg_aggregates_versions')) {
    variable_set('advagg_needs_update', TRUE);
  }
  else {
    variable_del('advagg_needs_update');
  }
}