Juergen Posted August 23, 2021 Share Posted August 23, 2021 Hello @ all I am struggeling with a saving problem of pages and could not find the reason. Description: I am using the following Hook inside a module: public function ready() { $this->addHookAfter('Modules::saveConfig', $this, 'setPageStatus'); } This Hook runs after the module was saved and triggers the the following setPageStatus method : /** * Sets the status of pages using the fl_register or fl_activation template to unpublished or published depending on the value of the * input_selectloginregister inputfield * @param HookEvent $e */ protected function setPageStatus(HookEvent $e) { $pages = wire('pages')->find('template=fl_register|fl_activation', ['findAll' => true]); foreach($pages as $p){ $p->setOutputFormatting(false); if($e->arguments(1)['input_selectloginregister'] == 'login'){ $p->addStatus('unpublished'); } else { $p->removeStatus('unpublished'); } $p->save(); $p->setOutputFormatting(true); } } I have found out that $p->save() method is responsible for the hight execution time and the error, but I do not know why. Everytime I remove this method the problem is gone. but of course the status will not be saved. Just to mention: There are always only 2 pages that will be saved - not more!!! Does anyone has an idea why the saving of the pages can exceed the execution time or a way to find out where the problem could be. Thanks in advance Link to comment Share on other sites More sharing options...
Juergen Posted August 24, 2021 Author Share Posted August 24, 2021 I found out that it happens if I use save() method without a parameter that was not set before. If I use for example save('title') and I set the title first, it works. // Works $p->title = 'My title'; $p->save('title'); // Does not work if title was not set before $p->save('title'); // Unfortunately this does not work $p->addStautus(Page::statusUnpublished); $p->save('status'); // and this does no work too $p->addStautus(Page::statusUnpublished); $p->save(); Any hints how to save the status? Link to comment Share on other sites More sharing options...
Juergen Posted August 24, 2021 Author Share Posted August 24, 2021 Problem is solved! I installed a new installation on XAMPP and now it works without problems - I guess there was going something wrong during the developement of the module inside the database. Best regards Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now