Skip to content

Fix Nextcloud 33/34 compatibility#240

Open
tareko wants to merge 1 commit into
CarnetApp:mainfrom
tareko:fix/nextcloud-34
Open

Fix Nextcloud 33/34 compatibility#240
tareko wants to merge 1 commit into
CarnetApp:mainfrom
tareko:fix/nextcloud-34

Conversation

@tareko

@tareko tareko commented Jul 18, 2026

Copy link
Copy Markdown

Note: This PR was AI-assisted. I used opencode with Qwen 3.6 27B and Kimi K3, with Kimi K3 doing the code writing.

Fixes #238, refs #239.

Nextcloud 34 removed the long-deprecated OC\Server getter methods (getRootFolder, getConfig, getUserManager, getURLGenerator, getContentSecurityPolicyNonceManager, ...), deprecated since before Nextcloud 20. On NC 34.0.0 this makes Carnet fail with e.g.:

Call to undefined method OC\Server::getRootFolder()

when running occ update:check, and breaks several app pages that call \OC::$server->getURLGenerator().

Changes

  • lib/AppInfo/Application.php: resolve services via IContainer::get() with the corresponding OCP interfaces (IConfig, IRootFolder, IUserManager, IUserSession) instead of the removed ServerContainer getters. The app container falls back to the server container for OCP\\/OC\\ service names, so this keeps working on older versions too.
  • templates (writer, new_editor, importer, exporter, new_browser, browser, settings): fall back to \OCP\Server::get(\OCP\IURLGenerator::class) and \OCP\Server::get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class) (the same call core uses in lib/private/Template/functions.php) when the legacy getters are gone, guarded by method_exists/class_exists so older Nextcloud and ownCloud keep working unchanged.
  • lib/Settings/AdminSettings.php: the whole class declaration was wrapped in method_exists(\OC::$server, 'getContentSecurityPolicyNonceManager'), which means the class would not exist at all on NC34 (breaking admin settings registration). It is now defined unconditionally.
  • appinfo/info.xml: raise max-version to 34, bump version to 0.25.14 with a CHANGELOG entry.

All edited files pass php -l, and every API used was verified against the nextcloud/server stable34 sources (including that the legacy \OC\Files postWrite/postDelete hooks are still emitted by HookConnector).

Nextcloud 34 removed the long-deprecated OC\Server getter methods
(getRootFolder, getConfig, getUserManager, getURLGenerator,
getContentSecurityPolicyNonceManager, ...), causing fatal errors such
as "Call to undefined method OC\Server::getRootFolder()" (fixes CarnetApp#238,
refs CarnetApp#239).

- Application.php: resolve services via IContainer::get() with the
  corresponding OCP interfaces (IConfig, IRootFolder, IUserManager,
  IUserSession) instead of removed ServerContainer getters
- templates: fall back to \OCP\Server::get(IURLGenerator::class) and
  \OCP\Server::get(ContentSecurityPolicyNonceManager::class) (the same
  call core uses) when the legacy getters are gone, keeping backward
  compatibility with older Nextcloud/ownCloud versions
- AdminSettings: always define the class; the method_exists() guard
  around the class declaration made it disappear entirely on NC34
- info.xml: allow installation on Nextcloud 33/34, bump 0.25.14
@zentala

zentala commented Jul 24, 2026

Copy link
Copy Markdown

Thanks for this @tareko — confirming it fixes the removed OC\Server:: getters on Nextcloud 34 (refs #239, #238).

One more spot is still needed for the app to actually load on NC34, though: lib/AppInfo/Application.php::connectWatcher() still uses the legacy filesystem-hook API:

$root->listen('\OC\Files', 'postWrite',  function (Node $node) use ($container) { ... });
$root->listen('\OC\Files', 'postDelete', function (Node $node) use ($container) { ... });

On NC34 that throws during app bootstrap:

Error during app service registration: Class "OCA\Files\AppInfo\Application" not found
  at OC\Files\Node\LazyFolder->listen(...)  (Application.php:41)

so the app enables in the DB but can't be loaded (occ app:list --enabled won't show it).

Heads-up on the "obvious" migration: porting the two listen() calls to IEventDispatcher + NodeWrittenEvent/NodeDeletedEvent compiles and loads, but the listener then fires inside the write transaction, so re-processing the just-written node throws OCP\Lock\LockedException — which breaks editing notes (the sample note becomes uneditable). Verified on NC 34.0.0.

Two ways forward:

  1. Minimal stopgap — make connectWatcher() a no-op so the app loads and note create/edit (via NoteController) works; only the external-file-change watcher is lost:

    public function connectWatcher(IAppContainer $container) {
        return; // NC34: legacy $root->listen() hook API removed
    }
  2. Proper fix — event listeners that skip locked nodes (catch LockedException) or defer FSHooks to a background job, so the watcher survives without fighting the active write lock.

Happy to send either as a follow-up commit to this branch if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling "occ update:check" generate an error "Call to undefined method OC\Server::getRootFolder()"

2 participants