You are here

function minifyjs_remove_minified_file in Minify JS 7

Same name and namespace in other branches
  1. 8 minifyjs.module \minifyjs_remove_minified_file()

Helper function removes the file, the entry in the file_managed table and sets the file status as unminified.

2 calls to minifyjs_remove_minified_file()
minifyjs_remove_minified_file_operation in ./minifyjs.admin.inc
Helper function for batch, remove minified file operation.
minifyjs_restore_original_file in ./minifyjs.admin.inc
Helper function to restore the un-minified file:

File

./minifyjs.admin.inc, line 441
Hook and helper functions for the Minify JS module.

Code

function minifyjs_remove_minified_file($fid, $reset = FALSE) {

  // Get minified uri from the minifyjs_file table.
  $result = db_select('minifyjs_file', 'm')
    ->fields('m', array(
    'minified_uri',
  ))
    ->condition('m.fid', $fid)
    ->execute();
  if ($result
    ->rowCount()) {
    $file = $result
      ->fetchObject();

    // Get the fid of the minified table.
    $result = db_select('file_managed', 'f')
      ->fields('f', array(
      'fid',
    ))
      ->condition('f.uri', $file->minified_uri)
      ->execute();
    if ($result
      ->rowCount()) {
      $file = $result
        ->fetchObject();

      // Remove the file from the file_managed table
      $file = file_load($file->fid);
      file_delete($file, TRUE);

      // Set the file status to non-minfied.
      db_update('minifyjs_file')
        ->fields(array(
        'minified_uri' => '',
        'minified_size' => 0,
        'minified_modified' => 0,
      ))
        ->condition('fid', $fid)
        ->execute();

      // Clear the cache so this change will be reflected in
      // minifyjs_load_all_files()
      if ($reset) {
        cache_clear_all(MINIFYJS_CACHE_CID, 'cache');
      }
      return TRUE;
    }
  }
  return t('File not found. Check that the file ID is correct.');
}