joe_g Posted yesterday at 12:54 PM Share Posted yesterday at 12:54 PM Hey there, I run into a strange problem with a live site that's been running okay for quite some time. I installed sury so it runs the latest php always (this was before debian shipped with php 8). So the only thing that could have changed is the php version... I think. Its on php 8.3.13 and PW 3.0.229. Anyway, if i create a page with some text field it saves ..sometimes. On average every second time. I press save and the page reloads, but then sometimes without the latest update. There is nothing in the PW error log, nothing in the apache error log, also no console errors. To make things weirder, I have another test version of the same site running on the same server and that one is working great. So it might actually be that something is up with this particular install... I'm totally stumped. If you got any ideas i'd love to hear them! Link to comment Share on other sites More sharing options...
Sanyaissues Posted yesterday at 02:32 PM Share Posted yesterday at 02:32 PM I have no idea but in that case I would start by: 1. Activating debug mode. 2. If you have TracyDebugger go to ProcessWire info Pannel > Clear Session, Cookies, & Modules Refresh. If you don't, install it 😉 3. Just for the sake of it Clear all your caches 4. Log what's happening when the page is saved: Put this in your ready.php $this->addHookBefore('Pages::save', function (HookEvent $event) { $page = $event->arguments(0); bd("Attempting to save: {$page->title}"); }); $this->addHookAfter('Pages::save', function (HookEvent $event) { $page = $event->arguments(0); bd("Saved: $page->title"); }); $this->addHookBefore('Pages::saved', function (HookEvent $event) { $page = $event->arguments(0); $changes = $event->arguments(1); bd($changes, "Changes on $page->title"); }); Check the Dumps: 2 Link to comment Share on other sites More sharing options...
joe_g Posted 7 hours ago Author Share Posted 7 hours ago aha thank you! In the mean time the server crashed, pdo_mysql disappeared somehow. If i try to make a new PW install i get "PDO (pdo_mysql) is required (for MySQL database)". So I moved the site to a new server and to my surprise the sometimes-not-saving bug is still happening on the new server. It almost feels like i have two unrelated problems. In any case, when saving it looks normal - changes are listed (below) it's just that it doesn't actually save anything. I'll try a site-export-import next, to see if i that can clear some database problems... Link to comment Share on other sites More sharing options...
joe_g Posted 5 hours ago Author Share Posted 5 hours ago aha, this code (in admin.php) seems to be the culprit: Leaving this code and saving many times (it will fail to save every 2-5 times) and then eventually the mysql install dies entirely. I think it's the first time I managed to truly crash a PW install. You think I might be doing something verboten in the code below? $pages->addHookAfter('saveReady', function($event) { //the following code borks the database! if($p->template->name == 'event') { $home = wire('pages')->get('/'); if(!$p->onfrontpage) { $home->of(false); $home->home->remove($p); $home->save(); } if($p->enddate>time() && $p->onfrontpage) { if(!$home->home->has($p)) { $home->of(false); $home->home->add($p); wire('pages')->message('Added ' . $p->title . ' to the homepage'); $home->of(false); $home->save(); } $p->of(false); $p->onfrontpage = 0; } } } Link to comment Share on other sites More sharing options...
Jan Romero Posted 4 hours ago Share Posted 4 hours ago May want to pass ['noHooks' => true] to the save() call to prevent the hook from being called recursively: https://processwire.com/api/ref/pages/save/ (I also like the 'quiet' option). 1 Link to comment Share on other sites More sharing options...
joe_g Posted 1 hour ago Author Share Posted 1 hour ago Thanks! That sounds great, I'll try that. I think i just graduated to yellow belt in hooks 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