Search the Community
Showing results for tags 'abort'.
-
Hi all, I have a module which creates numerous fields, pages etc. I would like to disable the ability to uninstall the module if any of the generated pages have children, as a mistaken uninstall could really mess up any website which is using it. Im curious about what is the best way to achieve this, currently I have some like: public function ___uninstall(){ error_log('---- UNINSTALL!! ----'); //check to see if any config pages have been added and abort uninstall if true //to avoid uninstalling and losing any work which has been done up to this point. if($this->canWeUninstall()) { //remove pages $this->deletePages($this->cPages->getPages()); //remove templates and field groups $this->deleteTemplates($this->cTemplates->getTemplates()); //remove repeaters $this->deleteRepeaters($this->cRepeaters->getRepeaters()); //delete fields $this->deleteFields($this->cFields->getFields(), $this->cRepeaters->getRepeaters()); } else { error_log('Uninstall aborted because config settings exist!'); $this->error('Whoops! Module cant be uninstalled as it appears to be in use.'); return; } } This works in the sense that it doesn't remove any of the generated content, which is good as it wont break the website. However it still shows the module as uninstalled, I can achieve what i'm looking for by replacing 'return' with 'die' but that results in a white page and looks rather rubbish so its not really a great solution. I would imagine there must be a better way to achieve this, any thoughts? Would it be possible to do this check via a hook before uninstallation and abort before we get to the point of running the uninstall() method, as I imagine that is what updates the DB to turn the module off so to speak?