Jump to content

Keeping image files if images in field get deleted?


saschapi
 Share

Recommended Posts

Easiest way might be to hook after Pagefiles::delete and just empty the “unlinkQueue” array.

delete() just calls remove(), which removes the item from the Field and schedules the file for deletion by putting it into unlinkQueue:

https://github.com/processwire/processwire/blob/51629cdd5f381d3881133baf83e1bd2d9306f867/wire/core/Pagefiles.php#L433

edit: okay, that won’t work because unlinkQueue is protected. i’m running out of ideas.

if you modify core/pagefile.php to add three underscores in front of unlink(), you can replace that method with a hook:

wire()->addHookBefore('Pagefile::unlink', function (HookEvent $event) {
    $event->replace = true;
});

that’ll work, but it’s ugly.

Link to comment
Share on other sites

23 hours ago, saschapi said:

is it possible to keep image files in their folders if an image is removed from an image file?

Images are also linked externally and it would be nice to keep old versions.

Maybe I have been staring at my empty coffee mug for too long but I don't get the logic behind this :-).

Could you please explain your use case some more? My thinking is that you delete things you no longer need and are sure you won't need. None of these seems to apply to your images. If you need them as some external resource, then why delete them in the first place? Secondly, depending on the number of pages and/or images involved and the frequency of the 'change image operations', you might be creating more headache for yourself in the future. You might end up with lots of orphaned image files in the sense that they are no longer being tracked by ProcessWire. You would have to dig into the file system to do maintenance. You would have to come up with a system for which images are still in use in ProcessWire and which have been decoupled but still in use as external resources. And what about images that may no longer be in use as an external resource? This sounds like a nightmare scenario to me.

So whilst you could probably copy the images before they are deleted, I don't think that's the first approach to consider. Maybe if you could give us a better description of the situation including whether those external sites are ProcessWire sites. Please also explain why you want to delete the images in the first place. Hopefully we can then suggest other solutions and/or approaches, even about the external linking part :-).

  • Like 1
Link to comment
Share on other sites

@kongondo absolutely understandable. :) I have maneuvered myself into a strange setup with two sites with different systems (one that I inherited form another freelancer). One page imports stuff from the other but only in a certain frequency. My problem resulted in something changing on the source page (PW) and the reference on the other site being wrong at that point (different file name). 

I just managed to fix this (5 minutes ago) by changing the import on the other page (importing the images instead of linking to them). So this topic is resolved. My reflex to fix things on the PW site must be, because it is always easy to do stuff in PW and the other system is a different kind of breed. :) 

Thanks for trying to pitch in. :) you were right, to fiddle with this issue on the site of the source was not the right way. 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...