Code that can be used to permanently delete unused/orphaned files in drupal 9 and 8.
// get all files ids
$fids = \Drupal::entityQuery('file')->execute();
$file_usage = \Drupal::service('file.usage');
// loop all fids and load files by fid
foreach ($fids as $fid) {
$file = \Drupal\file\Entity\File::load($fid);
$usage = $file_usage->listUsage($file);
// check if file not used
if (count($usage) == 0) {
$file->delete();
}
}
wartalab.blogspot.com is the best website and blog to provide tutorial for the, PHP, Drupal, Drupal 8 and general topic. Visit for programming knowledge and tutorial and solution
Drupal 8 and 9 delete file programmatically
Subscribe to:
Post Comments (Atom)
Write a program in PHP to reverse a number
A number can be written in reverse order. For example 12345 = 54321 <?php $ num = 23456; $ revnum = 0; while ($ num > 1) { $...
-
Code that can be used to permanently delete unused/orphaned files in drupal 9 and 8. // get all files ids $fids = \Drupal:: entityQuery ...
-
What are advantages of Drupal What are disadvantages of Drupal Difference between Drupal 7 and 8 How to connect multiple database to Drupal ...
-
For taxonomy term $ aliasManager = \Drupal::service(' path_alias.manager '); $ alias = $aliasManager->getAliasByPath(' /taxon...
-
Drupal 8 has introduced symfony request reponse object. So anything related to request/response header or body level changes should be usin...
-
The Drupal session management subsystem is built on top of the Symfony session component. It is optimized in order to minimize the impact o...
-
Entity Query In Drupal entityQuery allows Web developers to query Drupal entities and its fields in a SQL-like way. A Drupal site's tabl...
-
A views in Drupal provide graphical interface for listing information. The views module allows administrators and site designers to create, ...
-
In Drupal, clean URLs are enabled by default and can't be disabled. However, a rewrite module must be installed on your web server. Che...
-
Dependency injection is a technique whereby one object supplies the dependencies of another object What is Dependency Injection — Wikipe...
-
"Render Arrays" or "Renderable Arrays" are the building blocks of a Drupal page, starting with Drupal 7. A render array...
No comments:
Post a Comment