You are here

function minifyjs_load_all_files in Minify JS 8

Same name and namespace in other branches
  1. 7 minifyjs.module \minifyjs_load_all_files()

Helper function - load all of the minifyjs_file records from cache or directly from the database.

Return value

array $files

12 calls to minifyjs_load_all_files()
drush_minifyjs_minify_js in ./minifyjs.drush.inc
Drush command logic. drush_[COMMAND_NAME]().
drush_minifyjs_minify_js_skip in ./minifyjs.drush.inc
Drush command logic. drush_[COMMAND_NAME]().
FileManager::scan in src/Controller/FileManager.php
Scans the system for javascript.
ManageFilesForm::buildForm in src/Form/ManageFilesForm.php
Form constructor.
ManageFilesForm::submitForm in src/Form/ManageFilesForm.php
Form submission handler.

... See full list

File

./minifyjs.module, line 128

Code

function minifyjs_load_all_files() {

  // load files from cache
  if ($cache = \Drupal::cache()
    ->get(MINIFYJS_CACHE_CID)) {
    return $cache->data;
  }

  // re-build cache
  $result = \Drupal::database()
    ->select('minifyjs_file', 'f')
    ->fields('f')
    ->orderBy('uri')
    ->execute();
  $exclusions = \Drupal::config('minifyjs.config')
    ->get('exclusion_list');
  $files = [];
  while ($file = $result
    ->fetchObject()) {

    // ignore the exclusions
    if (!\Drupal::service('path.matcher')
      ->matchPath($file->uri, $exclusions)) {
      $files[$file->fid] = $file;
    }
  }

  // cache for 1 day
  \Drupal::cache()
    ->set(MINIFYJS_CACHE_CID, $files, strtotime('+1 day', \Drupal::time()
    ->getRequestTime()));
  return $files;
}