Import SQL but pages, books, bookshelves don't appear #2170

Closed
opened 2026-02-05 03:11:45 +03:00 by OVERLORD · 8 comments
Owner

Originally created by @csjjpm on GitHub (Mar 24, 2021).

As my other issue has not been resolved I've installed from scratch.

I am running SQL statements in phpmysql by adding the new columns (deleted_at, owned_by) but the content is not being displayed for my user.

My user is #3 and the owned_by I set in the SQL is '3'.

any ideas?

Originally created by @csjjpm on GitHub (Mar 24, 2021). As my other issue has not been resolved I've installed from scratch. I am running SQL statements in phpmysql by adding the new columns (deleted_at, owned_by) but the content is not being displayed for my user. My user is #3 and the owned_by I set in the SQL is '3'. any ideas?
Author
Owner

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

Hi @csjjpm,
I'm not really understanding where you've gotten to, Are you now migrating old rows to the new database or manually altering the old database?

Not seeing content can be due to the deleted_at values being non-null or by the joint_permissions data being incorrect. There is a command to regenerate this table: https://www.bookstackapp.com/docs/admin/commands/#regenerate-access-permissions

That said, manual altering may dig you into a deeper hole. Manual changes will get you out of sync with the migrations and cause issues on every upgrade. Are you now getting migration issues again?

If you want we could try to work out what's gone wrong in the past and re-align things. I'd need to ideally know the version of your last BookStack version and, for your last working DB state/copy, the output from the following sql commands:

select * from information_schema.columns
where table_schema = 'bookstack'
order by table_name,ordinal_position;

select * from bookstack.migrations;

You'll need to change bookstack to match your own BookStack database name.

@ssddanbrown commented on GitHub (Mar 24, 2021): Hi @csjjpm, I'm not really understanding where you've gotten to, Are you now migrating old rows to the new database or manually altering the old database? Not seeing content can be due to the `deleted_at` values being non-null or by the `joint_permissions` data being incorrect. There is a command to regenerate this table: https://www.bookstackapp.com/docs/admin/commands/#regenerate-access-permissions That said, manual altering may dig you into a deeper hole. Manual changes will get you out of sync with the migrations and cause issues on every upgrade. Are you now getting migration issues again? If you want we could try to work out what's gone wrong in the past and re-align things. I'd need to ideally know the version of your last BookStack version and, **_for your last working DB state/copy_**, the output from the following sql commands: ```sql select * from information_schema.columns where table_schema = 'bookstack' order by table_name,ordinal_position; select * from bookstack.migrations; ``` You'll need to change `bookstack` to match your own BookStack database name.
Author
Owner

@csjjpm commented on GitHub (Mar 24, 2021):

ok, thanks for the direction. I'll try the permissions fix furst.

@csjjpm commented on GitHub (Mar 24, 2021): ok, thanks for the direction. I'll try the permissions fix furst.
Author
Owner

@csjjpm commented on GitHub (Mar 24, 2021):

To reply to your questions I am inseting SQL statements in order to restore my content. I'm doing it table by table as I've got to add the two new columns deleted_at and owned_by. I think my original version was 0.30.1 bu the migrate command failed at some point.
I only need the shelves, books and pages and it should be fine. I've run the permission fix and I can see the content I've inserted so far. I'll finish the rest off later and check.
thanks for your help.

@csjjpm commented on GitHub (Mar 24, 2021): To reply to your questions I am inseting SQL statements in order to restore my content. I'm doing it table by table as I've got to add the two new columns deleted_at and owned_by. I think my original version was 0.30.1 bu the migrate command failed at some point. I only need the shelves, books and pages and it should be fine. I've run the permission fix and I can see the content I've inserted so far. I'll finish the rest off later and check. thanks for your help.
Author
Owner

@csjjpm commented on GitHub (Mar 26, 2021):

Hi,
some of my inserts work after fixing permissions and others fail. I think it could be some characters in the text which is failing. It could be pages which have http/s links in the text.

This is the error

HP Warning:  Module 'gd' already loaded in Unknown on line 0
PHP Warning:  Module 'sqlite3' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_sqlite' already loaded in Unknown on line 0

   ErrorException  : Trying to get property 'restricted' of non-object

  at /usr/local/www/BookStack/app/Auth/Permissions/PermissionService.php:462
    458|
    459|         // For pages with a chapter, Check if explicit permissions areset on the Chapter
    460|         if ($entity instanceof Page && intval($entity->chapter_id) !==0) {
    461|             $chapter = $this->getChapter($entity->chapter_id);
  > 462|             $hasPermissiveAccessToParents = $hasPermissiveAccessToParents && !$chapter->restricted;
    463|             if ($chapter->restricted) {
    464|                 $hasExplicitAccessToParents = $this->mapHasActiveRestriction($permissionMap, $chapter, $role, $restrictionAction);
    465|             }
    466|         }

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError()
      /usr/local/www/BookStack/app/Auth/Permissions/PermissionService.php:462

  2   BookStack\Auth\Permissions\PermissionService::createJointPermissionData()
      /usr/local/www/BookStack/app/Auth/Permissions/PermissionService.php:393

  Please use the argument -v to see more details.

   Whoops\Exception\ErrorException  : Module 'pdo_sqlite' already loaded

  at Unknown:0
    1|

  Exception trace:

  1   Whoops\Run::handleError()
      /usr/local/www/BookStack/vendor/filp/whoops/src/Whoops/Run.php:454

This is the text:


INSERT INTO `pages` (`id`, `book_id`, `chapter_id`, `name`, `slug`, `html`, `text`, `priority`, `created_at`, `updated_at`, `created_by`, `updated_by`, `restricted`, `draft`, `markdown`, `revision_count`, `template`, `deleted_at`, `owned_by`) VALUES
(5, 2, 1, 'PKG fixes', 'pkg-fixes', '<div id=\"bkmrk-to-enable-repository\">to enable repository access to other repositories</div>\r\n<div id=\"bkmrk-https%3A%2F%2Fwww.reddit.c\"><a href=\"https://www.reddit.com/r/freenas/comments/9ljgtz/unable_to_install_openvpn_in_transmission_jail/\" target=\"_blank\" rel=\"noopener\" shape=\"rect\">https://www.reddit.com/r/freenas/comments/9ljgtz/unable_to_install_openvpn_in_transmission_jail/</a></div>\r\n<div id=\"bkmrk-\"></div>\r\n<div id=\"bkmrk--0\"></div>\r\n<div id=\"bkmrk-https%3A%2F%2Fwww.ixsystem\">https://www.ixsystems.com/community/threads/guide-setting-up-transmission-with-openvpn-and-pia.24566/</div>', 'to enable repository access to other repositories\r\nhttps://www.reddit.com/r/freenas/comments/9ljgtz/unable_to_install_openvpn_in_transmission_jail/\r\n\r\n\r\nhttps://www.ixsystems.com/community/threads/guide-setting-up-transmission-with-openvpn-and-pia.24566/', 1, '2020-04-02 08:32:09', '2020-04-02 08:32:25', 3, 3, 0, 0, '', 1, 0,NULL,3);

Another example:

INSERT INTO `pages` (`id`, `book_id`, `chapter_id`, `name`, `slug`, `html`, `text`, `priority`, `created_at`, `updated_at`, `created_by`, `updated_by`, `restricted`, `draft`, `markdown`, `revision_count`, `template`, `deleted_at`, `owned_by`) VALUES
(6, 2, 1, 'Upgrading EMBY', 'upgrading-emby', '<p id=\"bkmrk-https%3A%2F%2Femby.media%2Fc\"><a href=\"https://emby.media/community/index.php?/topic/73417-4110-playback-errors-freenas-112/\" target=\"_blank\" rel=\"noopener\" shape=\"rect\">https://emby.media/community/index.php?/topic/73417-4110-playback-errors-freenas-112/</a></p>', 'https://emby.media/community/index.php?/topic/73417-4110-playback-errors-freenas-112/', 2, '2020-04-02 08:32:42', '2020-04-02 08:32:57', 3, 3, 0, 0, '', 1, 0,NULL,3);
@csjjpm commented on GitHub (Mar 26, 2021): Hi, some of my inserts work after fixing permissions and others fail. I think it could be some characters in the text which is failing. It could be pages which have http/s links in the text. This is the error ``` HP Warning: Module 'gd' already loaded in Unknown on line 0 PHP Warning: Module 'sqlite3' already loaded in Unknown on line 0 PHP Warning: Module 'pdo_sqlite' already loaded in Unknown on line 0 ErrorException : Trying to get property 'restricted' of non-object at /usr/local/www/BookStack/app/Auth/Permissions/PermissionService.php:462 458| 459| // For pages with a chapter, Check if explicit permissions areset on the Chapter 460| if ($entity instanceof Page && intval($entity->chapter_id) !==0) { 461| $chapter = $this->getChapter($entity->chapter_id); > 462| $hasPermissiveAccessToParents = $hasPermissiveAccessToParents && !$chapter->restricted; 463| if ($chapter->restricted) { 464| $hasExplicitAccessToParents = $this->mapHasActiveRestriction($permissionMap, $chapter, $role, $restrictionAction); 465| } 466| } Exception trace: 1 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError() /usr/local/www/BookStack/app/Auth/Permissions/PermissionService.php:462 2 BookStack\Auth\Permissions\PermissionService::createJointPermissionData() /usr/local/www/BookStack/app/Auth/Permissions/PermissionService.php:393 Please use the argument -v to see more details. Whoops\Exception\ErrorException : Module 'pdo_sqlite' already loaded at Unknown:0 1| Exception trace: 1 Whoops\Run::handleError() /usr/local/www/BookStack/vendor/filp/whoops/src/Whoops/Run.php:454 ``` This is the text: ``` INSERT INTO `pages` (`id`, `book_id`, `chapter_id`, `name`, `slug`, `html`, `text`, `priority`, `created_at`, `updated_at`, `created_by`, `updated_by`, `restricted`, `draft`, `markdown`, `revision_count`, `template`, `deleted_at`, `owned_by`) VALUES (5, 2, 1, 'PKG fixes', 'pkg-fixes', '<div id=\"bkmrk-to-enable-repository\">to enable repository access to other repositories</div>\r\n<div id=\"bkmrk-https%3A%2F%2Fwww.reddit.c\"><a href=\"https://www.reddit.com/r/freenas/comments/9ljgtz/unable_to_install_openvpn_in_transmission_jail/\" target=\"_blank\" rel=\"noopener\" shape=\"rect\">https://www.reddit.com/r/freenas/comments/9ljgtz/unable_to_install_openvpn_in_transmission_jail/</a></div>\r\n<div id=\"bkmrk-\"></div>\r\n<div id=\"bkmrk--0\"></div>\r\n<div id=\"bkmrk-https%3A%2F%2Fwww.ixsystem\">https://www.ixsystems.com/community/threads/guide-setting-up-transmission-with-openvpn-and-pia.24566/</div>', 'to enable repository access to other repositories\r\nhttps://www.reddit.com/r/freenas/comments/9ljgtz/unable_to_install_openvpn_in_transmission_jail/\r\n\r\n\r\nhttps://www.ixsystems.com/community/threads/guide-setting-up-transmission-with-openvpn-and-pia.24566/', 1, '2020-04-02 08:32:09', '2020-04-02 08:32:25', 3, 3, 0, 0, '', 1, 0,NULL,3); ``` Another example: ``` INSERT INTO `pages` (`id`, `book_id`, `chapter_id`, `name`, `slug`, `html`, `text`, `priority`, `created_at`, `updated_at`, `created_by`, `updated_by`, `restricted`, `draft`, `markdown`, `revision_count`, `template`, `deleted_at`, `owned_by`) VALUES (6, 2, 1, 'Upgrading EMBY', 'upgrading-emby', '<p id=\"bkmrk-https%3A%2F%2Femby.media%2Fc\"><a href=\"https://emby.media/community/index.php?/topic/73417-4110-playback-errors-freenas-112/\" target=\"_blank\" rel=\"noopener\" shape=\"rect\">https://emby.media/community/index.php?/topic/73417-4110-playback-errors-freenas-112/</a></p>', 'https://emby.media/community/index.php?/topic/73417-4110-playback-errors-freenas-112/', 2, '2020-04-02 08:32:42', '2020-04-02 08:32:57', 3, 3, 0, 0, '', 1, 0,NULL,3); ```
Author
Owner

@ssddanbrown commented on GitHub (Mar 26, 2021):

That error looks to be from running the regenerate permissions command, not from a database insert.

When are you running the regenerate permissions command? The system will rely on all content existing, with the correct IDs, including related items (Chapters, Books etc..) I'd only expect that to work if all original content was restored and existing.

There also appear to be issues with your environment since you're getting warnings about php modules being loaded more than once.

@ssddanbrown commented on GitHub (Mar 26, 2021): That error looks to be from running the regenerate permissions command, not from a database insert. When are you running the regenerate permissions command? The system will rely on all content existing, with the correct IDs, including related items (Chapters, Books etc..) I'd only expect that to work if all original content was restored and existing. There also appear to be issues with your environment since you're getting warnings about php modules being loaded more than once.
Author
Owner

@csjjpm commented on GitHub (Mar 27, 2021):

Hi. Yes the error was from the permissions command after inserting those lines.

I inserted line then ran permissions, inserted line ran permissions. Most passed and those above failed. The chapters, books etc had already been restored.

All the permissions that failed were on inserts containing http links.

@csjjpm commented on GitHub (Mar 27, 2021): Hi. Yes the error was from the permissions command after inserting those lines. I inserted line then ran permissions, inserted line ran permissions. Most passed and those above failed. The chapters, books etc had already been restored. All the permissions that failed were on inserts containing http links.
Author
Owner

@csjjpm commented on GitHub (Mar 27, 2021):

I created a new page and then copied in the text via the interface. Then ran permissions fix with no error.

There seems to be a way it has been stored and then exported as 'html' from your table that it breaks the permission function after inserting again.

@csjjpm commented on GitHub (Mar 27, 2021): I created a new page and then copied in the text via the interface. Then ran permissions fix with no error. There seems to be a way it has been stored and then exported as 'html' from your table that it breaks the permission function after inserting again.
Author
Owner

@csjjpm commented on GitHub (Mar 27, 2021):

Anyway, I only had a handful of pages to import and I've done them manually now. Thank you for making a great bit of software as I replaced my Evernote with this. I look forward to an Android app :-)

@csjjpm commented on GitHub (Mar 27, 2021): Anyway, I only had a handful of pages to import and I've done them manually now. Thank you for making a great bit of software as I replaced my Evernote with this. I look forward to an Android app :-)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2170