Completed
Push — master ( 08b58a...0efd05 )
by Daniel
30:08 queued 21s
created
apps/workflowengine/lib/Controller/GlobalWorkflowsController.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@
 block discarded – undo
30 30
 
31 31
 class GlobalWorkflowsController extends AWorkflowController {
32 32
 
33
-	/** @var ScopeContext */
34
-	private $scopeContext;
33
+    /** @var ScopeContext */
34
+    private $scopeContext;
35 35
 
36
-	protected function getScopeContext(): ScopeContext {
37
-		if ($this->scopeContext === null) {
38
-			$this->scopeContext = new ScopeContext(IManager::SCOPE_ADMIN);
39
-		}
40
-		return $this->scopeContext;
41
-	}
36
+    protected function getScopeContext(): ScopeContext {
37
+        if ($this->scopeContext === null) {
38
+            $this->scopeContext = new ScopeContext(IManager::SCOPE_ADMIN);
39
+        }
40
+        return $this->scopeContext;
41
+    }
42 42
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/SFTP_Key.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -30,19 +30,19 @@
 block discarded – undo
30 30
 use OCP\IL10N;
31 31
 
32 32
 class SFTP_Key extends Backend {
33
-	public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) {
34
-		$this
35
-			->setIdentifier('\OC\Files\Storage\SFTP_Key')
36
-			->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
37
-			->setText($l->t('SFTP with secret key login'))
38
-			->addParameters([
39
-				new DefinitionParameter('host', $l->t('Host')),
40
-				(new DefinitionParameter('root', $l->t('Remote subfolder')))
41
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
42
-			])
43
-			->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
44
-			->setLegacyAuthMechanism($legacyAuth)
45
-			->deprecateTo($sftpBackend)
46
-		;
47
-	}
33
+    public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) {
34
+        $this
35
+            ->setIdentifier('\OC\Files\Storage\SFTP_Key')
36
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
37
+            ->setText($l->t('SFTP with secret key login'))
38
+            ->addParameters([
39
+                new DefinitionParameter('host', $l->t('Host')),
40
+                (new DefinitionParameter('root', $l->t('Remote subfolder')))
41
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
42
+            ])
43
+            ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
44
+            ->setLegacyAuthMechanism($legacyAuth)
45
+            ->deprecateTo($sftpBackend)
46
+        ;
47
+    }
48 48
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Config/UserPlaceholderHandler.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -25,19 +25,19 @@
 block discarded – undo
25 25
 namespace OCA\Files_External\Config;
26 26
 
27 27
 class UserPlaceholderHandler extends UserContext implements IConfigHandler {
28
-	use SimpleSubstitutionTrait;
28
+    use SimpleSubstitutionTrait;
29 29
 
30
-	/**
31
-	 * @param mixed $optionValue
32
-	 * @return mixed the same type as $optionValue
33
-	 * @since 16.0.0
34
-	 */
35
-	public function handle($optionValue) {
36
-		$this->placeholder = 'user';
37
-		$uid = $this->getUserId();
38
-		if ($uid === null) {
39
-			return $optionValue;
40
-		}
41
-		return $this->processInput($optionValue, $uid);
42
-	}
30
+    /**
31
+     * @param mixed $optionValue
32
+     * @return mixed the same type as $optionValue
33
+     * @since 16.0.0
34
+     */
35
+    public function handle($optionValue) {
36
+        $this->placeholder = 'user';
37
+        $uid = $this->getUserId();
38
+        if ($uid === null) {
39
+            return $optionValue;
40
+        }
41
+        return $this->processInput($optionValue, $uid);
42
+    }
43 43
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Config/SimpleSubstitutionTrait.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,57 +31,57 @@
 block discarded – undo
31 31
  * @since 16.0.0
32 32
  */
33 33
 trait SimpleSubstitutionTrait {
34
-	/**
35
-	 * @var string the placeholder without $ prefix
36
-	 * @since 16.0.0
37
-	 */
38
-	protected $placeholder;
34
+    /**
35
+     * @var string the placeholder without $ prefix
36
+     * @since 16.0.0
37
+     */
38
+    protected $placeholder;
39 39
 
40
-	/** @var string */
41
-	protected $sanitizedPlaceholder;
40
+    /** @var string */
41
+    protected $sanitizedPlaceholder;
42 42
 
43
-	/**
44
-	 * @param mixed $optionValue
45
-	 * @param string $replacement
46
-	 * @return mixed
47
-	 * @since 16.0.0
48
-	 */
49
-	private function processInput($optionValue, string $replacement) {
50
-		$this->checkPlaceholder();
51
-		if (is_array($optionValue)) {
52
-			foreach ($optionValue as &$value) {
53
-				$value = $this->substituteIfString($value, $replacement);
54
-			}
55
-		} else {
56
-			$optionValue = $this->substituteIfString($optionValue, $replacement);
57
-		}
58
-		return $optionValue;
59
-	}
43
+    /**
44
+     * @param mixed $optionValue
45
+     * @param string $replacement
46
+     * @return mixed
47
+     * @since 16.0.0
48
+     */
49
+    private function processInput($optionValue, string $replacement) {
50
+        $this->checkPlaceholder();
51
+        if (is_array($optionValue)) {
52
+            foreach ($optionValue as &$value) {
53
+                $value = $this->substituteIfString($value, $replacement);
54
+            }
55
+        } else {
56
+            $optionValue = $this->substituteIfString($optionValue, $replacement);
57
+        }
58
+        return $optionValue;
59
+    }
60 60
 
61
-	/**
62
-	 * @throws \RuntimeException
63
-	 */
64
-	protected function checkPlaceholder(): void {
65
-		$this->sanitizedPlaceholder = trim(strtolower($this->placeholder));
66
-		if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
67
-			throw new \RuntimeException(sprintf(
68
-				'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder
69
-			));
70
-		}
71
-		if ($this->sanitizedPlaceholder === '') {
72
-			throw new \RuntimeException('Invalid empty placeholder');
73
-		}
74
-	}
61
+    /**
62
+     * @throws \RuntimeException
63
+     */
64
+    protected function checkPlaceholder(): void {
65
+        $this->sanitizedPlaceholder = trim(strtolower($this->placeholder));
66
+        if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
67
+            throw new \RuntimeException(sprintf(
68
+                'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder
69
+            ));
70
+        }
71
+        if ($this->sanitizedPlaceholder === '') {
72
+            throw new \RuntimeException('Invalid empty placeholder');
73
+        }
74
+    }
75 75
 
76
-	/**
77
-	 * @param mixed $value
78
-	 * @param string $replacement
79
-	 * @return mixed
80
-	 */
81
-	protected function substituteIfString($value, string $replacement) {
82
-		if (is_string($value)) {
83
-			return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value);
84
-		}
85
-		return $value;
86
-	}
76
+    /**
77
+     * @param mixed $value
78
+     * @param string $replacement
79
+     * @return mixed
80
+     */
81
+    protected function substituteIfString($value, string $replacement) {
82
+        if (is_string($value)) {
83
+            return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value);
84
+        }
85
+        return $value;
86
+    }
87 87
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	protected function checkPlaceholder(): void {
65 65
 		$this->sanitizedPlaceholder = trim(strtolower($this->placeholder));
66
-		if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
66
+		if (!(bool) \preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) {
67 67
 			throw new \RuntimeException(sprintf(
68 68
 				'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder
69 69
 			));
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	protected function substituteIfString($value, string $replacement) {
82 82
 		if (is_string($value)) {
83
-			return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value);
83
+			return str_ireplace('$'.$this->sanitizedPlaceholder, $replacement, $value);
84 84
 		}
85 85
 		return $value;
86 86
 	}
Please login to merge, or discard this patch.
apps/comments/lib/Collaboration/CommentersSorter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,11 +60,11 @@
 block discarded – undo
60 60
 			// at least on PHP 5.6 usort turned out to be not stable. So we add
61 61
 			// the current index to the value and compare it on a draw
62 62
 			$i = 0;
63
-			$workArray = array_map(function ($element) use (&$i) {
63
+			$workArray = array_map(function($element) use (&$i) {
64 64
 				return [$i++, $element];
65 65
 			}, $byType);
66 66
 
67
-			usort($workArray, function ($a, $b) use ($commenters, $type) {
67
+			usort($workArray, function($a, $b) use ($commenters, $type) {
68 68
 				$r = $this->compare($a[1], $b[1], $commenters[$type]);
69 69
 				if ($r === 0) {
70 70
 					$r = $a[0] - $b[0];
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -9,83 +9,83 @@
 block discarded – undo
9 9
 use OCP\Comments\ICommentsManager;
10 10
 
11 11
 class CommentersSorter implements ISorter {
12
-	public function __construct(
13
-		private ICommentsManager $commentsManager,
14
-	) {
15
-	}
12
+    public function __construct(
13
+        private ICommentsManager $commentsManager,
14
+    ) {
15
+    }
16 16
 
17
-	public function getId(): string {
18
-		return 'commenters';
19
-	}
17
+    public function getId(): string {
18
+        return 'commenters';
19
+    }
20 20
 
21
-	/**
22
-	 * Sorts people who commented on the given item atop (descelating) of the
23
-	 * others
24
-	 *
25
-	 * @param array &$sortArray
26
-	 * @param array $context
27
-	 */
28
-	public function sort(array &$sortArray, array $context): void {
29
-		$commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
30
-		if (count($commenters) === 0) {
31
-			return;
32
-		}
21
+    /**
22
+     * Sorts people who commented on the given item atop (descelating) of the
23
+     * others
24
+     *
25
+     * @param array &$sortArray
26
+     * @param array $context
27
+     */
28
+    public function sort(array &$sortArray, array $context): void {
29
+        $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
30
+        if (count($commenters) === 0) {
31
+            return;
32
+        }
33 33
 
34
-		foreach ($sortArray as $type => &$byType) {
35
-			if (!isset($commenters[$type])) {
36
-				continue;
37
-			}
34
+        foreach ($sortArray as $type => &$byType) {
35
+            if (!isset($commenters[$type])) {
36
+                continue;
37
+            }
38 38
 
39
-			// at least on PHP 5.6 usort turned out to be not stable. So we add
40
-			// the current index to the value and compare it on a draw
41
-			$i = 0;
42
-			$workArray = array_map(function ($element) use (&$i) {
43
-				return [$i++, $element];
44
-			}, $byType);
39
+            // at least on PHP 5.6 usort turned out to be not stable. So we add
40
+            // the current index to the value and compare it on a draw
41
+            $i = 0;
42
+            $workArray = array_map(function ($element) use (&$i) {
43
+                return [$i++, $element];
44
+            }, $byType);
45 45
 
46
-			usort($workArray, function ($a, $b) use ($commenters, $type) {
47
-				$r = $this->compare($a[1], $b[1], $commenters[$type]);
48
-				if ($r === 0) {
49
-					$r = $a[0] - $b[0];
50
-				}
51
-				return $r;
52
-			});
46
+            usort($workArray, function ($a, $b) use ($commenters, $type) {
47
+                $r = $this->compare($a[1], $b[1], $commenters[$type]);
48
+                if ($r === 0) {
49
+                    $r = $a[0] - $b[0];
50
+                }
51
+                return $r;
52
+            });
53 53
 
54
-			// and remove the index values again
55
-			$byType = array_column($workArray, 1);
56
-		}
57
-	}
54
+            // and remove the index values again
55
+            $byType = array_column($workArray, 1);
56
+        }
57
+    }
58 58
 
59
-	/**
60
-	 * @return array<string, array<string, int>>
61
-	 */
62
-	protected function retrieveCommentsInformation(string $type, string $id): array {
63
-		$comments = $this->commentsManager->getForObject($type, $id);
64
-		if (count($comments) === 0) {
65
-			return [];
66
-		}
59
+    /**
60
+     * @return array<string, array<string, int>>
61
+     */
62
+    protected function retrieveCommentsInformation(string $type, string $id): array {
63
+        $comments = $this->commentsManager->getForObject($type, $id);
64
+        if (count($comments) === 0) {
65
+            return [];
66
+        }
67 67
 
68
-		$actors = [];
69
-		foreach ($comments as $comment) {
70
-			if (!isset($actors[$comment->getActorType()])) {
71
-				$actors[$comment->getActorType()] = [];
72
-			}
73
-			if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
74
-				$actors[$comment->getActorType()][$comment->getActorId()] = 1;
75
-			} else {
76
-				$actors[$comment->getActorType()][$comment->getActorId()]++;
77
-			}
78
-		}
79
-		return $actors;
80
-	}
68
+        $actors = [];
69
+        foreach ($comments as $comment) {
70
+            if (!isset($actors[$comment->getActorType()])) {
71
+                $actors[$comment->getActorType()] = [];
72
+            }
73
+            if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
74
+                $actors[$comment->getActorType()][$comment->getActorId()] = 1;
75
+            } else {
76
+                $actors[$comment->getActorType()][$comment->getActorId()]++;
77
+            }
78
+        }
79
+        return $actors;
80
+    }
81 81
 
82
-	protected function compare(array $a, array $b, array $commenters): int {
83
-		$a = $a['value']['shareWith'];
84
-		$b = $b['value']['shareWith'];
82
+    protected function compare(array $a, array $b, array $commenters): int {
83
+        $a = $a['value']['shareWith'];
84
+        $b = $b['value']['shareWith'];
85 85
 
86
-		$valueA = $commenters[$a] ?? 0;
87
-		$valueB = $commenters[$b] ?? 0;
86
+        $valueA = $commenters[$a] ?? 0;
87
+        $valueB = $commenters[$b] ?? 0;
88 88
 
89
-		return $valueB - $valueA;
90
-	}
89
+        return $valueB - $valueA;
90
+    }
91 91
 }
Please login to merge, or discard this patch.
core/templates/loginflow/authpicker.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 	<h2><?php p($l->t('Connect to your account')) ?></h2>
31 31
 	<p class="info">
32 32
 		<?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [
33
-			'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
33
+			'<strong>'.\OCP\Util::sanitizeHTML($_['client']).'</strong>',
34 34
 			\OCP\Util::sanitizeHTML($_['instanceName'])
35 35
 		])) ?>
36 36
 	</p>
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
 	<h2><?php p($l->t('Connect to your account')) ?></h2>
32 32
 	<p class="info">
33 33
 		<?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [
34
-			'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
35
-			\OCP\Util::sanitizeHTML($_['instanceName'])
36
-		])) ?>
34
+            '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
35
+            \OCP\Util::sanitizeHTML($_['instanceName'])
36
+        ])) ?>
37 37
 	</p>
38 38
 
39 39
 	<div class="notecard warning">
Please login to merge, or discard this patch.
core/templates/error.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 			<p><?php p($error['error']) ?></p>
7 7
 			<?php if (isset($error['hint']) && $error['hint']): ?>
8 8
 				<p class='hint'><?php p($error['hint']) ?></p>
9
-			<?php endif;?>
9
+			<?php endif; ?>
10 10
 		</li>
11 11
 	<?php endforeach ?>
12 12
 	</ul>
Please login to merge, or discard this patch.
core/Command/Encryption/ChangeKeyStorageRoot.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		}
143 143
 
144 144
 		$result = $this->rootView->file_put_contents(
145
-			$newRoot . '/' . Storage::KEY_STORAGE_MARKER,
145
+			$newRoot.'/'.Storage::KEY_STORAGE_MARKER,
146 146
 			'Nextcloud will detect this folder as key storage root only if this file exists'
147 147
 		);
148 148
 
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	protected function moveSystemKeys($oldRoot, $newRoot) {
162 162
 		if (
163
-			$this->rootView->is_dir($oldRoot . '/files_encryption') &&
164
-			$this->targetExists($newRoot . '/files_encryption') === false
163
+			$this->rootView->is_dir($oldRoot.'/files_encryption') &&
164
+			$this->targetExists($newRoot.'/files_encryption') === false
165 165
 		) {
166
-			$this->rootView->rename($oldRoot . '/files_encryption', $newRoot . '/files_encryption');
166
+			$this->rootView->rename($oldRoot.'/files_encryption', $newRoot.'/files_encryption');
167 167
 		}
168 168
 	}
169 169
 
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot) {
219 219
 		if ($this->userManager->userExists($user)) {
220
-			$source = $oldRoot . '/' . $user . '/files_encryption';
221
-			$target = $newRoot . '/' . $user . '/files_encryption';
220
+			$source = $oldRoot.'/'.$user.'/files_encryption';
221
+			$target = $newRoot.'/'.$user.'/files_encryption';
222 222
 			if (
223 223
 				$this->rootView->is_dir($source) &&
224 224
 				$this->targetExists($target) === false
225 225
 			) {
226
-				$this->prepareParentFolder($newRoot . '/' . $user);
226
+				$this->prepareParentFolder($newRoot.'/'.$user);
227 227
 				$this->rootView->rename($source, $target);
228 228
 			}
229 229
 		}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 			$sub_dirs = explode('/', ltrim($path, '/'));
242 242
 			$dir = '';
243 243
 			foreach ($sub_dirs as $sub_dir) {
244
-				$dir .= '/' . $sub_dir;
244
+				$dir .= '/'.$sub_dir;
245 245
 				if ($this->rootView->file_exists($dir) === false) {
246 246
 					$this->rootView->mkdir($dir);
247 247
 				}
Please login to merge, or discard this patch.
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -22,208 +22,208 @@
 block discarded – undo
22 22
 use Symfony\Component\Console\Question\ConfirmationQuestion;
23 23
 
24 24
 class ChangeKeyStorageRoot extends Command {
25
-	public function __construct(
26
-		protected View $rootView,
27
-		protected IUserManager $userManager,
28
-		protected IConfig $config,
29
-		protected Util $util,
30
-		protected QuestionHelper $questionHelper,
31
-	) {
32
-		parent::__construct();
33
-	}
34
-
35
-	protected function configure() {
36
-		parent::configure();
37
-		$this
38
-			->setName('encryption:change-key-storage-root')
39
-			->setDescription('Change key storage root')
40
-			->addArgument(
41
-				'newRoot',
42
-				InputArgument::OPTIONAL,
43
-				'new root of the key storage relative to the data folder'
44
-			);
45
-	}
46
-
47
-	protected function execute(InputInterface $input, OutputInterface $output): int {
48
-		$oldRoot = $this->util->getKeyStorageRoot();
49
-		$newRoot = $input->getArgument('newRoot');
50
-
51
-		if ($newRoot === null) {
52
-			$question = new ConfirmationQuestion('No storage root given, do you want to reset the key storage root to the default location? (y/n) ', false);
53
-			if (!$this->questionHelper->ask($input, $output, $question)) {
54
-				return 1;
55
-			}
56
-			$newRoot = '';
57
-		}
58
-
59
-		$oldRootDescription = $oldRoot !== '' ? $oldRoot : 'default storage location';
60
-		$newRootDescription = $newRoot !== '' ? $newRoot : 'default storage location';
61
-		$output->writeln("Change key storage root from <info>$oldRootDescription</info> to <info>$newRootDescription</info>");
62
-		$success = $this->moveAllKeys($oldRoot, $newRoot, $output);
63
-		if ($success) {
64
-			$this->util->setKeyStorageRoot($newRoot);
65
-			$output->writeln('');
66
-			$output->writeln("Key storage root successfully changed to <info>$newRootDescription</info>");
67
-			return 0;
68
-		}
69
-		return 1;
70
-	}
71
-
72
-	/**
73
-	 * move keys to new key storage root
74
-	 *
75
-	 * @param string $oldRoot
76
-	 * @param string $newRoot
77
-	 * @param OutputInterface $output
78
-	 * @return bool
79
-	 * @throws \Exception
80
-	 */
81
-	protected function moveAllKeys($oldRoot, $newRoot, OutputInterface $output) {
82
-		$output->writeln('Start to move keys:');
83
-
84
-		if ($this->rootView->is_dir($oldRoot) === false) {
85
-			$output->writeln('No old keys found: Nothing needs to be moved');
86
-			return false;
87
-		}
88
-
89
-		$this->prepareNewRoot($newRoot);
90
-		$this->moveSystemKeys($oldRoot, $newRoot);
91
-		$this->moveUserKeys($oldRoot, $newRoot, $output);
92
-
93
-		return true;
94
-	}
95
-
96
-	/**
97
-	 * prepare new key storage
98
-	 *
99
-	 * @param string $newRoot
100
-	 * @throws \Exception
101
-	 */
102
-	protected function prepareNewRoot($newRoot) {
103
-		if ($this->rootView->is_dir($newRoot) === false) {
104
-			throw new \Exception("New root folder doesn't exist. Please create the folder or check the permissions and try again.");
105
-		}
106
-
107
-		$result = $this->rootView->file_put_contents(
108
-			$newRoot . '/' . Storage::KEY_STORAGE_MARKER,
109
-			'Nextcloud will detect this folder as key storage root only if this file exists'
110
-		);
111
-
112
-		if (!$result) {
113
-			throw new \Exception("Can't access the new root folder. Please check the permissions and make sure that the folder is in your data folder");
114
-		}
115
-	}
116
-
117
-
118
-	/**
119
-	 * move system key folder
120
-	 *
121
-	 * @param string $oldRoot
122
-	 * @param string $newRoot
123
-	 */
124
-	protected function moveSystemKeys($oldRoot, $newRoot) {
125
-		if (
126
-			$this->rootView->is_dir($oldRoot . '/files_encryption') &&
127
-			$this->targetExists($newRoot . '/files_encryption') === false
128
-		) {
129
-			$this->rootView->rename($oldRoot . '/files_encryption', $newRoot . '/files_encryption');
130
-		}
131
-	}
132
-
133
-
134
-	/**
135
-	 * setup file system for the given user
136
-	 *
137
-	 * @param string $uid
138
-	 */
139
-	protected function setupUserFS($uid) {
140
-		\OC_Util::tearDownFS();
141
-		\OC_Util::setupFS($uid);
142
-	}
143
-
144
-
145
-	/**
146
-	 * iterate over each user and move the keys to the new storage
147
-	 *
148
-	 * @param string $oldRoot
149
-	 * @param string $newRoot
150
-	 * @param OutputInterface $output
151
-	 */
152
-	protected function moveUserKeys($oldRoot, $newRoot, OutputInterface $output) {
153
-		$progress = new ProgressBar($output);
154
-		$progress->start();
155
-
156
-
157
-		foreach ($this->userManager->getBackends() as $backend) {
158
-			$limit = 500;
159
-			$offset = 0;
160
-			do {
161
-				$users = $backend->getUsers('', $limit, $offset);
162
-				foreach ($users as $user) {
163
-					$progress->advance();
164
-					$this->setupUserFS($user);
165
-					$this->moveUserEncryptionFolder($user, $oldRoot, $newRoot);
166
-				}
167
-				$offset += $limit;
168
-			} while (count($users) >= $limit);
169
-		}
170
-		$progress->finish();
171
-	}
172
-
173
-	/**
174
-	 * move user encryption folder to new root folder
175
-	 *
176
-	 * @param string $user
177
-	 * @param string $oldRoot
178
-	 * @param string $newRoot
179
-	 * @throws \Exception
180
-	 */
181
-	protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot) {
182
-		if ($this->userManager->userExists($user)) {
183
-			$source = $oldRoot . '/' . $user . '/files_encryption';
184
-			$target = $newRoot . '/' . $user . '/files_encryption';
185
-			if (
186
-				$this->rootView->is_dir($source) &&
187
-				$this->targetExists($target) === false
188
-			) {
189
-				$this->prepareParentFolder($newRoot . '/' . $user);
190
-				$this->rootView->rename($source, $target);
191
-			}
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * Make preparations to filesystem for saving a key file
197
-	 *
198
-	 * @param string $path relative to data/
199
-	 */
200
-	protected function prepareParentFolder($path) {
201
-		$path = Filesystem::normalizePath($path);
202
-		// If the file resides within a subdirectory, create it
203
-		if ($this->rootView->file_exists($path) === false) {
204
-			$sub_dirs = explode('/', ltrim($path, '/'));
205
-			$dir = '';
206
-			foreach ($sub_dirs as $sub_dir) {
207
-				$dir .= '/' . $sub_dir;
208
-				if ($this->rootView->file_exists($dir) === false) {
209
-					$this->rootView->mkdir($dir);
210
-				}
211
-			}
212
-		}
213
-	}
214
-
215
-	/**
216
-	 * check if target already exists
217
-	 *
218
-	 * @param $path
219
-	 * @return bool
220
-	 * @throws \Exception
221
-	 */
222
-	protected function targetExists($path) {
223
-		if ($this->rootView->file_exists($path)) {
224
-			throw new \Exception("new folder '$path' already exists");
225
-		}
226
-
227
-		return false;
228
-	}
25
+    public function __construct(
26
+        protected View $rootView,
27
+        protected IUserManager $userManager,
28
+        protected IConfig $config,
29
+        protected Util $util,
30
+        protected QuestionHelper $questionHelper,
31
+    ) {
32
+        parent::__construct();
33
+    }
34
+
35
+    protected function configure() {
36
+        parent::configure();
37
+        $this
38
+            ->setName('encryption:change-key-storage-root')
39
+            ->setDescription('Change key storage root')
40
+            ->addArgument(
41
+                'newRoot',
42
+                InputArgument::OPTIONAL,
43
+                'new root of the key storage relative to the data folder'
44
+            );
45
+    }
46
+
47
+    protected function execute(InputInterface $input, OutputInterface $output): int {
48
+        $oldRoot = $this->util->getKeyStorageRoot();
49
+        $newRoot = $input->getArgument('newRoot');
50
+
51
+        if ($newRoot === null) {
52
+            $question = new ConfirmationQuestion('No storage root given, do you want to reset the key storage root to the default location? (y/n) ', false);
53
+            if (!$this->questionHelper->ask($input, $output, $question)) {
54
+                return 1;
55
+            }
56
+            $newRoot = '';
57
+        }
58
+
59
+        $oldRootDescription = $oldRoot !== '' ? $oldRoot : 'default storage location';
60
+        $newRootDescription = $newRoot !== '' ? $newRoot : 'default storage location';
61
+        $output->writeln("Change key storage root from <info>$oldRootDescription</info> to <info>$newRootDescription</info>");
62
+        $success = $this->moveAllKeys($oldRoot, $newRoot, $output);
63
+        if ($success) {
64
+            $this->util->setKeyStorageRoot($newRoot);
65
+            $output->writeln('');
66
+            $output->writeln("Key storage root successfully changed to <info>$newRootDescription</info>");
67
+            return 0;
68
+        }
69
+        return 1;
70
+    }
71
+
72
+    /**
73
+     * move keys to new key storage root
74
+     *
75
+     * @param string $oldRoot
76
+     * @param string $newRoot
77
+     * @param OutputInterface $output
78
+     * @return bool
79
+     * @throws \Exception
80
+     */
81
+    protected function moveAllKeys($oldRoot, $newRoot, OutputInterface $output) {
82
+        $output->writeln('Start to move keys:');
83
+
84
+        if ($this->rootView->is_dir($oldRoot) === false) {
85
+            $output->writeln('No old keys found: Nothing needs to be moved');
86
+            return false;
87
+        }
88
+
89
+        $this->prepareNewRoot($newRoot);
90
+        $this->moveSystemKeys($oldRoot, $newRoot);
91
+        $this->moveUserKeys($oldRoot, $newRoot, $output);
92
+
93
+        return true;
94
+    }
95
+
96
+    /**
97
+     * prepare new key storage
98
+     *
99
+     * @param string $newRoot
100
+     * @throws \Exception
101
+     */
102
+    protected function prepareNewRoot($newRoot) {
103
+        if ($this->rootView->is_dir($newRoot) === false) {
104
+            throw new \Exception("New root folder doesn't exist. Please create the folder or check the permissions and try again.");
105
+        }
106
+
107
+        $result = $this->rootView->file_put_contents(
108
+            $newRoot . '/' . Storage::KEY_STORAGE_MARKER,
109
+            'Nextcloud will detect this folder as key storage root only if this file exists'
110
+        );
111
+
112
+        if (!$result) {
113
+            throw new \Exception("Can't access the new root folder. Please check the permissions and make sure that the folder is in your data folder");
114
+        }
115
+    }
116
+
117
+
118
+    /**
119
+     * move system key folder
120
+     *
121
+     * @param string $oldRoot
122
+     * @param string $newRoot
123
+     */
124
+    protected function moveSystemKeys($oldRoot, $newRoot) {
125
+        if (
126
+            $this->rootView->is_dir($oldRoot . '/files_encryption') &&
127
+            $this->targetExists($newRoot . '/files_encryption') === false
128
+        ) {
129
+            $this->rootView->rename($oldRoot . '/files_encryption', $newRoot . '/files_encryption');
130
+        }
131
+    }
132
+
133
+
134
+    /**
135
+     * setup file system for the given user
136
+     *
137
+     * @param string $uid
138
+     */
139
+    protected function setupUserFS($uid) {
140
+        \OC_Util::tearDownFS();
141
+        \OC_Util::setupFS($uid);
142
+    }
143
+
144
+
145
+    /**
146
+     * iterate over each user and move the keys to the new storage
147
+     *
148
+     * @param string $oldRoot
149
+     * @param string $newRoot
150
+     * @param OutputInterface $output
151
+     */
152
+    protected function moveUserKeys($oldRoot, $newRoot, OutputInterface $output) {
153
+        $progress = new ProgressBar($output);
154
+        $progress->start();
155
+
156
+
157
+        foreach ($this->userManager->getBackends() as $backend) {
158
+            $limit = 500;
159
+            $offset = 0;
160
+            do {
161
+                $users = $backend->getUsers('', $limit, $offset);
162
+                foreach ($users as $user) {
163
+                    $progress->advance();
164
+                    $this->setupUserFS($user);
165
+                    $this->moveUserEncryptionFolder($user, $oldRoot, $newRoot);
166
+                }
167
+                $offset += $limit;
168
+            } while (count($users) >= $limit);
169
+        }
170
+        $progress->finish();
171
+    }
172
+
173
+    /**
174
+     * move user encryption folder to new root folder
175
+     *
176
+     * @param string $user
177
+     * @param string $oldRoot
178
+     * @param string $newRoot
179
+     * @throws \Exception
180
+     */
181
+    protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot) {
182
+        if ($this->userManager->userExists($user)) {
183
+            $source = $oldRoot . '/' . $user . '/files_encryption';
184
+            $target = $newRoot . '/' . $user . '/files_encryption';
185
+            if (
186
+                $this->rootView->is_dir($source) &&
187
+                $this->targetExists($target) === false
188
+            ) {
189
+                $this->prepareParentFolder($newRoot . '/' . $user);
190
+                $this->rootView->rename($source, $target);
191
+            }
192
+        }
193
+    }
194
+
195
+    /**
196
+     * Make preparations to filesystem for saving a key file
197
+     *
198
+     * @param string $path relative to data/
199
+     */
200
+    protected function prepareParentFolder($path) {
201
+        $path = Filesystem::normalizePath($path);
202
+        // If the file resides within a subdirectory, create it
203
+        if ($this->rootView->file_exists($path) === false) {
204
+            $sub_dirs = explode('/', ltrim($path, '/'));
205
+            $dir = '';
206
+            foreach ($sub_dirs as $sub_dir) {
207
+                $dir .= '/' . $sub_dir;
208
+                if ($this->rootView->file_exists($dir) === false) {
209
+                    $this->rootView->mkdir($dir);
210
+                }
211
+            }
212
+        }
213
+    }
214
+
215
+    /**
216
+     * check if target already exists
217
+     *
218
+     * @param $path
219
+     * @return bool
220
+     * @throws \Exception
221
+     */
222
+    protected function targetExists($path) {
223
+        if ($this->rootView->file_exists($path)) {
224
+            throw new \Exception("new folder '$path' already exists");
225
+        }
226
+
227
+        return false;
228
+    }
229 229
 }
Please login to merge, or discard this patch.
core/Command/Config/System/DeleteConfig.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
 		if (count($configNames) > 1) {
69 69
 			if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
70
-				$output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
70
+				$output->writeln('<error>System config '.implode(' => ', $configNames).' could not be deleted because it did not exist</error>');
71 71
 				return 1;
72 72
 			}
73 73
 
@@ -76,21 +76,21 @@  discard block
 block discarded – undo
76 76
 			try {
77 77
 				$value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists'));
78 78
 			} catch (\UnexpectedValueException $e) {
79
-				$output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
79
+				$output->writeln('<error>System config '.implode(' => ', $configNames).' could not be deleted because it did not exist</error>');
80 80
 				return 1;
81 81
 			}
82 82
 
83 83
 			$this->systemConfig->setValue($configName, $value);
84
-			$output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>');
84
+			$output->writeln('<info>System config value '.implode(' => ', $configNames).' deleted</info>');
85 85
 			return 0;
86 86
 		} else {
87 87
 			if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
88
-				$output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>');
88
+				$output->writeln('<error>System config '.$configName.' could not be deleted because it did not exist</error>');
89 89
 				return 1;
90 90
 			}
91 91
 
92 92
 			$this->systemConfig->deleteValue($configName);
93
-			$output->writeln('<info>System config value ' . $configName . ' deleted</info>');
93
+			$output->writeln('<info>System config value '.$configName.' deleted</info>');
94 94
 			return 0;
95 95
 		}
96 96
 	}
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -30,83 +30,83 @@
 block discarded – undo
30 30
 use Symfony\Component\Console\Output\OutputInterface;
31 31
 
32 32
 class DeleteConfig extends Base {
33
-	public function __construct(
34
-		SystemConfig $systemConfig,
35
-	) {
36
-		parent::__construct($systemConfig);
37
-	}
33
+    public function __construct(
34
+        SystemConfig $systemConfig,
35
+    ) {
36
+        parent::__construct($systemConfig);
37
+    }
38 38
 
39
-	protected function configure() {
40
-		parent::configure();
39
+    protected function configure() {
40
+        parent::configure();
41 41
 
42
-		$this
43
-			->setName('config:system:delete')
44
-			->setDescription('Delete a system config value')
45
-			->addArgument(
46
-				'name',
47
-				InputArgument::REQUIRED | InputArgument::IS_ARRAY,
48
-				'Name of the config to delete, specify multiple for array parameter'
49
-			)
50
-			->addOption(
51
-				'error-if-not-exists',
52
-				null,
53
-				InputOption::VALUE_NONE,
54
-				'Checks whether the config exists before deleting it'
55
-			)
56
-		;
57
-	}
42
+        $this
43
+            ->setName('config:system:delete')
44
+            ->setDescription('Delete a system config value')
45
+            ->addArgument(
46
+                'name',
47
+                InputArgument::REQUIRED | InputArgument::IS_ARRAY,
48
+                'Name of the config to delete, specify multiple for array parameter'
49
+            )
50
+            ->addOption(
51
+                'error-if-not-exists',
52
+                null,
53
+                InputOption::VALUE_NONE,
54
+                'Checks whether the config exists before deleting it'
55
+            )
56
+        ;
57
+    }
58 58
 
59
-	protected function execute(InputInterface $input, OutputInterface $output): int {
60
-		$configNames = $input->getArgument('name');
61
-		$configName = $configNames[0];
59
+    protected function execute(InputInterface $input, OutputInterface $output): int {
60
+        $configNames = $input->getArgument('name');
61
+        $configName = $configNames[0];
62 62
 
63
-		if (count($configNames) > 1) {
64
-			if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
65
-				$output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
66
-				return 1;
67
-			}
63
+        if (count($configNames) > 1) {
64
+            if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
65
+                $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
66
+                return 1;
67
+            }
68 68
 
69
-			$value = $this->systemConfig->getValue($configName);
69
+            $value = $this->systemConfig->getValue($configName);
70 70
 
71
-			try {
72
-				$value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists'));
73
-			} catch (\UnexpectedValueException $e) {
74
-				$output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
75
-				return 1;
76
-			}
71
+            try {
72
+                $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists'));
73
+            } catch (\UnexpectedValueException $e) {
74
+                $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
75
+                return 1;
76
+            }
77 77
 
78
-			$this->systemConfig->setValue($configName, $value);
79
-			$output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>');
80
-			return 0;
81
-		} else {
82
-			if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
83
-				$output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>');
84
-				return 1;
85
-			}
78
+            $this->systemConfig->setValue($configName, $value);
79
+            $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>');
80
+            return 0;
81
+        } else {
82
+            if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
83
+                $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>');
84
+                return 1;
85
+            }
86 86
 
87
-			$this->systemConfig->deleteValue($configName);
88
-			$output->writeln('<info>System config value ' . $configName . ' deleted</info>');
89
-			return 0;
90
-		}
91
-	}
87
+            $this->systemConfig->deleteValue($configName);
88
+            $output->writeln('<info>System config value ' . $configName . ' deleted</info>');
89
+            return 0;
90
+        }
91
+    }
92 92
 
93
-	protected function removeSubValue($keys, $currentValue, $throwError) {
94
-		$nextKey = array_shift($keys);
93
+    protected function removeSubValue($keys, $currentValue, $throwError) {
94
+        $nextKey = array_shift($keys);
95 95
 
96
-		if (is_array($currentValue)) {
97
-			if (isset($currentValue[$nextKey])) {
98
-				if (empty($keys)) {
99
-					unset($currentValue[$nextKey]);
100
-				} else {
101
-					$currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError);
102
-				}
103
-			} elseif ($throwError) {
104
-				throw new \UnexpectedValueException('Config parameter does not exist');
105
-			}
106
-		} elseif ($throwError) {
107
-			throw new \UnexpectedValueException('Config parameter does not exist');
108
-		}
96
+        if (is_array($currentValue)) {
97
+            if (isset($currentValue[$nextKey])) {
98
+                if (empty($keys)) {
99
+                    unset($currentValue[$nextKey]);
100
+                } else {
101
+                    $currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError);
102
+                }
103
+            } elseif ($throwError) {
104
+                throw new \UnexpectedValueException('Config parameter does not exist');
105
+            }
106
+        } elseif ($throwError) {
107
+            throw new \UnexpectedValueException('Config parameter does not exist');
108
+        }
109 109
 
110
-		return $currentValue;
111
-	}
110
+        return $currentValue;
111
+    }
112 112
 }
Please login to merge, or discard this patch.