Panel page update ( Hook )

There is something wrong with the javascript in the panel I think,
trying out some hooks and on page update, it just loads forever (extremly slow, localhost), but the
text file field is updated instantly… Just try it for yourself…

kirby()->hook('panel.page.update', function($page) {
        try {
            $page->update(array(
                'hello' => "Please update me sir !!"
            ));
        } catch(Exception $e) {
            echo $e->getMessage();
        }
    });

Yes, I can reproduce it and have created an issue on GitHub

hmm my entire mac finder file system shut down as well, :fearful: (localhost) when
I tried to navigate to the file on my computer… Had to restart it…
Don´t know if it is related or not…

No issues in:

Toolkit version: 2.2.3
Kirby version: 2.2.3
Panel version: 2.2.3

Hmm it seems like this preloader bar thing that is supposed to show the progress of things is the evil thing here, take for instance deleting a file the progress bar starts and it takes more then an second.
In 2.2.3 everything happens instantly, and no progress bar, perhaps the progress bar was introduced in the latest version ?

I just needed an update hook today and the hook worked perfectly fine. So thinking about it again if found that with your hook, the panel get’s into an endless spin, because the update hook is triggered over and over again. I’m going to close the issue now.

:joy: yeah, “update, update, update…” feeling a bit… > :flushed:
thanks @texnixe !

I had the same problem. I added an “if” to check if the update was necessary or done so it won’t loop for ever :
(the “parution” date check method is really not elegant but it worked…)

kirby()->hook('panel.page.update', 'run');

function run($page) {
    
    if ($page->parent()->parution()!="") {
      $p = $page->parution();
      $pp = $page->parent()->parution();
      settype($p, "string");
      settype($pp, "string");
      $difd = (strcmp($p, $pp) == 0);
      if  ($difd==0){
    try {
      $page->update(array(
        '$parution' => $pp
      ));
      } catch (Exception $e) {echo $e->getMessage();}
      
  } 
}
   
}

You can do the same thing a bit more elegant like so:

kirby()->hook('panel.page.update', function($page) {
  if($page->parent()->parution()->isNotEmpty()) {
    $p  = $page->parution()->toString();
    $pp = $page->parent()->parution()->toString();
    
    if($p !== $pp) {
      try {
        $page->update(array(
          'parution' => $pp
        ));
      } catch (Exception $e) {
        echo $e->getMessage();
      }
    }
  }
});
1 Like

Thank you lukasbestle, your way works just fine !

could also be a bug in 2.3.0

I don’t think this is related. If you do a $page->update() within an update hook, as soon as the page is updated, the update hook is triggered again, the page is again updated, the update hook is triggered and so on ad infinitum. So you need to find a way to get out of that loop.

Week later: Now that I think about it again, the update hook should not get into a loop when a page is updated from within the hook, because the panel.page.update hook is not triggered on updating a page from outside of the panel. So this is a bug after all.