You are here

advagg_js_compress.install in Advanced CSS/JS Aggregation 7.2

Handles AdvAgg JS compress installation and upgrade tasks.

File

advagg_js_compress/advagg_js_compress.install
View source
<?php

/**
 * @file
 * Handles AdvAgg JS compress installation and upgrade tasks.
 */

/**
 * @addtogroup hooks
 * @{
 */

/**
 * Implements hook_requirements().
 */
function advagg_js_compress_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();

  // If not at runtime, return here.
  if ($phase !== 'runtime') {
    return $requirements;
  }

  // Make sure a compressor is being used.
  if (variable_get('advagg_js_compressor', ADVAGG_JS_COMPRESSOR) == 0 && variable_get('advagg_js_compress_inline', ADVAGG_JS_COMPRESS_INLINE) == 0) {

    // Check all files.
    $file_settings = variable_get('advagg_js_compressor_file_settings', array());
    $compression_used = FALSE;
    foreach ($file_settings as $setting) {
      if (!empty($setting)) {
        $compression_used = TRUE;
        break;
      }
    }
    if (!$compression_used) {
      $config_path = advagg_admin_config_root_path();
      $requirements['advagg_js_compress_not_on'] = array(
        'title' => $t('AdvAgg JS Compressor'),
        'severity' => REQUIREMENT_WARNING,
        'value' => $t('AdvAgg JS Compression is disabled.'),
        'description' => $t('Go to the <a href="@settings">advagg js compress settings page</a> and select a compressor, or go to the <a href="@modules">modules page</a> and disable the "AdvAgg Compress Javascript" module.', array(
          '@settings' => url($config_path . '/advagg/js-compress'),
          '@modules' => url('admin/modules', array(
            'fragment' => 'edit-modules-advanced-cssjs-aggregation',
          )),
        )),
      );
    }
  }
  $requirements += advagg_js_compress_check_cache_bin();
  return $requirements;
}

/**
 * Upgrade AdvAgg JS Compress versions (6.x-1.x and 7.x-1.x) to 7.x-2.x.
 */
function advagg_js_compress_update_7200(&$sandbox) {

  // Bail if old DB Table does not exist.
  if (!db_table_exists('cache_advagg_js_compress_inline') && !db_table_exists('cache_advagg_js_compress_file')) {
    return t('Nothing needed to happen in AdvAgg JS Compress.');
  }

  // Remove all old advagg css compress variables.
  db_delete('variable')
    ->condition('name', 'advagg_js%compress%', 'LIKE')
    ->execute();

  // Remove old schema.
  if (db_table_exists('cache_advagg_js_compress_inline')) {
    db_drop_table('cache_advagg_js_compress_inline');
  }
  if (db_table_exists('cache_advagg_js_compress_file')) {
    db_drop_table('cache_advagg_js_compress_file');
  }
  return t('Upgraded AdvAgg JS Compress to 7.x-2.x.');
}

/**
 * Clear the cache_advagg_info cache.
 */
function advagg_js_compress_update_7201(&$sandbox) {
  cache_clear_all('advagg:js_compress:', 'cache_advagg_info', TRUE);
  return t('Cleared the cache_advagg_info cache of js_compress entries.');
}

/**
 * Change variable names so they are prefixed with the modules name.
 */
function advagg_js_compress_update_7202(&$sandbox) {

  // Rename advagg_js_inline_compressor to advagg_js_compress_inline.
  $old = variable_get('advagg_js_inline_compressor', NULL);
  if (!is_null($old)) {
    variable_del('advagg_js_inline_compressor');
  }
  if ($old !== ADVAGG_JS_COMPRESS_INLINE) {
    variable_set('advagg_js_compress_inline', $old);
  }

  // Rename advagg_js_inline_compress_if_not_cacheable to
  // advagg_js_compress_inline_if_not_cacheable.
  $old = variable_get('advagg_js_inline_compress_if_not_cacheable', NULL);
  if (!is_null($old)) {
    variable_del('advagg_js_inline_compress_if_not_cacheable');
  }
  if ($old !== ADVAGG_JS_COMPRESS_INLINE_IF_NOT_CACHEABLE) {
    variable_set('advagg_js_compress_inline_if_not_cacheable', $old);
  }

  // Rename advagg_js_inline_compress_if_not_cacheable to
  // advagg_js_compress_inline_if_not_cacheable.
  $old = variable_get('advagg_js_inline_compress_if_not_cacheable', NULL);
  if (!is_null($old)) {
    variable_del('advagg_js_inline_compress_if_not_cacheable');
  }
  if ($old !== ADVAGG_JS_COMPRESS_INLINE_IF_NOT_CACHEABLE) {
    variable_set('advagg_js_compress_inline_if_not_cacheable', $old);
  }

  // Rename advagg_js_max_compress_ratio to advagg_js_compress_max_ratio.
  $old = variable_get('advagg_js_max_compress_ratio', NULL);
  if (!is_null($old)) {
    variable_del('advagg_js_max_compress_ratio');
  }
  if ($old !== ADVAGG_JS_COMPRESS_MAX_RATIO) {
    variable_set('advagg_js_compress_max_ratio', $old);
  }
}

/**
 * Remove unused variables from the variable table.
 *
 * Implements hook_update_N().
 */
function advagg_js_compress_update_7203(&$sandbox) {

  // Remove all old advagg css compress variables.
  db_delete('variable')
    ->condition('name', 'advagg_js_compressor_file_settings_%', 'LIKE')
    ->execute();
}

/**
 * @} End of "addtogroup hooks".
 */

Functions

Namesort descending Description
advagg_js_compress_requirements Implements hook_requirements().
advagg_js_compress_update_7200 Upgrade AdvAgg JS Compress versions (6.x-1.x and 7.x-1.x) to 7.x-2.x.
advagg_js_compress_update_7201 Clear the cache_advagg_info cache.
advagg_js_compress_update_7202 Change variable names so they are prefixed with the modules name.
advagg_js_compress_update_7203 Remove unused variables from the variable table.