Passed
Push — master ( 61a02b...010b07 )
by Roeland
19:08 queued 08:59
created
apps/files_sharing/lib/Activity/Settings/Shared.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
27 27
 
28 28
 class Shared implements ISetting {
29 29
 
30
-	/** @var IL10N */
31
-	protected $l;
30
+    /** @var IL10N */
31
+    protected $l;
32 32
 
33
-	/**
34
-	 * @param IL10N $l
35
-	 */
36
-	public function __construct(IL10N $l) {
37
-		$this->l = $l;
38
-	}
33
+    /**
34
+     * @param IL10N $l
35
+     */
36
+    public function __construct(IL10N $l) {
37
+        $this->l = $l;
38
+    }
39 39
 
40
-	/**
41
-	 * @return string Lowercase a-z and underscore only identifier
42
-	 * @since 11.0.0
43
-	 */
44
-	public function getIdentifier() {
45
-		return 'shared';
46
-	}
40
+    /**
41
+     * @return string Lowercase a-z and underscore only identifier
42
+     * @since 11.0.0
43
+     */
44
+    public function getIdentifier() {
45
+        return 'shared';
46
+    }
47 47
 
48
-	/**
49
-	 * @return string A translated string
50
-	 * @since 11.0.0
51
-	 */
52
-	public function getName() {
53
-		return $this->l->t('A file or folder has been <strong>shared</strong>');
54
-	}
48
+    /**
49
+     * @return string A translated string
50
+     * @since 11.0.0
51
+     */
52
+    public function getName() {
53
+        return $this->l->t('A file or folder has been <strong>shared</strong>');
54
+    }
55 55
 
56
-	/**
57
-	 * @return int whether the filter should be rather on the top or bottom of
58
-	 * the admin section. The filters are arranged in ascending order of the
59
-	 * priority values. It is required to return a value between 0 and 100.
60
-	 * @since 11.0.0
61
-	 */
62
-	public function getPriority() {
63
-		return 10;
64
-	}
56
+    /**
57
+     * @return int whether the filter should be rather on the top or bottom of
58
+     * the admin section. The filters are arranged in ascending order of the
59
+     * priority values. It is required to return a value between 0 and 100.
60
+     * @since 11.0.0
61
+     */
62
+    public function getPriority() {
63
+        return 10;
64
+    }
65 65
 
66
-	/**
67
-	 * @return bool True when the option can be changed for the stream
68
-	 * @since 11.0.0
69
-	 */
70
-	public function canChangeStream() {
71
-		return true;
72
-	}
66
+    /**
67
+     * @return bool True when the option can be changed for the stream
68
+     * @since 11.0.0
69
+     */
70
+    public function canChangeStream() {
71
+        return true;
72
+    }
73 73
 
74
-	/**
75
-	 * @return bool True when the option can be changed for the stream
76
-	 * @since 11.0.0
77
-	 */
78
-	public function isDefaultEnabledStream() {
79
-		return true;
80
-	}
74
+    /**
75
+     * @return bool True when the option can be changed for the stream
76
+     * @since 11.0.0
77
+     */
78
+    public function isDefaultEnabledStream() {
79
+        return true;
80
+    }
81 81
 
82
-	/**
83
-	 * @return bool True when the option can be changed for the mail
84
-	 * @since 11.0.0
85
-	 */
86
-	public function canChangeMail() {
87
-		return true;
88
-	}
82
+    /**
83
+     * @return bool True when the option can be changed for the mail
84
+     * @since 11.0.0
85
+     */
86
+    public function canChangeMail() {
87
+        return true;
88
+    }
89 89
 
90
-	/**
91
-	 * @return bool True when the option can be changed for the stream
92
-	 * @since 11.0.0
93
-	 */
94
-	public function isDefaultEnabledMail() {
95
-		return false;
96
-	}
90
+    /**
91
+     * @return bool True when the option can be changed for the stream
92
+     * @since 11.0.0
93
+     */
94
+    public function isDefaultEnabledMail() {
95
+        return false;
96
+    }
97 97
 }
98 98
 
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/S3.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,18 +24,18 @@
 block discarded – undo
24 24
 use OCP\Files\ObjectStore\IObjectStore;
25 25
 
26 26
 class S3 implements IObjectStore {
27
-	use S3ConnectionTrait;
28
-	use S3ObjectTrait;
27
+    use S3ConnectionTrait;
28
+    use S3ObjectTrait;
29 29
 
30
-	public function __construct($parameters) {
31
-		$this->parseParams($parameters);
32
-	}
30
+    public function __construct($parameters) {
31
+        $this->parseParams($parameters);
32
+    }
33 33
 
34
-	/**
35
-	 * @return string the container or bucket name where objects are stored
36
-	 * @since 7.0.0
37
-	 */
38
-	public function getStorageId() {
39
-		return $this->id;
40
-	}
34
+    /**
35
+     * @return string the container or bucket name where objects are stored
36
+     * @since 7.0.0
37
+     */
38
+    public function getStorageId() {
39
+        return $this->id;
40
+    }
41 41
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Import.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -39,187 +39,187 @@
 block discarded – undo
39 39
 use Symfony\Component\Console\Output\OutputInterface;
40 40
 
41 41
 class Import extends Base {
42
-	/**
43
-	 * @var GlobalStoragesService
44
-	 */
45
-	private $globalService;
46
-
47
-	/**
48
-	 * @var UserStoragesService
49
-	 */
50
-	private $userService;
51
-
52
-	/**
53
-	 * @var IUserSession
54
-	 */
55
-	private $userSession;
56
-
57
-	/**
58
-	 * @var IUserManager
59
-	 */
60
-	private $userManager;
61
-
62
-	/** @var ImportLegacyStoragesService */
63
-	private $importLegacyStorageService;
64
-
65
-	/** @var BackendService */
66
-	private $backendService;
67
-
68
-	function __construct(GlobalStoragesService $globalService,
69
-						 UserStoragesService $userService,
70
-						 IUserSession $userSession,
71
-						 IUserManager $userManager,
72
-						 ImportLegacyStoragesService $importLegacyStorageService,
73
-						 BackendService $backendService
74
-	) {
75
-		parent::__construct();
76
-		$this->globalService = $globalService;
77
-		$this->userService = $userService;
78
-		$this->userSession = $userSession;
79
-		$this->userManager = $userManager;
80
-		$this->importLegacyStorageService = $importLegacyStorageService;
81
-		$this->backendService = $backendService;
82
-	}
83
-
84
-	protected function configure() {
85
-		$this
86
-			->setName('files_external:import')
87
-			->setDescription('Import mount configurations')
88
-			->addOption(
89
-				'user',
90
-				'',
91
-				InputOption::VALUE_OPTIONAL,
92
-				'user to add the mount configurations for, if not set the mount will be added as system mount'
93
-			)
94
-			->addArgument(
95
-				'path',
96
-				InputArgument::REQUIRED,
97
-				'path to a json file containing the mounts to import, use "-" to read from stdin'
98
-			)
99
-			->addOption(
100
-				'dry',
101
-				'',
102
-				InputOption::VALUE_NONE,
103
-				'Don\'t save the imported mounts, only list the new mounts'
104
-			);
105
-		parent::configure();
106
-	}
107
-
108
-	protected function execute(InputInterface $input, OutputInterface $output) {
109
-		$user = $input->getOption('user');
110
-		$path = $input->getArgument('path');
111
-		if ($path === '-') {
112
-			$json = file_get_contents('php://stdin');
113
-		} else {
114
-			if (!file_exists($path)) {
115
-				$output->writeln('<error>File not found: ' . $path . '</error>');
116
-				return 1;
117
-			}
118
-			$json = file_get_contents($path);
119
-		}
120
-		if (!is_string($json) || strlen($json) < 2) {
121
-			$output->writeln('<error>Error while reading json</error>');
122
-			return 1;
123
-		}
124
-		$data = json_decode($json, true);
125
-		if (!is_array($data)) {
126
-			$output->writeln('<error>Error while parsing json</error>');
127
-			return 1;
128
-		}
129
-
130
-		$isLegacy = isset($data['user']) || isset($data['group']);
131
-		if ($isLegacy) {
132
-			$this->importLegacyStorageService->setData($data);
133
-			$mounts = $this->importLegacyStorageService->getAllStorages();
134
-			foreach ($mounts as $mount) {
135
-				if ($mount->getBackendOption('password') === false) {
136
-					$output->writeln('<error>Failed to decrypt password</error>');
137
-					return 1;
138
-				}
139
-			}
140
-		} else {
141
-			if (!isset($data[0])) { //normalize to an array of mounts
142
-				$data = [$data];
143
-			}
144
-			$mounts = array_map([$this, 'parseData'], $data);
145
-		}
146
-
147
-		if ($user) {
148
-			// ensure applicables are correct for personal mounts
149
-			foreach ($mounts as $mount) {
150
-				$mount->setApplicableGroups([]);
151
-				$mount->setApplicableUsers([$user]);
152
-			}
153
-		}
154
-
155
-		$storageService = $this->getStorageService($user);
156
-
157
-		$existingMounts = $storageService->getAllStorages();
158
-
159
-		foreach ($mounts as $mount) {
160
-			foreach ($existingMounts as $existingMount) {
161
-				if (
162
-					$existingMount->getMountPoint() === $mount->getMountPoint() &&
163
-					$existingMount->getApplicableGroups() === $mount->getApplicableGroups() &&
164
-					$existingMount->getApplicableUsers() === $mount->getApplicableUsers() &&
165
-					$existingMount->getBackendOptions() === $mount->getBackendOptions()
166
-				) {
167
-					$output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>");
168
-					return 1;
169
-				}
170
-			}
171
-		}
172
-
173
-		if ($input->getOption('dry')) {
174
-			if (count($mounts) === 0) {
175
-				$output->writeln('<error>No mounts to be imported</error>');
176
-				return 1;
177
-			}
178
-			$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
179
-			$listInput = new ArrayInput([], $listCommand->getDefinition());
180
-			$listInput->setOption('output', $input->getOption('output'));
181
-			$listInput->setOption('show-password', true);
182
-			$listCommand->listMounts($user, $mounts, $listInput, $output);
183
-		} else {
184
-			foreach ($mounts as $mount) {
185
-				$storageService->addStorage($mount);
186
-			}
187
-		}
188
-		return 0;
189
-	}
190
-
191
-	private function parseData(array $data) {
192
-		$mount = new StorageConfig($data['mount_id']);
193
-		$mount->setMountPoint($data['mount_point']);
194
-		$mount->setBackend($this->getBackendByClass($data['storage']));
195
-		$authBackend = $this->backendService->getAuthMechanism($data['authentication_type']);
196
-		$mount->setAuthMechanism($authBackend);
197
-		$mount->setBackendOptions($data['configuration']);
198
-		$mount->setMountOptions($data['options']);
199
-		$mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []);
200
-		$mount->setApplicableGroups(isset($data['applicable_groups']) ? $data['applicable_groups'] : []);
201
-		return $mount;
202
-	}
203
-
204
-	private function getBackendByClass($className) {
205
-		$backends = $this->backendService->getBackends();
206
-		foreach ($backends as $backend) {
207
-			if ($backend->getStorageClass() === $className) {
208
-				return $backend;
209
-			}
210
-		}
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
-	}
42
+    /**
43
+     * @var GlobalStoragesService
44
+     */
45
+    private $globalService;
46
+
47
+    /**
48
+     * @var UserStoragesService
49
+     */
50
+    private $userService;
51
+
52
+    /**
53
+     * @var IUserSession
54
+     */
55
+    private $userSession;
56
+
57
+    /**
58
+     * @var IUserManager
59
+     */
60
+    private $userManager;
61
+
62
+    /** @var ImportLegacyStoragesService */
63
+    private $importLegacyStorageService;
64
+
65
+    /** @var BackendService */
66
+    private $backendService;
67
+
68
+    function __construct(GlobalStoragesService $globalService,
69
+                            UserStoragesService $userService,
70
+                            IUserSession $userSession,
71
+                            IUserManager $userManager,
72
+                            ImportLegacyStoragesService $importLegacyStorageService,
73
+                            BackendService $backendService
74
+    ) {
75
+        parent::__construct();
76
+        $this->globalService = $globalService;
77
+        $this->userService = $userService;
78
+        $this->userSession = $userSession;
79
+        $this->userManager = $userManager;
80
+        $this->importLegacyStorageService = $importLegacyStorageService;
81
+        $this->backendService = $backendService;
82
+    }
83
+
84
+    protected function configure() {
85
+        $this
86
+            ->setName('files_external:import')
87
+            ->setDescription('Import mount configurations')
88
+            ->addOption(
89
+                'user',
90
+                '',
91
+                InputOption::VALUE_OPTIONAL,
92
+                'user to add the mount configurations for, if not set the mount will be added as system mount'
93
+            )
94
+            ->addArgument(
95
+                'path',
96
+                InputArgument::REQUIRED,
97
+                'path to a json file containing the mounts to import, use "-" to read from stdin'
98
+            )
99
+            ->addOption(
100
+                'dry',
101
+                '',
102
+                InputOption::VALUE_NONE,
103
+                'Don\'t save the imported mounts, only list the new mounts'
104
+            );
105
+        parent::configure();
106
+    }
107
+
108
+    protected function execute(InputInterface $input, OutputInterface $output) {
109
+        $user = $input->getOption('user');
110
+        $path = $input->getArgument('path');
111
+        if ($path === '-') {
112
+            $json = file_get_contents('php://stdin');
113
+        } else {
114
+            if (!file_exists($path)) {
115
+                $output->writeln('<error>File not found: ' . $path . '</error>');
116
+                return 1;
117
+            }
118
+            $json = file_get_contents($path);
119
+        }
120
+        if (!is_string($json) || strlen($json) < 2) {
121
+            $output->writeln('<error>Error while reading json</error>');
122
+            return 1;
123
+        }
124
+        $data = json_decode($json, true);
125
+        if (!is_array($data)) {
126
+            $output->writeln('<error>Error while parsing json</error>');
127
+            return 1;
128
+        }
129
+
130
+        $isLegacy = isset($data['user']) || isset($data['group']);
131
+        if ($isLegacy) {
132
+            $this->importLegacyStorageService->setData($data);
133
+            $mounts = $this->importLegacyStorageService->getAllStorages();
134
+            foreach ($mounts as $mount) {
135
+                if ($mount->getBackendOption('password') === false) {
136
+                    $output->writeln('<error>Failed to decrypt password</error>');
137
+                    return 1;
138
+                }
139
+            }
140
+        } else {
141
+            if (!isset($data[0])) { //normalize to an array of mounts
142
+                $data = [$data];
143
+            }
144
+            $mounts = array_map([$this, 'parseData'], $data);
145
+        }
146
+
147
+        if ($user) {
148
+            // ensure applicables are correct for personal mounts
149
+            foreach ($mounts as $mount) {
150
+                $mount->setApplicableGroups([]);
151
+                $mount->setApplicableUsers([$user]);
152
+            }
153
+        }
154
+
155
+        $storageService = $this->getStorageService($user);
156
+
157
+        $existingMounts = $storageService->getAllStorages();
158
+
159
+        foreach ($mounts as $mount) {
160
+            foreach ($existingMounts as $existingMount) {
161
+                if (
162
+                    $existingMount->getMountPoint() === $mount->getMountPoint() &&
163
+                    $existingMount->getApplicableGroups() === $mount->getApplicableGroups() &&
164
+                    $existingMount->getApplicableUsers() === $mount->getApplicableUsers() &&
165
+                    $existingMount->getBackendOptions() === $mount->getBackendOptions()
166
+                ) {
167
+                    $output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>");
168
+                    return 1;
169
+                }
170
+            }
171
+        }
172
+
173
+        if ($input->getOption('dry')) {
174
+            if (count($mounts) === 0) {
175
+                $output->writeln('<error>No mounts to be imported</error>');
176
+                return 1;
177
+            }
178
+            $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
179
+            $listInput = new ArrayInput([], $listCommand->getDefinition());
180
+            $listInput->setOption('output', $input->getOption('output'));
181
+            $listInput->setOption('show-password', true);
182
+            $listCommand->listMounts($user, $mounts, $listInput, $output);
183
+        } else {
184
+            foreach ($mounts as $mount) {
185
+                $storageService->addStorage($mount);
186
+            }
187
+        }
188
+        return 0;
189
+    }
190
+
191
+    private function parseData(array $data) {
192
+        $mount = new StorageConfig($data['mount_id']);
193
+        $mount->setMountPoint($data['mount_point']);
194
+        $mount->setBackend($this->getBackendByClass($data['storage']));
195
+        $authBackend = $this->backendService->getAuthMechanism($data['authentication_type']);
196
+        $mount->setAuthMechanism($authBackend);
197
+        $mount->setBackendOptions($data['configuration']);
198
+        $mount->setMountOptions($data['options']);
199
+        $mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []);
200
+        $mount->setApplicableGroups(isset($data['applicable_groups']) ? $data['applicable_groups'] : []);
201
+        return $mount;
202
+    }
203
+
204
+    private function getBackendByClass($className) {
205
+        $backends = $this->backendService->getBackends();
206
+        foreach ($backends as $backend) {
207
+            if ($backend->getStorageClass() === $className) {
208
+                return $backend;
209
+            }
210
+        }
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_sharing/lib/Middleware/OCSShareAPIMiddleware.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -11,43 +11,43 @@
 block discarded – undo
11 11
 use OCP\Share\IManager;
12 12
 
13 13
 class OCSShareAPIMiddleware extends Middleware {
14
-	/** @var IManager */
15
-	private $shareManager;
16
-	/** @var IL10N */
17
-	private $l;
14
+    /** @var IManager */
15
+    private $shareManager;
16
+    /** @var IL10N */
17
+    private $l;
18 18
 
19
-	public function __construct(IManager $shareManager,
20
-								IL10N $l) {
21
-		$this->shareManager = $shareManager;
22
-		$this->l = $l;
23
-	}
19
+    public function __construct(IManager $shareManager,
20
+                                IL10N $l) {
21
+        $this->shareManager = $shareManager;
22
+        $this->l = $l;
23
+    }
24 24
 
25
-	/**
26
-	 * @param Controller $controller
27
-	 * @param string $methodName
28
-	 *
29
-	 * @throws OCSNotFoundException
30
-	 */
31
-	public function beforeController($controller, $methodName) {
32
-		if ($controller instanceof ShareAPIController) {
33
-			if (!$this->shareManager->shareApiEnabled()) {
34
-				throw new OCSNotFoundException($this->l->t('Share API is disabled'));
35
-			}
36
-		}
37
-	}
25
+    /**
26
+     * @param Controller $controller
27
+     * @param string $methodName
28
+     *
29
+     * @throws OCSNotFoundException
30
+     */
31
+    public function beforeController($controller, $methodName) {
32
+        if ($controller instanceof ShareAPIController) {
33
+            if (!$this->shareManager->shareApiEnabled()) {
34
+                throw new OCSNotFoundException($this->l->t('Share API is disabled'));
35
+            }
36
+        }
37
+    }
38 38
 
39
-	/**
40
-	 * @param Controller $controller
41
-	 * @param string $methodName
42
-	 * @param Response $response
43
-	 * @return Response
44
-	 */
45
-	public function afterController($controller, $methodName, Response $response) {
46
-		if ($controller instanceof ShareAPIController) {
47
-			/** @var ShareAPIController $controller */
48
-			$controller->cleanup();
49
-		}
39
+    /**
40
+     * @param Controller $controller
41
+     * @param string $methodName
42
+     * @param Response $response
43
+     * @return Response
44
+     */
45
+    public function afterController($controller, $methodName, Response $response) {
46
+        if ($controller instanceof ShareAPIController) {
47
+            /** @var ShareAPIController $controller */
48
+            $controller->cleanup();
49
+        }
50 50
 
51
-		return $response;
52
-	}
51
+        return $response;
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -33,161 +33,161 @@
 block discarded – undo
33 33
 
34 34
 class OCIExpressionBuilder extends ExpressionBuilder {
35 35
 
36
-	/**
37
-	 * @param mixed $column
38
-	 * @param mixed|null $type
39
-	 * @return array|IQueryFunction|string
40
-	 */
41
-	protected function prepareColumn($column, $type) {
42
-		if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
43
-			$column = $this->castColumn($column, $type);
44
-		} else {
45
-			$column = $this->helper->quoteColumnNames($column);
46
-		}
47
-		return $column;
48
-	}
49
-
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function comparison($x, $operator, $y, $type = null) {
54
-		$x = $this->prepareColumn($x, $type);
55
-		$y = $this->prepareColumn($y, $type);
56
-
57
-		return $this->expressionBuilder->comparison($x, $operator, $y);
58
-	}
59
-
60
-	/**
61
-	 * @inheritdoc
62
-	 */
63
-	public function eq($x, $y, $type = null) {
64
-		$x = $this->prepareColumn($x, $type);
65
-		$y = $this->prepareColumn($y, $type);
66
-
67
-		return $this->expressionBuilder->eq($x, $y);
68
-	}
69
-
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	public function neq($x, $y, $type = null) {
74
-		$x = $this->prepareColumn($x, $type);
75
-		$y = $this->prepareColumn($y, $type);
76
-
77
-		return $this->expressionBuilder->neq($x, $y);
78
-	}
79
-
80
-	/**
81
-	 * @inheritdoc
82
-	 */
83
-	public function lt($x, $y, $type = null) {
84
-		$x = $this->prepareColumn($x, $type);
85
-		$y = $this->prepareColumn($y, $type);
86
-
87
-		return $this->expressionBuilder->lt($x, $y);
88
-	}
89
-
90
-	/**
91
-	 * @inheritdoc
92
-	 */
93
-	public function lte($x, $y, $type = null) {
94
-		$x = $this->prepareColumn($x, $type);
95
-		$y = $this->prepareColumn($y, $type);
96
-
97
-		return $this->expressionBuilder->lte($x, $y);
98
-	}
99
-
100
-	/**
101
-	 * @inheritdoc
102
-	 */
103
-	public function gt($x, $y, $type = null) {
104
-		$x = $this->prepareColumn($x, $type);
105
-		$y = $this->prepareColumn($y, $type);
106
-
107
-		return $this->expressionBuilder->gt($x, $y);
108
-	}
109
-
110
-	/**
111
-	 * @inheritdoc
112
-	 */
113
-	public function gte($x, $y, $type = null) {
114
-		$x = $this->prepareColumn($x, $type);
115
-		$y = $this->prepareColumn($y, $type);
116
-
117
-		return $this->expressionBuilder->gte($x, $y);
118
-	}
119
-
120
-	/**
121
-	 * @inheritdoc
122
-	 */
123
-	public function in($x, $y, $type = null) {
124
-		$x = $this->prepareColumn($x, $type);
125
-		$y = $this->prepareColumn($y, $type);
126
-
127
-		return $this->expressionBuilder->in($x, $y);
128
-	}
129
-
130
-	/**
131
-	 * @inheritdoc
132
-	 */
133
-	public function notIn($x, $y, $type = null) {
134
-		$x = $this->prepareColumn($x, $type);
135
-		$y = $this->prepareColumn($y, $type);
136
-
137
-		return $this->expressionBuilder->notIn($x, $y);
138
-	}
139
-
140
-	/**
141
-	 * Creates a $x = '' statement, because Oracle needs a different check
142
-	 *
143
-	 * @param string $x The field in string format to be inspected by the comparison.
144
-	 * @return string
145
-	 * @since 13.0.0
146
-	 */
147
-	public function emptyString($x) {
148
-		return $this->isNull($x);
149
-	}
150
-
151
-	/**
152
-	 * Creates a `$x <> ''` statement, because Oracle needs a different check
153
-	 *
154
-	 * @param string $x The field in string format to be inspected by the comparison.
155
-	 * @return string
156
-	 * @since 13.0.0
157
-	 */
158
-	public function nonEmptyString($x) {
159
-		return $this->isNotNull($x);
160
-	}
161
-
162
-	/**
163
-	 * Returns a IQueryFunction that casts the column to the given type
164
-	 *
165
-	 * @param string $column
166
-	 * @param mixed $type One of IQueryBuilder::PARAM_*
167
-	 * @return IQueryFunction
168
-	 */
169
-	public function castColumn($column, $type) {
170
-		if ($type === IQueryBuilder::PARAM_STR) {
171
-			$column = $this->helper->quoteColumnName($column);
172
-			return new QueryFunction('to_char(' . $column . ')');
173
-		}
174
-
175
-		return parent::castColumn($column, $type);
176
-	}
177
-
178
-	/**
179
-	 * @inheritdoc
180
-	 */
181
-	public function like($x, $y, $type = null) {
182
-		return parent::like($x, $y, $type) . " ESCAPE '\\'";
183
-	}
184
-
185
-	/**
186
-	 * @inheritdoc
187
-	 */
188
-	public function iLike($x, $y, $type = null) {
189
-		$x = $this->helper->quoteColumnName($x);
190
-		$y = $this->helper->quoteColumnName($y);
191
-		return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
192
-	}
36
+    /**
37
+     * @param mixed $column
38
+     * @param mixed|null $type
39
+     * @return array|IQueryFunction|string
40
+     */
41
+    protected function prepareColumn($column, $type) {
42
+        if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
43
+            $column = $this->castColumn($column, $type);
44
+        } else {
45
+            $column = $this->helper->quoteColumnNames($column);
46
+        }
47
+        return $column;
48
+    }
49
+
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function comparison($x, $operator, $y, $type = null) {
54
+        $x = $this->prepareColumn($x, $type);
55
+        $y = $this->prepareColumn($y, $type);
56
+
57
+        return $this->expressionBuilder->comparison($x, $operator, $y);
58
+    }
59
+
60
+    /**
61
+     * @inheritdoc
62
+     */
63
+    public function eq($x, $y, $type = null) {
64
+        $x = $this->prepareColumn($x, $type);
65
+        $y = $this->prepareColumn($y, $type);
66
+
67
+        return $this->expressionBuilder->eq($x, $y);
68
+    }
69
+
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    public function neq($x, $y, $type = null) {
74
+        $x = $this->prepareColumn($x, $type);
75
+        $y = $this->prepareColumn($y, $type);
76
+
77
+        return $this->expressionBuilder->neq($x, $y);
78
+    }
79
+
80
+    /**
81
+     * @inheritdoc
82
+     */
83
+    public function lt($x, $y, $type = null) {
84
+        $x = $this->prepareColumn($x, $type);
85
+        $y = $this->prepareColumn($y, $type);
86
+
87
+        return $this->expressionBuilder->lt($x, $y);
88
+    }
89
+
90
+    /**
91
+     * @inheritdoc
92
+     */
93
+    public function lte($x, $y, $type = null) {
94
+        $x = $this->prepareColumn($x, $type);
95
+        $y = $this->prepareColumn($y, $type);
96
+
97
+        return $this->expressionBuilder->lte($x, $y);
98
+    }
99
+
100
+    /**
101
+     * @inheritdoc
102
+     */
103
+    public function gt($x, $y, $type = null) {
104
+        $x = $this->prepareColumn($x, $type);
105
+        $y = $this->prepareColumn($y, $type);
106
+
107
+        return $this->expressionBuilder->gt($x, $y);
108
+    }
109
+
110
+    /**
111
+     * @inheritdoc
112
+     */
113
+    public function gte($x, $y, $type = null) {
114
+        $x = $this->prepareColumn($x, $type);
115
+        $y = $this->prepareColumn($y, $type);
116
+
117
+        return $this->expressionBuilder->gte($x, $y);
118
+    }
119
+
120
+    /**
121
+     * @inheritdoc
122
+     */
123
+    public function in($x, $y, $type = null) {
124
+        $x = $this->prepareColumn($x, $type);
125
+        $y = $this->prepareColumn($y, $type);
126
+
127
+        return $this->expressionBuilder->in($x, $y);
128
+    }
129
+
130
+    /**
131
+     * @inheritdoc
132
+     */
133
+    public function notIn($x, $y, $type = null) {
134
+        $x = $this->prepareColumn($x, $type);
135
+        $y = $this->prepareColumn($y, $type);
136
+
137
+        return $this->expressionBuilder->notIn($x, $y);
138
+    }
139
+
140
+    /**
141
+     * Creates a $x = '' statement, because Oracle needs a different check
142
+     *
143
+     * @param string $x The field in string format to be inspected by the comparison.
144
+     * @return string
145
+     * @since 13.0.0
146
+     */
147
+    public function emptyString($x) {
148
+        return $this->isNull($x);
149
+    }
150
+
151
+    /**
152
+     * Creates a `$x <> ''` statement, because Oracle needs a different check
153
+     *
154
+     * @param string $x The field in string format to be inspected by the comparison.
155
+     * @return string
156
+     * @since 13.0.0
157
+     */
158
+    public function nonEmptyString($x) {
159
+        return $this->isNotNull($x);
160
+    }
161
+
162
+    /**
163
+     * Returns a IQueryFunction that casts the column to the given type
164
+     *
165
+     * @param string $column
166
+     * @param mixed $type One of IQueryBuilder::PARAM_*
167
+     * @return IQueryFunction
168
+     */
169
+    public function castColumn($column, $type) {
170
+        if ($type === IQueryBuilder::PARAM_STR) {
171
+            $column = $this->helper->quoteColumnName($column);
172
+            return new QueryFunction('to_char(' . $column . ')');
173
+        }
174
+
175
+        return parent::castColumn($column, $type);
176
+    }
177
+
178
+    /**
179
+     * @inheritdoc
180
+     */
181
+    public function like($x, $y, $type = null) {
182
+        return parent::like($x, $y, $type) . " ESCAPE '\\'";
183
+    }
184
+
185
+    /**
186
+     * @inheritdoc
187
+     */
188
+    public function iLike($x, $y, $type = null) {
189
+        $x = $this->helper->quoteColumnName($x);
190
+        $y = $this->helper->quoteColumnName($y);
191
+        return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
192
+    }
193 193
 }
Please login to merge, or discard this patch.
apps/federation/lib/DbHandler.php 1 patch
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -42,294 +42,294 @@
 block discarded – undo
42 42
  */
43 43
 class DbHandler {
44 44
 
45
-	/** @var  IDBConnection */
46
-	private $connection;
47
-
48
-	/** @var  IL10N */
49
-	private $IL10N;
50
-
51
-	/** @var string  */
52
-	private $dbTable = 'trusted_servers';
53
-
54
-	/**
55
-	 * @param IDBConnection $connection
56
-	 * @param IL10N $il10n
57
-	 */
58
-	public function __construct(
59
-		IDBConnection $connection,
60
-		IL10N $il10n
61
-	) {
62
-		$this->connection = $connection;
63
-		$this->IL10N = $il10n;
64
-	}
65
-
66
-	/**
67
-	 * add server to the list of trusted servers
68
-	 *
69
-	 * @param string $url
70
-	 * @return int
71
-	 * @throws HintException
72
-	 */
73
-	public function addServer($url) {
74
-		$hash = $this->hash($url);
75
-		$url = rtrim($url, '/');
76
-		$query = $this->connection->getQueryBuilder();
77
-		$query->insert($this->dbTable)
78
-			->values(
79
-				[
80
-					'url' =>  $query->createParameter('url'),
81
-					'url_hash' => $query->createParameter('url_hash'),
82
-				]
83
-			)
84
-			->setParameter('url', $url)
85
-			->setParameter('url_hash', $hash);
86
-
87
-		$result = $query->execute();
88
-
89
-		if ($result) {
90
-			return (int)$this->connection->lastInsertId('*PREFIX*'.$this->dbTable);
91
-		}
92
-
93
-		$message = 'Internal failure, Could not add trusted server: ' . $url;
94
-		$message_t = $this->IL10N->t('Could not add server');
95
-		throw new HintException($message, $message_t);
96
-	}
97
-
98
-	/**
99
-	 * remove server from the list of trusted servers
100
-	 *
101
-	 * @param int $id
102
-	 */
103
-	public function removeServer($id) {
104
-		$query = $this->connection->getQueryBuilder();
105
-		$query->delete($this->dbTable)
106
-			->where($query->expr()->eq('id', $query->createParameter('id')))
107
-			->setParameter('id', $id);
108
-		$query->execute();
109
-	}
110
-
111
-	/**
112
-	 * get trusted server with given ID
113
-	 *
114
-	 * @param int $id
115
-	 * @return array
116
-	 * @throws \Exception
117
-	 */
118
-	public function getServerById($id) {
119
-		$query = $this->connection->getQueryBuilder();
120
-		$query->select('*')->from($this->dbTable)
121
-			->where($query->expr()->eq('id', $query->createParameter('id')))
122
-			->setParameter('id', $id);
123
-		$query->execute();
124
-		$result = $query->execute()->fetchAll();
125
-
126
-		if (empty($result)) {
127
-			throw new \Exception('No Server found with ID: ' . $id);
128
-		}
129
-
130
-		return $result[0];
131
-	}
132
-
133
-	/**
134
-	 * get all trusted servers
135
-	 *
136
-	 * @return array
137
-	 */
138
-	public function getAllServer() {
139
-		$query = $this->connection->getQueryBuilder();
140
-		$query->select(['url', 'url_hash', 'id', 'status', 'shared_secret', 'sync_token'])
141
-			->from($this->dbTable);
142
-		$statement = $query->execute();
143
-		$result = $statement->fetchAll();
144
-		$statement->closeCursor();
145
-		return $result;
146
-	}
147
-
148
-	/**
149
-	 * check if server already exists in the database table
150
-	 *
151
-	 * @param string $url
152
-	 * @return bool
153
-	 */
154
-	public function serverExists($url) {
155
-		$hash = $this->hash($url);
156
-		$query = $this->connection->getQueryBuilder();
157
-		$query->select('url')
158
-			->from($this->dbTable)
159
-			->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
160
-			->setParameter('url_hash', $hash);
161
-		$statement = $query->execute();
162
-		$result = $statement->fetchAll();
163
-		$statement->closeCursor();
164
-
165
-		return !empty($result);
166
-	}
167
-
168
-	/**
169
-	 * write token to database. Token is used to exchange the secret
170
-	 *
171
-	 * @param string $url
172
-	 * @param string $token
173
-	 */
174
-	public function addToken($url, $token) {
175
-		$hash = $this->hash($url);
176
-		$query = $this->connection->getQueryBuilder();
177
-		$query->update($this->dbTable)
178
-			->set('token', $query->createParameter('token'))
179
-			->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
180
-			->setParameter('url_hash', $hash)
181
-			->setParameter('token', $token);
182
-		$query->execute();
183
-	}
184
-
185
-	/**
186
-	 * get token stored in database
187
-	 *
188
-	 * @param string $url
189
-	 * @return string
190
-	 * @throws \Exception
191
-	 */
192
-	public function getToken($url) {
193
-		$hash = $this->hash($url);
194
-		$query = $this->connection->getQueryBuilder();
195
-		$query->select('token')->from($this->dbTable)
196
-			->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
197
-			->setParameter('url_hash', $hash);
198
-
199
-		$statement = $query->execute();
200
-		$result = $statement->fetch();
201
-		$statement->closeCursor();
202
-
203
-		if (!isset($result['token'])) {
204
-			throw new \Exception('No token found for: ' . $url);
205
-		}
206
-
207
-		return $result['token'];
208
-	}
209
-
210
-	/**
211
-	 * add shared Secret to database
212
-	 *
213
-	 * @param string $url
214
-	 * @param string $sharedSecret
215
-	 */
216
-	public function addSharedSecret($url, $sharedSecret) {
217
-		$hash = $this->hash($url);
218
-		$query = $this->connection->getQueryBuilder();
219
-		$query->update($this->dbTable)
220
-			->set('shared_secret', $query->createParameter('sharedSecret'))
221
-			->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
222
-			->setParameter('url_hash', $hash)
223
-			->setParameter('sharedSecret', $sharedSecret);
224
-		$query->execute();
225
-	}
226
-
227
-	/**
228
-	 * get shared secret from database
229
-	 *
230
-	 * @param string $url
231
-	 * @return string
232
-	 */
233
-	public function getSharedSecret($url) {
234
-		$hash = $this->hash($url);
235
-		$query = $this->connection->getQueryBuilder();
236
-		$query->select('shared_secret')->from($this->dbTable)
237
-			->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
238
-			->setParameter('url_hash', $hash);
239
-
240
-		$statement = $query->execute();
241
-		$result = $statement->fetch();
242
-		$statement->closeCursor();
243
-		return $result['shared_secret'];
244
-	}
245
-
246
-	/**
247
-	 * set server status
248
-	 *
249
-	 * @param string $url
250
-	 * @param int $status
251
-	 * @param string|null $token
252
-	 */
253
-	public function setServerStatus($url, $status, $token = null) {
254
-		$hash = $this->hash($url);
255
-		$query = $this->connection->getQueryBuilder();
256
-		$query->update($this->dbTable)
257
-				->set('status', $query->createNamedParameter($status))
258
-				->where($query->expr()->eq('url_hash', $query->createNamedParameter($hash)));
259
-		if (!is_null($token)) {
260
-			$query->set('sync_token', $query->createNamedParameter($token));
261
-		}
262
-		$query->execute();
263
-	}
264
-
265
-	/**
266
-	 * get server status
267
-	 *
268
-	 * @param string $url
269
-	 * @return int
270
-	 */
271
-	public function getServerStatus($url) {
272
-		$hash = $this->hash($url);
273
-		$query = $this->connection->getQueryBuilder();
274
-		$query->select('status')->from($this->dbTable)
275
-				->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
276
-				->setParameter('url_hash', $hash);
277
-
278
-		$statement = $query->execute();
279
-		$result = $statement->fetch();
280
-		$statement->closeCursor();
281
-		return (int)$result['status'];
282
-	}
283
-
284
-	/**
285
-	 * create hash from URL
286
-	 *
287
-	 * @param string $url
288
-	 * @return string
289
-	 */
290
-	protected function hash($url) {
291
-		$normalized = $this->normalizeUrl($url);
292
-		return sha1($normalized);
293
-	}
294
-
295
-	/**
296
-	 * normalize URL, used to create the sha1 hash
297
-	 *
298
-	 * @param string $url
299
-	 * @return string
300
-	 */
301
-	protected function normalizeUrl($url) {
302
-		$normalized = $url;
303
-
304
-		if (strpos($url, 'https://') === 0) {
305
-			$normalized = substr($url, strlen('https://'));
306
-		} else if (strpos($url, 'http://') === 0) {
307
-			$normalized = substr($url, strlen('http://'));
308
-		}
309
-
310
-		$normalized = Filesystem::normalizePath($normalized);
311
-		$normalized = trim($normalized, '/');
312
-
313
-		return $normalized;
314
-	}
315
-
316
-	/**
317
-	 * @param $username
318
-	 * @param $password
319
-	 * @return bool
320
-	 */
321
-	public function auth($username, $password) {
322
-		if ($username !== 'system') {
323
-			return false;
324
-		}
325
-		$query = $this->connection->getQueryBuilder();
326
-		$query->select('url')->from($this->dbTable)
327
-				->where($query->expr()->eq('shared_secret', $query->createNamedParameter($password)));
328
-
329
-		$statement = $query->execute();
330
-		$result = $statement->fetch();
331
-		$statement->closeCursor();
332
-		return !empty($result);
333
-	}
45
+    /** @var  IDBConnection */
46
+    private $connection;
47
+
48
+    /** @var  IL10N */
49
+    private $IL10N;
50
+
51
+    /** @var string  */
52
+    private $dbTable = 'trusted_servers';
53
+
54
+    /**
55
+     * @param IDBConnection $connection
56
+     * @param IL10N $il10n
57
+     */
58
+    public function __construct(
59
+        IDBConnection $connection,
60
+        IL10N $il10n
61
+    ) {
62
+        $this->connection = $connection;
63
+        $this->IL10N = $il10n;
64
+    }
65
+
66
+    /**
67
+     * add server to the list of trusted servers
68
+     *
69
+     * @param string $url
70
+     * @return int
71
+     * @throws HintException
72
+     */
73
+    public function addServer($url) {
74
+        $hash = $this->hash($url);
75
+        $url = rtrim($url, '/');
76
+        $query = $this->connection->getQueryBuilder();
77
+        $query->insert($this->dbTable)
78
+            ->values(
79
+                [
80
+                    'url' =>  $query->createParameter('url'),
81
+                    'url_hash' => $query->createParameter('url_hash'),
82
+                ]
83
+            )
84
+            ->setParameter('url', $url)
85
+            ->setParameter('url_hash', $hash);
86
+
87
+        $result = $query->execute();
88
+
89
+        if ($result) {
90
+            return (int)$this->connection->lastInsertId('*PREFIX*'.$this->dbTable);
91
+        }
92
+
93
+        $message = 'Internal failure, Could not add trusted server: ' . $url;
94
+        $message_t = $this->IL10N->t('Could not add server');
95
+        throw new HintException($message, $message_t);
96
+    }
97
+
98
+    /**
99
+     * remove server from the list of trusted servers
100
+     *
101
+     * @param int $id
102
+     */
103
+    public function removeServer($id) {
104
+        $query = $this->connection->getQueryBuilder();
105
+        $query->delete($this->dbTable)
106
+            ->where($query->expr()->eq('id', $query->createParameter('id')))
107
+            ->setParameter('id', $id);
108
+        $query->execute();
109
+    }
110
+
111
+    /**
112
+     * get trusted server with given ID
113
+     *
114
+     * @param int $id
115
+     * @return array
116
+     * @throws \Exception
117
+     */
118
+    public function getServerById($id) {
119
+        $query = $this->connection->getQueryBuilder();
120
+        $query->select('*')->from($this->dbTable)
121
+            ->where($query->expr()->eq('id', $query->createParameter('id')))
122
+            ->setParameter('id', $id);
123
+        $query->execute();
124
+        $result = $query->execute()->fetchAll();
125
+
126
+        if (empty($result)) {
127
+            throw new \Exception('No Server found with ID: ' . $id);
128
+        }
129
+
130
+        return $result[0];
131
+    }
132
+
133
+    /**
134
+     * get all trusted servers
135
+     *
136
+     * @return array
137
+     */
138
+    public function getAllServer() {
139
+        $query = $this->connection->getQueryBuilder();
140
+        $query->select(['url', 'url_hash', 'id', 'status', 'shared_secret', 'sync_token'])
141
+            ->from($this->dbTable);
142
+        $statement = $query->execute();
143
+        $result = $statement->fetchAll();
144
+        $statement->closeCursor();
145
+        return $result;
146
+    }
147
+
148
+    /**
149
+     * check if server already exists in the database table
150
+     *
151
+     * @param string $url
152
+     * @return bool
153
+     */
154
+    public function serverExists($url) {
155
+        $hash = $this->hash($url);
156
+        $query = $this->connection->getQueryBuilder();
157
+        $query->select('url')
158
+            ->from($this->dbTable)
159
+            ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
160
+            ->setParameter('url_hash', $hash);
161
+        $statement = $query->execute();
162
+        $result = $statement->fetchAll();
163
+        $statement->closeCursor();
164
+
165
+        return !empty($result);
166
+    }
167
+
168
+    /**
169
+     * write token to database. Token is used to exchange the secret
170
+     *
171
+     * @param string $url
172
+     * @param string $token
173
+     */
174
+    public function addToken($url, $token) {
175
+        $hash = $this->hash($url);
176
+        $query = $this->connection->getQueryBuilder();
177
+        $query->update($this->dbTable)
178
+            ->set('token', $query->createParameter('token'))
179
+            ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
180
+            ->setParameter('url_hash', $hash)
181
+            ->setParameter('token', $token);
182
+        $query->execute();
183
+    }
184
+
185
+    /**
186
+     * get token stored in database
187
+     *
188
+     * @param string $url
189
+     * @return string
190
+     * @throws \Exception
191
+     */
192
+    public function getToken($url) {
193
+        $hash = $this->hash($url);
194
+        $query = $this->connection->getQueryBuilder();
195
+        $query->select('token')->from($this->dbTable)
196
+            ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
197
+            ->setParameter('url_hash', $hash);
198
+
199
+        $statement = $query->execute();
200
+        $result = $statement->fetch();
201
+        $statement->closeCursor();
202
+
203
+        if (!isset($result['token'])) {
204
+            throw new \Exception('No token found for: ' . $url);
205
+        }
206
+
207
+        return $result['token'];
208
+    }
209
+
210
+    /**
211
+     * add shared Secret to database
212
+     *
213
+     * @param string $url
214
+     * @param string $sharedSecret
215
+     */
216
+    public function addSharedSecret($url, $sharedSecret) {
217
+        $hash = $this->hash($url);
218
+        $query = $this->connection->getQueryBuilder();
219
+        $query->update($this->dbTable)
220
+            ->set('shared_secret', $query->createParameter('sharedSecret'))
221
+            ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
222
+            ->setParameter('url_hash', $hash)
223
+            ->setParameter('sharedSecret', $sharedSecret);
224
+        $query->execute();
225
+    }
226
+
227
+    /**
228
+     * get shared secret from database
229
+     *
230
+     * @param string $url
231
+     * @return string
232
+     */
233
+    public function getSharedSecret($url) {
234
+        $hash = $this->hash($url);
235
+        $query = $this->connection->getQueryBuilder();
236
+        $query->select('shared_secret')->from($this->dbTable)
237
+            ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
238
+            ->setParameter('url_hash', $hash);
239
+
240
+        $statement = $query->execute();
241
+        $result = $statement->fetch();
242
+        $statement->closeCursor();
243
+        return $result['shared_secret'];
244
+    }
245
+
246
+    /**
247
+     * set server status
248
+     *
249
+     * @param string $url
250
+     * @param int $status
251
+     * @param string|null $token
252
+     */
253
+    public function setServerStatus($url, $status, $token = null) {
254
+        $hash = $this->hash($url);
255
+        $query = $this->connection->getQueryBuilder();
256
+        $query->update($this->dbTable)
257
+                ->set('status', $query->createNamedParameter($status))
258
+                ->where($query->expr()->eq('url_hash', $query->createNamedParameter($hash)));
259
+        if (!is_null($token)) {
260
+            $query->set('sync_token', $query->createNamedParameter($token));
261
+        }
262
+        $query->execute();
263
+    }
264
+
265
+    /**
266
+     * get server status
267
+     *
268
+     * @param string $url
269
+     * @return int
270
+     */
271
+    public function getServerStatus($url) {
272
+        $hash = $this->hash($url);
273
+        $query = $this->connection->getQueryBuilder();
274
+        $query->select('status')->from($this->dbTable)
275
+                ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))
276
+                ->setParameter('url_hash', $hash);
277
+
278
+        $statement = $query->execute();
279
+        $result = $statement->fetch();
280
+        $statement->closeCursor();
281
+        return (int)$result['status'];
282
+    }
283
+
284
+    /**
285
+     * create hash from URL
286
+     *
287
+     * @param string $url
288
+     * @return string
289
+     */
290
+    protected function hash($url) {
291
+        $normalized = $this->normalizeUrl($url);
292
+        return sha1($normalized);
293
+    }
294
+
295
+    /**
296
+     * normalize URL, used to create the sha1 hash
297
+     *
298
+     * @param string $url
299
+     * @return string
300
+     */
301
+    protected function normalizeUrl($url) {
302
+        $normalized = $url;
303
+
304
+        if (strpos($url, 'https://') === 0) {
305
+            $normalized = substr($url, strlen('https://'));
306
+        } else if (strpos($url, 'http://') === 0) {
307
+            $normalized = substr($url, strlen('http://'));
308
+        }
309
+
310
+        $normalized = Filesystem::normalizePath($normalized);
311
+        $normalized = trim($normalized, '/');
312
+
313
+        return $normalized;
314
+    }
315
+
316
+    /**
317
+     * @param $username
318
+     * @param $password
319
+     * @return bool
320
+     */
321
+    public function auth($username, $password) {
322
+        if ($username !== 'system') {
323
+            return false;
324
+        }
325
+        $query = $this->connection->getQueryBuilder();
326
+        $query->select('url')->from($this->dbTable)
327
+                ->where($query->expr()->eq('shared_secret', $query->createNamedParameter($password)));
328
+
329
+        $statement = $query->execute();
330
+        $result = $statement->fetch();
331
+        $statement->closeCursor();
332
+        return !empty($result);
333
+    }
334 334
 
335 335
 }
Please login to merge, or discard this patch.
apps/federation/lib/Command/SyncFederationAddressBooks.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -30,45 +30,45 @@
 block discarded – undo
30 30
 
31 31
 class SyncFederationAddressBooks extends Command {
32 32
 
33
-	/** @var \OCA\Federation\SyncFederationAddressBooks */
34
-	private $syncService;
33
+    /** @var \OCA\Federation\SyncFederationAddressBooks */
34
+    private $syncService;
35 35
 
36
-	/**
37
-	 * @param \OCA\Federation\SyncFederationAddressBooks $syncService
38
-	 */
39
-	public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
40
-		parent::__construct();
36
+    /**
37
+     * @param \OCA\Federation\SyncFederationAddressBooks $syncService
38
+     */
39
+    public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
40
+        parent::__construct();
41 41
 
42
-		$this->syncService = $syncService;
43
-	}
42
+        $this->syncService = $syncService;
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('federation:sync-addressbooks')
48
-			->setDescription('Synchronizes addressbooks of all federated clouds');
49
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('federation:sync-addressbooks')
48
+            ->setDescription('Synchronizes addressbooks of all federated clouds');
49
+    }
50 50
 
51
-	/**
52
-	 * @param InputInterface $input
53
-	 * @param OutputInterface $output
54
-	 * @return int
55
-	 */
56
-	protected function execute(InputInterface $input, OutputInterface $output) {
51
+    /**
52
+     * @param InputInterface $input
53
+     * @param OutputInterface $output
54
+     * @return int
55
+     */
56
+    protected function execute(InputInterface $input, OutputInterface $output) {
57 57
 
58
-		$progress = new ProgressBar($output);
59
-		$progress->start();
60
-		$this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
61
-			if ($ex instanceof \Exception) {
62
-				$output->writeln("Error while syncing $url : " . $ex->getMessage());
58
+        $progress = new ProgressBar($output);
59
+        $progress->start();
60
+        $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
61
+            if ($ex instanceof \Exception) {
62
+                $output->writeln("Error while syncing $url : " . $ex->getMessage());
63 63
 
64
-			} else {
65
-				$progress->advance();
66
-			}
67
-		});
64
+            } else {
65
+                $progress->advance();
66
+            }
67
+        });
68 68
 
69
-		$progress->finish();
70
-		$output->writeln('');
69
+        $progress->finish();
70
+        $output->writeln('');
71 71
 
72
-		return 0;
73
-	}
72
+        return 0;
73
+    }
74 74
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Migration/UUIDFixUser.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@
 block discarded – undo
30 30
 use OCP\IConfig;
31 31
 
32 32
 class UUIDFixUser extends UUIDFix {
33
-	public function __construct(UserMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) {
34
-		$this->mapper = $mapper;
35
-		$groupPluginManager = \OC::$server->query('LDAPGroupPluginManager');
36
-		$this->proxy = new Group_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $groupPluginManager);
37
-	}
33
+    public function __construct(UserMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) {
34
+        $this->mapper = $mapper;
35
+        $groupPluginManager = \OC::$server->query('LDAPGroupPluginManager');
36
+        $this->proxy = new Group_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $groupPluginManager);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/private/Lockdown/Filesystem/NullStorage.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -25,155 +25,155 @@
 block discarded – undo
25 25
 use OCP\Files\Storage\IStorage;
26 26
 
27 27
 class NullStorage extends Common {
28
-	public function __construct($parameters) {
29
-		parent::__construct($parameters);
30
-	}
28
+    public function __construct($parameters) {
29
+        parent::__construct($parameters);
30
+    }
31 31
 
32
-	public function getId() {
33
-		return 'null';
34
-	}
32
+    public function getId() {
33
+        return 'null';
34
+    }
35 35
 
36
-	public function mkdir($path) {
37
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
38
-	}
36
+    public function mkdir($path) {
37
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
38
+    }
39 39
 
40
-	public function rmdir($path) {
41
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
42
-	}
40
+    public function rmdir($path) {
41
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
42
+    }
43 43
 
44
-	public function opendir($path) {
45
-		return new IteratorDirectory([]);
46
-	}
44
+    public function opendir($path) {
45
+        return new IteratorDirectory([]);
46
+    }
47 47
 
48
-	public function is_dir($path) {
49
-		return $path === '';
50
-	}
48
+    public function is_dir($path) {
49
+        return $path === '';
50
+    }
51 51
 
52
-	public function is_file($path) {
53
-		return false;
54
-	}
52
+    public function is_file($path) {
53
+        return false;
54
+    }
55 55
 
56
-	public function stat($path) {
57
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
58
-	}
56
+    public function stat($path) {
57
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
58
+    }
59 59
 
60
-	public function filetype($path) {
61
-		return ($path === '') ? 'dir' : false;
62
-	}
60
+    public function filetype($path) {
61
+        return ($path === '') ? 'dir' : false;
62
+    }
63 63
 
64
-	public function filesize($path) {
65
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
66
-	}
64
+    public function filesize($path) {
65
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
66
+    }
67 67
 
68
-	public function isCreatable($path) {
69
-		return false;
70
-	}
68
+    public function isCreatable($path) {
69
+        return false;
70
+    }
71 71
 
72
-	public function isReadable($path) {
73
-		return $path === '';
74
-	}
72
+    public function isReadable($path) {
73
+        return $path === '';
74
+    }
75 75
 
76
-	public function isUpdatable($path) {
77
-		return false;
78
-	}
76
+    public function isUpdatable($path) {
77
+        return false;
78
+    }
79 79
 
80
-	public function isDeletable($path) {
81
-		return false;
82
-	}
80
+    public function isDeletable($path) {
81
+        return false;
82
+    }
83 83
 
84
-	public function isSharable($path) {
85
-		return false;
86
-	}
84
+    public function isSharable($path) {
85
+        return false;
86
+    }
87 87
 
88
-	public function getPermissions($path) {
89
-		return null;
90
-	}
88
+    public function getPermissions($path) {
89
+        return null;
90
+    }
91 91
 
92
-	public function file_exists($path) {
93
-		return $path === '';
94
-	}
92
+    public function file_exists($path) {
93
+        return $path === '';
94
+    }
95 95
 
96
-	public function filemtime($path) {
97
-		return ($path === '') ? time() : false;
98
-	}
96
+    public function filemtime($path) {
97
+        return ($path === '') ? time() : false;
98
+    }
99 99
 
100
-	public function file_get_contents($path) {
101
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
102
-	}
100
+    public function file_get_contents($path) {
101
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
102
+    }
103 103
 
104
-	public function file_put_contents($path, $data) {
105
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
106
-	}
104
+    public function file_put_contents($path, $data) {
105
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
106
+    }
107 107
 
108
-	public function unlink($path) {
109
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
110
-	}
108
+    public function unlink($path) {
109
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
110
+    }
111 111
 
112
-	public function rename($path1, $path2) {
113
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
114
-	}
112
+    public function rename($path1, $path2) {
113
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
114
+    }
115 115
 
116
-	public function copy($path1, $path2) {
117
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
118
-	}
116
+    public function copy($path1, $path2) {
117
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
118
+    }
119 119
 
120
-	public function fopen($path, $mode) {
121
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
122
-	}
120
+    public function fopen($path, $mode) {
121
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
122
+    }
123 123
 
124
-	public function getMimeType($path) {
125
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
126
-	}
124
+    public function getMimeType($path) {
125
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
126
+    }
127 127
 
128
-	public function hash($type, $path, $raw = false) {
129
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
130
-	}
128
+    public function hash($type, $path, $raw = false) {
129
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
130
+    }
131 131
 
132
-	public function free_space($path) {
133
-		return FileInfo::SPACE_UNKNOWN;
134
-	}
132
+    public function free_space($path) {
133
+        return FileInfo::SPACE_UNKNOWN;
134
+    }
135 135
 
136
-	public function touch($path, $mtime = null) {
137
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
138
-	}
136
+    public function touch($path, $mtime = null) {
137
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
138
+    }
139 139
 
140
-	public function getLocalFile($path) {
141
-		return false;
142
-	}
140
+    public function getLocalFile($path) {
141
+        return false;
142
+    }
143 143
 
144
-	public function hasUpdated($path, $time) {
145
-		return false;
146
-	}
144
+    public function hasUpdated($path, $time) {
145
+        return false;
146
+    }
147 147
 
148
-	public function getETag($path) {
149
-		return '';
150
-	}
148
+    public function getETag($path) {
149
+        return '';
150
+    }
151 151
 
152
-	public function isLocal() {
153
-		return false;
154
-	}
152
+    public function isLocal() {
153
+        return false;
154
+    }
155 155
 
156
-	public function getDirectDownload($path) {
157
-		return false;
158
-	}
156
+    public function getDirectDownload($path) {
157
+        return false;
158
+    }
159 159
 
160
-	public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
161
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
162
-	}
160
+    public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
161
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
162
+    }
163 163
 
164
-	public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
165
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
166
-	}
164
+    public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
165
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
166
+    }
167 167
 
168
-	public function test() {
169
-		return true;
170
-	}
168
+    public function test() {
169
+        return true;
170
+    }
171 171
 
172
-	public function getOwner($path) {
173
-		return null;
174
-	}
172
+    public function getOwner($path) {
173
+        return null;
174
+    }
175 175
 
176
-	public function getCache($path = '', $storage = null) {
177
-		return new NullCache();
178
-	}
176
+    public function getCache($path = '', $storage = null) {
177
+        return new NullCache();
178
+    }
179 179
 }
Please login to merge, or discard this patch.