Passed
Push — master ( ce1d7f...26df2c )
by Joas
14:35 queued 13s
created
apps/files_external/lib/Lib/Backend/SMB_OC.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 		$username_as_share = ($storage->getBackendOption('username_as_share') === true);
66 66
 
67 67
 		if ($username_as_share) {
68
-			$share = '/' . $storage->getBackendOption('user');
68
+			$share = '/'.$storage->getBackendOption('user');
69 69
 			$storage->setBackendOption('share', $share);
70 70
 		}
71 71
 	}
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -37,35 +37,35 @@
 block discarded – undo
37 37
  * Deprecated SMB_OC class - use SMB with the password::sessioncredentials auth mechanism
38 38
  */
39 39
 class SMB_OC extends Backend {
40
-	use LegacyDependencyCheckPolyfill;
40
+    use LegacyDependencyCheckPolyfill;
41 41
 
42
-	public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBackend) {
43
-		$this
44
-			->setIdentifier('\OC\Files\Storage\SMB_OC')
45
-			->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
46
-			->setText($l->t('SMB/CIFS using OC login'))
47
-			->addParameters([
48
-				new DefinitionParameter('host', $l->t('Host')),
49
-				(new DefinitionParameter('username_as_share', $l->t('Username as share')))
50
-					->setType(DefinitionParameter::VALUE_BOOLEAN),
51
-				(new DefinitionParameter('share', $l->t('Share')))
52
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
53
-				(new DefinitionParameter('root', $l->t('Remote subfolder')))
54
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
55
-			])
56
-			->setPriority(BackendService::PRIORITY_DEFAULT - 10)
57
-			->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
58
-			->setLegacyAuthMechanism($legacyAuth)
59
-			->deprecateTo($smbBackend)
60
-		;
61
-	}
42
+    public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBackend) {
43
+        $this
44
+            ->setIdentifier('\OC\Files\Storage\SMB_OC')
45
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
46
+            ->setText($l->t('SMB/CIFS using OC login'))
47
+            ->addParameters([
48
+                new DefinitionParameter('host', $l->t('Host')),
49
+                (new DefinitionParameter('username_as_share', $l->t('Username as share')))
50
+                    ->setType(DefinitionParameter::VALUE_BOOLEAN),
51
+                (new DefinitionParameter('share', $l->t('Share')))
52
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
53
+                (new DefinitionParameter('root', $l->t('Remote subfolder')))
54
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
55
+            ])
56
+            ->setPriority(BackendService::PRIORITY_DEFAULT - 10)
57
+            ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
58
+            ->setLegacyAuthMechanism($legacyAuth)
59
+            ->deprecateTo($smbBackend)
60
+        ;
61
+    }
62 62
 
63
-	public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
64
-		$username_as_share = ($storage->getBackendOption('username_as_share') === true);
63
+    public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
64
+        $username_as_share = ($storage->getBackendOption('username_as_share') === true);
65 65
 
66
-		if ($username_as_share) {
67
-			$share = '/' . $storage->getBackendOption('user');
68
-			$storage->setBackendOption('share', $share);
69
-		}
70
-	}
66
+        if ($username_as_share) {
67
+            $share = '/' . $storage->getBackendOption('user');
68
+            $storage->setBackendOption('share', $share);
69
+        }
70
+    }
71 71
 }
Please login to merge, or discard this patch.
apps/files/lib/Service/TagService.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
 		}
123 123
 
124 124
 		$eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
125
-		$this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
125
+		$this->dispatcher->dispatch(self::class.'::'.$eventName, new GenericEvent(null, [
126 126
 			'userId' => $user->getUID(),
127 127
 			'fileId' => $fileId,
128 128
 			'path' => $path,
Please login to merge, or discard this patch.
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -38,110 +38,110 @@
 block discarded – undo
38 38
  */
39 39
 class TagService {
40 40
 
41
-	/** @var IUserSession */
42
-	private $userSession;
43
-	/** @var IManager */
44
-	private $activityManager;
45
-	/** @var ITags */
46
-	private $tagger;
47
-	/** @var Folder */
48
-	private $homeFolder;
49
-	/** @var EventDispatcherInterface */
50
-	private $dispatcher;
41
+    /** @var IUserSession */
42
+    private $userSession;
43
+    /** @var IManager */
44
+    private $activityManager;
45
+    /** @var ITags */
46
+    private $tagger;
47
+    /** @var Folder */
48
+    private $homeFolder;
49
+    /** @var EventDispatcherInterface */
50
+    private $dispatcher;
51 51
 
52
-	/**
53
-	 * @param IUserSession $userSession
54
-	 * @param IManager $activityManager
55
-	 * @param ITags $tagger
56
-	 * @param Folder $homeFolder
57
-	 * @param EventDispatcherInterface $dispatcher
58
-	 */
59
-	public function __construct(
60
-		IUserSession $userSession,
61
-		IManager $activityManager,
62
-		ITags $tagger,
63
-		Folder $homeFolder,
64
-		EventDispatcherInterface $dispatcher
65
-	) {
66
-		$this->userSession = $userSession;
67
-		$this->activityManager = $activityManager;
68
-		$this->tagger = $tagger;
69
-		$this->homeFolder = $homeFolder;
70
-		$this->dispatcher = $dispatcher;
71
-	}
52
+    /**
53
+     * @param IUserSession $userSession
54
+     * @param IManager $activityManager
55
+     * @param ITags $tagger
56
+     * @param Folder $homeFolder
57
+     * @param EventDispatcherInterface $dispatcher
58
+     */
59
+    public function __construct(
60
+        IUserSession $userSession,
61
+        IManager $activityManager,
62
+        ITags $tagger,
63
+        Folder $homeFolder,
64
+        EventDispatcherInterface $dispatcher
65
+    ) {
66
+        $this->userSession = $userSession;
67
+        $this->activityManager = $activityManager;
68
+        $this->tagger = $tagger;
69
+        $this->homeFolder = $homeFolder;
70
+        $this->dispatcher = $dispatcher;
71
+    }
72 72
 
73
-	/**
74
-	 * Updates the tags of the specified file path.
75
-	 * The passed tags are absolute, which means they will
76
-	 * replace the actual tag selection.
77
-	 *
78
-	 * @param string $path path
79
-	 * @param array  $tags array of tags
80
-	 * @return array list of tags
81
-	 * @throws \OCP\Files\NotFoundException if the file does not exist
82
-	 */
83
-	public function updateFileTags($path, $tags) {
84
-		$fileId = $this->homeFolder->get($path)->getId();
73
+    /**
74
+     * Updates the tags of the specified file path.
75
+     * The passed tags are absolute, which means they will
76
+     * replace the actual tag selection.
77
+     *
78
+     * @param string $path path
79
+     * @param array  $tags array of tags
80
+     * @return array list of tags
81
+     * @throws \OCP\Files\NotFoundException if the file does not exist
82
+     */
83
+    public function updateFileTags($path, $tags) {
84
+        $fileId = $this->homeFolder->get($path)->getId();
85 85
 
86
-		$currentTags = $this->tagger->getTagsForObjects([$fileId]);
86
+        $currentTags = $this->tagger->getTagsForObjects([$fileId]);
87 87
 
88
-		if (!empty($currentTags)) {
89
-			$currentTags = current($currentTags);
90
-		}
88
+        if (!empty($currentTags)) {
89
+            $currentTags = current($currentTags);
90
+        }
91 91
 
92
-		$newTags = array_diff($tags, $currentTags);
93
-		foreach ($newTags as $tag) {
94
-			if ($tag === ITags::TAG_FAVORITE) {
95
-				$this->addActivity(true, $fileId, $path);
96
-			}
97
-			$this->tagger->tagAs($fileId, $tag);
98
-		}
99
-		$deletedTags = array_diff($currentTags, $tags);
100
-		foreach ($deletedTags as $tag) {
101
-			if ($tag === ITags::TAG_FAVORITE) {
102
-				$this->addActivity(false, $fileId, $path);
103
-			}
104
-			$this->tagger->unTag($fileId, $tag);
105
-		}
92
+        $newTags = array_diff($tags, $currentTags);
93
+        foreach ($newTags as $tag) {
94
+            if ($tag === ITags::TAG_FAVORITE) {
95
+                $this->addActivity(true, $fileId, $path);
96
+            }
97
+            $this->tagger->tagAs($fileId, $tag);
98
+        }
99
+        $deletedTags = array_diff($currentTags, $tags);
100
+        foreach ($deletedTags as $tag) {
101
+            if ($tag === ITags::TAG_FAVORITE) {
102
+                $this->addActivity(false, $fileId, $path);
103
+            }
104
+            $this->tagger->unTag($fileId, $tag);
105
+        }
106 106
 
107
-		// TODO: re-read from tagger to make sure the
108
-		// list is up to date, in case of concurrent changes ?
109
-		return $tags;
110
-	}
107
+        // TODO: re-read from tagger to make sure the
108
+        // list is up to date, in case of concurrent changes ?
109
+        return $tags;
110
+    }
111 111
 
112
-	/**
113
-	 * @param bool $addToFavorite
114
-	 * @param int $fileId
115
-	 * @param string $path
116
-	 */
117
-	protected function addActivity($addToFavorite, $fileId, $path) {
118
-		$user = $this->userSession->getUser();
119
-		if (!$user instanceof IUser) {
120
-			return;
121
-		}
112
+    /**
113
+     * @param bool $addToFavorite
114
+     * @param int $fileId
115
+     * @param string $path
116
+     */
117
+    protected function addActivity($addToFavorite, $fileId, $path) {
118
+        $user = $this->userSession->getUser();
119
+        if (!$user instanceof IUser) {
120
+            return;
121
+        }
122 122
 
123
-		$eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
124
-		$this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
125
-			'userId' => $user->getUID(),
126
-			'fileId' => $fileId,
127
-			'path' => $path,
128
-		]));
123
+        $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
124
+        $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
125
+            'userId' => $user->getUID(),
126
+            'fileId' => $fileId,
127
+            'path' => $path,
128
+        ]));
129 129
 
130
-		$event = $this->activityManager->generateEvent();
131
-		try {
132
-			$event->setApp('files')
133
-				->setObject('files', $fileId, $path)
134
-				->setType('favorite')
135
-				->setAuthor($user->getUID())
136
-				->setAffectedUser($user->getUID())
137
-				->setTimestamp(time())
138
-				->setSubject(
139
-					$addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED,
140
-					['id' => $fileId, 'path' => $path]
141
-				);
142
-			$this->activityManager->publish($event);
143
-		} catch (\InvalidArgumentException $e) {
144
-		} catch (\BadMethodCallException $e) {
145
-		}
146
-	}
130
+        $event = $this->activityManager->generateEvent();
131
+        try {
132
+            $event->setApp('files')
133
+                ->setObject('files', $fileId, $path)
134
+                ->setType('favorite')
135
+                ->setAuthor($user->getUID())
136
+                ->setAffectedUser($user->getUID())
137
+                ->setTimestamp(time())
138
+                ->setSubject(
139
+                    $addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED,
140
+                    ['id' => $fileId, 'path' => $path]
141
+                );
142
+            $this->activityManager->publish($event);
143
+        } catch (\InvalidArgumentException $e) {
144
+        } catch (\BadMethodCallException $e) {
145
+        }
146
+    }
147 147
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudId.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -30,35 +30,35 @@
 block discarded – undo
30 30
  * @since 12.0.0
31 31
  */
32 32
 interface ICloudId {
33
-	/**
34
-	 * The remote cloud id
35
-	 *
36
-	 * @return string
37
-	 * @since 12.0.0
38
-	 */
39
-	public function getId(): string;
33
+    /**
34
+     * The remote cloud id
35
+     *
36
+     * @return string
37
+     * @since 12.0.0
38
+     */
39
+    public function getId(): string;
40 40
 
41
-	/**
42
-	 * Get a clean representation of the cloud id for display
43
-	 *
44
-	 * @return string
45
-	 * @since 12.0.0
46
-	 */
47
-	public function getDisplayId(): string;
41
+    /**
42
+     * Get a clean representation of the cloud id for display
43
+     *
44
+     * @return string
45
+     * @since 12.0.0
46
+     */
47
+    public function getDisplayId(): string;
48 48
 
49
-	/**
50
-	 * The username on the remote server
51
-	 *
52
-	 * @return string
53
-	 * @since 12.0.0
54
-	 */
55
-	public function getUser(): string;
49
+    /**
50
+     * The username on the remote server
51
+     *
52
+     * @return string
53
+     * @since 12.0.0
54
+     */
55
+    public function getUser(): string;
56 56
 
57
-	/**
58
-	 * The base address of the remote server
59
-	 *
60
-	 * @return string
61
-	 * @since 12.0.0
62
-	 */
63
-	public function getRemote(): string;
57
+    /**
58
+     * The base address of the remote server
59
+     *
60
+     * @return string
61
+     * @since 12.0.0
62
+     */
63
+    public function getRemote(): string;
64 64
 }
Please login to merge, or discard this patch.
lib/public/Http/Client/IClientService.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
  * @since 8.1.0
32 32
  */
33 33
 interface IClientService {
34
-	/**
35
-	 * @return IClient
36
-	 * @since 8.1.0
37
-	 */
38
-	public function newClient(): IClient;
34
+    /**
35
+     * @return IClient
36
+     * @since 8.1.0
37
+     */
38
+    public function newClient(): IClient;
39 39
 }
Please login to merge, or discard this patch.
lib/public/Http/Client/IResponse.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,28 +32,28 @@
 block discarded – undo
32 32
  * @since 8.1.0
33 33
  */
34 34
 interface IResponse {
35
-	/**
36
-	 * @return string|resource
37
-	 * @since 8.1.0
38
-	 */
39
-	public function getBody();
35
+    /**
36
+     * @return string|resource
37
+     * @since 8.1.0
38
+     */
39
+    public function getBody();
40 40
 
41
-	/**
42
-	 * @return int
43
-	 * @since 8.1.0
44
-	 */
45
-	public function getStatusCode(): int;
41
+    /**
42
+     * @return int
43
+     * @since 8.1.0
44
+     */
45
+    public function getStatusCode(): int;
46 46
 
47
-	/**
48
-	 * @param string $key
49
-	 * @return string
50
-	 * @since 8.1.0
51
-	 */
52
-	public function getHeader(string $key): string;
47
+    /**
48
+     * @param string $key
49
+     * @return string
50
+     * @since 8.1.0
51
+     */
52
+    public function getHeader(string $key): string;
53 53
 
54
-	/**
55
-	 * @return array
56
-	 * @since 8.1.0
57
-	 */
58
-	public function getHeaders(): array;
54
+    /**
55
+     * @return array
56
+     * @since 8.1.0
57
+     */
58
+    public function getHeaders(): array;
59 59
 }
Please login to merge, or discard this patch.
lib/public/Security/IHasher.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -45,23 +45,23 @@
 block discarded – undo
45 45
  * @since 8.0.0
46 46
  */
47 47
 interface IHasher {
48
-	/**
49
-	 * Hashes a message using PHP's `password_hash` functionality.
50
-	 * Please note that the size of the returned string is not guaranteed
51
-	 * and can be up to 255 characters.
52
-	 *
53
-	 * @param string $message Message to generate hash from
54
-	 * @return string Hash of the message with appended version parameter
55
-	 * @since 8.0.0
56
-	 */
57
-	public function hash(string $message): string;
48
+    /**
49
+     * Hashes a message using PHP's `password_hash` functionality.
50
+     * Please note that the size of the returned string is not guaranteed
51
+     * and can be up to 255 characters.
52
+     *
53
+     * @param string $message Message to generate hash from
54
+     * @return string Hash of the message with appended version parameter
55
+     * @since 8.0.0
56
+     */
57
+    public function hash(string $message): string;
58 58
 
59
-	/**
60
-	 * @param string $message Message to verify
61
-	 * @param string $hash Assumed hash of the message
62
-	 * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
63
-	 * @return bool Whether $hash is a valid hash of $message
64
-	 * @since 8.0.0
65
-	 */
66
-	public function verify(string $message, string $hash, &$newHash = null): bool ;
59
+    /**
60
+     * @param string $message Message to verify
61
+     * @param string $hash Assumed hash of the message
62
+     * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
63
+     * @return bool Whether $hash is a valid hash of $message
64
+     * @since 8.0.0
65
+     */
66
+    public function verify(string $message, string $hash, &$newHash = null): bool ;
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,5 +63,5 @@
 block discarded – undo
63 63
 	 * @return bool Whether $hash is a valid hash of $message
64 64
 	 * @since 8.0.0
65 65
 	 */
66
-	public function verify(string $message, string $hash, &$newHash = null): bool ;
66
+	public function verify(string $message, string $hash, &$newHash = null): bool;
67 67
 }
Please login to merge, or discard this patch.
core/Migrations/Version13000Date20170814074715.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -29,50 +29,50 @@
 block discarded – undo
29 29
 
30 30
 class Version13000Date20170814074715 extends SimpleMigrationStep {
31 31
 
32
-	/**
33
-	 * @param IOutput $output
34
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
35
-	 * @param array $options
36
-	 * @since 13.0.0
37
-	 */
38
-	public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
39
-	}
32
+    /**
33
+     * @param IOutput $output
34
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
35
+     * @param array $options
36
+     * @since 13.0.0
37
+     */
38
+    public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
39
+    }
40 40
 
41
-	/**
42
-	 * @param IOutput $output
43
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
44
-	 * @param array $options
45
-	 * @return null|ISchemaWrapper
46
-	 * @since 13.0.0
47
-	 */
48
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
49
-		/** @var ISchemaWrapper $schema */
50
-		$schema = $schemaClosure();
41
+    /**
42
+     * @param IOutput $output
43
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
44
+     * @param array $options
45
+     * @return null|ISchemaWrapper
46
+     * @since 13.0.0
47
+     */
48
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
49
+        /** @var ISchemaWrapper $schema */
50
+        $schema = $schemaClosure();
51 51
 
52 52
 
53
-		if (!$schema->hasTable('accounts')) {
54
-			$table = $schema->createTable('accounts');
55
-			$table->addColumn('uid', 'string', [
56
-				'notnull' => true,
57
-				'length' => 64,
58
-				'default' => '',
59
-			]);
60
-			$table->addColumn('data', 'text', [
61
-				'notnull' => true,
62
-				'default' => '',
63
-			]);
64
-			$table->setPrimaryKey(['uid']);
65
-		}
53
+        if (!$schema->hasTable('accounts')) {
54
+            $table = $schema->createTable('accounts');
55
+            $table->addColumn('uid', 'string', [
56
+                'notnull' => true,
57
+                'length' => 64,
58
+                'default' => '',
59
+            ]);
60
+            $table->addColumn('data', 'text', [
61
+                'notnull' => true,
62
+                'default' => '',
63
+            ]);
64
+            $table->setPrimaryKey(['uid']);
65
+        }
66 66
 
67
-		return $schema;
68
-	}
67
+        return $schema;
68
+    }
69 69
 
70
-	/**
71
-	 * @param IOutput $output
72
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
73
-	 * @param array $options
74
-	 * @since 13.0.0
75
-	 */
76
-	public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
77
-	}
70
+    /**
71
+     * @param IOutput $output
72
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
73
+     * @param array $options
74
+     * @since 13.0.0
75
+     */
76
+    public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607113030.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -31,75 +31,75 @@
 block discarded – undo
31 31
 
32 32
 class Version1002Date20170607113030 extends SimpleMigrationStep {
33 33
 
34
-	/** @var IDBConnection */
35
-	protected $connection;
34
+    /** @var IDBConnection */
35
+    protected $connection;
36 36
 
37
-	/**
38
-	 * @param IDBConnection $connection
39
-	 */
40
-	public function __construct(IDBConnection $connection) {
41
-		$this->connection = $connection;
42
-	}
37
+    /**
38
+     * @param IDBConnection $connection
39
+     */
40
+    public function __construct(IDBConnection $connection) {
41
+        $this->connection = $connection;
42
+    }
43 43
 
44
-	/**
45
-	 * @param IOutput $output
46
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
47
-	 * @param array $options
48
-	 * @since 13.0.0
49
-	 */
50
-	public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
51
-		/** @var ISchemaWrapper $schema */
52
-		$schema = $schemaClosure();
44
+    /**
45
+     * @param IOutput $output
46
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
47
+     * @param array $options
48
+     * @since 13.0.0
49
+     */
50
+    public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
51
+        /** @var ISchemaWrapper $schema */
52
+        $schema = $schemaClosure();
53 53
 
54
-		if (!$schema->hasTable('twofactor_backup_codes')) {
55
-			// Legacy table does not exist
56
-			return;
57
-		}
54
+        if (!$schema->hasTable('twofactor_backup_codes')) {
55
+            // Legacy table does not exist
56
+            return;
57
+        }
58 58
 
59
-		$insert = $this->connection->getQueryBuilder();
60
-		$insert->insert('twofactor_backupcodes')
61
-			->values([
62
-				// Inserting with id might fail: 'id' => $insert->createParameter('id'),
63
-				'user_id' => $insert->createParameter('user_id'),
64
-				'code' => $insert->createParameter('code'),
65
-				'used' => $insert->createParameter('used'),
66
-			]);
59
+        $insert = $this->connection->getQueryBuilder();
60
+        $insert->insert('twofactor_backupcodes')
61
+            ->values([
62
+                // Inserting with id might fail: 'id' => $insert->createParameter('id'),
63
+                'user_id' => $insert->createParameter('user_id'),
64
+                'code' => $insert->createParameter('code'),
65
+                'used' => $insert->createParameter('used'),
66
+            ]);
67 67
 
68
-		$query = $this->connection->getQueryBuilder();
69
-		$query->select('*')
70
-			->from('twofactor_backup_codes')
71
-			->orderBy('id', 'ASC');
72
-		$result = $query->execute();
68
+        $query = $this->connection->getQueryBuilder();
69
+        $query->select('*')
70
+            ->from('twofactor_backup_codes')
71
+            ->orderBy('id', 'ASC');
72
+        $result = $query->execute();
73 73
 
74
-		$output->startProgress();
75
-		while ($row = $result->fetch()) {
76
-			$output->advance();
74
+        $output->startProgress();
75
+        while ($row = $result->fetch()) {
76
+            $output->advance();
77 77
 
78
-			$insert
79
-				// Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT)
80
-				->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR)
81
-				->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR)
82
-				->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT)
83
-				->execute();
84
-		}
85
-		$output->finishProgress();
86
-	}
78
+            $insert
79
+                // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT)
80
+                ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR)
81
+                ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR)
82
+                ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT)
83
+                ->execute();
84
+        }
85
+        $output->finishProgress();
86
+    }
87 87
 
88
-	/**
89
-	 * @param IOutput $output
90
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
91
-	 * @param array $options
92
-	 * @return null|ISchemaWrapper
93
-	 * @since 13.0.0
94
-	 */
95
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
96
-		/** @var ISchemaWrapper $schema */
97
-		$schema = $schemaClosure();
88
+    /**
89
+     * @param IOutput $output
90
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
91
+     * @param array $options
92
+     * @return null|ISchemaWrapper
93
+     * @since 13.0.0
94
+     */
95
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
96
+        /** @var ISchemaWrapper $schema */
97
+        $schema = $schemaClosure();
98 98
 
99
-		if ($schema->hasTable('twofactor_backup_codes')) {
100
-			$schema->dropTable('twofactor_backup_codes');
101
-			return $schema;
102
-		}
103
-		return null;
104
-	}
99
+        if ($schema->hasTable('twofactor_backup_codes')) {
100
+            $schema->dropTable('twofactor_backup_codes');
101
+            return $schema;
102
+        }
103
+        return null;
104
+    }
105 105
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/StoragesService.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
 	}
73 73
 
74 74
 	protected function getStorageConfigFromDBMount(array $mount) {
75
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
75
+		$applicableUsers = array_filter($mount['applicable'], function($applicable) {
76 76
 			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
77 77
 		});
78
-		$applicableUsers = array_map(function ($applicable) {
78
+		$applicableUsers = array_map(function($applicable) {
79 79
 			return $applicable['value'];
80 80
 		}, $applicableUsers);
81 81
 
82
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
82
+		$applicableGroups = array_filter($mount['applicable'], function($applicable) {
83 83
 			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
84 84
 		});
85
-		$applicableGroups = array_map(function ($applicable) {
85
+		$applicableGroups = array_map(function($applicable) {
86 86
 			return $applicable['value'];
87 87
 		}, $applicableGroups);
88 88
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 				$mount['priority']
99 99
 			);
100 100
 			$config->setType($mount['type']);
101
-			$config->setId((int)$mount['mount_id']);
101
+			$config->setId((int) $mount['mount_id']);
102 102
 			return $config;
103 103
 		} catch (\UnexpectedValueException $e) {
104 104
 			// don't die if a storage backend doesn't exist
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	protected function readConfig() {
127 127
 		$mounts = $this->readDBConfig();
128 128
 		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
129
-		$configs = array_filter($configs, function ($config) {
129
+		$configs = array_filter($configs, function($config) {
130 130
 			return $config instanceof StorageConfig;
131 131
 		});
132 132
 
133
-		$keys = array_map(function (StorageConfig $config) {
133
+		$keys = array_map(function(StorageConfig $config) {
134 134
 			return $config->getId();
135 135
 		}, $configs);
136 136
 
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 		$mount = $this->dbConfig->getMountById($id);
150 150
 
151 151
 		if (!is_array($mount)) {
152
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
152
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
153 153
 		}
154 154
 
155 155
 		$config = $this->getStorageConfigFromDBMount($mount);
156 156
 		if ($this->isApplicable($config)) {
157 157
 			return $config;
158 158
 		} else {
159
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
159
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
160 160
 		}
161 161
 	}
162 162
 
@@ -379,13 +379,13 @@  discard block
 block discarded – undo
379 379
 		$existingMount = $this->dbConfig->getMountById($id);
380 380
 
381 381
 		if (!is_array($existingMount)) {
382
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
382
+			throw new NotFoundException('Storage with ID "'.$id.'" not found while updating storage');
383 383
 		}
384 384
 
385 385
 		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
386 386
 
387 387
 		if ($oldStorage->getBackend() instanceof InvalidBackend) {
388
-			throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
388
+			throw new NotFoundException('Storage with id "'.$id.'" cannot be edited due to missing backend');
389 389
 		}
390 390
 
391 391
 		$removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 		$existingMount = $this->dbConfig->getMountById($id);
463 463
 
464 464
 		if (!is_array($existingMount)) {
465
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
465
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
466 466
 		}
467 467
 
468 468
 		$this->dbConfig->removeMount($id);
Please login to merge, or discard this patch.
Indentation   +454 added lines, -454 removed lines patch added patch discarded remove patch
@@ -49,458 +49,458 @@
 block discarded – undo
49 49
  */
50 50
 abstract class StoragesService {
51 51
 
52
-	/** @var BackendService */
53
-	protected $backendService;
54
-
55
-	/**
56
-	 * @var DBConfigService
57
-	 */
58
-	protected $dbConfig;
59
-
60
-	/**
61
-	 * @var IUserMountCache
62
-	 */
63
-	protected $userMountCache;
64
-
65
-	/**
66
-	 * @param BackendService $backendService
67
-	 * @param DBConfigService $dbConfigService
68
-	 * @param IUserMountCache $userMountCache
69
-	 */
70
-	public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) {
71
-		$this->backendService = $backendService;
72
-		$this->dbConfig = $dbConfigService;
73
-		$this->userMountCache = $userMountCache;
74
-	}
75
-
76
-	protected function readDBConfig() {
77
-		return $this->dbConfig->getAdminMounts();
78
-	}
79
-
80
-	protected function getStorageConfigFromDBMount(array $mount) {
81
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
82
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
83
-		});
84
-		$applicableUsers = array_map(function ($applicable) {
85
-			return $applicable['value'];
86
-		}, $applicableUsers);
87
-
88
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
89
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
90
-		});
91
-		$applicableGroups = array_map(function ($applicable) {
92
-			return $applicable['value'];
93
-		}, $applicableGroups);
94
-
95
-		try {
96
-			$config = $this->createStorage(
97
-				$mount['mount_point'],
98
-				$mount['storage_backend'],
99
-				$mount['auth_backend'],
100
-				$mount['config'],
101
-				$mount['options'],
102
-				array_values($applicableUsers),
103
-				array_values($applicableGroups),
104
-				$mount['priority']
105
-			);
106
-			$config->setType($mount['type']);
107
-			$config->setId((int)$mount['mount_id']);
108
-			return $config;
109
-		} catch (\UnexpectedValueException $e) {
110
-			// don't die if a storage backend doesn't exist
111
-			\OC::$server->getLogger()->logException($e, [
112
-				'message' => 'Could not load storage.',
113
-				'level' => ILogger::ERROR,
114
-				'app' => 'files_external',
115
-			]);
116
-			return null;
117
-		} catch (\InvalidArgumentException $e) {
118
-			\OC::$server->getLogger()->logException($e, [
119
-				'message' => 'Could not load storage.',
120
-				'level' => ILogger::ERROR,
121
-				'app' => 'files_external',
122
-			]);
123
-			return null;
124
-		}
125
-	}
126
-
127
-	/**
128
-	 * Read the external storage config
129
-	 *
130
-	 * @return array map of storage id to storage config
131
-	 */
132
-	protected function readConfig() {
133
-		$mounts = $this->readDBConfig();
134
-		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
135
-		$configs = array_filter($configs, function ($config) {
136
-			return $config instanceof StorageConfig;
137
-		});
138
-
139
-		$keys = array_map(function (StorageConfig $config) {
140
-			return $config->getId();
141
-		}, $configs);
142
-
143
-		return array_combine($keys, $configs);
144
-	}
145
-
146
-	/**
147
-	 * Get a storage with status
148
-	 *
149
-	 * @param int $id storage id
150
-	 *
151
-	 * @return StorageConfig
152
-	 * @throws NotFoundException if the storage with the given id was not found
153
-	 */
154
-	public function getStorage($id) {
155
-		$mount = $this->dbConfig->getMountById($id);
156
-
157
-		if (!is_array($mount)) {
158
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
159
-		}
160
-
161
-		$config = $this->getStorageConfigFromDBMount($mount);
162
-		if ($this->isApplicable($config)) {
163
-			return $config;
164
-		} else {
165
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
166
-		}
167
-	}
168
-
169
-	/**
170
-	 * Check whether this storage service should provide access to a storage
171
-	 *
172
-	 * @param StorageConfig $config
173
-	 * @return bool
174
-	 */
175
-	abstract protected function isApplicable(StorageConfig $config);
176
-
177
-	/**
178
-	 * Gets all storages, valid or not
179
-	 *
180
-	 * @return StorageConfig[] array of storage configs
181
-	 */
182
-	public function getAllStorages() {
183
-		return $this->readConfig();
184
-	}
185
-
186
-	/**
187
-	 * Gets all valid storages
188
-	 *
189
-	 * @return StorageConfig[]
190
-	 */
191
-	public function getStorages() {
192
-		return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
193
-	}
194
-
195
-	/**
196
-	 * Validate storage
197
-	 * FIXME: De-duplicate with StoragesController::validate()
198
-	 *
199
-	 * @param StorageConfig $storage
200
-	 * @return bool
201
-	 */
202
-	protected function validateStorage(StorageConfig $storage) {
203
-		/** @var Backend */
204
-		$backend = $storage->getBackend();
205
-		/** @var AuthMechanism */
206
-		$authMechanism = $storage->getAuthMechanism();
207
-
208
-		if (!$backend->isVisibleFor($this->getVisibilityType())) {
209
-			// not permitted to use backend
210
-			return false;
211
-		}
212
-		if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
213
-			// not permitted to use auth mechanism
214
-			return false;
215
-		}
216
-
217
-		return true;
218
-	}
219
-
220
-	/**
221
-	 * Get the visibility type for this controller, used in validation
222
-	 *
223
-	 * @return string BackendService::VISIBILITY_* constants
224
-	 */
225
-	abstract public function getVisibilityType();
226
-
227
-	/**
228
-	 * @return integer
229
-	 */
230
-	protected function getType() {
231
-		return DBConfigService::MOUNT_TYPE_ADMIN;
232
-	}
233
-
234
-	/**
235
-	 * Add new storage to the configuration
236
-	 *
237
-	 * @param StorageConfig $newStorage storage attributes
238
-	 *
239
-	 * @return StorageConfig storage config, with added id
240
-	 */
241
-	public function addStorage(StorageConfig $newStorage) {
242
-		$allStorages = $this->readConfig();
243
-
244
-		$configId = $this->dbConfig->addMount(
245
-			$newStorage->getMountPoint(),
246
-			$newStorage->getBackend()->getIdentifier(),
247
-			$newStorage->getAuthMechanism()->getIdentifier(),
248
-			$newStorage->getPriority(),
249
-			$this->getType()
250
-		);
251
-
252
-		$newStorage->setId($configId);
253
-
254
-		foreach ($newStorage->getApplicableUsers() as $user) {
255
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
256
-		}
257
-		foreach ($newStorage->getApplicableGroups() as $group) {
258
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
259
-		}
260
-		foreach ($newStorage->getBackendOptions() as $key => $value) {
261
-			$this->dbConfig->setConfig($configId, $key, $value);
262
-		}
263
-		foreach ($newStorage->getMountOptions() as $key => $value) {
264
-			$this->dbConfig->setOption($configId, $key, $value);
265
-		}
266
-
267
-		if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
268
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
269
-		}
270
-
271
-		// add new storage
272
-		$allStorages[$configId] = $newStorage;
273
-
274
-		$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
275
-
276
-		$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
277
-		return $newStorage;
278
-	}
279
-
280
-	/**
281
-	 * Create a storage from its parameters
282
-	 *
283
-	 * @param string $mountPoint storage mount point
284
-	 * @param string $backendIdentifier backend identifier
285
-	 * @param string $authMechanismIdentifier authentication mechanism identifier
286
-	 * @param array $backendOptions backend-specific options
287
-	 * @param array|null $mountOptions mount-specific options
288
-	 * @param array|null $applicableUsers users for which to mount the storage
289
-	 * @param array|null $applicableGroups groups for which to mount the storage
290
-	 * @param int|null $priority priority
291
-	 *
292
-	 * @return StorageConfig
293
-	 */
294
-	public function createStorage(
295
-		$mountPoint,
296
-		$backendIdentifier,
297
-		$authMechanismIdentifier,
298
-		$backendOptions,
299
-		$mountOptions = null,
300
-		$applicableUsers = null,
301
-		$applicableGroups = null,
302
-		$priority = null
303
-	) {
304
-		$backend = $this->backendService->getBackend($backendIdentifier);
305
-		if (!$backend) {
306
-			$backend = new InvalidBackend($backendIdentifier);
307
-		}
308
-		$authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
309
-		if (!$authMechanism) {
310
-			$authMechanism = new InvalidAuth($authMechanismIdentifier);
311
-		}
312
-		$newStorage = new StorageConfig();
313
-		$newStorage->setMountPoint($mountPoint);
314
-		$newStorage->setBackend($backend);
315
-		$newStorage->setAuthMechanism($authMechanism);
316
-		$newStorage->setBackendOptions($backendOptions);
317
-		if (isset($mountOptions)) {
318
-			$newStorage->setMountOptions($mountOptions);
319
-		}
320
-		if (isset($applicableUsers)) {
321
-			$newStorage->setApplicableUsers($applicableUsers);
322
-		}
323
-		if (isset($applicableGroups)) {
324
-			$newStorage->setApplicableGroups($applicableGroups);
325
-		}
326
-		if (isset($priority)) {
327
-			$newStorage->setPriority($priority);
328
-		}
329
-
330
-		return $newStorage;
331
-	}
332
-
333
-	/**
334
-	 * Triggers the given hook signal for all the applicables given
335
-	 *
336
-	 * @param string $signal signal
337
-	 * @param string $mountPoint hook mount pount param
338
-	 * @param string $mountType hook mount type param
339
-	 * @param array $applicableArray array of applicable users/groups for which to trigger the hook
340
-	 */
341
-	protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
342
-		foreach ($applicableArray as $applicable) {
343
-			\OCP\Util::emitHook(
344
-				Filesystem::CLASSNAME,
345
-				$signal,
346
-				[
347
-					Filesystem::signal_param_path => $mountPoint,
348
-					Filesystem::signal_param_mount_type => $mountType,
349
-					Filesystem::signal_param_users => $applicable,
350
-				]
351
-			);
352
-		}
353
-	}
354
-
355
-	/**
356
-	 * Triggers $signal for all applicable users of the given
357
-	 * storage
358
-	 *
359
-	 * @param StorageConfig $storage storage data
360
-	 * @param string $signal signal to trigger
361
-	 */
362
-	abstract protected function triggerHooks(StorageConfig $storage, $signal);
363
-
364
-	/**
365
-	 * Triggers signal_create_mount or signal_delete_mount to
366
-	 * accommodate for additions/deletions in applicableUsers
367
-	 * and applicableGroups fields.
368
-	 *
369
-	 * @param StorageConfig $oldStorage old storage data
370
-	 * @param StorageConfig $newStorage new storage data
371
-	 */
372
-	abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
373
-
374
-	/**
375
-	 * Update storage to the configuration
376
-	 *
377
-	 * @param StorageConfig $updatedStorage storage attributes
378
-	 *
379
-	 * @return StorageConfig storage config
380
-	 * @throws NotFoundException if the given storage does not exist in the config
381
-	 */
382
-	public function updateStorage(StorageConfig $updatedStorage) {
383
-		$id = $updatedStorage->getId();
384
-
385
-		$existingMount = $this->dbConfig->getMountById($id);
386
-
387
-		if (!is_array($existingMount)) {
388
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
389
-		}
390
-
391
-		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
392
-
393
-		if ($oldStorage->getBackend() instanceof InvalidBackend) {
394
-			throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
395
-		}
396
-
397
-		$removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
398
-		$removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
399
-		$addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
400
-		$addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
401
-
402
-		$oldUserCount = count($oldStorage->getApplicableUsers());
403
-		$oldGroupCount = count($oldStorage->getApplicableGroups());
404
-		$newUserCount = count($updatedStorage->getApplicableUsers());
405
-		$newGroupCount = count($updatedStorage->getApplicableGroups());
406
-		$wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
407
-		$isGlobal = ($newUserCount + $newGroupCount) === 0;
408
-
409
-		foreach ($removedUsers as $user) {
410
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
411
-		}
412
-		foreach ($removedGroups as $group) {
413
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
414
-		}
415
-		foreach ($addedUsers as $user) {
416
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
417
-		}
418
-		foreach ($addedGroups as $group) {
419
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
420
-		}
421
-
422
-		if ($wasGlobal && !$isGlobal) {
423
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
424
-		} elseif (!$wasGlobal && $isGlobal) {
425
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
426
-		}
427
-
428
-		$changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
429
-		$changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
430
-
431
-		foreach ($changedConfig as $key => $value) {
432
-			if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
433
-				$this->dbConfig->setConfig($id, $key, $value);
434
-			}
435
-		}
436
-		foreach ($changedOptions as $key => $value) {
437
-			$this->dbConfig->setOption($id, $key, $value);
438
-		}
439
-
440
-		if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
441
-			$this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
442
-		}
443
-
444
-		if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
445
-			$this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
446
-		}
447
-
448
-		$this->triggerChangeHooks($oldStorage, $updatedStorage);
449
-
450
-		if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
451
-			$this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
452
-		} else {
453
-			$storageId = $this->getStorageId($updatedStorage);
454
-			foreach ($removedUsers as $userId) {
455
-				$this->userMountCache->removeUserStorageMount($storageId, $userId);
456
-			}
457
-		}
458
-
459
-		return $this->getStorage($id);
460
-	}
461
-
462
-	/**
463
-	 * Delete the storage with the given id.
464
-	 *
465
-	 * @param int $id storage id
466
-	 *
467
-	 * @throws NotFoundException if no storage was found with the given id
468
-	 */
469
-	public function removeStorage($id) {
470
-		$existingMount = $this->dbConfig->getMountById($id);
471
-
472
-		if (!is_array($existingMount)) {
473
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
474
-		}
475
-
476
-		$this->dbConfig->removeMount($id);
477
-
478
-		$deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
479
-		$this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
480
-
481
-		// delete oc_storages entries and oc_filecache
482
-		\OC\Files\Cache\Storage::cleanByMountId($id);
483
-	}
484
-
485
-	/**
486
-	 * Construct the storage implementation
487
-	 *
488
-	 * @param StorageConfig $storageConfig
489
-	 * @return int
490
-	 */
491
-	private function getStorageId(StorageConfig $storageConfig) {
492
-		try {
493
-			$class = $storageConfig->getBackend()->getStorageClass();
494
-			/** @var \OC\Files\Storage\Storage $storage */
495
-			$storage = new $class($storageConfig->getBackendOptions());
496
-
497
-			// auth mechanism should fire first
498
-			$storage = $storageConfig->getBackend()->wrapStorage($storage);
499
-			$storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
500
-
501
-			return $storage->getStorageCache()->getNumericId();
502
-		} catch (\Exception $e) {
503
-			return -1;
504
-		}
505
-	}
52
+    /** @var BackendService */
53
+    protected $backendService;
54
+
55
+    /**
56
+     * @var DBConfigService
57
+     */
58
+    protected $dbConfig;
59
+
60
+    /**
61
+     * @var IUserMountCache
62
+     */
63
+    protected $userMountCache;
64
+
65
+    /**
66
+     * @param BackendService $backendService
67
+     * @param DBConfigService $dbConfigService
68
+     * @param IUserMountCache $userMountCache
69
+     */
70
+    public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) {
71
+        $this->backendService = $backendService;
72
+        $this->dbConfig = $dbConfigService;
73
+        $this->userMountCache = $userMountCache;
74
+    }
75
+
76
+    protected function readDBConfig() {
77
+        return $this->dbConfig->getAdminMounts();
78
+    }
79
+
80
+    protected function getStorageConfigFromDBMount(array $mount) {
81
+        $applicableUsers = array_filter($mount['applicable'], function ($applicable) {
82
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
83
+        });
84
+        $applicableUsers = array_map(function ($applicable) {
85
+            return $applicable['value'];
86
+        }, $applicableUsers);
87
+
88
+        $applicableGroups = array_filter($mount['applicable'], function ($applicable) {
89
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
90
+        });
91
+        $applicableGroups = array_map(function ($applicable) {
92
+            return $applicable['value'];
93
+        }, $applicableGroups);
94
+
95
+        try {
96
+            $config = $this->createStorage(
97
+                $mount['mount_point'],
98
+                $mount['storage_backend'],
99
+                $mount['auth_backend'],
100
+                $mount['config'],
101
+                $mount['options'],
102
+                array_values($applicableUsers),
103
+                array_values($applicableGroups),
104
+                $mount['priority']
105
+            );
106
+            $config->setType($mount['type']);
107
+            $config->setId((int)$mount['mount_id']);
108
+            return $config;
109
+        } catch (\UnexpectedValueException $e) {
110
+            // don't die if a storage backend doesn't exist
111
+            \OC::$server->getLogger()->logException($e, [
112
+                'message' => 'Could not load storage.',
113
+                'level' => ILogger::ERROR,
114
+                'app' => 'files_external',
115
+            ]);
116
+            return null;
117
+        } catch (\InvalidArgumentException $e) {
118
+            \OC::$server->getLogger()->logException($e, [
119
+                'message' => 'Could not load storage.',
120
+                'level' => ILogger::ERROR,
121
+                'app' => 'files_external',
122
+            ]);
123
+            return null;
124
+        }
125
+    }
126
+
127
+    /**
128
+     * Read the external storage config
129
+     *
130
+     * @return array map of storage id to storage config
131
+     */
132
+    protected function readConfig() {
133
+        $mounts = $this->readDBConfig();
134
+        $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
135
+        $configs = array_filter($configs, function ($config) {
136
+            return $config instanceof StorageConfig;
137
+        });
138
+
139
+        $keys = array_map(function (StorageConfig $config) {
140
+            return $config->getId();
141
+        }, $configs);
142
+
143
+        return array_combine($keys, $configs);
144
+    }
145
+
146
+    /**
147
+     * Get a storage with status
148
+     *
149
+     * @param int $id storage id
150
+     *
151
+     * @return StorageConfig
152
+     * @throws NotFoundException if the storage with the given id was not found
153
+     */
154
+    public function getStorage($id) {
155
+        $mount = $this->dbConfig->getMountById($id);
156
+
157
+        if (!is_array($mount)) {
158
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
159
+        }
160
+
161
+        $config = $this->getStorageConfigFromDBMount($mount);
162
+        if ($this->isApplicable($config)) {
163
+            return $config;
164
+        } else {
165
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
166
+        }
167
+    }
168
+
169
+    /**
170
+     * Check whether this storage service should provide access to a storage
171
+     *
172
+     * @param StorageConfig $config
173
+     * @return bool
174
+     */
175
+    abstract protected function isApplicable(StorageConfig $config);
176
+
177
+    /**
178
+     * Gets all storages, valid or not
179
+     *
180
+     * @return StorageConfig[] array of storage configs
181
+     */
182
+    public function getAllStorages() {
183
+        return $this->readConfig();
184
+    }
185
+
186
+    /**
187
+     * Gets all valid storages
188
+     *
189
+     * @return StorageConfig[]
190
+     */
191
+    public function getStorages() {
192
+        return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
193
+    }
194
+
195
+    /**
196
+     * Validate storage
197
+     * FIXME: De-duplicate with StoragesController::validate()
198
+     *
199
+     * @param StorageConfig $storage
200
+     * @return bool
201
+     */
202
+    protected function validateStorage(StorageConfig $storage) {
203
+        /** @var Backend */
204
+        $backend = $storage->getBackend();
205
+        /** @var AuthMechanism */
206
+        $authMechanism = $storage->getAuthMechanism();
207
+
208
+        if (!$backend->isVisibleFor($this->getVisibilityType())) {
209
+            // not permitted to use backend
210
+            return false;
211
+        }
212
+        if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
213
+            // not permitted to use auth mechanism
214
+            return false;
215
+        }
216
+
217
+        return true;
218
+    }
219
+
220
+    /**
221
+     * Get the visibility type for this controller, used in validation
222
+     *
223
+     * @return string BackendService::VISIBILITY_* constants
224
+     */
225
+    abstract public function getVisibilityType();
226
+
227
+    /**
228
+     * @return integer
229
+     */
230
+    protected function getType() {
231
+        return DBConfigService::MOUNT_TYPE_ADMIN;
232
+    }
233
+
234
+    /**
235
+     * Add new storage to the configuration
236
+     *
237
+     * @param StorageConfig $newStorage storage attributes
238
+     *
239
+     * @return StorageConfig storage config, with added id
240
+     */
241
+    public function addStorage(StorageConfig $newStorage) {
242
+        $allStorages = $this->readConfig();
243
+
244
+        $configId = $this->dbConfig->addMount(
245
+            $newStorage->getMountPoint(),
246
+            $newStorage->getBackend()->getIdentifier(),
247
+            $newStorage->getAuthMechanism()->getIdentifier(),
248
+            $newStorage->getPriority(),
249
+            $this->getType()
250
+        );
251
+
252
+        $newStorage->setId($configId);
253
+
254
+        foreach ($newStorage->getApplicableUsers() as $user) {
255
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
256
+        }
257
+        foreach ($newStorage->getApplicableGroups() as $group) {
258
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
259
+        }
260
+        foreach ($newStorage->getBackendOptions() as $key => $value) {
261
+            $this->dbConfig->setConfig($configId, $key, $value);
262
+        }
263
+        foreach ($newStorage->getMountOptions() as $key => $value) {
264
+            $this->dbConfig->setOption($configId, $key, $value);
265
+        }
266
+
267
+        if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
268
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
269
+        }
270
+
271
+        // add new storage
272
+        $allStorages[$configId] = $newStorage;
273
+
274
+        $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
275
+
276
+        $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
277
+        return $newStorage;
278
+    }
279
+
280
+    /**
281
+     * Create a storage from its parameters
282
+     *
283
+     * @param string $mountPoint storage mount point
284
+     * @param string $backendIdentifier backend identifier
285
+     * @param string $authMechanismIdentifier authentication mechanism identifier
286
+     * @param array $backendOptions backend-specific options
287
+     * @param array|null $mountOptions mount-specific options
288
+     * @param array|null $applicableUsers users for which to mount the storage
289
+     * @param array|null $applicableGroups groups for which to mount the storage
290
+     * @param int|null $priority priority
291
+     *
292
+     * @return StorageConfig
293
+     */
294
+    public function createStorage(
295
+        $mountPoint,
296
+        $backendIdentifier,
297
+        $authMechanismIdentifier,
298
+        $backendOptions,
299
+        $mountOptions = null,
300
+        $applicableUsers = null,
301
+        $applicableGroups = null,
302
+        $priority = null
303
+    ) {
304
+        $backend = $this->backendService->getBackend($backendIdentifier);
305
+        if (!$backend) {
306
+            $backend = new InvalidBackend($backendIdentifier);
307
+        }
308
+        $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
309
+        if (!$authMechanism) {
310
+            $authMechanism = new InvalidAuth($authMechanismIdentifier);
311
+        }
312
+        $newStorage = new StorageConfig();
313
+        $newStorage->setMountPoint($mountPoint);
314
+        $newStorage->setBackend($backend);
315
+        $newStorage->setAuthMechanism($authMechanism);
316
+        $newStorage->setBackendOptions($backendOptions);
317
+        if (isset($mountOptions)) {
318
+            $newStorage->setMountOptions($mountOptions);
319
+        }
320
+        if (isset($applicableUsers)) {
321
+            $newStorage->setApplicableUsers($applicableUsers);
322
+        }
323
+        if (isset($applicableGroups)) {
324
+            $newStorage->setApplicableGroups($applicableGroups);
325
+        }
326
+        if (isset($priority)) {
327
+            $newStorage->setPriority($priority);
328
+        }
329
+
330
+        return $newStorage;
331
+    }
332
+
333
+    /**
334
+     * Triggers the given hook signal for all the applicables given
335
+     *
336
+     * @param string $signal signal
337
+     * @param string $mountPoint hook mount pount param
338
+     * @param string $mountType hook mount type param
339
+     * @param array $applicableArray array of applicable users/groups for which to trigger the hook
340
+     */
341
+    protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
342
+        foreach ($applicableArray as $applicable) {
343
+            \OCP\Util::emitHook(
344
+                Filesystem::CLASSNAME,
345
+                $signal,
346
+                [
347
+                    Filesystem::signal_param_path => $mountPoint,
348
+                    Filesystem::signal_param_mount_type => $mountType,
349
+                    Filesystem::signal_param_users => $applicable,
350
+                ]
351
+            );
352
+        }
353
+    }
354
+
355
+    /**
356
+     * Triggers $signal for all applicable users of the given
357
+     * storage
358
+     *
359
+     * @param StorageConfig $storage storage data
360
+     * @param string $signal signal to trigger
361
+     */
362
+    abstract protected function triggerHooks(StorageConfig $storage, $signal);
363
+
364
+    /**
365
+     * Triggers signal_create_mount or signal_delete_mount to
366
+     * accommodate for additions/deletions in applicableUsers
367
+     * and applicableGroups fields.
368
+     *
369
+     * @param StorageConfig $oldStorage old storage data
370
+     * @param StorageConfig $newStorage new storage data
371
+     */
372
+    abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
373
+
374
+    /**
375
+     * Update storage to the configuration
376
+     *
377
+     * @param StorageConfig $updatedStorage storage attributes
378
+     *
379
+     * @return StorageConfig storage config
380
+     * @throws NotFoundException if the given storage does not exist in the config
381
+     */
382
+    public function updateStorage(StorageConfig $updatedStorage) {
383
+        $id = $updatedStorage->getId();
384
+
385
+        $existingMount = $this->dbConfig->getMountById($id);
386
+
387
+        if (!is_array($existingMount)) {
388
+            throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
389
+        }
390
+
391
+        $oldStorage = $this->getStorageConfigFromDBMount($existingMount);
392
+
393
+        if ($oldStorage->getBackend() instanceof InvalidBackend) {
394
+            throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
395
+        }
396
+
397
+        $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
398
+        $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
399
+        $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
400
+        $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
401
+
402
+        $oldUserCount = count($oldStorage->getApplicableUsers());
403
+        $oldGroupCount = count($oldStorage->getApplicableGroups());
404
+        $newUserCount = count($updatedStorage->getApplicableUsers());
405
+        $newGroupCount = count($updatedStorage->getApplicableGroups());
406
+        $wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
407
+        $isGlobal = ($newUserCount + $newGroupCount) === 0;
408
+
409
+        foreach ($removedUsers as $user) {
410
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
411
+        }
412
+        foreach ($removedGroups as $group) {
413
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
414
+        }
415
+        foreach ($addedUsers as $user) {
416
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
417
+        }
418
+        foreach ($addedGroups as $group) {
419
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
420
+        }
421
+
422
+        if ($wasGlobal && !$isGlobal) {
423
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
424
+        } elseif (!$wasGlobal && $isGlobal) {
425
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
426
+        }
427
+
428
+        $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
429
+        $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
430
+
431
+        foreach ($changedConfig as $key => $value) {
432
+            if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
433
+                $this->dbConfig->setConfig($id, $key, $value);
434
+            }
435
+        }
436
+        foreach ($changedOptions as $key => $value) {
437
+            $this->dbConfig->setOption($id, $key, $value);
438
+        }
439
+
440
+        if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
441
+            $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
442
+        }
443
+
444
+        if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
445
+            $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
446
+        }
447
+
448
+        $this->triggerChangeHooks($oldStorage, $updatedStorage);
449
+
450
+        if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
451
+            $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
452
+        } else {
453
+            $storageId = $this->getStorageId($updatedStorage);
454
+            foreach ($removedUsers as $userId) {
455
+                $this->userMountCache->removeUserStorageMount($storageId, $userId);
456
+            }
457
+        }
458
+
459
+        return $this->getStorage($id);
460
+    }
461
+
462
+    /**
463
+     * Delete the storage with the given id.
464
+     *
465
+     * @param int $id storage id
466
+     *
467
+     * @throws NotFoundException if no storage was found with the given id
468
+     */
469
+    public function removeStorage($id) {
470
+        $existingMount = $this->dbConfig->getMountById($id);
471
+
472
+        if (!is_array($existingMount)) {
473
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
474
+        }
475
+
476
+        $this->dbConfig->removeMount($id);
477
+
478
+        $deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
479
+        $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
480
+
481
+        // delete oc_storages entries and oc_filecache
482
+        \OC\Files\Cache\Storage::cleanByMountId($id);
483
+    }
484
+
485
+    /**
486
+     * Construct the storage implementation
487
+     *
488
+     * @param StorageConfig $storageConfig
489
+     * @return int
490
+     */
491
+    private function getStorageId(StorageConfig $storageConfig) {
492
+        try {
493
+            $class = $storageConfig->getBackend()->getStorageClass();
494
+            /** @var \OC\Files\Storage\Storage $storage */
495
+            $storage = new $class($storageConfig->getBackendOptions());
496
+
497
+            // auth mechanism should fire first
498
+            $storage = $storageConfig->getBackend()->wrapStorage($storage);
499
+            $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
500
+
501
+            return $storage->getStorageCache()->getNumericId();
502
+        } catch (\Exception $e) {
503
+            return -1;
504
+        }
505
+    }
506 506
 }
Please login to merge, or discard this patch.