Recently, we have found a very old bug where dragging and dropping chapters across parts would corrupt the ordering in the database. Due to how the sorting routine worked, it sometimes resulted in chapters with the same order in the mysql database (2 chapters in the 3rd order). While the ordering was still relatively stable due to the nature of the queries and how mysql stores the data, this ambiguity in the menu order could have caused parts and chapters to appear in the wrong order when a mysql dump was restored.
This bug was fixed in Pressbooks 6.22.0 (Release v6.22.0 · pressbooks/pressbooks · GitHub), and this fix prevented any further corruption of the menu_order values in the database.
We have also created a PHP script (download here) that fetches all of the parts and chapters from the table of content and corrects the menu_order value in the database. To execute this script you will need the following:
- WP-CLI (https://wp-cli.org/). (we recommend the latest version, 2.11)
- Pressbooks v 6.22.0 or greater (we recommend the latest release 6.22.1)
- Shell access to your Pressbooks/WordPress installation
To execute the script, copy fix-order.php into the installation directory of your Pressbooks/Wordpress installation. If you’re using Bedrock (recommended), this would be the directory that has ‘config, vendor, web and wp-cli.yml in it (you could also run this from inside the ‘web’ directory if you don’t see the wp-cli.yml file).
To execute the script on a single book, you can run this from the shell prompt:
wp eval-file fix-order.php BOOKID dry-run
where BOOKID is the ID number of the book you want to fix.
The dry-run option in that command will show you what would be done (or any errors if it finds problems) but will not make any changes to the database. Remove that option to make the actual changes.
wp eval-file fix-order.php BOOKID
To execute the script on all books in your network, you can run this in bash or zsh shell:
for bookid in $(wp site list --fields=blog_id --format=ids); do \
wp eval-file fix-order.php $bookid; \
done
This will update the sort order on all books in your network