Passed
Push — master ( ebedbf...47a21f )
by Joas
12:46 queued 18s
created
apps/files_versions/lib/Command/CleanUp.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -33,83 +33,83 @@
 block discarded – undo
33 33
 
34 34
 class CleanUp extends Command {
35 35
 
36
-	/** @var IUserManager */
37
-	protected $userManager;
36
+    /** @var IUserManager */
37
+    protected $userManager;
38 38
 
39
-	/** @var IRootFolder */
40
-	protected $rootFolder;
39
+    /** @var IRootFolder */
40
+    protected $rootFolder;
41 41
 
42
-	/**
43
-	 * @param IRootFolder $rootFolder
44
-	 * @param IUserManager $userManager
45
-	 */
46
-	public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
47
-		parent::__construct();
48
-		$this->userManager = $userManager;
49
-		$this->rootFolder = $rootFolder;
50
-	}
42
+    /**
43
+     * @param IRootFolder $rootFolder
44
+     * @param IUserManager $userManager
45
+     */
46
+    public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
47
+        parent::__construct();
48
+        $this->userManager = $userManager;
49
+        $this->rootFolder = $rootFolder;
50
+    }
51 51
 
52
-	protected function configure() {
53
-		$this
54
-			->setName('versions:cleanup')
55
-			->setDescription('Delete versions')
56
-			->addArgument(
57
-				'user_id',
58
-				InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
59
-				'delete versions of the given user(s), if no user is given all versions will be deleted'
60
-			);
61
-	}
52
+    protected function configure() {
53
+        $this
54
+            ->setName('versions:cleanup')
55
+            ->setDescription('Delete versions')
56
+            ->addArgument(
57
+                'user_id',
58
+                InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
59
+                'delete versions of the given user(s), if no user is given all versions will be deleted'
60
+            );
61
+    }
62 62
 
63 63
 
64
-	protected function execute(InputInterface $input, OutputInterface $output): int {
65
-		$users = $input->getArgument('user_id');
66
-		if (!empty($users)) {
67
-			foreach ($users as $user) {
68
-				if ($this->userManager->userExists($user)) {
69
-					$output->writeln("Delete versions of   <info>$user</info>");
70
-					$this->deleteVersions($user);
71
-				} else {
72
-					$output->writeln("<error>Unknown user $user</error>");
73
-					return 1;
74
-				}
75
-			}
76
-		} else {
77
-			$output->writeln('Delete all versions');
78
-			foreach ($this->userManager->getBackends() as $backend) {
79
-				$name = get_class($backend);
64
+    protected function execute(InputInterface $input, OutputInterface $output): int {
65
+        $users = $input->getArgument('user_id');
66
+        if (!empty($users)) {
67
+            foreach ($users as $user) {
68
+                if ($this->userManager->userExists($user)) {
69
+                    $output->writeln("Delete versions of   <info>$user</info>");
70
+                    $this->deleteVersions($user);
71
+                } else {
72
+                    $output->writeln("<error>Unknown user $user</error>");
73
+                    return 1;
74
+                }
75
+            }
76
+        } else {
77
+            $output->writeln('Delete all versions');
78
+            foreach ($this->userManager->getBackends() as $backend) {
79
+                $name = get_class($backend);
80 80
 
81
-				if ($backend instanceof IUserBackend) {
82
-					$name = $backend->getBackendName();
83
-				}
81
+                if ($backend instanceof IUserBackend) {
82
+                    $name = $backend->getBackendName();
83
+                }
84 84
 
85
-				$output->writeln("Delete versions for users on backend <info>$name</info>");
85
+                $output->writeln("Delete versions for users on backend <info>$name</info>");
86 86
 
87
-				$limit = 500;
88
-				$offset = 0;
89
-				do {
90
-					$users = $backend->getUsers('', $limit, $offset);
91
-					foreach ($users as $user) {
92
-						$output->writeln("   <info>$user</info>");
93
-						$this->deleteVersions($user);
94
-					}
95
-					$offset += $limit;
96
-				} while (count($users) >= $limit);
97
-			}
98
-		}
99
-		return 0;
100
-	}
87
+                $limit = 500;
88
+                $offset = 0;
89
+                do {
90
+                    $users = $backend->getUsers('', $limit, $offset);
91
+                    foreach ($users as $user) {
92
+                        $output->writeln("   <info>$user</info>");
93
+                        $this->deleteVersions($user);
94
+                    }
95
+                    $offset += $limit;
96
+                } while (count($users) >= $limit);
97
+            }
98
+        }
99
+        return 0;
100
+    }
101 101
 
102 102
 
103
-	/**
104
-	 * delete versions for the given user
105
-	 *
106
-	 * @param string $user
107
-	 */
108
-	protected function deleteVersions($user) {
109
-		\OC_Util::tearDownFS();
110
-		\OC_Util::setupFS($user);
111
-		if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) {
112
-			$this->rootFolder->get('/' . $user . '/files_versions')->delete();
113
-		}
114
-	}
103
+    /**
104
+     * delete versions for the given user
105
+     *
106
+     * @param string $user
107
+     */
108
+    protected function deleteVersions($user) {
109
+        \OC_Util::tearDownFS();
110
+        \OC_Util::setupFS($user);
111
+        if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) {
112
+            $this->rootFolder->get('/' . $user . '/files_versions')->delete();
113
+        }
114
+    }
115 115
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Delete.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -39,77 +39,77 @@
 block discarded – undo
39 39
 use Symfony\Component\Console\Question\ConfirmationQuestion;
40 40
 
41 41
 class Delete extends Base {
42
-	/**
43
-	 * @var GlobalStoragesService
44
-	 */
45
-	protected $globalService;
42
+    /**
43
+     * @var GlobalStoragesService
44
+     */
45
+    protected $globalService;
46 46
 
47
-	/**
48
-	 * @var UserStoragesService
49
-	 */
50
-	protected $userService;
47
+    /**
48
+     * @var UserStoragesService
49
+     */
50
+    protected $userService;
51 51
 
52
-	/**
53
-	 * @var IUserSession
54
-	 */
55
-	protected $userSession;
52
+    /**
53
+     * @var IUserSession
54
+     */
55
+    protected $userSession;
56 56
 
57
-	/**
58
-	 * @var IUserManager
59
-	 */
60
-	protected $userManager;
57
+    /**
58
+     * @var IUserManager
59
+     */
60
+    protected $userManager;
61 61
 
62
-	public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
63
-		parent::__construct();
64
-		$this->globalService = $globalService;
65
-		$this->userService = $userService;
66
-		$this->userSession = $userSession;
67
-		$this->userManager = $userManager;
68
-	}
62
+    public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
63
+        parent::__construct();
64
+        $this->globalService = $globalService;
65
+        $this->userService = $userService;
66
+        $this->userSession = $userSession;
67
+        $this->userManager = $userManager;
68
+    }
69 69
 
70
-	protected function configure() {
71
-		$this
72
-			->setName('files_external:delete')
73
-			->setDescription('Delete an external mount')
74
-			->addArgument(
75
-				'mount_id',
76
-				InputArgument::REQUIRED,
77
-				'The id of the mount to edit'
78
-			)->addOption(
79
-				'yes',
80
-				'y',
81
-				InputOption::VALUE_NONE,
82
-				'Skip confirmation'
83
-			);
84
-		parent::configure();
85
-	}
70
+    protected function configure() {
71
+        $this
72
+            ->setName('files_external:delete')
73
+            ->setDescription('Delete an external mount')
74
+            ->addArgument(
75
+                'mount_id',
76
+                InputArgument::REQUIRED,
77
+                'The id of the mount to edit'
78
+            )->addOption(
79
+                'yes',
80
+                'y',
81
+                InputOption::VALUE_NONE,
82
+                'Skip confirmation'
83
+            );
84
+        parent::configure();
85
+    }
86 86
 
87
-	protected function execute(InputInterface $input, OutputInterface $output): int {
88
-		$mountId = $input->getArgument('mount_id');
89
-		try {
90
-			$mount = $this->globalService->getStorage($mountId);
91
-		} catch (NotFoundException $e) {
92
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
93
-			return 404;
94
-		}
87
+    protected function execute(InputInterface $input, OutputInterface $output): int {
88
+        $mountId = $input->getArgument('mount_id');
89
+        try {
90
+            $mount = $this->globalService->getStorage($mountId);
91
+        } catch (NotFoundException $e) {
92
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
93
+            return 404;
94
+        }
95 95
 
96
-		$noConfirm = $input->getOption('yes');
96
+        $noConfirm = $input->getOption('yes');
97 97
 
98
-		if (!$noConfirm) {
99
-			$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
100
-			$listInput = new ArrayInput([], $listCommand->getDefinition());
101
-			$listInput->setOption('output', $input->getOption('output'));
102
-			$listCommand->listMounts(null, [$mount], $listInput, $output);
98
+        if (!$noConfirm) {
99
+            $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
100
+            $listInput = new ArrayInput([], $listCommand->getDefinition());
101
+            $listInput->setOption('output', $input->getOption('output'));
102
+            $listCommand->listMounts(null, [$mount], $listInput, $output);
103 103
 
104
-			$questionHelper = $this->getHelper('question');
105
-			$question = new ConfirmationQuestion('Delete this mount? [y/N] ', false);
104
+            $questionHelper = $this->getHelper('question');
105
+            $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false);
106 106
 
107
-			if (!$questionHelper->ask($input, $output, $question)) {
108
-				return 1;
109
-			}
110
-		}
107
+            if (!$questionHelper->ask($input, $output, $question)) {
108
+                return 1;
109
+            }
110
+        }
111 111
 
112
-		$this->globalService->removeStorage($mountId);
113
-		return 0;
114
-	}
112
+        $this->globalService->removeStorage($mountId);
113
+        return 0;
114
+    }
115 115
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Create.php 1 patch
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -44,182 +44,182 @@
 block discarded – undo
44 44
 use Symfony\Component\Console\Output\OutputInterface;
45 45
 
46 46
 class Create extends Base {
47
-	/**
48
-	 * @var GlobalStoragesService
49
-	 */
50
-	private $globalService;
51
-
52
-	/**
53
-	 * @var UserStoragesService
54
-	 */
55
-	private $userService;
56
-
57
-	/**
58
-	 * @var IUserManager
59
-	 */
60
-	private $userManager;
61
-
62
-	/** @var BackendService */
63
-	private $backendService;
64
-
65
-	/** @var IUserSession */
66
-	private $userSession;
67
-
68
-	public function __construct(GlobalStoragesService $globalService,
69
-						 UserStoragesService $userService,
70
-						 IUserManager $userManager,
71
-						 IUserSession $userSession,
72
-						 BackendService $backendService
73
-	) {
74
-		parent::__construct();
75
-		$this->globalService = $globalService;
76
-		$this->userService = $userService;
77
-		$this->userManager = $userManager;
78
-		$this->userSession = $userSession;
79
-		$this->backendService = $backendService;
80
-	}
81
-
82
-	protected function configure() {
83
-		$this
84
-			->setName('files_external:create')
85
-			->setDescription('Create a new mount configuration')
86
-			->addOption(
87
-				'user',
88
-				'',
89
-				InputOption::VALUE_OPTIONAL,
90
-				'user to add the mount configuration for, if not set the mount will be added as system mount'
91
-			)
92
-			->addArgument(
93
-				'mount_point',
94
-				InputArgument::REQUIRED,
95
-				'mount point for the new mount'
96
-			)
97
-			->addArgument(
98
-				'storage_backend',
99
-				InputArgument::REQUIRED,
100
-				'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
101
-			)
102
-			->addArgument(
103
-				'authentication_backend',
104
-				InputArgument::REQUIRED,
105
-				'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
106
-			)
107
-			->addOption(
108
-				'config',
109
-				'c',
110
-				InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
111
-				'Mount configuration option in key=value format'
112
-			)
113
-			->addOption(
114
-				'dry',
115
-				'',
116
-				InputOption::VALUE_NONE,
117
-				'Don\'t save the created mount, only list the new mount'
118
-			);
119
-		parent::configure();
120
-	}
121
-
122
-	protected function execute(InputInterface $input, OutputInterface $output): int {
123
-		$user = $input->getOption('user');
124
-		$mountPoint = $input->getArgument('mount_point');
125
-		$storageIdentifier = $input->getArgument('storage_backend');
126
-		$authIdentifier = $input->getArgument('authentication_backend');
127
-		$configInput = $input->getOption('config');
128
-
129
-		$storageBackend = $this->backendService->getBackend($storageIdentifier);
130
-		$authBackend = $this->backendService->getAuthMechanism($authIdentifier);
131
-
132
-		if (!Filesystem::isValidPath($mountPoint)) {
133
-			$output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
134
-			return 1;
135
-		}
136
-		if (is_null($storageBackend)) {
137
-			$output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
138
-			return 404;
139
-		}
140
-		if (is_null($authBackend)) {
141
-			$output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
142
-			return 404;
143
-		}
144
-		$supportedSchemes = array_keys($storageBackend->getAuthSchemes());
145
-		if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
146
-			$output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
147
-			return 1;
148
-		}
149
-
150
-		$config = [];
151
-		foreach ($configInput as $configOption) {
152
-			if (!strpos($configOption, '=')) {
153
-				$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
154
-				return 1;
155
-			}
156
-			list($key, $value) = explode('=', $configOption, 2);
157
-			if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
158
-				$output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
159
-				return 1;
160
-			}
161
-			$config[$key] = $value;
162
-		}
163
-
164
-		$mount = new StorageConfig();
165
-		$mount->setMountPoint($mountPoint);
166
-		$mount->setBackend($storageBackend);
167
-		$mount->setAuthMechanism($authBackend);
168
-		$mount->setBackendOptions($config);
169
-
170
-		if ($user) {
171
-			if (!$this->userManager->userExists($user)) {
172
-				$output->writeln('<error>User "' . $user . '" not found</error>');
173
-				return 1;
174
-			}
175
-			$mount->setApplicableUsers([$user]);
176
-		}
177
-
178
-		if ($input->getOption('dry')) {
179
-			$this->showMount($user, $mount, $input, $output);
180
-		} else {
181
-			$this->getStorageService($user)->addStorage($mount);
182
-			if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
183
-				$output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
184
-			} else {
185
-				$output->writeln((string)$mount->getId());
186
-			}
187
-		}
188
-		return 0;
189
-	}
190
-
191
-	private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
192
-		$params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
193
-		foreach ($params as $param) {
194
-			/** @var DefinitionParameter $param */
195
-			if ($param->getName() === $key) {
196
-				if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
197
-					$value = ($value === 'true');
198
-				}
199
-				return true;
200
-			}
201
-		}
202
-		return false;
203
-	}
204
-
205
-	private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
206
-		$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
207
-		$listInput = new ArrayInput([], $listCommand->getDefinition());
208
-		$listInput->setOption('output', $input->getOption('output'));
209
-		$listInput->setOption('show-password', true);
210
-		$listCommand->listMounts($user, [$mount], $listInput, $output);
211
-	}
212
-
213
-	protected function getStorageService($userId) {
214
-		if (!empty($userId)) {
215
-			$user = $this->userManager->get($userId);
216
-			if (is_null($user)) {
217
-				throw new NoUserException("user $userId not found");
218
-			}
219
-			$this->userSession->setUser($user);
220
-			return $this->userService;
221
-		} else {
222
-			return $this->globalService;
223
-		}
224
-	}
47
+    /**
48
+     * @var GlobalStoragesService
49
+     */
50
+    private $globalService;
51
+
52
+    /**
53
+     * @var UserStoragesService
54
+     */
55
+    private $userService;
56
+
57
+    /**
58
+     * @var IUserManager
59
+     */
60
+    private $userManager;
61
+
62
+    /** @var BackendService */
63
+    private $backendService;
64
+
65
+    /** @var IUserSession */
66
+    private $userSession;
67
+
68
+    public function __construct(GlobalStoragesService $globalService,
69
+                            UserStoragesService $userService,
70
+                            IUserManager $userManager,
71
+                            IUserSession $userSession,
72
+                            BackendService $backendService
73
+    ) {
74
+        parent::__construct();
75
+        $this->globalService = $globalService;
76
+        $this->userService = $userService;
77
+        $this->userManager = $userManager;
78
+        $this->userSession = $userSession;
79
+        $this->backendService = $backendService;
80
+    }
81
+
82
+    protected function configure() {
83
+        $this
84
+            ->setName('files_external:create')
85
+            ->setDescription('Create a new mount configuration')
86
+            ->addOption(
87
+                'user',
88
+                '',
89
+                InputOption::VALUE_OPTIONAL,
90
+                'user to add the mount configuration for, if not set the mount will be added as system mount'
91
+            )
92
+            ->addArgument(
93
+                'mount_point',
94
+                InputArgument::REQUIRED,
95
+                'mount point for the new mount'
96
+            )
97
+            ->addArgument(
98
+                'storage_backend',
99
+                InputArgument::REQUIRED,
100
+                'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
101
+            )
102
+            ->addArgument(
103
+                'authentication_backend',
104
+                InputArgument::REQUIRED,
105
+                'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
106
+            )
107
+            ->addOption(
108
+                'config',
109
+                'c',
110
+                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
111
+                'Mount configuration option in key=value format'
112
+            )
113
+            ->addOption(
114
+                'dry',
115
+                '',
116
+                InputOption::VALUE_NONE,
117
+                'Don\'t save the created mount, only list the new mount'
118
+            );
119
+        parent::configure();
120
+    }
121
+
122
+    protected function execute(InputInterface $input, OutputInterface $output): int {
123
+        $user = $input->getOption('user');
124
+        $mountPoint = $input->getArgument('mount_point');
125
+        $storageIdentifier = $input->getArgument('storage_backend');
126
+        $authIdentifier = $input->getArgument('authentication_backend');
127
+        $configInput = $input->getOption('config');
128
+
129
+        $storageBackend = $this->backendService->getBackend($storageIdentifier);
130
+        $authBackend = $this->backendService->getAuthMechanism($authIdentifier);
131
+
132
+        if (!Filesystem::isValidPath($mountPoint)) {
133
+            $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
134
+            return 1;
135
+        }
136
+        if (is_null($storageBackend)) {
137
+            $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
138
+            return 404;
139
+        }
140
+        if (is_null($authBackend)) {
141
+            $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
142
+            return 404;
143
+        }
144
+        $supportedSchemes = array_keys($storageBackend->getAuthSchemes());
145
+        if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
146
+            $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
147
+            return 1;
148
+        }
149
+
150
+        $config = [];
151
+        foreach ($configInput as $configOption) {
152
+            if (!strpos($configOption, '=')) {
153
+                $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
154
+                return 1;
155
+            }
156
+            list($key, $value) = explode('=', $configOption, 2);
157
+            if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
158
+                $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
159
+                return 1;
160
+            }
161
+            $config[$key] = $value;
162
+        }
163
+
164
+        $mount = new StorageConfig();
165
+        $mount->setMountPoint($mountPoint);
166
+        $mount->setBackend($storageBackend);
167
+        $mount->setAuthMechanism($authBackend);
168
+        $mount->setBackendOptions($config);
169
+
170
+        if ($user) {
171
+            if (!$this->userManager->userExists($user)) {
172
+                $output->writeln('<error>User "' . $user . '" not found</error>');
173
+                return 1;
174
+            }
175
+            $mount->setApplicableUsers([$user]);
176
+        }
177
+
178
+        if ($input->getOption('dry')) {
179
+            $this->showMount($user, $mount, $input, $output);
180
+        } else {
181
+            $this->getStorageService($user)->addStorage($mount);
182
+            if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
183
+                $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
184
+            } else {
185
+                $output->writeln((string)$mount->getId());
186
+            }
187
+        }
188
+        return 0;
189
+    }
190
+
191
+    private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
192
+        $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
193
+        foreach ($params as $param) {
194
+            /** @var DefinitionParameter $param */
195
+            if ($param->getName() === $key) {
196
+                if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
197
+                    $value = ($value === 'true');
198
+                }
199
+                return true;
200
+            }
201
+        }
202
+        return false;
203
+    }
204
+
205
+    private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
206
+        $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
207
+        $listInput = new ArrayInput([], $listCommand->getDefinition());
208
+        $listInput->setOption('output', $input->getOption('output'));
209
+        $listInput->setOption('show-password', true);
210
+        $listCommand->listMounts($user, [$mount], $listInput, $output);
211
+    }
212
+
213
+    protected function getStorageService($userId) {
214
+        if (!empty($userId)) {
215
+            $user = $this->userManager->get($userId);
216
+            if (is_null($user)) {
217
+                throw new NoUserException("user $userId not found");
218
+            }
219
+            $this->userSession->setUser($user);
220
+            return $this->userService;
221
+        } else {
222
+            return $this->globalService;
223
+        }
224
+    }
225 225
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Notify.php 1 patch
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -46,253 +46,253 @@
 block discarded – undo
46 46
 use Symfony\Component\Console\Output\OutputInterface;
47 47
 
48 48
 class Notify extends Base {
49
-	/** @var GlobalStoragesService */
50
-	private $globalService;
51
-	/** @var IDBConnection */
52
-	private $connection;
53
-	/** @var ILogger */
54
-	private $logger;
49
+    /** @var GlobalStoragesService */
50
+    private $globalService;
51
+    /** @var IDBConnection */
52
+    private $connection;
53
+    /** @var ILogger */
54
+    private $logger;
55 55
 
56
-	public function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) {
57
-		parent::__construct();
58
-		$this->globalService = $globalService;
59
-		$this->connection = $connection;
60
-		$this->logger = $logger;
61
-	}
56
+    public function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) {
57
+        parent::__construct();
58
+        $this->globalService = $globalService;
59
+        $this->connection = $connection;
60
+        $this->logger = $logger;
61
+    }
62 62
 
63
-	protected function configure() {
64
-		$this
65
-			->setName('files_external:notify')
66
-			->setDescription('Listen for active update notifications for a configured external mount')
67
-			->addArgument(
68
-				'mount_id',
69
-				InputArgument::REQUIRED,
70
-				'the mount id of the mount to listen to'
71
-			)->addOption(
72
-				'user',
73
-				'u',
74
-				InputOption::VALUE_REQUIRED,
75
-				'The username for the remote mount (required only for some mount configuration that don\'t store credentials)'
76
-			)->addOption(
77
-				'password',
78
-				'p',
79
-				InputOption::VALUE_REQUIRED,
80
-				'The password for the remote mount (required only for some mount configuration that don\'t store credentials)'
81
-			)->addOption(
82
-				'path',
83
-				'',
84
-				InputOption::VALUE_REQUIRED,
85
-				'The directory in the storage to listen for updates in',
86
-				'/'
87
-			);
88
-		parent::configure();
89
-	}
63
+    protected function configure() {
64
+        $this
65
+            ->setName('files_external:notify')
66
+            ->setDescription('Listen for active update notifications for a configured external mount')
67
+            ->addArgument(
68
+                'mount_id',
69
+                InputArgument::REQUIRED,
70
+                'the mount id of the mount to listen to'
71
+            )->addOption(
72
+                'user',
73
+                'u',
74
+                InputOption::VALUE_REQUIRED,
75
+                'The username for the remote mount (required only for some mount configuration that don\'t store credentials)'
76
+            )->addOption(
77
+                'password',
78
+                'p',
79
+                InputOption::VALUE_REQUIRED,
80
+                'The password for the remote mount (required only for some mount configuration that don\'t store credentials)'
81
+            )->addOption(
82
+                'path',
83
+                '',
84
+                InputOption::VALUE_REQUIRED,
85
+                'The directory in the storage to listen for updates in',
86
+                '/'
87
+            );
88
+        parent::configure();
89
+    }
90 90
 
91
-	protected function execute(InputInterface $input, OutputInterface $output): int {
92
-		$mount = $this->globalService->getStorage($input->getArgument('mount_id'));
93
-		if (is_null($mount)) {
94
-			$output->writeln('<error>Mount not found</error>');
95
-			return 1;
96
-		}
97
-		$noAuth = false;
98
-		try {
99
-			$authBackend = $mount->getAuthMechanism();
100
-			$authBackend->manipulateStorageConfig($mount);
101
-		} catch (InsufficientDataForMeaningfulAnswerException $e) {
102
-			$noAuth = true;
103
-		} catch (StorageNotAvailableException $e) {
104
-			$noAuth = true;
105
-		}
91
+    protected function execute(InputInterface $input, OutputInterface $output): int {
92
+        $mount = $this->globalService->getStorage($input->getArgument('mount_id'));
93
+        if (is_null($mount)) {
94
+            $output->writeln('<error>Mount not found</error>');
95
+            return 1;
96
+        }
97
+        $noAuth = false;
98
+        try {
99
+            $authBackend = $mount->getAuthMechanism();
100
+            $authBackend->manipulateStorageConfig($mount);
101
+        } catch (InsufficientDataForMeaningfulAnswerException $e) {
102
+            $noAuth = true;
103
+        } catch (StorageNotAvailableException $e) {
104
+            $noAuth = true;
105
+        }
106 106
 
107
-		if ($input->getOption('user')) {
108
-			$mount->setBackendOption('user', $input->getOption('user'));
109
-		} elseif (isset($_ENV['NOTIFY_USER'])) {
110
-			$mount->setBackendOption('user', $_ENV['NOTIFY_USER']);
111
-		} elseif (isset($_SERVER['NOTIFY_USER'])) {
112
-			$mount->setBackendOption('user', $_SERVER['NOTIFY_USER']);
113
-		}
114
-		if ($input->getOption('password')) {
115
-			$mount->setBackendOption('password', $input->getOption('password'));
116
-		} elseif (isset($_ENV['NOTIFY_PASSWORD'])) {
117
-			$mount->setBackendOption('password', $_ENV['NOTIFY_PASSWORD']);
118
-		} elseif (isset($_SERVER['NOTIFY_PASSWORD'])) {
119
-			$mount->setBackendOption('password', $_SERVER['NOTIFY_PASSWORD']);
120
-		}
107
+        if ($input->getOption('user')) {
108
+            $mount->setBackendOption('user', $input->getOption('user'));
109
+        } elseif (isset($_ENV['NOTIFY_USER'])) {
110
+            $mount->setBackendOption('user', $_ENV['NOTIFY_USER']);
111
+        } elseif (isset($_SERVER['NOTIFY_USER'])) {
112
+            $mount->setBackendOption('user', $_SERVER['NOTIFY_USER']);
113
+        }
114
+        if ($input->getOption('password')) {
115
+            $mount->setBackendOption('password', $input->getOption('password'));
116
+        } elseif (isset($_ENV['NOTIFY_PASSWORD'])) {
117
+            $mount->setBackendOption('password', $_ENV['NOTIFY_PASSWORD']);
118
+        } elseif (isset($_SERVER['NOTIFY_PASSWORD'])) {
119
+            $mount->setBackendOption('password', $_SERVER['NOTIFY_PASSWORD']);
120
+        }
121 121
 
122
-		try {
123
-			$storage = $this->createStorage($mount);
124
-		} catch (\Exception $e) {
125
-			$output->writeln('<error>Error while trying to create storage</error>');
126
-			if ($noAuth) {
127
-				$output->writeln('<error>Username and/or password required</error>');
128
-			}
129
-			return 1;
130
-		}
131
-		if (!$storage instanceof INotifyStorage) {
132
-			$output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
133
-			return 1;
134
-		}
122
+        try {
123
+            $storage = $this->createStorage($mount);
124
+        } catch (\Exception $e) {
125
+            $output->writeln('<error>Error while trying to create storage</error>');
126
+            if ($noAuth) {
127
+                $output->writeln('<error>Username and/or password required</error>');
128
+            }
129
+            return 1;
130
+        }
131
+        if (!$storage instanceof INotifyStorage) {
132
+            $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
133
+            return 1;
134
+        }
135 135
 
136
-		$verbose = $input->getOption('verbose');
136
+        $verbose = $input->getOption('verbose');
137 137
 
138
-		$path = trim($input->getOption('path'), '/');
139
-		$notifyHandler = $storage->notify($path);
140
-		$this->selfTest($storage, $notifyHandler, $verbose, $output);
141
-		$notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
142
-			if ($verbose) {
143
-				$this->logUpdate($change, $output);
144
-			}
145
-			if ($change instanceof IRenameChange) {
146
-				$this->markParentAsOutdated($mount->getId(), $change->getTargetPath(), $output);
147
-			}
148
-			$this->markParentAsOutdated($mount->getId(), $change->getPath(), $output);
149
-		});
150
-		return 0;
151
-	}
138
+        $path = trim($input->getOption('path'), '/');
139
+        $notifyHandler = $storage->notify($path);
140
+        $this->selfTest($storage, $notifyHandler, $verbose, $output);
141
+        $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
142
+            if ($verbose) {
143
+                $this->logUpdate($change, $output);
144
+            }
145
+            if ($change instanceof IRenameChange) {
146
+                $this->markParentAsOutdated($mount->getId(), $change->getTargetPath(), $output);
147
+            }
148
+            $this->markParentAsOutdated($mount->getId(), $change->getPath(), $output);
149
+        });
150
+        return 0;
151
+    }
152 152
 
153
-	private function createStorage(StorageConfig $mount) {
154
-		$class = $mount->getBackend()->getStorageClass();
155
-		return new $class($mount->getBackendOptions());
156
-	}
153
+    private function createStorage(StorageConfig $mount) {
154
+        $class = $mount->getBackend()->getStorageClass();
155
+        return new $class($mount->getBackendOptions());
156
+    }
157 157
 
158
-	private function markParentAsOutdated($mountId, $path, OutputInterface $output) {
159
-		$parent = ltrim(dirname($path), '/');
160
-		if ($parent === '.') {
161
-			$parent = '';
162
-		}
158
+    private function markParentAsOutdated($mountId, $path, OutputInterface $output) {
159
+        $parent = ltrim(dirname($path), '/');
160
+        if ($parent === '.') {
161
+            $parent = '';
162
+        }
163 163
 
164
-		try {
165
-			$storageIds = $this->getStorageIds($mountId);
166
-		} catch (DriverException $ex) {
167
-			$this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]);
168
-			$this->connection = $this->reconnectToDatabase($this->connection, $output);
169
-			$output->writeln('<info>Needed to reconnect to the database</info>');
170
-			$storageIds = $this->getStorageIds($mountId);
171
-		}
172
-		if (count($storageIds) === 0) {
173
-			throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId);
174
-		}
175
-		$storageIds = array_map('intval', $storageIds);
164
+        try {
165
+            $storageIds = $this->getStorageIds($mountId);
166
+        } catch (DriverException $ex) {
167
+            $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]);
168
+            $this->connection = $this->reconnectToDatabase($this->connection, $output);
169
+            $output->writeln('<info>Needed to reconnect to the database</info>');
170
+            $storageIds = $this->getStorageIds($mountId);
171
+        }
172
+        if (count($storageIds) === 0) {
173
+            throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId);
174
+        }
175
+        $storageIds = array_map('intval', $storageIds);
176 176
 
177
-		$result = $this->updateParent($storageIds, $parent);
178
-		if ($result === 0) {
179
-			//TODO: Find existing parent further up the tree in the database and register that folder instead.
180
-			$this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.');
181
-		}
182
-	}
177
+        $result = $this->updateParent($storageIds, $parent);
178
+        if ($result === 0) {
179
+            //TODO: Find existing parent further up the tree in the database and register that folder instead.
180
+            $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.');
181
+        }
182
+    }
183 183
 
184
-	private function logUpdate(IChange $change, OutputInterface $output) {
185
-		switch ($change->getType()) {
186
-			case INotifyStorage::NOTIFY_ADDED:
187
-				$text = 'added';
188
-				break;
189
-			case INotifyStorage::NOTIFY_MODIFIED:
190
-				$text = 'modified';
191
-				break;
192
-			case INotifyStorage::NOTIFY_REMOVED:
193
-				$text = 'removed';
194
-				break;
195
-			case INotifyStorage::NOTIFY_RENAMED:
196
-				$text = 'renamed';
197
-				break;
198
-			default:
199
-				return;
200
-		}
184
+    private function logUpdate(IChange $change, OutputInterface $output) {
185
+        switch ($change->getType()) {
186
+            case INotifyStorage::NOTIFY_ADDED:
187
+                $text = 'added';
188
+                break;
189
+            case INotifyStorage::NOTIFY_MODIFIED:
190
+                $text = 'modified';
191
+                break;
192
+            case INotifyStorage::NOTIFY_REMOVED:
193
+                $text = 'removed';
194
+                break;
195
+            case INotifyStorage::NOTIFY_RENAMED:
196
+                $text = 'renamed';
197
+                break;
198
+            default:
199
+                return;
200
+        }
201 201
 
202
-		$text .= ' ' . $change->getPath();
203
-		if ($change instanceof IRenameChange) {
204
-			$text .= ' to ' . $change->getTargetPath();
205
-		}
202
+        $text .= ' ' . $change->getPath();
203
+        if ($change instanceof IRenameChange) {
204
+            $text .= ' to ' . $change->getTargetPath();
205
+        }
206 206
 
207
-		$output->writeln($text);
208
-	}
207
+        $output->writeln($text);
208
+    }
209 209
 
210
-	/**
211
-	 * @param int $mountId
212
-	 * @return array
213
-	 */
214
-	private function getStorageIds($mountId) {
215
-		$qb = $this->connection->getQueryBuilder();
216
-		return $qb
217
-			->select('storage_id')
218
-			->from('mounts')
219
-			->where($qb->expr()->eq('mount_id', $qb->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
220
-			->execute()
221
-			->fetchAll(\PDO::FETCH_COLUMN);
222
-	}
210
+    /**
211
+     * @param int $mountId
212
+     * @return array
213
+     */
214
+    private function getStorageIds($mountId) {
215
+        $qb = $this->connection->getQueryBuilder();
216
+        return $qb
217
+            ->select('storage_id')
218
+            ->from('mounts')
219
+            ->where($qb->expr()->eq('mount_id', $qb->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
220
+            ->execute()
221
+            ->fetchAll(\PDO::FETCH_COLUMN);
222
+    }
223 223
 
224
-	/**
225
-	 * @param array $storageIds
226
-	 * @param string $parent
227
-	 * @return int
228
-	 */
229
-	private function updateParent($storageIds, $parent) {
230
-		$pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/'));
231
-		$qb = $this->connection->getQueryBuilder();
232
-		return $qb
233
-			->update('filecache')
234
-			->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
235
-			->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids')))
236
-			->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR)))
237
-			->execute();
238
-	}
224
+    /**
225
+     * @param array $storageIds
226
+     * @param string $parent
227
+     * @return int
228
+     */
229
+    private function updateParent($storageIds, $parent) {
230
+        $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/'));
231
+        $qb = $this->connection->getQueryBuilder();
232
+        return $qb
233
+            ->update('filecache')
234
+            ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
235
+            ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids')))
236
+            ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR)))
237
+            ->execute();
238
+    }
239 239
 
240
-	/**
241
-	 * @return \OCP\IDBConnection
242
-	 */
243
-	private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) {
244
-		try {
245
-			$connection->close();
246
-		} catch (\Exception $ex) {
247
-			$this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]);
248
-			$output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>");
249
-		}
250
-		while (!$connection->isConnected()) {
251
-			try {
252
-				$connection->connect();
253
-			} catch (\Exception $ex) {
254
-				$this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]);
255
-				$output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>");
256
-				sleep(60);
257
-			}
258
-		}
259
-		return $connection;
260
-	}
240
+    /**
241
+     * @return \OCP\IDBConnection
242
+     */
243
+    private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) {
244
+        try {
245
+            $connection->close();
246
+        } catch (\Exception $ex) {
247
+            $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]);
248
+            $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>");
249
+        }
250
+        while (!$connection->isConnected()) {
251
+            try {
252
+                $connection->connect();
253
+            } catch (\Exception $ex) {
254
+                $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]);
255
+                $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>");
256
+                sleep(60);
257
+            }
258
+        }
259
+        return $connection;
260
+    }
261 261
 
262 262
 
263
-	private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
264
-		usleep(100 * 1000); //give time for the notify to start
265
-		$storage->file_put_contents('/.nc_test_file.txt', 'test content');
266
-		$storage->mkdir('/.nc_test_folder');
267
-		$storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
263
+    private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
264
+        usleep(100 * 1000); //give time for the notify to start
265
+        $storage->file_put_contents('/.nc_test_file.txt', 'test content');
266
+        $storage->mkdir('/.nc_test_folder');
267
+        $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
268 268
 
269
-		usleep(100 * 1000); //time for all changes to be processed
270
-		$changes = $notifyHandler->getChanges();
269
+        usleep(100 * 1000); //time for all changes to be processed
270
+        $changes = $notifyHandler->getChanges();
271 271
 
272
-		$storage->unlink('/.nc_test_file.txt');
273
-		$storage->unlink('/.nc_test_folder/subfile.txt');
274
-		$storage->rmdir('/.nc_test_folder');
272
+        $storage->unlink('/.nc_test_file.txt');
273
+        $storage->unlink('/.nc_test_folder/subfile.txt');
274
+        $storage->rmdir('/.nc_test_folder');
275 275
 
276
-		usleep(100 * 1000); //time for all changes to be processed
277
-		$notifyHandler->getChanges(); // flush
276
+        usleep(100 * 1000); //time for all changes to be processed
277
+        $notifyHandler->getChanges(); // flush
278 278
 
279
-		$foundRootChange = false;
280
-		$foundSubfolderChange = false;
279
+        $foundRootChange = false;
280
+        $foundSubfolderChange = false;
281 281
 
282
-		foreach ($changes as $change) {
283
-			if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') {
284
-				$foundRootChange = true;
285
-			} elseif ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') {
286
-				$foundSubfolderChange = true;
287
-			}
288
-		}
282
+        foreach ($changes as $change) {
283
+            if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') {
284
+                $foundRootChange = true;
285
+            } elseif ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') {
286
+                $foundSubfolderChange = true;
287
+            }
288
+        }
289 289
 
290
-		if ($foundRootChange && $foundSubfolderChange && $verbose) {
291
-			$output->writeln('<info>Self-test successful</info>');
292
-		} elseif ($foundRootChange && !$foundSubfolderChange) {
293
-			$output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
294
-		} elseif (!$foundRootChange) {
295
-			$output->writeln('<error>Error while running self-test, no changes detected</error>');
296
-		}
297
-	}
290
+        if ($foundRootChange && $foundSubfolderChange && $verbose) {
291
+            $output->writeln('<info>Self-test successful</info>');
292
+        } elseif ($foundRootChange && !$foundSubfolderChange) {
293
+            $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
294
+        } elseif (!$foundRootChange) {
295
+            $output->writeln('<error>Error while running self-test, no changes detected</error>');
296
+        }
297
+    }
298 298
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/ListCommand.php 1 patch
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -39,241 +39,241 @@
 block discarded – undo
39 39
 use Symfony\Component\Console\Output\OutputInterface;
40 40
 
41 41
 class ListCommand extends Base {
42
-	/**
43
-	 * @var GlobalStoragesService
44
-	 */
45
-	protected $globalService;
42
+    /**
43
+     * @var GlobalStoragesService
44
+     */
45
+    protected $globalService;
46 46
 
47
-	/**
48
-	 * @var UserStoragesService
49
-	 */
50
-	protected $userService;
47
+    /**
48
+     * @var UserStoragesService
49
+     */
50
+    protected $userService;
51 51
 
52
-	/**
53
-	 * @var IUserSession
54
-	 */
55
-	protected $userSession;
52
+    /**
53
+     * @var IUserSession
54
+     */
55
+    protected $userSession;
56 56
 
57
-	/**
58
-	 * @var IUserManager
59
-	 */
60
-	protected $userManager;
57
+    /**
58
+     * @var IUserManager
59
+     */
60
+    protected $userManager;
61 61
 
62
-	public const ALL = -1;
62
+    public const ALL = -1;
63 63
 
64
-	public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
65
-		parent::__construct();
66
-		$this->globalService = $globalService;
67
-		$this->userService = $userService;
68
-		$this->userSession = $userSession;
69
-		$this->userManager = $userManager;
70
-	}
64
+    public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
65
+        parent::__construct();
66
+        $this->globalService = $globalService;
67
+        $this->userService = $userService;
68
+        $this->userSession = $userSession;
69
+        $this->userManager = $userManager;
70
+    }
71 71
 
72
-	protected function configure() {
73
-		$this
74
-			->setName('files_external:list')
75
-			->setDescription('List configured admin or personal mounts')
76
-			->addArgument(
77
-				'user_id',
78
-				InputArgument::OPTIONAL,
79
-				'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
80
-			)->addOption(
81
-				'show-password',
82
-				'',
83
-				InputOption::VALUE_NONE,
84
-				'show passwords and secrets'
85
-			)->addOption(
86
-				'full',
87
-				null,
88
-				InputOption::VALUE_NONE,
89
-				'don\'t truncate long values in table output'
90
-			)->addOption(
91
-				'all',
92
-				'a',
93
-				InputOption::VALUE_NONE,
94
-				'show both system wide mounts and all personal mounts'
95
-			);
96
-		parent::configure();
97
-	}
72
+    protected function configure() {
73
+        $this
74
+            ->setName('files_external:list')
75
+            ->setDescription('List configured admin or personal mounts')
76
+            ->addArgument(
77
+                'user_id',
78
+                InputArgument::OPTIONAL,
79
+                'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
80
+            )->addOption(
81
+                'show-password',
82
+                '',
83
+                InputOption::VALUE_NONE,
84
+                'show passwords and secrets'
85
+            )->addOption(
86
+                'full',
87
+                null,
88
+                InputOption::VALUE_NONE,
89
+                'don\'t truncate long values in table output'
90
+            )->addOption(
91
+                'all',
92
+                'a',
93
+                InputOption::VALUE_NONE,
94
+                'show both system wide mounts and all personal mounts'
95
+            );
96
+        parent::configure();
97
+    }
98 98
 
99
-	protected function execute(InputInterface $input, OutputInterface $output): int {
100
-		if ($input->getOption('all')) {
101
-			/** @var  $mounts StorageConfig[] */
102
-			$mounts = $this->globalService->getStorageForAllUsers();
103
-			$userId = self::ALL;
104
-		} else {
105
-			$userId = $input->getArgument('user_id');
106
-			$storageService = $this->getStorageService($userId);
99
+    protected function execute(InputInterface $input, OutputInterface $output): int {
100
+        if ($input->getOption('all')) {
101
+            /** @var  $mounts StorageConfig[] */
102
+            $mounts = $this->globalService->getStorageForAllUsers();
103
+            $userId = self::ALL;
104
+        } else {
105
+            $userId = $input->getArgument('user_id');
106
+            $storageService = $this->getStorageService($userId);
107 107
 
108
-			/** @var  $mounts StorageConfig[] */
109
-			$mounts = $storageService->getAllStorages();
110
-		}
108
+            /** @var  $mounts StorageConfig[] */
109
+            $mounts = $storageService->getAllStorages();
110
+        }
111 111
 
112
-		$this->listMounts($userId, $mounts, $input, $output);
113
-		return 0;
114
-	}
112
+        $this->listMounts($userId, $mounts, $input, $output);
113
+        return 0;
114
+    }
115 115
 
116
-	/**
117
-	 * @param $userId $userId
118
-	 * @param StorageConfig[] $mounts
119
-	 * @param InputInterface $input
120
-	 * @param OutputInterface $output
121
-	 */
122
-	public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) {
123
-		$outputType = $input->getOption('output');
124
-		if (count($mounts) === 0) {
125
-			if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
126
-				$output->writeln('[]');
127
-			} else {
128
-				if ($userId === self::ALL) {
129
-					$output->writeln("<info>No mounts configured</info>");
130
-				} elseif ($userId) {
131
-					$output->writeln("<info>No mounts configured by $userId</info>");
132
-				} else {
133
-					$output->writeln("<info>No admin mounts configured</info>");
134
-				}
135
-			}
136
-			return;
137
-		}
116
+    /**
117
+     * @param $userId $userId
118
+     * @param StorageConfig[] $mounts
119
+     * @param InputInterface $input
120
+     * @param OutputInterface $output
121
+     */
122
+    public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) {
123
+        $outputType = $input->getOption('output');
124
+        if (count($mounts) === 0) {
125
+            if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
126
+                $output->writeln('[]');
127
+            } else {
128
+                if ($userId === self::ALL) {
129
+                    $output->writeln("<info>No mounts configured</info>");
130
+                } elseif ($userId) {
131
+                    $output->writeln("<info>No mounts configured by $userId</info>");
132
+                } else {
133
+                    $output->writeln("<info>No admin mounts configured</info>");
134
+                }
135
+            }
136
+            return;
137
+        }
138 138
 
139
-		$headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
139
+        $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
140 140
 
141
-		if (!$userId || $userId === self::ALL) {
142
-			$headers[] = 'Applicable Users';
143
-			$headers[] = 'Applicable Groups';
144
-		}
145
-		if ($userId === self::ALL) {
146
-			$headers[] = 'Type';
147
-		}
141
+        if (!$userId || $userId === self::ALL) {
142
+            $headers[] = 'Applicable Users';
143
+            $headers[] = 'Applicable Groups';
144
+        }
145
+        if ($userId === self::ALL) {
146
+            $headers[] = 'Type';
147
+        }
148 148
 
149
-		if (!$input->getOption('show-password')) {
150
-			$hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
151
-			foreach ($mounts as $mount) {
152
-				$config = $mount->getBackendOptions();
153
-				foreach ($config as $key => $value) {
154
-					if (in_array($key, $hideKeys)) {
155
-						$mount->setBackendOption($key, '***');
156
-					}
157
-				}
158
-			}
159
-		}
149
+        if (!$input->getOption('show-password')) {
150
+            $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
151
+            foreach ($mounts as $mount) {
152
+                $config = $mount->getBackendOptions();
153
+                foreach ($config as $key => $value) {
154
+                    if (in_array($key, $hideKeys)) {
155
+                        $mount->setBackendOption($key, '***');
156
+                    }
157
+                }
158
+            }
159
+        }
160 160
 
161
-		if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
162
-			$keys = array_map(function ($header) {
163
-				return strtolower(str_replace(' ', '_', $header));
164
-			}, $headers);
161
+        if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
162
+            $keys = array_map(function ($header) {
163
+                return strtolower(str_replace(' ', '_', $header));
164
+            }, $headers);
165 165
 
166
-			$pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
167
-				$values = [
168
-					$config->getId(),
169
-					$config->getMountPoint(),
170
-					$config->getBackend()->getStorageClass(),
171
-					$config->getAuthMechanism()->getIdentifier(),
172
-					$config->getBackendOptions(),
173
-					$config->getMountOptions()
174
-				];
175
-				if (!$userId || $userId === self::ALL) {
176
-					$values[] = $config->getApplicableUsers();
177
-					$values[] = $config->getApplicableGroups();
178
-				}
179
-				if ($userId === self::ALL) {
180
-					$values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal';
181
-				}
166
+            $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
167
+                $values = [
168
+                    $config->getId(),
169
+                    $config->getMountPoint(),
170
+                    $config->getBackend()->getStorageClass(),
171
+                    $config->getAuthMechanism()->getIdentifier(),
172
+                    $config->getBackendOptions(),
173
+                    $config->getMountOptions()
174
+                ];
175
+                if (!$userId || $userId === self::ALL) {
176
+                    $values[] = $config->getApplicableUsers();
177
+                    $values[] = $config->getApplicableGroups();
178
+                }
179
+                if ($userId === self::ALL) {
180
+                    $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal';
181
+                }
182 182
 
183
-				return array_combine($keys, $values);
184
-			}, $mounts);
185
-			if ($outputType === self::OUTPUT_FORMAT_JSON) {
186
-				$output->writeln(json_encode(array_values($pairs)));
187
-			} else {
188
-				$output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
189
-			}
190
-		} else {
191
-			$full = $input->getOption('full');
192
-			$defaultMountOptions = [
193
-				'encrypt' => true,
194
-				'previews' => true,
195
-				'filesystem_check_changes' => 1,
196
-				'enable_sharing' => false,
197
-				'encoding_compatibility' => false,
198
-				'readonly' => false,
199
-			];
200
-			$rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
201
-				$storageConfig = $config->getBackendOptions();
202
-				$keys = array_keys($storageConfig);
203
-				$values = array_values($storageConfig);
183
+                return array_combine($keys, $values);
184
+            }, $mounts);
185
+            if ($outputType === self::OUTPUT_FORMAT_JSON) {
186
+                $output->writeln(json_encode(array_values($pairs)));
187
+            } else {
188
+                $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
189
+            }
190
+        } else {
191
+            $full = $input->getOption('full');
192
+            $defaultMountOptions = [
193
+                'encrypt' => true,
194
+                'previews' => true,
195
+                'filesystem_check_changes' => 1,
196
+                'enable_sharing' => false,
197
+                'encoding_compatibility' => false,
198
+                'readonly' => false,
199
+            ];
200
+            $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
201
+                $storageConfig = $config->getBackendOptions();
202
+                $keys = array_keys($storageConfig);
203
+                $values = array_values($storageConfig);
204 204
 
205
-				if (!$full) {
206
-					$values = array_map(function ($value) {
207
-						if (is_string($value) && strlen($value) > 32) {
208
-							return substr($value, 0, 6) . '...' . substr($value, -6, 6);
209
-						} else {
210
-							return $value;
211
-						}
212
-					}, $values);
213
-				}
205
+                if (!$full) {
206
+                    $values = array_map(function ($value) {
207
+                        if (is_string($value) && strlen($value) > 32) {
208
+                            return substr($value, 0, 6) . '...' . substr($value, -6, 6);
209
+                        } else {
210
+                            return $value;
211
+                        }
212
+                    }, $values);
213
+                }
214 214
 
215
-				$configStrings = array_map(function ($key, $value) {
216
-					return $key . ': ' . json_encode($value);
217
-				}, $keys, $values);
218
-				$configString = implode(', ', $configStrings);
215
+                $configStrings = array_map(function ($key, $value) {
216
+                    return $key . ': ' . json_encode($value);
217
+                }, $keys, $values);
218
+                $configString = implode(', ', $configStrings);
219 219
 
220
-				$mountOptions = $config->getMountOptions();
221
-				// hide defaults
222
-				foreach ($mountOptions as $key => $value) {
223
-					if ($value === $defaultMountOptions[$key]) {
224
-						unset($mountOptions[$key]);
225
-					}
226
-				}
227
-				$keys = array_keys($mountOptions);
228
-				$values = array_values($mountOptions);
220
+                $mountOptions = $config->getMountOptions();
221
+                // hide defaults
222
+                foreach ($mountOptions as $key => $value) {
223
+                    if ($value === $defaultMountOptions[$key]) {
224
+                        unset($mountOptions[$key]);
225
+                    }
226
+                }
227
+                $keys = array_keys($mountOptions);
228
+                $values = array_values($mountOptions);
229 229
 
230
-				$optionsStrings = array_map(function ($key, $value) {
231
-					return $key . ': ' . json_encode($value);
232
-				}, $keys, $values);
233
-				$optionsString = implode(', ', $optionsStrings);
230
+                $optionsStrings = array_map(function ($key, $value) {
231
+                    return $key . ': ' . json_encode($value);
232
+                }, $keys, $values);
233
+                $optionsString = implode(', ', $optionsStrings);
234 234
 
235
-				$values = [
236
-					$config->getId(),
237
-					$config->getMountPoint(),
238
-					$config->getBackend()->getText(),
239
-					$config->getAuthMechanism()->getText(),
240
-					$configString,
241
-					$optionsString
242
-				];
235
+                $values = [
236
+                    $config->getId(),
237
+                    $config->getMountPoint(),
238
+                    $config->getBackend()->getText(),
239
+                    $config->getAuthMechanism()->getText(),
240
+                    $configString,
241
+                    $optionsString
242
+                ];
243 243
 
244
-				if (!$userId || $userId === self::ALL) {
245
-					$applicableUsers = implode(', ', $config->getApplicableUsers());
246
-					$applicableGroups = implode(', ', $config->getApplicableGroups());
247
-					if ($applicableUsers === '' && $applicableGroups === '') {
248
-						$applicableUsers = 'All';
249
-					}
250
-					$values[] = $applicableUsers;
251
-					$values[] = $applicableGroups;
252
-				}
253
-				if ($userId === self::ALL) {
254
-					$values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal';
255
-				}
244
+                if (!$userId || $userId === self::ALL) {
245
+                    $applicableUsers = implode(', ', $config->getApplicableUsers());
246
+                    $applicableGroups = implode(', ', $config->getApplicableGroups());
247
+                    if ($applicableUsers === '' && $applicableGroups === '') {
248
+                        $applicableUsers = 'All';
249
+                    }
250
+                    $values[] = $applicableUsers;
251
+                    $values[] = $applicableGroups;
252
+                }
253
+                if ($userId === self::ALL) {
254
+                    $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal';
255
+                }
256 256
 
257
-				return $values;
258
-			}, $mounts);
257
+                return $values;
258
+            }, $mounts);
259 259
 
260
-			$table = new Table($output);
261
-			$table->setHeaders($headers);
262
-			$table->setRows($rows);
263
-			$table->render();
264
-		}
265
-	}
260
+            $table = new Table($output);
261
+            $table->setHeaders($headers);
262
+            $table->setRows($rows);
263
+            $table->render();
264
+        }
265
+    }
266 266
 
267
-	protected function getStorageService($userId) {
268
-		if (!empty($userId)) {
269
-			$user = $this->userManager->get($userId);
270
-			if (is_null($user)) {
271
-				throw new NoUserException("user $userId not found");
272
-			}
273
-			$this->userSession->setUser($user);
274
-			return $this->userService;
275
-		} else {
276
-			return $this->globalService;
277
-		}
278
-	}
267
+    protected function getStorageService($userId) {
268
+        if (!empty($userId)) {
269
+            $user = $this->userManager->get($userId);
270
+            if (is_null($user)) {
271
+                throw new NoUserException("user $userId not found");
272
+            }
273
+            $this->userSession->setUser($user);
274
+            return $this->userService;
275
+        } else {
276
+            return $this->globalService;
277
+        }
278
+    }
279 279
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Config.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -34,88 +34,88 @@
 block discarded – undo
34 34
 use Symfony\Component\Console\Output\OutputInterface;
35 35
 
36 36
 class Config extends Base {
37
-	/**
38
-	 * @var GlobalStoragesService
39
-	 */
40
-	protected $globalService;
37
+    /**
38
+     * @var GlobalStoragesService
39
+     */
40
+    protected $globalService;
41 41
 
42
-	public function __construct(GlobalStoragesService $globalService) {
43
-		parent::__construct();
44
-		$this->globalService = $globalService;
45
-	}
42
+    public function __construct(GlobalStoragesService $globalService) {
43
+        parent::__construct();
44
+        $this->globalService = $globalService;
45
+    }
46 46
 
47
-	protected function configure() {
48
-		$this
49
-			->setName('files_external:config')
50
-			->setDescription('Manage backend configuration for a mount')
51
-			->addArgument(
52
-				'mount_id',
53
-				InputArgument::REQUIRED,
54
-				'The id of the mount to edit'
55
-			)->addArgument(
56
-				'key',
57
-				InputArgument::REQUIRED,
58
-				'key of the config option to set/get'
59
-			)->addArgument(
60
-				'value',
61
-				InputArgument::OPTIONAL,
62
-				'value to set the config option to, when no value is provided the existing value will be printed'
63
-			);
64
-		parent::configure();
65
-	}
47
+    protected function configure() {
48
+        $this
49
+            ->setName('files_external:config')
50
+            ->setDescription('Manage backend configuration for a mount')
51
+            ->addArgument(
52
+                'mount_id',
53
+                InputArgument::REQUIRED,
54
+                'The id of the mount to edit'
55
+            )->addArgument(
56
+                'key',
57
+                InputArgument::REQUIRED,
58
+                'key of the config option to set/get'
59
+            )->addArgument(
60
+                'value',
61
+                InputArgument::OPTIONAL,
62
+                'value to set the config option to, when no value is provided the existing value will be printed'
63
+            );
64
+        parent::configure();
65
+    }
66 66
 
67
-	protected function execute(InputInterface $input, OutputInterface $output): int {
68
-		$mountId = $input->getArgument('mount_id');
69
-		$key = $input->getArgument('key');
70
-		try {
71
-			$mount = $this->globalService->getStorage($mountId);
72
-		} catch (NotFoundException $e) {
73
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
74
-			return 404;
75
-		}
67
+    protected function execute(InputInterface $input, OutputInterface $output): int {
68
+        $mountId = $input->getArgument('mount_id');
69
+        $key = $input->getArgument('key');
70
+        try {
71
+            $mount = $this->globalService->getStorage($mountId);
72
+        } catch (NotFoundException $e) {
73
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
74
+            return 404;
75
+        }
76 76
 
77
-		$value = $input->getArgument('value');
78
-		if ($value !== null) {
79
-			$this->setOption($mount, $key, $value, $output);
80
-		} else {
81
-			$this->getOption($mount, $key, $output);
82
-		}
83
-		return 0;
84
-	}
77
+        $value = $input->getArgument('value');
78
+        if ($value !== null) {
79
+            $this->setOption($mount, $key, $value, $output);
80
+        } else {
81
+            $this->getOption($mount, $key, $output);
82
+        }
83
+        return 0;
84
+    }
85 85
 
86
-	/**
87
-	 * @param StorageConfig $mount
88
-	 * @param string $key
89
-	 * @param OutputInterface $output
90
-	 */
91
-	protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
92
-		if ($key === 'mountpoint' || $key === 'mount_point') {
93
-			$value = $mount->getMountPoint();
94
-		} else {
95
-			$value = $mount->getBackendOption($key);
96
-		}
97
-		if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly
98
-			$value = json_encode($value);
99
-		}
100
-		$output->writeln($value);
101
-	}
86
+    /**
87
+     * @param StorageConfig $mount
88
+     * @param string $key
89
+     * @param OutputInterface $output
90
+     */
91
+    protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
92
+        if ($key === 'mountpoint' || $key === 'mount_point') {
93
+            $value = $mount->getMountPoint();
94
+        } else {
95
+            $value = $mount->getBackendOption($key);
96
+        }
97
+        if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly
98
+            $value = json_encode($value);
99
+        }
100
+        $output->writeln($value);
101
+    }
102 102
 
103
-	/**
104
-	 * @param StorageConfig $mount
105
-	 * @param string $key
106
-	 * @param string $value
107
-	 * @param OutputInterface $output
108
-	 */
109
-	protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
110
-		$decoded = json_decode($value, true);
111
-		if (!is_null($decoded) && json_encode($decoded) === $value) {
112
-			$value = $decoded;
113
-		}
114
-		if ($key === 'mountpoint' || $key === 'mount_point') {
115
-			$mount->setMountPoint($value);
116
-		} else {
117
-			$mount->setBackendOption($key, $value);
118
-		}
119
-		$this->globalService->updateStorage($mount);
120
-	}
103
+    /**
104
+     * @param StorageConfig $mount
105
+     * @param string $key
106
+     * @param string $value
107
+     * @param OutputInterface $output
108
+     */
109
+    protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
110
+        $decoded = json_decode($value, true);
111
+        if (!is_null($decoded) && json_encode($decoded) === $value) {
112
+            $value = $decoded;
113
+        }
114
+        if ($key === 'mountpoint' || $key === 'mount_point') {
115
+            $mount->setMountPoint($value);
116
+        } else {
117
+            $mount->setBackendOption($key, $value);
118
+        }
119
+        $this->globalService->updateStorage($mount);
120
+    }
121 121
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Verify.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -38,109 +38,109 @@
 block discarded – undo
38 38
 use Symfony\Component\Console\Output\OutputInterface;
39 39
 
40 40
 class Verify extends Base {
41
-	/**
42
-	 * @var GlobalStoragesService
43
-	 */
44
-	protected $globalService;
41
+    /**
42
+     * @var GlobalStoragesService
43
+     */
44
+    protected $globalService;
45 45
 
46
-	public function __construct(GlobalStoragesService $globalService) {
47
-		parent::__construct();
48
-		$this->globalService = $globalService;
49
-	}
46
+    public function __construct(GlobalStoragesService $globalService) {
47
+        parent::__construct();
48
+        $this->globalService = $globalService;
49
+    }
50 50
 
51
-	protected function configure() {
52
-		$this
53
-			->setName('files_external:verify')
54
-			->setDescription('Verify mount configuration')
55
-			->addArgument(
56
-				'mount_id',
57
-				InputArgument::REQUIRED,
58
-				'The id of the mount to check'
59
-			)->addOption(
60
-				'config',
61
-				'c',
62
-				InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
63
-				'Additional config option to set before checking in key=value pairs, required for certain auth backends such as login credentails'
64
-			);
65
-		parent::configure();
66
-	}
51
+    protected function configure() {
52
+        $this
53
+            ->setName('files_external:verify')
54
+            ->setDescription('Verify mount configuration')
55
+            ->addArgument(
56
+                'mount_id',
57
+                InputArgument::REQUIRED,
58
+                'The id of the mount to check'
59
+            )->addOption(
60
+                'config',
61
+                'c',
62
+                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
63
+                'Additional config option to set before checking in key=value pairs, required for certain auth backends such as login credentails'
64
+            );
65
+        parent::configure();
66
+    }
67 67
 
68
-	protected function execute(InputInterface $input, OutputInterface $output): int {
69
-		$mountId = $input->getArgument('mount_id');
70
-		$configInput = $input->getOption('config');
68
+    protected function execute(InputInterface $input, OutputInterface $output): int {
69
+        $mountId = $input->getArgument('mount_id');
70
+        $configInput = $input->getOption('config');
71 71
 
72
-		try {
73
-			$mount = $this->globalService->getStorage($mountId);
74
-		} catch (NotFoundException $e) {
75
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
76
-			return 404;
77
-		}
72
+        try {
73
+            $mount = $this->globalService->getStorage($mountId);
74
+        } catch (NotFoundException $e) {
75
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
76
+            return 404;
77
+        }
78 78
 
79
-		$this->updateStorageStatus($mount, $configInput, $output);
79
+        $this->updateStorageStatus($mount, $configInput, $output);
80 80
 
81
-		$this->writeArrayInOutputFormat($input, $output, [
82
-			'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()),
83
-			'code' => $mount->getStatus(),
84
-			'message' => $mount->getStatusMessage()
85
-		]);
86
-		return 0;
87
-	}
81
+        $this->writeArrayInOutputFormat($input, $output, [
82
+            'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()),
83
+            'code' => $mount->getStatus(),
84
+            'message' => $mount->getStatusMessage()
85
+        ]);
86
+        return 0;
87
+    }
88 88
 
89
-	private function manipulateStorageConfig(StorageConfig $storage) {
90
-		/** @var AuthMechanism */
91
-		$authMechanism = $storage->getAuthMechanism();
92
-		$authMechanism->manipulateStorageConfig($storage);
93
-		/** @var Backend */
94
-		$backend = $storage->getBackend();
95
-		$backend->manipulateStorageConfig($storage);
96
-	}
89
+    private function manipulateStorageConfig(StorageConfig $storage) {
90
+        /** @var AuthMechanism */
91
+        $authMechanism = $storage->getAuthMechanism();
92
+        $authMechanism->manipulateStorageConfig($storage);
93
+        /** @var Backend */
94
+        $backend = $storage->getBackend();
95
+        $backend->manipulateStorageConfig($storage);
96
+    }
97 97
 
98
-	private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) {
99
-		try {
100
-			try {
101
-				$this->manipulateStorageConfig($storage);
102
-			} catch (InsufficientDataForMeaningfulAnswerException $e) {
103
-				if (count($configInput) === 0) { // extra config options might solve the error
104
-					throw $e;
105
-				}
106
-			}
98
+    private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) {
99
+        try {
100
+            try {
101
+                $this->manipulateStorageConfig($storage);
102
+            } catch (InsufficientDataForMeaningfulAnswerException $e) {
103
+                if (count($configInput) === 0) { // extra config options might solve the error
104
+                    throw $e;
105
+                }
106
+            }
107 107
 
108
-			foreach ($configInput as $configOption) {
109
-				if (!strpos($configOption, '=')) {
110
-					$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
111
-					return;
112
-				}
113
-				list($key, $value) = explode('=', $configOption, 2);
114
-				$storage->setBackendOption($key, $value);
115
-			}
108
+            foreach ($configInput as $configOption) {
109
+                if (!strpos($configOption, '=')) {
110
+                    $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
111
+                    return;
112
+                }
113
+                list($key, $value) = explode('=', $configOption, 2);
114
+                $storage->setBackendOption($key, $value);
115
+            }
116 116
 
117
-			/** @var Backend */
118
-			$backend = $storage->getBackend();
119
-			// update status (can be time-consuming)
120
-			$storage->setStatus(
121
-				\OC_Mount_Config::getBackendStatus(
122
-					$backend->getStorageClass(),
123
-					$storage->getBackendOptions(),
124
-					false
125
-				)
126
-			);
127
-		} catch (InsufficientDataForMeaningfulAnswerException $e) {
128
-			$status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
129
-			$storage->setStatus(
130
-				$status,
131
-				$e->getMessage()
132
-			);
133
-		} catch (StorageNotAvailableException $e) {
134
-			$storage->setStatus(
135
-				$e->getCode(),
136
-				$e->getMessage()
137
-			);
138
-		} catch (\Exception $e) {
139
-			// FIXME: convert storage exceptions to StorageNotAvailableException
140
-			$storage->setStatus(
141
-				StorageNotAvailableException::STATUS_ERROR,
142
-				get_class($e) . ': ' . $e->getMessage()
143
-			);
144
-		}
145
-	}
117
+            /** @var Backend */
118
+            $backend = $storage->getBackend();
119
+            // update status (can be time-consuming)
120
+            $storage->setStatus(
121
+                \OC_Mount_Config::getBackendStatus(
122
+                    $backend->getStorageClass(),
123
+                    $storage->getBackendOptions(),
124
+                    false
125
+                )
126
+            );
127
+        } catch (InsufficientDataForMeaningfulAnswerException $e) {
128
+            $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
129
+            $storage->setStatus(
130
+                $status,
131
+                $e->getMessage()
132
+            );
133
+        } catch (StorageNotAvailableException $e) {
134
+            $storage->setStatus(
135
+                $e->getCode(),
136
+                $e->getMessage()
137
+            );
138
+        } catch (\Exception $e) {
139
+            // FIXME: convert storage exceptions to StorageNotAvailableException
140
+            $storage->setStatus(
141
+                StorageNotAvailableException::STATUS_ERROR,
142
+                get_class($e) . ': ' . $e->getMessage()
143
+            );
144
+        }
145
+    }
146 146
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Backends.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -33,92 +33,92 @@
 block discarded – undo
33 33
 use Symfony\Component\Console\Output\OutputInterface;
34 34
 
35 35
 class Backends extends Base {
36
-	/** @var BackendService */
37
-	private $backendService;
36
+    /** @var BackendService */
37
+    private $backendService;
38 38
 
39
-	public function __construct(BackendService $backendService
40
-	) {
41
-		parent::__construct();
39
+    public function __construct(BackendService $backendService
40
+    ) {
41
+        parent::__construct();
42 42
 
43
-		$this->backendService = $backendService;
44
-	}
43
+        $this->backendService = $backendService;
44
+    }
45 45
 
46
-	protected function configure() {
47
-		$this
48
-			->setName('files_external:backends')
49
-			->setDescription('Show available authentication and storage backends')
50
-			->addArgument(
51
-				'type',
52
-				InputArgument::OPTIONAL,
53
-				'only show backends of a certain type. Possible values are "authentication" or "storage"'
54
-			)->addArgument(
55
-				'backend',
56
-				InputArgument::OPTIONAL,
57
-				'only show information of a specific backend'
58
-			);
59
-		parent::configure();
60
-	}
46
+    protected function configure() {
47
+        $this
48
+            ->setName('files_external:backends')
49
+            ->setDescription('Show available authentication and storage backends')
50
+            ->addArgument(
51
+                'type',
52
+                InputArgument::OPTIONAL,
53
+                'only show backends of a certain type. Possible values are "authentication" or "storage"'
54
+            )->addArgument(
55
+                'backend',
56
+                InputArgument::OPTIONAL,
57
+                'only show information of a specific backend'
58
+            );
59
+        parent::configure();
60
+    }
61 61
 
62
-	protected function execute(InputInterface $input, OutputInterface $output): int {
63
-		$authBackends = $this->backendService->getAuthMechanisms();
64
-		$storageBackends = $this->backendService->getBackends();
62
+    protected function execute(InputInterface $input, OutputInterface $output): int {
63
+        $authBackends = $this->backendService->getAuthMechanisms();
64
+        $storageBackends = $this->backendService->getBackends();
65 65
 
66
-		$data = [
67
-			'authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends),
68
-			'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends)
69
-		];
66
+        $data = [
67
+            'authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends),
68
+            'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends)
69
+        ];
70 70
 
71
-		$type = $input->getArgument('type');
72
-		$backend = $input->getArgument('backend');
73
-		if ($type) {
74
-			if (!isset($data[$type])) {
75
-				$output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>');
76
-				return 1;
77
-			}
78
-			$data = $data[$type];
71
+        $type = $input->getArgument('type');
72
+        $backend = $input->getArgument('backend');
73
+        if ($type) {
74
+            if (!isset($data[$type])) {
75
+                $output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>');
76
+                return 1;
77
+            }
78
+            $data = $data[$type];
79 79
 
80
-			if ($backend) {
81
-				if (!isset($data[$backend])) {
82
-					$output->writeln('<error>Unknown backend "' . $backend . '" of type  "' . $type . '"</error>');
83
-					return 1;
84
-				}
85
-				$data = $data[$backend];
86
-			}
87
-		}
80
+            if ($backend) {
81
+                if (!isset($data[$backend])) {
82
+                    $output->writeln('<error>Unknown backend "' . $backend . '" of type  "' . $type . '"</error>');
83
+                    return 1;
84
+                }
85
+                $data = $data[$backend];
86
+            }
87
+        }
88 88
 
89
-		$this->writeArrayInOutputFormat($input, $output, $data);
90
-		return 0;
91
-	}
89
+        $this->writeArrayInOutputFormat($input, $output, $data);
90
+        return 0;
91
+    }
92 92
 
93
-	private function serializeAuthBackend(\JsonSerializable $backend) {
94
-		$data = $backend->jsonSerialize();
95
-		$result = [
96
-			'name' => $data['name'],
97
-			'identifier' => $data['identifier'],
98
-			'configuration' => $this->formatConfiguration($data['configuration'])
99
-		];
100
-		if ($backend instanceof Backend) {
101
-			$result['storage_class'] = $backend->getStorageClass();
102
-			$authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes()));
103
-			$result['supported_authentication_backends'] = array_keys($authBackends);
104
-			$authConfig = array_map(function (AuthMechanism $auth) {
105
-				return $this->serializeAuthBackend($auth)['configuration'];
106
-			}, $authBackends);
107
-			$result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig);
108
-		}
109
-		return $result;
110
-	}
93
+    private function serializeAuthBackend(\JsonSerializable $backend) {
94
+        $data = $backend->jsonSerialize();
95
+        $result = [
96
+            'name' => $data['name'],
97
+            'identifier' => $data['identifier'],
98
+            'configuration' => $this->formatConfiguration($data['configuration'])
99
+        ];
100
+        if ($backend instanceof Backend) {
101
+            $result['storage_class'] = $backend->getStorageClass();
102
+            $authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes()));
103
+            $result['supported_authentication_backends'] = array_keys($authBackends);
104
+            $authConfig = array_map(function (AuthMechanism $auth) {
105
+                return $this->serializeAuthBackend($auth)['configuration'];
106
+            }, $authBackends);
107
+            $result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig);
108
+        }
109
+        return $result;
110
+    }
111 111
 
112
-	/**
113
-	 * @param DefinitionParameter[] $parameters
114
-	 * @return string[]
115
-	 */
116
-	private function formatConfiguration(array $parameters) {
117
-		$configuration = array_filter($parameters, function (DefinitionParameter $parameter) {
118
-			return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN;
119
-		});
120
-		return array_map(function (DefinitionParameter $parameter) {
121
-			return $parameter->getTypeName();
122
-		}, $configuration);
123
-	}
112
+    /**
113
+     * @param DefinitionParameter[] $parameters
114
+     * @return string[]
115
+     */
116
+    private function formatConfiguration(array $parameters) {
117
+        $configuration = array_filter($parameters, function (DefinitionParameter $parameter) {
118
+            return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN;
119
+        });
120
+        return array_map(function (DefinitionParameter $parameter) {
121
+            return $parameter->getTypeName();
122
+        }, $configuration);
123
+    }
124 124
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Applicable.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -37,123 +37,123 @@
 block discarded – undo
37 37
 use Symfony\Component\Console\Output\OutputInterface;
38 38
 
39 39
 class Applicable extends Base {
40
-	/**
41
-	 * @var GlobalStoragesService
42
-	 */
43
-	protected $globalService;
40
+    /**
41
+     * @var GlobalStoragesService
42
+     */
43
+    protected $globalService;
44 44
 
45
-	/**
46
-	 * @var IUserManager
47
-	 */
48
-	private $userManager;
45
+    /**
46
+     * @var IUserManager
47
+     */
48
+    private $userManager;
49 49
 
50
-	/**
51
-	 * @var IGroupManager
52
-	 */
53
-	private $groupManager;
50
+    /**
51
+     * @var IGroupManager
52
+     */
53
+    private $groupManager;
54 54
 
55
-	public function __construct(
56
-		GlobalStoragesService $globalService,
57
-		IUserManager $userManager,
58
-		IGroupManager $groupManager
59
-	) {
60
-		parent::__construct();
61
-		$this->globalService = $globalService;
62
-		$this->userManager = $userManager;
63
-		$this->groupManager = $groupManager;
64
-	}
55
+    public function __construct(
56
+        GlobalStoragesService $globalService,
57
+        IUserManager $userManager,
58
+        IGroupManager $groupManager
59
+    ) {
60
+        parent::__construct();
61
+        $this->globalService = $globalService;
62
+        $this->userManager = $userManager;
63
+        $this->groupManager = $groupManager;
64
+    }
65 65
 
66
-	protected function configure() {
67
-		$this
68
-			->setName('files_external:applicable')
69
-			->setDescription('Manage applicable users and groups for a mount')
70
-			->addArgument(
71
-				'mount_id',
72
-				InputArgument::REQUIRED,
73
-				'The id of the mount to edit'
74
-			)->addOption(
75
-				'add-user',
76
-				'',
77
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
78
-				'user to add as applicable'
79
-			)->addOption(
80
-				'remove-user',
81
-				'',
82
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
83
-				'user to remove as applicable'
84
-			)->addOption(
85
-				'add-group',
86
-				'',
87
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
88
-				'group to add as applicable'
89
-			)->addOption(
90
-				'remove-group',
91
-				'',
92
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
93
-				'group to remove as applicable'
94
-			)->addOption(
95
-				'remove-all',
96
-				'',
97
-				InputOption::VALUE_NONE,
98
-				'Set the mount to be globally applicable'
99
-			);
100
-		parent::configure();
101
-	}
66
+    protected function configure() {
67
+        $this
68
+            ->setName('files_external:applicable')
69
+            ->setDescription('Manage applicable users and groups for a mount')
70
+            ->addArgument(
71
+                'mount_id',
72
+                InputArgument::REQUIRED,
73
+                'The id of the mount to edit'
74
+            )->addOption(
75
+                'add-user',
76
+                '',
77
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
78
+                'user to add as applicable'
79
+            )->addOption(
80
+                'remove-user',
81
+                '',
82
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
83
+                'user to remove as applicable'
84
+            )->addOption(
85
+                'add-group',
86
+                '',
87
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
88
+                'group to add as applicable'
89
+            )->addOption(
90
+                'remove-group',
91
+                '',
92
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
93
+                'group to remove as applicable'
94
+            )->addOption(
95
+                'remove-all',
96
+                '',
97
+                InputOption::VALUE_NONE,
98
+                'Set the mount to be globally applicable'
99
+            );
100
+        parent::configure();
101
+    }
102 102
 
103
-	protected function execute(InputInterface $input, OutputInterface $output): int {
104
-		$mountId = $input->getArgument('mount_id');
105
-		try {
106
-			$mount = $this->globalService->getStorage($mountId);
107
-		} catch (NotFoundException $e) {
108
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
109
-			return 404;
110
-		}
103
+    protected function execute(InputInterface $input, OutputInterface $output): int {
104
+        $mountId = $input->getArgument('mount_id');
105
+        try {
106
+            $mount = $this->globalService->getStorage($mountId);
107
+        } catch (NotFoundException $e) {
108
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
109
+            return 404;
110
+        }
111 111
 
112
-		if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
113
-			$output->writeln('<error>Can\'t change applicables on personal mounts</error>');
114
-			return 1;
115
-		}
112
+        if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
113
+            $output->writeln('<error>Can\'t change applicables on personal mounts</error>');
114
+            return 1;
115
+        }
116 116
 
117
-		$addUsers = $input->getOption('add-user');
118
-		$removeUsers = $input->getOption('remove-user');
119
-		$addGroups = $input->getOption('add-group');
120
-		$removeGroups = $input->getOption('remove-group');
117
+        $addUsers = $input->getOption('add-user');
118
+        $removeUsers = $input->getOption('remove-user');
119
+        $addGroups = $input->getOption('add-group');
120
+        $removeGroups = $input->getOption('remove-group');
121 121
 
122
-		$applicableUsers = $mount->getApplicableUsers();
123
-		$applicableGroups = $mount->getApplicableGroups();
122
+        $applicableUsers = $mount->getApplicableUsers();
123
+        $applicableGroups = $mount->getApplicableGroups();
124 124
 
125
-		if ((count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0) || $input->getOption('remove-all')) {
126
-			foreach ($addUsers as $addUser) {
127
-				if (!$this->userManager->userExists($addUser)) {
128
-					$output->writeln('<error>User "' . $addUser . '" not found</error>');
129
-					return 404;
130
-				}
131
-			}
132
-			foreach ($addGroups as $addGroup) {
133
-				if (!$this->groupManager->groupExists($addGroup)) {
134
-					$output->writeln('<error>Group "' . $addGroup . '" not found</error>');
135
-					return 404;
136
-				}
137
-			}
125
+        if ((count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0) || $input->getOption('remove-all')) {
126
+            foreach ($addUsers as $addUser) {
127
+                if (!$this->userManager->userExists($addUser)) {
128
+                    $output->writeln('<error>User "' . $addUser . '" not found</error>');
129
+                    return 404;
130
+                }
131
+            }
132
+            foreach ($addGroups as $addGroup) {
133
+                if (!$this->groupManager->groupExists($addGroup)) {
134
+                    $output->writeln('<error>Group "' . $addGroup . '" not found</error>');
135
+                    return 404;
136
+                }
137
+            }
138 138
 
139
-			if ($input->getOption('remove-all')) {
140
-				$applicableUsers = [];
141
-				$applicableGroups = [];
142
-			} else {
143
-				$applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
144
-				$applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
145
-				$applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
146
-				$applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
147
-			}
148
-			$mount->setApplicableUsers($applicableUsers);
149
-			$mount->setApplicableGroups($applicableGroups);
150
-			$this->globalService->updateStorage($mount);
151
-		}
139
+            if ($input->getOption('remove-all')) {
140
+                $applicableUsers = [];
141
+                $applicableGroups = [];
142
+            } else {
143
+                $applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
144
+                $applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
145
+                $applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
146
+                $applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
147
+            }
148
+            $mount->setApplicableUsers($applicableUsers);
149
+            $mount->setApplicableGroups($applicableGroups);
150
+            $this->globalService->updateStorage($mount);
151
+        }
152 152
 
153
-		$this->writeArrayInOutputFormat($input, $output, [
154
-			'users' => $applicableUsers,
155
-			'groups' => $applicableGroups
156
-		]);
157
-		return 0;
158
-	}
153
+        $this->writeArrayInOutputFormat($input, $output, [
154
+            'users' => $applicableUsers,
155
+            'groups' => $applicableGroups
156
+        ]);
157
+        return 0;
158
+    }
159 159
 }
Please login to merge, or discard this patch.