Better Trash

Pro version: auto delete trashed items

1 year 1 month ago #72979

Steve Burge's Avatar Steve Burge

Hi Peter,

Hope all is well!

Any chance of creating a Pro version of Better Trash that can auto delete trashed items (including K2 items)?

Thanks,
Nick

1 year 1 month ago #72981

Peter van Westen's Avatar Peter van Westen Admin

Deleting trashed items directly would make the whole trash useless.
So an option to auto delete items that have been in trash for longer than x amount of time could be a nice feature.

There is however no date stored in the item stating when it got trashed.
But there is a modified date. (Yes, just thinking out loud here.)
So I think it could be done to just base the time in trash on that. And when you edit a trashed item (for whatever weird reason) but keep it in trash, then that would reset the counter (modified date).

1 year 1 month ago #72982

Steve Burge's Avatar Steve Burge

That makes sense to me. I can't think of any issues with the suggested implementation.

1 year 1 month ago #72983

Peter van Westen's Avatar Peter van Westen Admin

I'll put this on my 'interesting' list. :D

1 year 1 month ago #72989

Peter van Westen's Avatar Peter van Westen Admin

Ok, tried to implement this, and was nearly done. But I have run into these issues for which I have no simple/clean solution:

1) The only list tables that store a modified date in core are content and categories. Modules, menu items and a lot of 3rd party tables don't have a modified date.
So that means it is not possible for those tables to see how long an item has been in trash.

2) The modified date does not get updated when trashing an item from the list view.
So let's say you have an item that you created/edited last month. Now you trash it from the list.
Then the modified date is still set to last month. Meaning the it would look like it has been trashed for a month if I base it on the modified date.

So the only solution to this is to create an extra trashed reference table in which I store references to all trashed items as soon as they get trashed, and store the date in that.
But that is a lot of extra work (and overhead).

1 year 1 month ago #72995

Steve Burge's Avatar Steve Burge

Nice! :)

1) Would it be easy to submit a pull request to the Joomla core for it? Or even better, a trashed date? I'd be glad to test the PR for it and it would likely be accepted quickly.

By the way, the project we're working on doesn't need it for modules, menu items, etc. It just needs it for K2 items. Last time they had 15,000 trashed items that piled up quickly. But, I could see users wanting a feature like that for those areas too, particularly for menu items.

2) Ouch. Adding a trashed date to core might be the best option then.

Thoughts?

1 year 1 month ago #72996

Peter van Westen's Avatar Peter van Westen Admin

Adding a trashed date column to all tables in core is no small task and not something I am willing to try and get into Joomla.
So I might take a look at the extra database table solution when I have some more time. There are events being triggers like 'onContentChangeState' that I could hook into.

1 year 1 month ago #73033

Steve Burge's Avatar Steve Burge

Sounds good.

By the way, there's github.com/joomla/joomla-cms/issues/8244 for:

2) The modified date does not get updated when trashing an item from the list view.

I'll see if I can figure out a bug fix for it and send in a PR.

1 year 1 month ago #73036

Peter van Westen's Avatar Peter van Westen Admin

Ok, next issue:
I have gone down this extra trashed items table. Which is coming along nicely.
I add/remove reference items to this based on the information passed via the triggers (onContentAfterSave, onContentAfterDelete, onContentChangeState).
This is working well.

BUT:
K2 is unfortunately not using these triggers.
So plugins have no way of interacting with the save/change actions K2 does.
It does, for some weird reason have a hacky implementation of triggering events only for the finder.

So in this setup of the auto-purging in Better Trash Pro, K2 will not be supported.

1 year 1 month ago #73038

Peter van Westen's Avatar Peter van Westen Admin

1 year 2 weeks ago #73830

Steve Burge's Avatar Steve Burge

Sorry for the delayed reply.

Thank you, Peter!

1 year 1 week ago #74047

Peter van Westen's Avatar Peter van Westen Admin

Please try the latest development version from:
www.regularlabs.com/development-releases

The auto-delete will only function for K2 when you have those new triggers in K2.
github.com/getk2/k2/pull/403