Fix Nextcloud 33/34 compatibility#240
Conversation
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
|
Thanks for this @tareko — confirming it fixes the removed One more spot is still needed for the app to actually load on NC34, though: $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: so the app enables in the DB but can't be loaded ( Heads-up on the "obvious" migration: porting the two Two ways forward:
Happy to send either as a follow-up commit to this branch if useful. |
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\Servergetter methods (getRootFolder,getConfig,getUserManager,getURLGenerator,getContentSecurityPolicyNonceManager, ...), deprecated since before Nextcloud 20. On NC 34.0.0 this makes Carnet fail with e.g.:when running
occ update:check, and breaks several app pages that call\OC::$server->getURLGenerator().Changes
IContainer::get()with the corresponding OCP interfaces (IConfig,IRootFolder,IUserManager,IUserSession) instead of the removedServerContainergetters. The app container falls back to the server container forOCP\\/OC\\service names, so this keeps working on older versions too.\OCP\Server::get(\OCP\IURLGenerator::class)and\OCP\Server::get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class)(the same call core uses inlib/private/Template/functions.php) when the legacy getters are gone, guarded bymethod_exists/class_existsso older Nextcloud and ownCloud keep working unchanged.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.max-versionto 34, bump version to 0.25.14 with a CHANGELOG entry.All edited files pass
php -l, and every API used was verified against thenextcloud/serverstable34 sources (including that the legacy\OC\FilespostWrite/postDelete hooks are still emitted byHookConnector).