Deleting a book does not delete corresponding table records #2218

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

Originally created by @tstkenny on GitHub (Apr 24, 2021).

I am developing a store procedure to save an existing book into a new book including chapters and pages and I found a related bug:

When you delete a book via UI, some of the relational table records are not deleted. e.g. joint_permission.

If you use the UI button to copy all the permissions in a BookShelf to all Books, the deleted books will APPEAR AGAIN, which is a serious bug.

A quick but dirty fix:

delete from books where deleted_at is not null;
delete from chapters where deleted_at is not null;
delete from pages where deleted_at is not null;
delete from joint_permissions where entity_type='BookStack\Page' AND entity_id not in (select id from pages);
delete from joint_permissions where entity_type='BookStack\Chapter' AND entity_id not in (select id from chapters);
delete from joint_permissions where entity_type='BookStack\Book' AND entity_id not in (select id from books);

Thank you.

Originally created by @tstkenny on GitHub (Apr 24, 2021). I am developing a store procedure to save an existing book into a new book including chapters and pages and I found a related bug: When you delete a book via UI, some of the relational table records are not deleted. e.g. joint_permission. If you use the UI button to copy all the permissions in a BookShelf to all Books, the deleted books will APPEAR AGAIN, which is a serious bug. A quick but dirty fix: delete from books where deleted_at is not null; delete from chapters where deleted_at is not null; delete from pages where deleted_at is not null; delete from joint_permissions where entity_type='BookStack\\Page' AND entity_id not in (select id from pages); delete from joint_permissions where entity_type='BookStack\\Chapter' AND entity_id not in (select id from chapters); delete from joint_permissions where entity_type='BookStack\\Book' AND entity_id not in (select id from books); Thank you.
Author
Owner

@ssddanbrown commented on GitHub (Apr 27, 2021):

Thanks for reporting @tstkenny,

Just to confirm, When you say "the deleted books will APPEAR AGAIN", do you mean within the user interface or do you mean within the database?

@ssddanbrown commented on GitHub (Apr 27, 2021): Thanks for reporting @tstkenny, Just to confirm, When you say "the deleted books will APPEAR AGAIN", do you mean within the user interface or do you mean within the database?
Author
Owner

@tstkenny commented on GitHub (May 1, 2021):

@ssddanbrown actually the record never got deleted so it stays in the database since beginning. The book will re-appear in the UI.

@tstkenny commented on GitHub (May 1, 2021): @ssddanbrown actually the record never got deleted so it stays in the database since beginning. The book will re-appear in the UI.
Author
Owner

@ssddanbrown commented on GitHub (May 1, 2021):

Hi @tstkenny,
I just attempted to re-produce this by doing the following:

  1. Delete a book that exists within a shelf via the UI.
  2. Run the "Copy Permissions" action from the shelf's Permission page.

After doing this the book did not re-appear but remained deleted, in the recycle bin, as expected and therefore did not re-appear in the shelf within the UI. I tested the and without custom permissions set on the shelf.
Does you instance behave differently? If so please can you confirm the version?

@ssddanbrown commented on GitHub (May 1, 2021): Hi @tstkenny, I just attempted to re-produce this by doing the following: 1. Delete a book that exists within a shelf via the UI. 2. Run the "Copy Permissions" action from the shelf's Permission page. After doing this the book did not re-appear but remained deleted, in the recycle bin, as expected and therefore did not re-appear in the shelf within the UI. I tested the and without custom permissions set on the shelf. Does you instance behave differently? If so please can you confirm the version?
Author
Owner

@ssddanbrown commented on GitHub (May 24, 2021):

Since there's been no follow-up I'm going to close this. If the issue remains and is something you still require to be fixed please open a new issue, referencing this one.

@ssddanbrown commented on GitHub (May 24, 2021): Since there's been no follow-up I'm going to close this. If the issue remains and is something you still require to be fixed please open a new issue, referencing this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2218