2

In my Drupal travels, I've used a number of CKeditor instant image-upload plugins; IMCE, Media, and another one (don't recall the name).

The three of them doesn't delete unused files (Like Drupal imagefield does automatically) and thus I sometimes need to upload the same file with them 6 or seven times and these duplicated can whey much gb's in a cumulative way.

Is there any way to make one of the CKeditor instant image-upload plugins delete the files automatically? or at least? Have you cam across something that does delete unused image files automatically? Thanks,

3 Answers 3

1

Try to check out the Fancy File Delete module. One of the things it can do based on the module page is

Deleting unused files from the whole install that are no longer attached to nodes & the file usage table. AKA deleting all the orphaned files.

I think this would require a manual process of deletion but this may solve the issue of deleting orphaned or unused duplicate images in your site.

1
  • Retroactively, I would recommend not to use the module since I've encountered deletion of some files that the module presented as not attached to any node, but AAMOF --- Was attached to some nodes... So I ended up losing about 10 to 12 images... :| I guess we should best wait that deleting unused CKeditor images will be part of some core.
    – user16289
    Commented Sep 14, 2015 at 18:33
0

I don't think there's an easy way to do this. It seems like you want a cross between what Imagefield and the other modules do and there just isn't a module ilke it as far as I know.

You could write your own module which overrides hook_presave to look at a node's body and determines all the images used, and adds that list to a filefield.

1
  • Well I have yet to acquire enough knowledge to write such a module so I guess I'll chew straw with this... For the near future.
    – user16289
    Commented Sep 5, 2015 at 22:14
0

You just need to set make_unused_managed_files_temporary to TRUE.

/**
 * Prevent unused files from being deleted.
 */
function file_update_8300() {
  // Disable deletion of unused permanent files.
  \Drupal::configFactory()->getEditable('file.settings')
    ->set('make_unused_managed_files_temporary', FALSE)
    ->save();

  return t('Files that have no remaining usages are no longer deleted by default.');
}

Unused temporary files older than temporary_maximum_age (default of 6 hours) are removed automatically by cron.

https://www.drupal.org/node/2891902

You can still opt out from this new default behavior, to go back to the old behavior (there is no user interface for going back, but it can be done using Drush or by making a site-specific code change to change the above configuration setting to true).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.