Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-03-02 21:38:21 +0300
committerRobin Appelman <robin@icewind.nl>2022-03-04 18:30:09 +0300
commitd81713e5c10baf8e14f9a8c4906d0255b18cbb1f (patch)
treec496d4c02ca5424b6ca2a697a3131d5e66f7e7a9
parent6c1d051ecd8bb4d76761da2c25d274e703a2fb97 (diff)
simplify setup of circular SetupManager<->Manager
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--apps/files_external/tests/PersonalMountTest.php8
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php8
-rw-r--r--lib/private/Files/Mount/Manager.php15
-rw-r--r--lib/private/Files/SetupManagerFactory.php58
-rw-r--r--tests/lib/Files/Mount/ManagerTest.php8
5 files changed, 68 insertions, 29 deletions
diff --git a/apps/files_external/tests/PersonalMountTest.php b/apps/files_external/tests/PersonalMountTest.php
index ff33f8e21a7..024695b0188 100644
--- a/apps/files_external/tests/PersonalMountTest.php
+++ b/apps/files_external/tests/PersonalMountTest.php
@@ -25,6 +25,7 @@
namespace OCA\Files_External\Tests;
use OC\Files\Mount\Manager;
+use OC\Files\SetupManagerFactory;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
use OCP\Diagnostics\IEventLogger;
@@ -51,12 +52,7 @@ class PersonalMountTest extends TestCase {
$mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo');
- $mountManager = new Manager(
- $this->createMock(IEventLogger::class),
- $this->createMock(IMountProviderCollection::class),
- $this->createMock(IUserManager::class),
- $this->createMock(IEventDispatcher::class)
- );
+ $mountManager = new Manager($this->createMock(SetupManagerFactory::class));
$mountManager->addMount($mount);
$this->assertEquals([$mount], $mountManager->findByStorageId('dummy'));
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index b6e9593918c..307b630970f 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -32,6 +32,7 @@ namespace OCA\Files_Sharing\Tests\External;
use OC\Federation\CloudIdManager;
use OC\Files\SetupManager;
+use OC\Files\SetupManagerFactory;
use OC\Files\Storage\StorageFactory;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider;
@@ -107,12 +108,7 @@ class ManagerTest extends TestCase {
$this->uid = $this->getUniqueID('user');
$this->user = $this->createUser($this->uid, '');
- $this->mountManager = new \OC\Files\Mount\Manager(
- $this->createMock(IEventLogger::class),
- $this->createMock(IMountProviderCollection::class),
- $this->createMock(IUserManager::class),
- $this->createMock(IEventDispatcher::class)
- );
+ $this->mountManager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
$this->clientService = $this->getMockBuilder(IClientService::class)
->disableOriginalConstructor()->getMock();
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php
index fc78d71adb4..5544b218658 100644
--- a/lib/private/Files/Mount/Manager.php
+++ b/lib/private/Files/Mount/Manager.php
@@ -26,18 +26,16 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace OC\Files\Mount;
use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
use OC\Files\SetupManager;
-use OCP\Diagnostics\IEventLogger;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\Files\Config\IMountProviderCollection;
+use OC\Files\SetupManagerFactory;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
-use OCP\IUserManager;
class Manager implements IMountManager {
/** @var MountPoint[] */
@@ -48,15 +46,10 @@ class Manager implements IMountManager {
private CappedMemoryCache $inPathCache;
private SetupManager $setupManager;
- public function __construct(
- IEventLogger $eventLogger,
- IMountProviderCollection $mountProviderCollection,
- IUserManager $userManager,
- IEventDispatcher $eventDispatcher
- ) {
+ public function __construct(SetupManagerFactory $setupManagerFactory) {
$this->pathCache = new CappedMemoryCache();
$this->inPathCache = new CappedMemoryCache();
- $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userManager, $eventDispatcher);
+ $this->setupManager = $setupManagerFactory->create($this);
}
/**
diff --git a/lib/private/Files/SetupManagerFactory.php b/lib/private/Files/SetupManagerFactory.php
new file mode 100644
index 00000000000..21628984256
--- /dev/null
+++ b/lib/private/Files/SetupManagerFactory.php
@@ -0,0 +1,58 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Files;
+
+use OCP\Diagnostics\IEventLogger;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\IMountProviderCollection;
+use OCP\Files\Mount\IMountManager;
+use OCP\IUserManager;
+
+class SetupManagerFactory {
+ private IEventLogger $eventLogger;
+ private IMountProviderCollection $mountProviderCollection;
+ private IUserManager $userManager;
+ private IEventDispatcher $eventDispatcher;
+ private ?SetupManager $setupManager;
+
+ public function __construct(
+ IEventLogger $eventLogger,
+ IMountProviderCollection $mountProviderCollection,
+ IUserManager $userManager,
+ IEventDispatcher $eventDispatcher
+ ) {
+ $this->eventLogger = $eventLogger;
+ $this->mountProviderCollection = $mountProviderCollection;
+ $this->userManager = $userManager;
+ $this->eventDispatcher = $eventDispatcher;
+ $this->setupManager = null;
+ }
+
+ public function create(IMountManager $mountManager): SetupManager {
+ if (!$this->setupManager) {
+ $this->setupManager = new SetupManager($this->eventLogger, $this->mountProviderCollection, $mountManager, $this->userManager, $this->eventDispatcher);
+ }
+ return $this->setupManager;
+ }
+}
diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php
index 159fffc7cb8..e834d77b73a 100644
--- a/tests/lib/Files/Mount/ManagerTest.php
+++ b/tests/lib/Files/Mount/ManagerTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Mount;
+use OC\Files\SetupManagerFactory;
use OC\Files\Storage\Temporary;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
@@ -28,12 +29,7 @@ class ManagerTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->manager = new \OC\Files\Mount\Manager(
- $this->createMock(IEventLogger::class),
- $this->createMock(IMountProviderCollection::class),
- $this->createMock(IUserManager::class),
- $this->createMock(IEventDispatcher::class),
- );
+ $this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
}
public function testFind() {