Hello everybody,
in my plugin Simple Events I would like to offer an option to have old events deleted automatically (for my own projects it would certainly be very useful). I have a problem with actually doing this, and also I am wondering how to best implement this.
I’ll start with the problem, as it’s pretty straightforward: how do I best delete a page in PHP, folder and all? I have a list of all pages of type event
with a past start date, now what do I do to delete them?
I couldn’t find anything in the docs, so I looked in the Admin plugin code which has a function for that: protected function taskDelete()
on line 2184 of admincontroller.php
. I went ahead and just tried the bit with Folder::delete($page->path());
substituting $page->path()
for my actual path string, and while I did not get any error, nothing got deleted either. I’ll next try copying the whole function and modifying it until it works… but if somebody can point me to a simpler method, that would be excellent.
The other thing is, when should this deleting actually be done? I’m thinking that this is absolutely a cronjob thing, but setting up a cronjob for Grav on a shared hosting server, which I am sure many people using this plugin are on, can be a daunting task – so far, I haven’t bothered doing it on mine!
So I might offer a button for doing this in the Admin plugin options, or I might do it whenever an Event page gets saved, the latter being super automagical but also the most risky. But in either case, I can’t do it for people who don’t use the Admin plugin.
What do you think? What would be the cleanest solution that still offers reasonable ease of use?
Thank you for your time!
Anna~