protected function MinifyJs::removeFile in Minify JS 8.2
Remove a file.
Helper function removes the file, the entry in the file_managed table and the entry in the minifyjs_file.
Parameters
string $file_uri: The URI of the file to remove.
Return value
bool The success of the operation.
1 call to MinifyJs::removeFile()
- MinifyJs::scan in src/
MinifyJs.php - Scan for files.
File
- src/
MinifyJs.php, line 394
Class
- MinifyJs
- Minify JS Service.
Namespace
Drupal\minifyjsCode
protected function removeFile($file_uri) {
// Get the fid and minified uri of the file.
$query = \Drupal::database()
->select('minifyjs_file', 'm')
->fields('m', [
'fid',
'minified_uri',
])
->condition('m.uri', $file_uri);
// Make sure that it exists.
if ($query
->countQuery()
->execute()
->fetchField() > 0) {
$file = $query
->execute()
->fetchObject();
// Handle the minified file, if applicable.
if (!empty($file->minified_uri)) {
// Get the fid of the minified file.
$query = \Drupal::database()
->select('file_managed', 'f')
->fields('f', [
'fid',
])
->condition('f.uri', $file->minified_uri);
if ($query
->countQuery()
->execute()
->fetchField() > 0) {
$minified_file = $query
->execute()
->fetchObject();
// Remove the file from the file_managed table.
$minified_file = File::load($minified_file->fid);
$minified_file
->delete();
}
}
// Remove the file from minifyjs_file table.
\Drupal::database()
->delete('minifyjs_file')
->condition('fid', $file->fid)
->execute();
return TRUE;
}
}