Same filename and directory in other branches
  1. 7.x-2.x advagg_js_compress/advagg_js_compress.install 1 comment

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.
 */

/**
 * Implements hook_enable().
 */
function advagg_js_compress_enable() {
    // Flush advagg caches.
    $cache_tables = advagg_flush_caches();
    foreach ($cache_tables as $table) {
        cache_clear_all('*', $table, TRUE);
    }
    // Check runtime requirements
    register_shutdown_function('advagg_js_compress_requirements', 'runtime');
}

/**
 * Implements hook_disable().
 */
function advagg_js_compress_disable() {
    // Flush advagg caches.
    $cache_tables = advagg_flush_caches();
    foreach ($cache_tables as $table) {
        cache_clear_all('*', $table, TRUE);
    }
}

/**
 * Implements hook_install().
 */
function advagg_js_compress_install() {
    // TODO The drupal_(un)install_schema functions are called automatically in D7.
    // drupal_install_schema('advagg_js_compress')
}

/**
 * Implements hook_uninstall().
 */
function advagg_js_compress_uninstall() {
    // Remove variables.
    variable_del('advagg_js_compress_packer_enable');
    variable_del('advagg_js_compress_inline_cache');
    variable_del('advagg_js_compress_file_cache');
    variable_del('advagg_js_compress_agg_files');
    variable_del('advagg_js_max_compress_ratio');
    variable_del('advagg_js_compress_callback');
    variable_del('advagg_js_compress_inline');
    variable_del('advagg_js_compress_ratio');
    variable_del('advagg_js_compressor');
    // Remove our cache table.
    cache_clear_all('*', 'cache_advagg_js_compress_inline', TRUE);
    cache_clear_all('*', 'cache_advagg_js_compress_file', TRUE);
    // TODO The drupal_(un)install_schema functions are called automatically in D7.
    // drupal_uninstall_schema('advagg_js_compress')
}

/**
 * Implements hook_requirements().
 */
function advagg_js_compress_requirements($phase) {
    $requirements = array();
    // Ensure translations don't break at install time
    $t = get_t();
    // Report Drupal version
    if ($phase == 'runtime') {
        $compressible = advagg_js_compress_check_callback();
        $advagg_js_compress_callback = variable_get('advagg_js_compress_callback', ADVAGG_JS_COMPRESS_CALLBACK);
        if (is_array($compressible)) {
            $requirements['advagg_js_compress_callback'] = array(
                'title' => $t('AdvAgg JS Compress - Callback'),
                'severity' => REQUIREMENT_WARNING,
                'value' => $t('The callback for testing if a JS file is compressible is not working.'),
                'description' => $t('As a result if jsmin+ encounters a file that it cannot compress, it will kill that PHP process.'),
            );
            if ($advagg_js_compress_callback != FALSE) {
                variable_set('advagg_js_compress_callback', FALSE);
            }
        }
        else {
            $requirements['advagg_js_compress_callback'] = array(
                'title' => $t('AdvAgg JS Compress - Callback'),
                'severity' => REQUIREMENT_OK,
                'value' => $t('The callback is working correctly.'),
            );
            if ($advagg_js_compress_callback == FALSE) {
                variable_set('advagg_js_compress_callback', TRUE);
            }
        }
        // Test the 'memory_limit' PHP configuration directive
        $memory_limit = ini_get('memory_limit');
        $compressor = variable_get('advagg_js_compressor', ADVAGG_JS_COMPRESSOR);
        // If $memory_limit contains a value of -1, the PHP runtime
        // doesn't impose a limit on memory used by PHP scripts
        if ($compressor == 0 && $memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size('96M')) {
            $requirements['advagg_js_compress_memory_limit'] = array(
                'title' => $t('AdvAgg JS Compress - Memory Limit'),
                'value' => $memory_limit,
                'severity' => REQUIREMENT_WARNING,
                'description' => $t('It is highly recommended that you set your PHP memory_limit at least 96M if you are going to use JSMin+.'),
            );
        }
    }
    return $requirements;
}

/**
 * Check to see if the CSS/JS generator is working.
 */
function advagg_js_compress_check_callback() {
    $filename = drupal_get_path('module', 'advagg_js_compress') . '/jquery.form.js';
    $files_to_test = array();
    $files_to_test[] = array(
        'md5' => md5($filename),
        'filename' => $filename,
    );
    $compressible = advagg_js_compress_test_compression($files_to_test);
    return $compressible;
}

/**
 * Implements hook_schema().
 */
function advagg_js_compress_schema() {
    $schema = array();
    // Create cache tables.
    $schema['cache_advagg_js_compress_inline'] = drupal_get_schema_unprocessed('system', 'cache');
    $schema['cache_advagg_js_compress_inline']['description'] = t('Cache table for Advanced CSS/JS Aggregations JS Compress module. Used to keep inline versions of compressed JS.');
    $schema['cache_advagg_js_compress_file'] = drupal_get_schema_unprocessed('system', 'cache');
    $schema['cache_advagg_js_compress_file']['description'] = t('Cache table for Advanced CSS/JS Aggregations JS Compress module. Used to keep the compressed JavaScript from the js files.');
    return $schema;
}

/**
 * Update 6100 - Clear file cache.
 */
function advagg_js_compress_update_6100() {
    $ret = array();
    cache_clear_all('*', 'cache_advagg_files_data', TRUE);
    $ret[] = array(
        'success' => TRUE,
        'query' => 'advagg files_data cache flushed.',
    );
    // hook_update_N() no longer returns a $ret array. Instead, return
    // nothing or a translated string indicating the update ran successfully.
    // See http://drupal.org/node/224333#update_sql.
    return t('TODO Add a descriptive string here to show in the UI.');
}

/**
 * Update 6101 - Create the cache_advagg_css_compress_inline cache table.
 */
function advagg_js_compress_update_6101() {
    $ret = array();
    // Create cache table.
    $schema = advagg_js_compress_schema();
    db_create_table('cache_advagg_js_compress_inline', $schema['cache_advagg_js_compress_inline']);
    // hook_update_N() no longer returns a $ret array. Instead, return
    // nothing or a translated string indicating the update ran successfully.
    // See http://drupal.org/node/224333#update_sql.
    return t('TODO Add a descriptive string here to show in the UI.');
}

/**
 * Update 6102 - Create the cache_advagg_css_compress_file cache table.
 */
function advagg_js_compress_update_6102() {
    $ret = array();
    // Create cache table.
    $schema = advagg_js_compress_schema();
    db_create_table('cache_advagg_js_compress_file', $schema['cache_advagg_js_compress_file']);
    // hook_update_N() no longer returns a $ret array. Instead, return
    // nothing or a translated string indicating the update ran successfully.
    // See http://drupal.org/node/224333#update_sql.
    return t('TODO Add a descriptive string here to show in the UI.');
}

/**
 * Update 6103 - Clear the cache_advagg_css_compress_file cache table.
 */
function advagg_js_compress_update_6103() {
    $ret = array();
    // Clear cache_advagg_js_compress_file cache.
    cache_clear_all('*', 'cache_advagg_js_compress_file', TRUE);
    $ret[] = array(
        'success' => TRUE,
        'query' => 'The cache_advagg_js_compress_file table has been cleared.',
    );
    // hook_update_N() no longer returns a $ret array. Instead, return
    // nothing or a translated string indicating the update ran successfully.
    // See http://drupal.org/node/224333#update_sql.
    return t('TODO Add a descriptive string here to show in the UI.');
}

Functions

Title Deprecated Summary
advagg_js_compress_check_callback Check to see if the CSS/JS generator is working.
advagg_js_compress_disable Implements hook_disable().
advagg_js_compress_enable Implements hook_enable().
advagg_js_compress_install Implements hook_install().
advagg_js_compress_requirements Implements hook_requirements().
advagg_js_compress_schema Implements hook_schema().
advagg_js_compress_uninstall Implements hook_uninstall().
advagg_js_compress_update_6100 Update 6100 - Clear file cache.
advagg_js_compress_update_6101 Update 6101 - Create the cache_advagg_css_compress_inline cache table.
advagg_js_compress_update_6102 Update 6102 - Create the cache_advagg_css_compress_file cache table.
advagg_js_compress_update_6103 Update 6103 - Clear the cache_advagg_css_compress_file cache table.