Jump to content

Always Fatal Error Maximum execution time of 120 seconds exceeded after page save via API [SOLVED]


Juergen
 Share

Recommended Posts

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

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

  • Juergen changed the title to Always Fatal Error Maximum execution time of 120 seconds exceeded after page save via API [SOLVED]

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...