Page order not updated after sorting #2955

Closed
opened 2026-02-05 05:50:04 +03:00 by OVERLORD · 19 comments
Owner

Originally created by @mrcompsci on GitHub (Aug 11, 2022).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

The order of pages within a chapter is not saved when using the sort function. The priority field in the database is not updated. This is true of existing books and chapters as well as newly created ones. No errors are displayed or logged.

Pages that aren't contained in a chapter sort as expected.

This seems to be the same issue as #3544 . To follow up on unanswered questions from that issue: Yes, I am using a user with administrative privileges. The JSON extension is enabled. I also added the debug line to BookSortController.php and confirmed that it is receiving the new order from the browser.

This system was upgraded from v0.29.0 to v22.03.1 in April and sorting hasn't worked since. It was upgraded again today to v22.07.3.

Exact BookStack Version

v22.07.3

Log Content

No response

PHP Version

7.4.30

Hosting Environment

Shared hosting environment:

cPanel Version: 104.0 (build 7)
Apache Version: 2.4.54
PHP Version: 7.2.34
MySQL Version: 10.3.35-MariaDB-cll-lve
Architecture: x86_64
Operating System: linux

Originally created by @mrcompsci on GitHub (Aug 11, 2022). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### Describe the Scenario The order of pages within a chapter is not saved when using the sort function. The priority field in the database is not updated. This is true of existing books and chapters as well as newly created ones. No errors are displayed or logged. Pages that aren't contained in a chapter sort as expected. This seems to be the same issue as #3544 . To follow up on unanswered questions from that issue: Yes, I am using a user with administrative privileges. The JSON extension is enabled. I also added the debug line to BookSortController.php and confirmed that it is receiving the new order from the browser. This system was upgraded from v0.29.0 to v22.03.1 in April and sorting hasn't worked since. It was upgraded again today to v22.07.3. ### Exact BookStack Version v22.07.3 ### Log Content _No response_ ### PHP Version 7.4.30 ### Hosting Environment Shared hosting environment: cPanel Version: 104.0 (build 7) Apache Version: 2.4.54 PHP Version: 7.2.34 MySQL Version: 10.3.35-MariaDB-cll-lve Architecture: x86_64 Operating System: linux
OVERLORD added the 🐕 Support label 2026-02-05 05:50:04 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Aug 12, 2022):

Hi @mrcompsci,

Where is the 7.2.34 php version coming from, is that the version of PHP being used for bookstack itself?

@ssddanbrown commented on GitHub (Aug 12, 2022): Hi @mrcompsci, Where is the `7.2.34` php version coming from, is that the version of PHP being used for bookstack itself?
Author
Owner

@mrcompsci commented on GitHub (Aug 12, 2022):

@ssddanbrown

I apologize for the contradiction. The CLI reports 7.2.34 as does cPanel's "server information" page, but if I use phpinfo() on the site itself, it reports 7.4.30.

@mrcompsci commented on GitHub (Aug 12, 2022): @ssddanbrown I apologize for the contradiction. The CLI reports 7.2.34 as does cPanel's "server information" page, but if I use phpinfo() on the site itself, it reports 7.4.30.
Author
Owner

@ssddanbrown commented on GitHub (Aug 12, 2022):

@mrcompsci Thanks for confirming. This is gonna be a bit tricky to solve other than attempting to replicate your environment directly, so you may need to bear with me to run through debugging steps.

Could you find the line highlighted here:
1fdf854ea7/app/Http/Controllers/BookSortController.php (L61)

and below it, add the following line:

dd($sortMap);

This should stop the sort action and spit out the sort data on save. On the output view, if existing, it would be helpful to expand some of the items by clicking the little arrows that should show.

@ssddanbrown commented on GitHub (Aug 12, 2022): @mrcompsci Thanks for confirming. This is gonna be a bit tricky to solve other than attempting to replicate your environment directly, so you may need to bear with me to run through debugging steps. Could you find the line highlighted here: https://github.com/BookStackApp/BookStack/blob/1fdf854ea735bf69e1c2666d8d23f66b243d7afe/app/Http/Controllers/BookSortController.php#L61 and **_below_** it, add the following line: ```php dd($sortMap); ``` This should stop the sort action and spit out the sort data on save. On the output view, if existing, it would be helpful to expand some of the items by clicking the little arrows that should show.
Author
Owner

@mrcompsci commented on GitHub (Aug 12, 2022):

@ssddanbrown Here is the output. I have three test pages within a chapter - Page 1A (item 1322), Page 2A (item 1323) and Page 3A (item 1324) which are currently in order 1-3. I just tried to sort them in reverse order.

^ BookStack\Entities\Tools\BookSortMap {#1278 ▼
  #mapData: array:4 [▼
    0 => BookStack\Entities\Tools\BookSortMapItem {#1547 ▶}
    1 => BookStack\Entities\Tools\BookSortMapItem {#1545 ▼
      +id: 1324
      +sort: 0
      +parentChapterId: 196
      +type: "page"
      +parentBookId: 45
    }
    2 => BookStack\Entities\Tools\BookSortMapItem {#1543 ▼
      +id: 1323
      +sort: 1
      +parentChapterId: 196
      +type: "page"
      +parentBookId: 45
    }
    3 => BookStack\Entities\Tools\BookSortMapItem {#1548 ▼
      +id: 1322
      +sort: 2
      +parentChapterId: 196
      +type: "page"
      +parentBookId: 45
    }
  ]
}
@mrcompsci commented on GitHub (Aug 12, 2022): @ssddanbrown Here is the output. I have three test pages within a chapter - Page 1A (item 1322), Page 2A (item 1323) and Page 3A (item 1324) which are currently in order 1-3. I just tried to sort them in reverse order. ``` ^ BookStack\Entities\Tools\BookSortMap {#1278 ▼ #mapData: array:4 [▼ 0 => BookStack\Entities\Tools\BookSortMapItem {#1547 ▶} 1 => BookStack\Entities\Tools\BookSortMapItem {#1545 ▼ +id: 1324 +sort: 0 +parentChapterId: 196 +type: "page" +parentBookId: 45 } 2 => BookStack\Entities\Tools\BookSortMapItem {#1543 ▼ +id: 1323 +sort: 1 +parentChapterId: 196 +type: "page" +parentBookId: 45 } 3 => BookStack\Entities\Tools\BookSortMapItem {#1548 ▼ +id: 1322 +sort: 2 +parentChapterId: 196 +type: "page" +parentBookId: 45 } ] } ```
Author
Owner

@ssddanbrown commented on GitHub (Aug 13, 2022):

Thanks for the info @mrcompsci,
That all looks fine. I'm getting the impression that permissions may be at play here.

When you say the following:

Yes, I am using a user with administrative privileges.

Does the user have all possible role permissions assigned? And are there any permission overrides set on the content being sorted?

@ssddanbrown commented on GitHub (Aug 13, 2022): Thanks for the info @mrcompsci, That all looks fine. I'm getting the impression that permissions may be at play here. When you say the following: > Yes, I am using a user with administrative privileges. Does the user have all possible role permissions assigned? And are there any permission overrides set on the content being sorted?
Author
Owner

@mrcompsci commented on GitHub (Aug 13, 2022):

@ssddanbrown

This user has the Admin role and one other assigned. The admin role has all permissions assigned.

user_permissions

The book I'm testing with did have custom permissions to hide it from the public, but I just tried disabling that and was still unable to sort pages. I even tried removing it from the custom role (leaving just Admin) but that had no effect on sorting.

@mrcompsci commented on GitHub (Aug 13, 2022): @ssddanbrown This user has the Admin role and one other assigned. The admin role has all permissions assigned. ![user_permissions](https://user-images.githubusercontent.com/14784837/184495441-9b09e4e3-afc9-4e78-8e71-f00915fa5422.png) The book I'm testing with did have custom permissions to hide it from the public, but I just tried disabling that and was still unable to sort pages. I even tried removing it from the custom role (leaving just Admin) but that had no effect on sorting.
Author
Owner

@ssddanbrown commented on GitHub (Aug 13, 2022):

Okay, as a next step, could you find the following file & lines:

1fdf854ea7/app/Entities/Tools/BookContents.php (L182-L184)

Then, before the return; line add dd('lacking permission');
This will help us determine if this is something permission related, since you're expected to have all permissions with your user setup.

@ssddanbrown commented on GitHub (Aug 13, 2022): Okay, as a next step, could you find the following file & lines: https://github.com/BookStackApp/BookStack/blob/1fdf854ea735bf69e1c2666d8d23f66b243d7afe/app/Entities/Tools/BookContents.php#L182-L184 Then, before the `return;` line add `dd('lacking permission');` This will help us determine if this is something permission related, since you're expected to have all permissions with your user setup.
Author
Owner

@mrcompsci commented on GitHub (Aug 13, 2022):

Yes, it does seem to be permission related. I received the "lacking permission" message when I tried to sort.

I confirmed again that the Admin role has all of the permissions assigned in the web interface, but perhaps something is wrong in the database?

admin_role

@mrcompsci commented on GitHub (Aug 13, 2022): Yes, it does seem to be permission related. I received the "lacking permission" message when I tried to sort. I confirmed again that the Admin role has all of the permissions assigned in the web interface, but perhaps something is wrong in the database? ![admin_role](https://user-images.githubusercontent.com/14784837/184498788-6ee36e75-e675-421b-8471-e4ecc7e7d9c9.png)
Author
Owner

@ssddanbrown commented on GitHub (Aug 14, 2022):

but perhaps something is wrong in the database?

Quite possible at this stage.

As the next debug step, could you find this section:

1fdf854ea7/app/Entities/Tools/BookContents.php (L252-L257)

and, above it, add the following:

dd($hasCurrentParentPermission, $newParentInRightLocation, $hasNewParentPermission, $hasPageEditPermission, $hasDeletePermissionIfMoving, $hasCreatePermissionIfMoving);

Then report output, if existing. Should allow us to find the exact failing permission check.

@ssddanbrown commented on GitHub (Aug 14, 2022): > but perhaps something is wrong in the database? Quite possible at this stage. As the next debug step, could you find this section: https://github.com/BookStackApp/BookStack/blob/1fdf854ea735bf69e1c2666d8d23f66b243d7afe/app/Entities/Tools/BookContents.php#L252-L257 and, above it, add the following: ```php dd($hasCurrentParentPermission, $newParentInRightLocation, $hasNewParentPermission, $hasPageEditPermission, $hasDeletePermissionIfMoving, $hasCreatePermissionIfMoving); ``` Then report output, if existing. Should allow us to find the exact failing permission check.
Author
Owner

@mrcompsci commented on GitHub (Aug 14, 2022):

$newParentInRightLocation is false:

^ true
^ false
^ true
^ true
^ true
^ true
@mrcompsci commented on GitHub (Aug 14, 2022): $newParentInRightLocation is false: ``` ^ true ^ false ^ true ^ true ^ true ^ true ```
Author
Owner

@mrcompsci commented on GitHub (Aug 23, 2022):

@ssddanbrown Do you have any suggestions for troubleshooting this further?

@mrcompsci commented on GitHub (Aug 23, 2022): @ssddanbrown Do you have any suggestions for troubleshooting this further?
Author
Owner

@ssddanbrown commented on GitHub (Aug 23, 2022):

@mrcompsci Sorry for lack of response.
Seems to be some misalignment in understanding the parent location.
Would be good to know what's going on there.

Where you placed the previous debug line, could you instead add the following:

if (!$newParentInRightLocation) {
	dd($sortMapItem, $newParent->book_id ?? false, $newBook->id ?? false);
}
@ssddanbrown commented on GitHub (Aug 23, 2022): @mrcompsci Sorry for lack of response. Seems to be some misalignment in understanding the parent location. Would be good to know what's going on there. Where you placed the previous debug line, could you instead add the following: ```php if (!$newParentInRightLocation) { dd($sortMapItem, $newParent->book_id ?? false, $newBook->id ?? false); } ```
Author
Owner

@mrcompsci commented on GitHub (Aug 23, 2022):

@ssddanbrown

^ BookStack\Entities\Tools\BookSortMapItem {#1540 ▼
  +id: 1323
  +sort: 0
  +parentChapterId: 196
  +type: "page"
  +parentBookId: 45
}

^ "45"

^ 45
@mrcompsci commented on GitHub (Aug 23, 2022): @ssddanbrown ``` ^ BookStack\Entities\Tools\BookSortMapItem {#1540 ▼ +id: 1323 +sort: 0 +parentChapterId: 196 +type: "page" +parentBookId: 45 } ^ "45" ^ 45 ```
Author
Owner

@ssddanbrown commented on GitHub (Aug 23, 2022):

Thanks for the info @mrcompsci, interesting result.

I get the impression your environment may be using an older PHP/MySQL driver that's rarely used.
Within CPanel, do you have options for the PHP MySQL driver, or do you have mulitple options for mysql-related PHP extensions?

@ssddanbrown commented on GitHub (Aug 23, 2022): Thanks for the info @mrcompsci, interesting result. I get the impression your environment may be using an older PHP/MySQL driver that's rarely used. Within CPanel, do you have options for the PHP MySQL driver, or do you have mulitple options for mysql-related PHP extensions?
Author
Owner

@mrcompsci commented on GitHub (Aug 23, 2022):

@ssddanbrown There are a few MySQL options in cPanel:

mysqli
mysqlnd (enabled)
nd_mysqli (enabled)
nd_pdo_mysql
pdo_mysql (enabled)

@mrcompsci commented on GitHub (Aug 23, 2022): @ssddanbrown There are a few MySQL options in cPanel: mysqli mysqlnd (enabled) nd_mysqli (enabled) nd_pdo_mysql pdo_mysql (enabled)
Author
Owner

@ssddanbrown commented on GitHub (Aug 23, 2022):

nd_pdo_mysql
pdo_mysql (enabled)

Could you try swapping those around? So disable pdo_mysql and enable nd_pdo_mysql.
Then restart apache/php (if possible) and see if that fixes things.

@ssddanbrown commented on GitHub (Aug 23, 2022): > nd_pdo_mysql > pdo_mysql (enabled) Could you try swapping those around? So disable `pdo_mysql` and enable `nd_pdo_mysql`. Then restart apache/php (if possible) and see if that fixes things.
Author
Owner

@mrcompsci commented on GitHub (Aug 24, 2022):

Disabling pdo_mysql and enabling nd_pro_mysql worked. Sorting is working properly now and it doesn't look like the change created any new issues. I never would have guessed that the MySQL driver needed to be changed. Thanks for your help!

@mrcompsci commented on GitHub (Aug 24, 2022): Disabling pdo_mysql and enabling nd_pro_mysql worked. Sorting is working properly now and it doesn't look like the change created any new issues. I never would have guessed that the MySQL driver needed to be changed. Thanks for your help!
Author
Owner

@ssddanbrown commented on GitHub (Aug 24, 2022):

Great news! Will therefore close this off.
Must admit, I didn't think the non-native driver was in use any more.
I'll keep an ear out though and, if this pops up again, maybe update the docs to specific driver version.

@ssddanbrown commented on GitHub (Aug 24, 2022): Great news! Will therefore close this off. Must admit, I didn't think the non-native driver was in use any more. I'll keep an ear out though and, if this pops up again, maybe update the docs to specific driver version.
Author
Owner

@jwtay1 commented on GitHub (Feb 14, 2023):

Finally! I was having the same issue and it took awhile to find this post as the correct solution.

@jwtay1 commented on GitHub (Feb 14, 2023): Finally! I was having the same issue and it took awhile to find this post as the correct solution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2955