]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove OCP\App and OCP\BackgroundJob 32363/head
authorCarl Schwan <carl@carlschwan.eu>
Thu, 12 May 2022 15:08:54 +0000 (17:08 +0200)
committerCarl Schwan <carl@carlschwan.eu>
Mon, 1 Aug 2022 07:46:40 +0000 (09:46 +0200)
Both deprecated since NC 23

IAppManager is the replacement for OCP\App unfortunately it can't be
dependency injected in classes used by the installed otherwise the
database connection is initialised too early

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
28 files changed:
apps/dav/lib/Connector/Sabre/File.php
apps/encryption/templates/mail.php
apps/federatedfilesharing/lib/Controller/RequestHandlerController.php
apps/files_trashbin/lib/Trashbin.php
apps/provisioning_api/tests/Controller/AppsControllerTest.php
apps/user_ldap/templates/part.settingcontrols.php
apps/user_ldap/templates/part.wizardcontrols.php
core/Command/Maintenance/Repair.php
core/Command/User/ResetPassword.php
core/register_command.php
core/templates/installation.php
core/templates/layout.base.php
core/templates/layout.guest.php
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/AppFramework/App.php
lib/private/Console/Application.php
lib/private/Encryption/File.php
lib/private/Encryption/Util.php
lib/private/Server.php
lib/private/URLGenerator.php
lib/private/Updater.php
lib/private/legacy/OC_App.php
lib/public/App.php [deleted file]
lib/public/App/IAppManager.php
lib/public/BackgroundJob.php [deleted file]
tests/lib/Encryption/UtilTest.php
tests/lib/UrlGeneratorTest.php

index ebcfdabc6b3c097fda749157ff7e8b5c70ac1672..94632b265dbf582871d9f284874fd392aedce691 100644 (file)
@@ -553,7 +553,7 @@ class File extends Node implements IFile {
         * @return array|bool
         */
        public function getDirectDownload() {
-               if (\OCP\App::isEnabled('encryption')) {
+               if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) {
                        return [];
                }
                /** @var \OCP\Files\Storage $storage */
index 2cfd415b64610d2a8c810c587aeb0ddeea793497..0db4b67d08daa6473c1f4d01d52658532eacf475 100644 (file)
@@ -7,7 +7,7 @@
                        <table cellspacing="0" cellpadding="0" border="0" width="600px">
                                <tr>
                                        <td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>">
-                                               <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
+                                               <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('core', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
                                        </td>
                                </tr>
                                <tr><td colspan="2">&nbsp;</td></tr>
index fe0c7a11ab7bc19b9e83b6aa5efc493d56e0e0af..c5e1a8b4e7e9e6832c31fd942c8f46472ac275fb 100644 (file)
@@ -35,6 +35,7 @@ use OCP\AppFramework\OCS\OCSBadRequestException;
 use OCP\AppFramework\OCS\OCSException;
 use OCP\AppFramework\OCS\OCSForbiddenException;
 use OCP\AppFramework\OCSController;
+use OCP\App\IAppManager;
 use OCP\Constants;
 use OCP\EventDispatcher\IEventDispatcher;
 use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
@@ -366,7 +367,7 @@ class RequestHandlerController extends OCSController {
         * @return bool
         */
        private function isS2SEnabled($incoming = false) {
-               $result = \OCP\App::isEnabled('files_sharing');
+               $result = \OCP\Server::get(IAppManager::class)->isEnabledForUser('files_sharing');
 
                if ($incoming) {
                        $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
index d449a136016e1e5111b078b302d8196d32c5f96a..975e9fd2557fd1d716663c507aa270ba1a3d701d 100644 (file)
@@ -54,6 +54,7 @@ use OC\Files\View;
 use OCA\Files_Trashbin\AppInfo\Application;
 use OCA\Files_Trashbin\Command\Expire;
 use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\App\IAppManager;
 use OCP\Files\File;
 use OCP\Files\Folder;
 use OCP\Files\NotFoundException;
@@ -395,7 +396,7 @@ class Trashbin {
         * @param integer $timestamp when the file was deleted
         */
        private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
-               if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
+               if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions') && !empty($ownerPath)) {
                        $user = OC_User::getUser();
                        $rootView = new View('/');
 
@@ -543,7 +544,7 @@ class Trashbin {
         * @return false|null
         */
        private static function restoreVersions(View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
-               if (\OCP\App::isEnabled('files_versions')) {
+               if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
                        $user = OC_User::getUser();
                        $rootView = new View('/');
 
@@ -704,7 +705,7 @@ class Trashbin {
         */
        private static function deleteVersions(View $view, $file, $filename, $timestamp, $user) {
                $size = 0;
-               if (\OCP\App::isEnabled('files_versions')) {
+               if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
                        if ($view->is_dir('files_trashbin/versions/' . $file)) {
                                $size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
                                $view->unlink('files_trashbin/versions/' . $file);
index d4237508a315d022dbdef9b8407e845fd1d6a0e3..187247b9f660f3afc40d89b0240e08b6410433c0 100644 (file)
@@ -67,7 +67,7 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
 
        public function testGetAppInfo() {
                $result = $this->api->getAppInfo('provisioning_api');
-               $expected = \OC_App::getAppInfo('provisioning_api');
+               $expected = $this->appManager->getAppInfo('provisioning_api');
                $this->assertEquals($expected, $result->getData());
        }
 
index a418885f47ed2e7a74b5c71a33e0bb98fb660f1a..97f80bc13f798b1101cdeac707749564dfa63fdc 100644 (file)
@@ -4,7 +4,7 @@
        </button>
        <a href="<?php p(link_to_docs('admin-ldap')); ?>"
                target="_blank" rel="noreferrer noopener">
-               <img src="<?php print_unescaped(image_path('', 'actions/info.svg')); ?>"
+               <img src="<?php print_unescaped(image_path('core', 'actions/info.svg')); ?>"
                        style="height:1.75ex" />
                <?php p($l->t('Help'));?>
        </a>
index bd84b23c76dbe02563d4d89f8b23eb9ec7f4af21..d9a6fab60e70448ae02fa3a9a436aa4d8036643f 100644 (file)
@@ -10,7 +10,7 @@
        </button>
        <a href="<?php p(link_to_docs('admin-ldap')); ?>"
                target="_blank" rel="noreferrer noopener">
-               <img src="<?php print_unescaped(image_path('', 'actions/info.svg')); ?>"
+               <img src="<?php print_unescaped(image_path('core', 'actions/info.svg')); ?>"
                        style="height:1.75ex" />
                <span class="ldap_grey"><?php p($l->t('Help'));?></span>
        </a>
index aa0f6a2a08648629713c9f1eb2b5ab6a934bf0dc..2c1fda7c8e4d94e3e1e07f141d20e1c92a6f62db 100644 (file)
@@ -82,7 +82,7 @@ class Repair extends Command {
                        if (!$this->appManager->isEnabledForUser($app)) {
                                continue;
                        }
-                       $info = \OC_App::getAppInfo($app);
+                       $info = $this->appManager->getAppInfo($app);
                        if (!is_array($info)) {
                                continue;
                        }
index 21bc5cc45b0003b1b8cd9056e67fa3ea542441a7..294cea38b7104fd1196f01cc8f8ed22ddd5c8270 100644 (file)
@@ -28,6 +28,7 @@
 namespace OC\Core\Command\User;
 
 use OC\Core\Command\Base;
+use OCP\App\IAppManager;
 use OCP\IUser;
 use OCP\IUserManager;
 use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
@@ -41,10 +42,12 @@ use Symfony\Component\Console\Question\Question;
 
 class ResetPassword extends Base {
        protected IUserManager $userManager;
+       private IAppManager $appManager;
 
-       public function __construct(IUserManager $userManager) {
-               $this->userManager = $userManager;
+       public function __construct(IUserManager $userManager, IAppManager $appManager) {
                parent::__construct();
+               $this->userManager = $userManager;
+               $this->appManager = $appManager;
        }
 
        protected function configure() {
@@ -84,7 +87,7 @@ class ResetPassword extends Base {
                        /** @var QuestionHelper $helper */
                        $helper = $this->getHelper('question');
 
-                       if (\OCP\App::isEnabled('encryption')) {
+                       if ($this->appManager->isEnabledForUser('encryption', $user)) {
                                $output->writeln(
                                        '<error>Warning: Resetting the password when using encryption will result in data loss!</error>'
                                );
index d80465e09066eb1cff2205b9d442b23fbd0c985a..98a653aed7e417edeb15eb608fa0d37044866ebb 100644 (file)
@@ -183,7 +183,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
        $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
        $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
        $application->add(\OC::$server->get(\OC\Core\Command\User\Report::class));
-       $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
+       $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager(), \OC::$server->getAppManager()));
        $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig()));
        $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
        $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
index b08f1cd9ac12d879c954a484d2ca6497c52000ac..45d9cfc925288b0c414f9073132d49289f9c10fa 100644 (file)
@@ -55,7 +55,7 @@ script('core', 'install');
 
        <?php if (!$_['directoryIsSet'] or !$_['dbIsSet'] or count($_['errors']) > 0): ?>
        <fieldset id="advancedHeader">
-               <legend><a id="showAdvanced" tabindex="0" href="#"><?php p($l->t('Storage & database')); ?><img src="<?php print_unescaped(image_path('', 'actions/caret.svg')); ?>" /></a></legend>
+               <legend><a id="showAdvanced" tabindex="0" href="#"><?php p($l->t('Storage & database')); ?><img src="<?php print_unescaped(image_path('core', 'actions/caret.svg')); ?>" /></a></legend>
        </fieldset>
        <?php endif; ?>
 
index 0eb80098889fcc24effb66d8a168ae0a83f795e1..d8a54bfec2e3eec8daa6bc03d80c48b2d865e1e1 100644 (file)
@@ -7,9 +7,9 @@
                </title>
                <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
                <meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>">
-               <link rel="icon" href="<?php print_unescaped(image_path('', 'favicon.ico')); /* IE11+ supports png */ ?>">
-               <link rel="apple-touch-icon" href="<?php print_unescaped(image_path('', 'favicon-touch.png')); ?>">
-               <link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
+               <link rel="icon" href="<?php print_unescaped(image_path('core', 'favicon.ico')); /* IE11+ supports png */ ?>">
+               <link rel="apple-touch-icon" href="<?php print_unescaped(image_path('core', 'favicon-touch.png')); ?>">
+               <link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('core', 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
                <?php emit_css_loading_tags($_); ?>
                <?php emit_script_loading_tags($_); ?>
                <?php print_unescaped($_['headers']); ?>
index 432bc4e860188bdfda384fb7e0c23320a3bbadc8..c275d9746b719af5511b845445d3e6dbe91f9f1a 100644 (file)
                <meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>">
                <?php } ?>
                <meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>">
-               <link rel="icon" href="<?php print_unescaped(image_path('', 'favicon.ico')); /* IE11+ supports png */ ?>">
-               <link rel="apple-touch-icon" href="<?php print_unescaped(image_path('', 'favicon-touch.png')); ?>">
-               <link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
-               <link rel="manifest" href="<?php print_unescaped(image_path('', 'manifest.json')); ?>">
+               <link rel="icon" href="<?php print_unescaped(image_path('core', 'favicon.ico')); /* IE11+ supports png */ ?>">
+               <link rel="apple-touch-icon" href="<?php print_unescaped(image_path('core', 'favicon-touch.png')); ?>">
+               <link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('core', 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
+               <link rel="manifest" href="<?php print_unescaped(image_path('core', 'manifest.json')); ?>">
                <?php emit_css_loading_tags($_); ?>
                <?php emit_script_loading_tags($_); ?>
                <?php print_unescaped($_['headers']); ?>
index 8853c1f17f48de2216e86e524715510c96d36b7d..b23f8b1fb6c11663f82e960b2397b4643c4cd987 100644 (file)
@@ -21,7 +21,6 @@ return array(
     'OCP\\Activity\\IManager' => $baseDir . '/lib/public/Activity/IManager.php',
     'OCP\\Activity\\IProvider' => $baseDir . '/lib/public/Activity/IProvider.php',
     'OCP\\Activity\\ISetting' => $baseDir . '/lib/public/Activity/ISetting.php',
-    'OCP\\App' => $baseDir . '/lib/public/App.php',
     'OCP\\AppFramework\\ApiController' => $baseDir . '/lib/public/AppFramework/ApiController.php',
     'OCP\\AppFramework\\App' => $baseDir . '/lib/public/AppFramework/App.php',
     'OCP\\AppFramework\\AuthPublicShareController' => $baseDir . '/lib/public/AppFramework/AuthPublicShareController.php',
@@ -110,7 +109,6 @@ return array(
     'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderForUserDisabled' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderForUserDisabled.php',
     'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderForUserEnabled' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderForUserEnabled.php',
     'OCP\\AutoloadNotAllowedException' => $baseDir . '/lib/public/AutoloadNotAllowedException.php',
-    'OCP\\BackgroundJob' => $baseDir . '/lib/public/BackgroundJob.php',
     'OCP\\BackgroundJob\\IJob' => $baseDir . '/lib/public/BackgroundJob/IJob.php',
     'OCP\\BackgroundJob\\IJobList' => $baseDir . '/lib/public/BackgroundJob/IJobList.php',
     'OCP\\BackgroundJob\\Job' => $baseDir . '/lib/public/BackgroundJob/Job.php',
index 5617430958d5d94eed7e7d2dfe169dbd71a6883e..f29c3f97da2ad7936b7e29bcf050d5790db59f5d 100644 (file)
@@ -54,7 +54,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
         'OCP\\Activity\\IManager' => __DIR__ . '/../../..' . '/lib/public/Activity/IManager.php',
         'OCP\\Activity\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Activity/IProvider.php',
         'OCP\\Activity\\ISetting' => __DIR__ . '/../../..' . '/lib/public/Activity/ISetting.php',
-        'OCP\\App' => __DIR__ . '/../../..' . '/lib/public/App.php',
         'OCP\\AppFramework\\ApiController' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ApiController.php',
         'OCP\\AppFramework\\App' => __DIR__ . '/../../..' . '/lib/public/AppFramework/App.php',
         'OCP\\AppFramework\\AuthPublicShareController' => __DIR__ . '/../../..' . '/lib/public/AppFramework/AuthPublicShareController.php',
@@ -143,7 +142,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
         'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderForUserDisabled' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderForUserDisabled.php',
         'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderForUserEnabled' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderForUserEnabled.php',
         'OCP\\AutoloadNotAllowedException' => __DIR__ . '/../../..' . '/lib/public/AutoloadNotAllowedException.php',
-        'OCP\\BackgroundJob' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob.php',
         'OCP\\BackgroundJob\\IJob' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IJob.php',
         'OCP\\BackgroundJob\\IJobList' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IJobList.php',
         'OCP\\BackgroundJob\\Job' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/Job.php',
index feebb32d5bcd6ea27ffe9972e8636c4c7d3c8934..170acba068956d233d3e4e3e4d3a5a0a36451910 100644 (file)
@@ -237,8 +237,6 @@ class App {
        /**
         * Shortcut for calling a controller method and printing the result.
         * Similar to App:main except that no headers will be sent.
-        * This should be used for example when registering sections via
-        * \OC\AppFramework\Core\API::registerAdmin()
         *
         * @param string $controllerName the name of the controller under which it is
         *                               stored in the DI container
index 12d54b48fa97ee8edcc5f11831e31efc1be81364..fc48f57e4995dfa370d4114322806b4f866a8bbd 100644 (file)
@@ -34,6 +34,7 @@ use OC\MemoryInfo;
 use OC\NeedsUpdateException;
 use OC_App;
 use OCP\AppFramework\QueryException;
+use OCP\App\IAppManager;
 use OCP\Console\ConsoleEvent;
 use OCP\IConfig;
 use OCP\IRequest;
@@ -117,13 +118,14 @@ class Application {
                                        $this->writeMaintenanceModeInfo($input, $output);
                                } else {
                                        OC_App::loadApps();
-                                       foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
+                                       $appManager = \OCP\Server::get(IAppManager::class);
+                                       foreach ($appManager->getInstalledApps() as $app) {
                                                $appPath = \OC_App::getAppPath($app);
                                                if ($appPath === false) {
                                                        continue;
                                                }
                                                // load commands using info.xml
-                                               $info = \OC_App::getAppInfo($app);
+                                               $info = $appManager->getAppInfo($app);
                                                if (isset($info['commands'])) {
                                                        $this->loadCommandsFromInfoXml($info['commands']);
                                                }
index 844059923bd9f53f88cf1e41322d47471e033454..87bc35bc1590c49ed95c01b17f8e90ce077a500d 100644 (file)
@@ -29,27 +29,22 @@ namespace OC\Encryption;
 
 use OCP\Cache\CappedMemoryCache;
 use OCA\Files_External\Service\GlobalStoragesService;
+use OCP\App\IAppManager;
 use OCP\Files\IRootFolder;
 use OCP\Files\NotFoundException;
 use OCP\Share\IManager;
 
 class File implements \OCP\Encryption\IFile {
-
-       /** @var Util */
-       protected $util;
-
-       /** @var IRootFolder */
-       private $rootFolder;
-
-       /** @var IManager */
-       private $shareManager;
+       protected Util $util;
+       private IRootFolder $rootFolder;
+       private IManager $shareManager;
 
        /**
-        * cache results of already checked folders
-        *
+        * Cache results of already checked folders
         * @var CappedMemoryCache<array>
         */
        protected CappedMemoryCache $cache;
+       private ?IAppManager $appManager = null;
 
        public function __construct(Util $util,
                                                                IRootFolder $rootFolder,
@@ -60,6 +55,14 @@ class File implements \OCP\Encryption\IFile {
                $this->shareManager = $shareManager;
        }
 
+       public function getAppManager(): IAppManager {
+               // Lazy evaluate app manager as it initialize the db too early otherwise
+               if ($this->appManager) {
+                       return $this->appManager;
+               }
+               $this->appManager = \OCP\Server::get(IAppManager::class);
+               return $this->appManager;
+       }
 
        /**
         * Get list of users with access to the file
@@ -110,7 +113,7 @@ class File implements \OCP\Encryption\IFile {
                }
 
                // check if it is a group mount
-               if (\OCP\App::isEnabled("files_external")) {
+               if ($this->getAppManager()->isEnabledForUser("files_external")) {
                        /** @var GlobalStoragesService $storageService */
                        $storageService = \OC::$server->get(GlobalStoragesService::class);
                        $storages = $storageService->getAllStorages();
index 174af2e8b8995ed82af8289e4aa57f3b60ae5a36..410ea19da81245e05262f32d068a84a27c7d0faf 100644 (file)
@@ -34,9 +34,12 @@ use OC\Files\Filesystem;
 use OC\Files\View;
 use OCA\Files_External\Lib\StorageConfig;
 use OCA\Files_External\Service\GlobalStoragesService;
+use OCP\App\IAppManager;
 use OCP\Encryption\IEncryptionModule;
 use OCP\IConfig;
+use OCP\IGroupManager;
 use OCP\IUser;
+use OCP\IUserManager;
 
 class Util {
        public const HEADER_START = 'HBEGIN';
@@ -65,29 +68,23 @@ class Util {
        /** @var array */
        protected $ocHeaderKeys;
 
-       /** @var \OC\User\Manager */
-       protected $userManager;
-
        /** @var IConfig */
        protected $config;
 
        /** @var array paths excluded from encryption */
        protected $excludedPaths;
-
-       /** @var \OC\Group\Manager $manager */
-       protected $groupManager;
+       protected IGroupManager $groupManager;
+       protected IUserManager $userManager;
 
        /**
         *
         * @param View $rootView
-        * @param \OC\User\Manager $userManager
-        * @param \OC\Group\Manager $groupManager
         * @param IConfig $config
         */
        public function __construct(
                View $rootView,
-               \OC\User\Manager $userManager,
-               \OC\Group\Manager $groupManager,
+               IUserManager $userManager,
+               IGroupManager $groupManager,
                IConfig $config) {
                $this->ocHeaderKeys = [
                        self::HEADER_ENCRYPTION_MODULE_KEY
@@ -275,7 +272,7 @@ class Util {
                } else {
                        $result = array_merge($result, $users);
 
-                       $groupManager = \OC::$server->getGroupManager();
+                       $groupManager = $this->groupManager;
                        foreach ($groups as $group) {
                                $groupObject = $groupManager->get($group);
                                if ($groupObject) {
@@ -299,7 +296,8 @@ class Util {
         * @return boolean
         */
        public function isSystemWideMountPoint($path, $uid) {
-               if (\OCP\App::isEnabled("files_external")) {
+               // No DI here as this initialise the db too soon
+               if (\OCP\Server::get(IAppManager::class)->isEnabledForUser("files_external")) {
                        /** @var GlobalStoragesService $storageService */
                        $storageService = \OC::$server->get(GlobalStoragesService::class);
                        $storages = $storageService->getAllStorages();
@@ -377,32 +375,29 @@ class Util {
        }
 
        /**
-        * check if recovery key is enabled for user
-        *
-        * @param string $uid
-        * @return boolean
+        * Check if recovery key is enabled for user
         */
-       public function recoveryEnabled($uid) {
+       public function recoveryEnabled(string $uid): bool {
                $enabled = $this->config->getUserValue($uid, 'encryption', 'recovery_enabled', '0');
 
                return $enabled === '1';
        }
 
        /**
-        * set new key storage root
+        * Set new key storage root
         *
         * @param string $root new key store root relative to the data folder
         */
-       public function setKeyStorageRoot($root) {
+       public function setKeyStorageRoot(string $root): void {
                $this->config->setAppValue('core', 'encryption_key_storage_root', $root);
        }
 
        /**
-        * get key storage root
+        * Get key storage root
         *
         * @return string key storage root
         */
-       public function getKeyStorageRoot() {
+       public function getKeyStorageRoot(): string {
                return $this->config->getAppValue('core', 'encryption_key_storage_root', '');
        }
 }
index 842f72fa1d098bfdba53aa379d505cf6614d2331..b473f4e75c00af80c5a1e841496e762ab0db3407 100644 (file)
@@ -353,7 +353,7 @@ class Server extends ServerContainer implements IServerContainer {
                        return new Profiler($c->get(SystemConfig::class));
                });
 
-               $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
+               $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager {
                        $view = new View();
                        $util = new Encryption\Util(
                                $view,
index 47979a038bae0e195395293b7d9e0d3a25112c7a..6115d4a221e32a39f43ea5d8100234dce167d202 100644 (file)
@@ -42,6 +42,8 @@ namespace OC;
 
 use OC\Route\Router;
 use OCA\Theming\ThemingDefaults;
+use OCP\App\AppPathNotFoundException;
+use OCP\App\IAppManager;
 use OCP\ICacheFactory;
 use OCP\IConfig;
 use OCP\IRequest;
@@ -65,12 +67,14 @@ class URLGenerator implements IURLGenerator {
        private $router;
        /** @var null|string */
        private $baseUrl = null;
+       private ?IAppManager $appManager = null;
 
        public function __construct(IConfig $config,
                                                                IUserSession $userSession,
                                                                ICacheFactory $cacheFactory,
                                                                IRequest $request,
-                                                               Router $router) {
+                                                               Router $router
+       ) {
                $this->config = $config;
                $this->userSession = $userSession;
                $this->cacheFactory = $cacheFactory;
@@ -78,6 +82,14 @@ class URLGenerator implements IURLGenerator {
                $this->router = $router;
        }
 
+       private function getAppManager(): IAppManager {
+               if ($this->appManager !== null) {
+                       return $this->appManager;
+               }
+               $this->appManager = \OCP\Server::get(IAppManager::class);
+               return $this->appManager;
+       }
+
        /**
         * Creates an url using a defined route
         *
@@ -132,7 +144,7 @@ class URLGenerator implements IURLGenerator {
                $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
 
                if ($appName !== '') {
-                       $app_path = \OC_App::getAppPath($appName);
+                       $app_path = $this->getAppManager()->getAppPath($appName);
                        // Check if the app is in the app folder
                        if ($app_path && file_exists($app_path . '/' . $file)) {
                                if (substr($file, -3) === 'php') {
@@ -142,7 +154,7 @@ class URLGenerator implements IURLGenerator {
                                        }
                                        $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : '';
                                } else {
-                                       $urlLinkTo = \OC_App::getAppWebPath($appName) . '/' . $file;
+                                       $urlLinkTo = $this->getAppManager()->getAppWebPath($appName) . '/' . $file;
                                }
                        } else {
                                $urlLinkTo = \OC::$WEBROOT . '/' . $appName . '/' . $file;
@@ -189,11 +201,20 @@ class URLGenerator implements IURLGenerator {
                //if a theme has a png but not an svg always use the png
                $basename = substr(basename($file), 0, -4);
 
-               $appPath = \OC_App::getAppPath($appName);
+               try {
+                       $appPath = $this->getAppManager()->getAppPath($appName);
+               } catch (AppPathNotFoundException $e) {
+                       if ($appName === 'core' || $appName === '') {
+                               $appName = 'core';
+                               $appPath = false;
+                       } else {
+                               throw new RuntimeException('image not found: image: ' . $file . ' webroot: ' . \OC::$WEBROOT . ' serverroot: ' . \OC::$SERVERROOT);
+                       }
+               }
 
                // Check if the app is in the app folder
                $path = '';
-               $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming');
+               $themingEnabled = $this->config->getSystemValue('installed', false) && $this->getAppManager()->isEnabledForUser('theming');
                $themingImagePath = false;
                if ($themingEnabled) {
                        $themingDefaults = \OC::$server->getThemingDefaults();
@@ -220,10 +241,10 @@ class URLGenerator implements IURLGenerator {
                } elseif ($themingEnabled && $themingImagePath) {
                        $path = $themingImagePath;
                } elseif ($appPath && file_exists($appPath . "/img/$file")) {
-                       $path = \OC_App::getAppWebPath($appName) . "/img/$file";
+                       $path = $this->getAppManager()->getAppWebPath($appName) . "/img/$file";
                } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
                        && file_exists($appPath . "/img/$basename.png")) {
-                       $path = \OC_App::getAppWebPath($appName) . "/img/$basename.png";
+                       $path = $this->getAppManager()->getAppWebPath($appName) . "/img/$basename.png";
                } elseif (!empty($appName) and file_exists(\OC::$SERVERROOT . "/$appName/img/$file")) {
                        $path = \OC::$WEBROOT . "/$appName/img/$file";
                } elseif (!empty($appName) and (!file_exists(\OC::$SERVERROOT . "/$appName/img/$basename.svg")
index 2c06cffcb199d0a2bfb9aef21c3d1d8a2a360b70..da989c4db91c353e8fd2f9608000ecd76df6a539 100644 (file)
@@ -378,7 +378,7 @@ class Updater extends BasicEmitter {
                $appManager = \OC::$server->getAppManager();
                foreach ($apps as $app) {
                        // check if the app is compatible with this version of Nextcloud
-                       $info = OC_App::getAppInfo($app);
+                       $info = $appManager->getAppInfo($app);
                        if ($info === null || !OC_App::isAppCompatible($version, $info)) {
                                if ($appManager->isShipped($app)) {
                                        throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
index 9fa13a56d3842ce1fe37e8fcff96c3db492e9b11..482fc4e88e7d622997b5ec90acfd6a0ca743b85a 100644 (file)
@@ -678,25 +678,6 @@ class OC_App {
                return $forms;
        }
 
-       /**
-        * register an admin form to be shown
-        *
-        * @param string $app
-        * @param string $page
-        */
-       public static function registerAdmin(string $app, string $page) {
-               self::$adminForms[] = $app . '/' . $page . '.php';
-       }
-
-       /**
-        * register a personal form to be shown
-        * @param string $app
-        * @param string $page
-        */
-       public static function registerPersonal(string $app, string $page) {
-               self::$personalForms[] = $app . '/' . $page . '.php';
-       }
-
        /**
         * @param array $entry
         * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface
diff --git a/lib/public/App.php b/lib/public/App.php
deleted file mode 100644 (file)
index 5103e62..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Frank Karlitschek <frank@karlitschek.de>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-// use OCP namespace for all classes that are considered public.
-// This means that they should be used by apps instead of the internal ownCloud classes
-
-namespace OCP;
-
-/**
- * This class provides functions to manage apps in ownCloud
- * @since 4.0.0
- * @deprecated 14.0.0
- */
-class App {
-
-
-       /**
-        * Register a Configuration Screen that should appear in the personal settings section.
-        * @param string $app appid
-        * @param string $page page to be included
-        * @return void
-        * @since 4.0.0
-        * @deprecated 14.0.0 Use settings section in appinfo.xml to register personal admin sections
-        */
-       public static function registerPersonal($app, $page) {
-               \OC_App::registerPersonal($app, $page);
-       }
-
-       /**
-        * Register a Configuration Screen that should appear in the Admin section.
-        * @param string $app string appid
-        * @param string $page string page to be included
-        * @return void
-        * @since 4.0.0
-        * @deprecated 14.0.0 Use settings section in appinfo.xml to register admin sections
-        */
-       public static function registerAdmin($app, $page) {
-               \OC_App::registerAdmin($app, $page);
-       }
-
-       /**
-        * Read app metadata from the info.xml file
-        * @param string $app id of the app or the path of the info.xml file
-        * @param boolean $path (optional)
-        * @return array|null
-        * @deprecated 14.0.0 ise \OC::$server->getAppManager()->getAppInfo($appId)
-        * @since 4.0.0
-        */
-       public static function getAppInfo($app, $path = false) {
-               return \OC_App::getAppInfo($app, $path);
-       }
-
-       /**
-        * checks whether or not an app is enabled
-        * @param string $app
-        * @return boolean
-        *
-        * This function checks whether or not an app is enabled.
-        * @since 4.0.0
-        * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
-        */
-       public static function isEnabled($app) {
-               return \OC::$server->getAppManager()->isEnabledForUser($app);
-       }
-
-       /**
-        * Get the last version of the app from appinfo/info.xml
-        * @param string $app
-        * @return string
-        * @since 4.0.0
-        * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion($appId)
-        */
-       public static function getAppVersion($app) {
-               return \OC::$server->getAppManager()->getAppVersion($app);
-       }
-}
index 7473b22942713f46abe8d24d5fcb8bd5a3f14305..e0b5c049290d6d73fc8b327835868cc3b884cc4b 100644 (file)
@@ -36,6 +36,9 @@ use OCP\IUser;
 /**
  * Interface IAppManager
  *
+ * @warning This interface shouldn't be included with dependency injection in
+ *          classes used for installing Nextcloud.
+ *
  * @since 8.0.0
  */
 interface IAppManager {
diff --git a/lib/public/BackgroundJob.php b/lib/public/BackgroundJob.php
deleted file mode 100644 (file)
index 2be11ab..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Jakob Sack <mail@jakobsack.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OCP;
-
-/**
- * @since 4.5.0
- * @deprecated 14.0.0
- */
-class BackgroundJob {
-       /**
-        * @since 5.0.0
-        * @deprecated 14.0.0
-        */
-       public static function getExecutionType() {
-               return '';
-       }
-
-       /**
-        * @since 5.0.0
-        * @deprecated 14.0.0
-        */
-       public static function setExecutionType($type) {
-       }
-}
index 02155be11ddab2fb4416dced481ab1729325fff4..248377fc698e96662dfa67401e33bf5ea3d45ca3 100644 (file)
@@ -8,6 +8,8 @@ use OCA\Files_External\Lib\StorageConfig;
 use OCA\Files_External\Service\GlobalStoragesService;
 use OCP\Encryption\IEncryptionModule;
 use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\IUserManager;
 use Test\TestCase;
 
 class UtilTest extends TestCase {
@@ -15,24 +17,21 @@ class UtilTest extends TestCase {
        /**
         * block size will always be 8192 for a PHP stream
         * @see https://bugs.php.net/bug.php?id=21641
-        * @var integer
         */
-       protected $headerSize = 8192;
+       protected int $headerSize = 8192;
 
        /** @var \PHPUnit\Framework\MockObject\MockObject */
        protected $view;
 
-       /** @var \PHPUnit\Framework\MockObject\MockObject */
+       /** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
        protected $userManager;
 
-       /** @var \PHPUnit\Framework\MockObject\MockObject */
+       /** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
        protected $groupManager;
 
-       /** @var \PHPUnit\Framework\MockObject\MockObject */
+       /** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
        private $config;
-
-       /** @var  \OC\Encryption\Util */
-       private $util;
+       private Util $util;
 
        protected function setUp(): void {
                parent::setUp();
@@ -40,17 +39,9 @@ class UtilTest extends TestCase {
                        ->disableOriginalConstructor()
                        ->getMock();
 
-               $this->userManager = $this->getMockBuilder('OC\User\Manager')
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $this->groupManager = $this->getMockBuilder('OC\Group\Manager')
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $this->config = $this->getMockBuilder(IConfig::class)
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $this->userManager = $this->createMock(IUserManager::class);
+               $this->groupManager = $this->createMock(IGroupManager::class);
+               $this->config = $this->createMock(IConfig::class);
 
                $this->util = new Util(
                        $this->view,
index 9e5795fc41e5351cefbdf666fad24a545b4d851e..7fdbb7fb37ea76206e2906111bf8285f0a501d1c 100644 (file)
@@ -297,7 +297,7 @@ class UrlGeneratorTest extends \Test\TestCase {
                $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl());
        }
 
-       public function provideDefaultApps() {
+       public function provideDefaultApps(): array {
                return [
                        // none specified, default to files
                        [
@@ -321,4 +321,18 @@ class UrlGeneratorTest extends \Test\TestCase {
                        ],
                ];
        }
+
+       public function imagePathProvider(): array {
+               return [
+                       ['core', 'favicon-mask.svg', \OC::$WEBROOT . '/core/img/favicon-mask.svg'],
+                       ['files', 'external.svg', \OC::$WEBROOT . '/apps/files/img/external.svg'],
+               ];
+       }
+
+       /**
+        * @dataProvider imagePathProvider
+        */
+       public function testImagePath(string $appName, string $file, string $result): void {
+               $this->assertSame($result, $this->urlGenerator->imagePath($appName, $file));
+       }
 }