You are here

function drush_advagg_js_compress in Advanced CSS/JS Aggregation 7.2

Callback function for drush advagg-js-compress.

Callback is called by using drush_hook_command() where hook is the name of the module (advagg) and command is the name of the Drush command with all "-" characters converted to "_" characters.

Parameters

string $filename: The filename to compress or all to redo all files.

1 string reference to 'drush_advagg_js_compress'
advagg_js_compress_drush_command in advagg_js_compress/advagg_js_compress.drush.inc
Implements hook_drush_command().

File

advagg_js_compress/advagg_js_compress.drush.inc, line 64
Drush commands for AdvAgg JS minification.

Code

function drush_advagg_js_compress($filename = '') {

  // Get the redo list.
  list($list, $redo_list) = advagg_js_compress_all_js_files_list();

  // Handle special use cases.
  if (!empty($filename)) {

    // Do all.
    if (strtolower($filename) === 'all') {
      $redo_list = $list;
    }
    else {

      // Do a single file, search for it in the $list.
      $redo_list = array();
      foreach ($list as $values) {
        if ($values['data'] === $filename) {
          $redo_list = array(
            $values,
          );
          break;
        }
      }

      // Let user know if that file was not found.
      if (empty($redo_list)) {
        drush_log(dt('The file @filename was not found.', array(
          '@filename' => $filename,
        )), 'notice');
        return;
      }
    }
  }

  // Return if nothing to do.
  if (empty($redo_list)) {
    drush_log(dt('All of @total js files are already minified.', array(
      '@total' => count($list),
    )), 'ok');
    return;
  }

  // Let user know what will happen.
  drush_log(dt('A total of @redo out of @total js files will be minified.', array(
    '@redo' => count($redo_list),
    '@total' => count($list),
  )), 'ok');

  // Compress js files and cache.
  advagg_js_compress_redo_files($redo_list, 0, TRUE);
}