function minifyjs_remove_minified_file in Minify JS 8
Same name and namespace in other branches
- 7 minifyjs.admin.inc \minifyjs_remove_minified_file()
Helper function removes the file, the entry in the file_managed table and sets the file status as unminified.
Parameters
int $fid:
bool $reset:
Return value
mixed
2 calls to minifyjs_remove_minified_file()
- FileManager::restore in src/
Controller/ FileManager.php - Remove the minified version of a single file (restore it).
- minifyjs_batch_remove_minified_file_operation in ./
minifyjs.module - Helper function for batch, remove minified file operation.
File
- ./
minifyjs.module, line 255
Code
function minifyjs_remove_minified_file($fid, $reset = FALSE) {
// Get minified uri from the minifyjs_file table.
$query = \Drupal::database()
->select('minifyjs_file', 'm')
->fields('m', array(
'minified_uri',
))
->condition('m.fid', $fid);
// make sure that it exists
if ($query
->countQuery()
->execute()
->fetchField() > 0) {
$file = $query
->execute()
->fetchObject();
// Get the fid of the minified table.
$query = db_select('file_managed', 'f')
->fields('f', array(
'fid',
))
->condition('f.uri', $file->minified_uri);
// make sure that it exists
if ($query
->countQuery()
->execute()
->fetchField() > 0) {
$file = $query
->execute()
->fetchObject();
// Remove the file from the file_managed table
$file = File::load($file->fid);
$file
->delete();
// Set the file status to non-minfied.
\Drupal::database()
->update('minifyjs_file')
->fields([
'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) {
\Drupal::cache()
->delete(MINIFYJS_CACHE_CID);
}
return TRUE;
}
}
return t('File not found. Check that the file ID is correct.');
}