Bookmarks: FoldersController._getRootFolderId() returning null instead of root folder id

Created on 18 Mar 2021  路  6Comments  路  Source: nextcloud/bookmarks

Log output

  • When trying to sync from Flocus Mozilla Firefox extention
Exception: Argument 1 passed to OCA\Bookmarks\Db\TreeMapper::getSubFolders() must be of the type int, null given, called in /usr/local/www/nextcloud/apps/bookmarks/lib/Controller/FoldersController.php on line 466

    /usr/local/www/nextcloud/lib/private/AppFramework/App.php - line 157:

    OC\AppFramework\Http\Dispatcher->dispatch()

    /usr/local/www/nextcloud/lib/private/Route/Router.php - line 302:

    OC\AppFramework\App::main()

    /usr/local/www/nextcloud/lib/base.php - line 993:

    OC\Route\Router->match()

    /usr/local/www/nextcloud/index.php - line 37:

    OC::handleRequest()

Caus茅 parTypeError: Argument 1 passed to OCA\Bookmarks\Db\TreeMapper::getSubFolders() must be of the type int, null given, called in /usr/local/www/nextcloud/apps/bookmarks/lib/Controller/FoldersController.php on line 466

    /usr/local/www/nextcloud/apps/bookmarks/lib/Controller/FoldersController.php - line 466:

    OCA\Bookmarks\Db\TreeMapper->getSubFolders()

    /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 218:

    OCA\Bookmarks\Controller\FoldersController->getFolders()

    /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 127:

    OC\AppFramework\Http\Dispatcher->executeController()

    /usr/local/www/nextcloud/lib/private/AppFramework/App.php - line 157:

    OC\AppFramework\Http\Dispatcher->dispatch()

    /usr/local/www/nextcloud/lib/private/Route/Router.php - line 302:

    OC\AppFramework\App::main()

    /usr/local/www/nextcloud/lib/base.php - line 993:

    OC\Route\Router->match()

    /usr/local/www/nextcloud/index.php - line 37:

    OC::handleRequest()
  • When trying to create a new bookmark folder from Nextcloud WebUI
Exception: Argument 1 passed to OCA\Bookmarks\Db\FolderMapper::find() must be of the type int, null given, called in /usr/local/www/nextcloud/apps/bookmarks/lib/Service/FolderService.php on line 108

    /usr/local/www/nextcloud/lib/private/AppFramework/App.php - line 157:

    OC\AppFramework\Http\Dispatcher->dispatch()

    /usr/local/www/nextcloud/lib/private/Route/Router.php - line 302:

    OC\AppFramework\App::main()

    /usr/local/www/nextcloud/lib/base.php - line 993:

    OC\Route\Router->match()

    /usr/local/www/nextcloud/index.php - line 37:

    OC::handleRequest()

Caus茅 parTypeError: Argument 1 passed to OCA\Bookmarks\Db\FolderMapper::find() must be of the type int, null given, called in /usr/local/www/nextcloud/apps/bookmarks/lib/Service/FolderService.php on line 108

    /usr/local/www/nextcloud/apps/bookmarks/lib/Service/FolderService.php - line 108:

    OCA\Bookmarks\Db\FolderMapper->find()

    /usr/local/www/nextcloud/apps/bookmarks/lib/Controller/FoldersController.php - line 196:

    OCA\Bookmarks\Service\FolderService->create()

    /usr/local/www/nextcloud/apps/bookmarks/lib/Controller/InternalFoldersController.php - line 38:

    OCA\Bookmarks\Controller\FoldersController->addFolder()

    /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 218:

    OCA\Bookmarks\Controller\InternalFoldersController->addFolder()

    /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 127:

    OC\AppFramework\Http\Dispatcher->executeController()

    /usr/local/www/nextcloud/lib/private/AppFramework/App.php - line 157:

    OC\AppFramework\Http\Dispatcher->dispatch()

    /usr/local/www/nextcloud/lib/private/Route/Router.php - line 302:

    OC\AppFramework\App::main()

    /usr/local/www/nextcloud/lib/base.php - line 993:

    OC\Route\Router->match()

    /usr/local/www/nextcloud/index.php - line 37:

    OC::handleRequest()

Quick investigation result

It looks like FoldersController.php#L106 is returning null.
This causes FoldersController.php#L133 returns null too and make sync/creation fails.

Environment

OS: FreeBSD 12.2-RELEASE-p3 amd64
Nextcloud: 21.0.0 (Official TrueNas plugin - Jail distro : 12.1-RELEASE-p13)
PHP: 7.4.15
MySQL: 5.7.33

bug

All 6 comments

Hey @ziouf

It could be that the user in question has multiple root folders assigned to them.

Could you run the following query in mysql?

SELECT * from oc_bookmarks_root_folders WHERE user_id = 'YOUR USER ID';

@marcelklehr

dbadmin@localhost [nextcloud]> SELECT * from oc_bookmarks_root_folders  WHERE user_id = 'cyril';
+---------+-----------+
| user_id | folder_id |
+---------+-----------+
| cyril   |         1 |
| cyril   |         2 |
+---------+-----------+
2 rows in set (0.00 sec)

How can it be possible to have multiple root folders ?

I'm not sure how this happens. Recovering with a DB backup may be a way to get to this state.

You can now try the following query to see which folder is empty and which one isn't:

SELECT * from oc_bookmarks_tree WHERE parent_folder = FOLDER_ID;

Substituting FOLDER_ID with the IDs from the last query.

The root folder that doesn't contain any items, can be safely deleted as follows:

DELETE from oc_bookmarks_root_folders WHERE folder_id = FOLDER_ID;

I think the likely cause of this is a race condition: When using the app for the first time, users don't have a root folder, yet. If multiple requests are sent to the server at the same time that require the creation of a root folder, the server will create multiple root folders.

@marcelklehr this is a credible hypothesis.
Because I'm on a fresh Nextcloud installation. I am the only user.

The issue happen after I tried to sync with Flocus Firefox extention to populate Nextcloud Bookmarks.

I ran

DELETE from oc_bookmarks_root_folders WHERE folder_id = 2;

After this, Flocus sync succeed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skoelzow picture skoelzow  路  4Comments

sunjam picture sunjam  路  4Comments

aproposnix picture aproposnix  路  6Comments

bernd-wechner picture bernd-wechner  路  4Comments

kc853 picture kc853  路  3Comments