nbcommunication Posted May 22, 2017 Share Posted May 22, 2017 Hi, I was adding a hook in admin.php which updates a field that is based on the sort value and runs after Pages::sorted. Looking through the docs, I figured hey I'll run $pages->sort($parent, true) so that the sort values are correct before setting the other field. Here's the basic hook: <?php namespace ProcessWire; $pages->addHookAfter("Pages::sorted", function($event) { $pages = $event->object; $page = $event->arguments(0); $pages->sort($page->parent, true); // Other stuff return; }); This kept returning the following exception: SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (in .../wire/core/PagesEditor.php line 1388) Now, thinking through this, sorting the pages in the admin probably runs the sortRebuild() function that the error is referring to anyway, so $pages->sort($parent, true) isn't needed at all and perhaps this is why the error is appearing. However, I've just run <?php namespace ProcessWire; if($user->hasRole("superuser")) { $pages->sort($pages->get(1072), true); } And this is returning the same error/exception. The parent called above has 14 child pages. Running 3.0.62. Is this something I'm doing wrong? Cheers, Chris NB Communication Link to comment Share on other sites More sharing options...
nbcommunication Posted May 22, 2017 Author Share Posted May 22, 2017 Stack trace from the second example, which I called on the 404 page... Error: Exception: SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (in ../wire/core/PagesEditor.php line 1388) #0 ../wire/core/PagesEditor.php(1388): PDOStatement->execute() #1 ../wire/core/Pages.php(882): ProcessWire\PagesEditor->sortRebuild(Object(ProcessWire\Page)) #2 ../wire/core/Wire.php(386): ProcessWire\Pages->___sort(Object(ProcessWire\Page), true) #3 ../wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___sort', Array) #4 ../wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Pages), 'sort', Array) #5 /home/stmasway/public_html/site/templates/404.php(9): ProcessWire\Wire->__call('sort', Array) #6 ../wire/core/TemplateFile.php(268): require('/home/stmasway/...') #7 ../wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #8 ../wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___render', Array) #9 ../wire/core/Wire. Link to comment Share on other sites More sharing options...
BitPoet Posted May 22, 2017 Share Posted May 22, 2017 That's probably because MySQL strict mode is enabled. sortRebuild() uses a "shortcut" notation for multiple updates using an "INSERT ... ON DUPLICATE KEY UPDATE ..." statement that fails in strict mode. Both disabling strict mode globally or adding the following in site/config.php should help: $config->dbSqlModes = array( "5.5.0" => "remove:STRICT_TRANS_TABLES,ONLY_FULL_GROUP_BY" ) This is already the default for MySQL >= 5.7, but both features may be active in 5.5 and 5.6 installations as well. There's already an open issue for this here. 2 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