Passed
Push — master ( 4e9cd2...bc8d14 )
by Roeland
19:16 queued 09:49
created
lib/private/Hooks/EmitterTrait.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param callable $callback
36 36
 	 */
37 37
 	public function listen($scope, $method, callable $callback) {
38
-		$eventName = $scope . '::' . $method;
38
+		$eventName = $scope.'::'.$method;
39 39
 		if (!isset($this->listeners[$eventName])) {
40 40
 			$this->listeners[$eventName] = [];
41 41
 		}
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		$names = [];
54 54
 		$allNames = array_keys($this->listeners);
55 55
 		if ($scope and $method) {
56
-			$name = $scope . '::' . $method;
56
+			$name = $scope.'::'.$method;
57 57
 			if (isset($this->listeners[$name])) {
58 58
 				$names[] = $name;
59 59
 			}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @param array $arguments optional
94 94
 	 */
95 95
 	protected function emit($scope, $method, array $arguments = []) {
96
-		$eventName = $scope . '::' . $method;
96
+		$eventName = $scope.'::'.$method;
97 97
 		if (isset($this->listeners[$eventName])) {
98 98
 			foreach ($this->listeners[$eventName] as $callback) {
99 99
 				call_user_func_array($callback, $arguments);
Please login to merge, or discard this patch.
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -25,80 +25,80 @@
 block discarded – undo
25 25
 
26 26
 trait EmitterTrait {
27 27
 
28
-	/**
29
-	 * @var callable[][] $listeners
30
-	 */
31
-	protected $listeners = [];
28
+    /**
29
+     * @var callable[][] $listeners
30
+     */
31
+    protected $listeners = [];
32 32
 
33
-	/**
34
-	 * @param string $scope
35
-	 * @param string $method
36
-	 * @param callable $callback
37
-	 */
38
-	public function listen($scope, $method, callable $callback) {
39
-		$eventName = $scope . '::' . $method;
40
-		if (!isset($this->listeners[$eventName])) {
41
-			$this->listeners[$eventName] = [];
42
-		}
43
-		if (array_search($callback, $this->listeners[$eventName], true) === false) {
44
-			$this->listeners[$eventName][] = $callback;
45
-		}
46
-	}
33
+    /**
34
+     * @param string $scope
35
+     * @param string $method
36
+     * @param callable $callback
37
+     */
38
+    public function listen($scope, $method, callable $callback) {
39
+        $eventName = $scope . '::' . $method;
40
+        if (!isset($this->listeners[$eventName])) {
41
+            $this->listeners[$eventName] = [];
42
+        }
43
+        if (array_search($callback, $this->listeners[$eventName], true) === false) {
44
+            $this->listeners[$eventName][] = $callback;
45
+        }
46
+    }
47 47
 
48
-	/**
49
-	 * @param string $scope optional
50
-	 * @param string $method optional
51
-	 * @param callable $callback optional
52
-	 */
53
-	public function removeListener($scope = null, $method = null, callable $callback = null) {
54
-		$names = [];
55
-		$allNames = array_keys($this->listeners);
56
-		if ($scope and $method) {
57
-			$name = $scope . '::' . $method;
58
-			if (isset($this->listeners[$name])) {
59
-				$names[] = $name;
60
-			}
61
-		} elseif ($scope) {
62
-			foreach ($allNames as $name) {
63
-				$parts = explode('::', $name, 2);
64
-				if ($parts[0] == $scope) {
65
-					$names[] = $name;
66
-				}
67
-			}
68
-		} elseif ($method) {
69
-			foreach ($allNames as $name) {
70
-				$parts = explode('::', $name, 2);
71
-				if ($parts[1] == $method) {
72
-					$names[] = $name;
73
-				}
74
-			}
75
-		} else {
76
-			$names = $allNames;
77
-		}
48
+    /**
49
+     * @param string $scope optional
50
+     * @param string $method optional
51
+     * @param callable $callback optional
52
+     */
53
+    public function removeListener($scope = null, $method = null, callable $callback = null) {
54
+        $names = [];
55
+        $allNames = array_keys($this->listeners);
56
+        if ($scope and $method) {
57
+            $name = $scope . '::' . $method;
58
+            if (isset($this->listeners[$name])) {
59
+                $names[] = $name;
60
+            }
61
+        } elseif ($scope) {
62
+            foreach ($allNames as $name) {
63
+                $parts = explode('::', $name, 2);
64
+                if ($parts[0] == $scope) {
65
+                    $names[] = $name;
66
+                }
67
+            }
68
+        } elseif ($method) {
69
+            foreach ($allNames as $name) {
70
+                $parts = explode('::', $name, 2);
71
+                if ($parts[1] == $method) {
72
+                    $names[] = $name;
73
+                }
74
+            }
75
+        } else {
76
+            $names = $allNames;
77
+        }
78 78
 
79
-		foreach ($names as $name) {
80
-			if ($callback) {
81
-				$index = array_search($callback, $this->listeners[$name], true);
82
-				if ($index !== false) {
83
-					unset($this->listeners[$name][$index]);
84
-				}
85
-			} else {
86
-				$this->listeners[$name] = [];
87
-			}
88
-		}
89
-	}
79
+        foreach ($names as $name) {
80
+            if ($callback) {
81
+                $index = array_search($callback, $this->listeners[$name], true);
82
+                if ($index !== false) {
83
+                    unset($this->listeners[$name][$index]);
84
+                }
85
+            } else {
86
+                $this->listeners[$name] = [];
87
+            }
88
+        }
89
+    }
90 90
 
91
-	/**
92
-	 * @param string $scope
93
-	 * @param string $method
94
-	 * @param array $arguments optional
95
-	 */
96
-	protected function emit($scope, $method, array $arguments = []) {
97
-		$eventName = $scope . '::' . $method;
98
-		if (isset($this->listeners[$eventName])) {
99
-			foreach ($this->listeners[$eventName] as $callback) {
100
-				call_user_func_array($callback, $arguments);
101
-			}
102
-		}
103
-	}
91
+    /**
92
+     * @param string $scope
93
+     * @param string $method
94
+     * @param array $arguments optional
95
+     */
96
+    protected function emit($scope, $method, array $arguments = []) {
97
+        $eventName = $scope . '::' . $method;
98
+        if (isset($this->listeners[$eventName])) {
99
+            foreach ($this->listeners[$eventName] as $callback) {
100
+                call_user_func_array($callback, $arguments);
101
+            }
102
+        }
103
+    }
104 104
 }
Please login to merge, or discard this patch.
lib/private/Hooks/ForwardingEmitter.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -31,35 +31,35 @@
 block discarded – undo
31 31
  * @package OC\Hooks
32 32
  */
33 33
 abstract class ForwardingEmitter extends BasicEmitter {
34
-	/**
35
-	 * @var \OC\Hooks\Emitter[] array
36
-	 */
37
-	private $forwardEmitters = [];
34
+    /**
35
+     * @var \OC\Hooks\Emitter[] array
36
+     */
37
+    private $forwardEmitters = [];
38 38
 
39
-	/**
40
-	 * @param string $scope
41
-	 * @param string $method
42
-	 * @param callable $callback
43
-	 */
44
-	public function listen($scope, $method, callable $callback) {
45
-		parent::listen($scope, $method, $callback);
46
-		foreach ($this->forwardEmitters as $emitter) {
47
-			$emitter->listen($scope, $method, $callback);
48
-		}
49
-	}
39
+    /**
40
+     * @param string $scope
41
+     * @param string $method
42
+     * @param callable $callback
43
+     */
44
+    public function listen($scope, $method, callable $callback) {
45
+        parent::listen($scope, $method, $callback);
46
+        foreach ($this->forwardEmitters as $emitter) {
47
+            $emitter->listen($scope, $method, $callback);
48
+        }
49
+    }
50 50
 
51
-	/**
52
-	 * @param \OC\Hooks\Emitter $emitter
53
-	 */
54
-	protected function forward(Emitter $emitter) {
55
-		$this->forwardEmitters[] = $emitter;
51
+    /**
52
+     * @param \OC\Hooks\Emitter $emitter
53
+     */
54
+    protected function forward(Emitter $emitter) {
55
+        $this->forwardEmitters[] = $emitter;
56 56
 
57
-		//forward all previously connected hooks
58
-		foreach ($this->listeners as $key => $listeners) {
59
-			list($scope, $method) = explode('::', $key, 2);
60
-			foreach ($listeners as $listener) {
61
-				$emitter->listen($scope, $method, $listener);
62
-			}
63
-		}
64
-	}
57
+        //forward all previously connected hooks
58
+        foreach ($this->listeners as $key => $listeners) {
59
+            list($scope, $method) = explode('::', $key, 2);
60
+            foreach ($listeners as $listener) {
61
+                $emitter->listen($scope, $method, $listener);
62
+            }
63
+        }
64
+    }
65 65
 }
Please login to merge, or discard this patch.
lib/private/Hooks/LegacyEmitter.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 namespace OC\Hooks;
25 25
 
26 26
 abstract class LegacyEmitter extends BasicEmitter {
27
-	/**
28
-	 * @param string $scope
29
-	 * @param string $method
30
-	 * @param array $arguments
31
-	 *
32
-	 * @suppress PhanAccessMethodProtected
33
-	 */
34
-	protected function emit($scope, $method, array $arguments = []) {
35
-		\OC_Hook::emit($scope, $method, $arguments);
36
-		parent::emit($scope, $method, $arguments);
37
-	}
27
+    /**
28
+     * @param string $scope
29
+     * @param string $method
30
+     * @param array $arguments
31
+     *
32
+     * @suppress PhanAccessMethodProtected
33
+     */
34
+    protected function emit($scope, $method, array $arguments = []) {
35
+        \OC_Hook::emit($scope, $method, $arguments);
36
+        parent::emit($scope, $method, $arguments);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/private/Template/ResourceLocator.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 				$this->doFind($resource);
76 76
 			} catch (ResourceNotFoundException $e) {
77 77
 				$resourceApp = substr($resource, 0, strpos($resource, '/'));
78
-				$this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
78
+				$this->logger->debug('Could not find resource file "'.$e->getResourcePath().'"', ['app' => $resourceApp]);
79 79
 			}
80 80
 		}
81 81
 		if (!empty($this->theme)) {
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 					$this->doFindTheme($resource);
85 85
 				} catch (ResourceNotFoundException $e) {
86 86
 					$resourceApp = substr($resource, 0, strpos($resource, '/'));
87
-					$this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
87
+					$this->logger->debug('Could not find resource file in theme "'.$e->getResourcePath().'"', ['app' => $resourceApp]);
88 88
 				}
89 89
 			}
90 90
 		}
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 		}
159 159
 		$this->resources[] = [$root, $webRoot, $file];
160 160
 
161
-		if ($throw && !is_file($root . '/' . $file)) {
161
+		if ($throw && !is_file($root.'/'.$file)) {
162 162
 			throw new ResourceNotFoundException($file, $webRoot);
163 163
 		}
164 164
 	}
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -30,173 +30,173 @@
 block discarded – undo
30 30
 namespace OC\Template;
31 31
 
32 32
 abstract class ResourceLocator {
33
-	protected $theme;
34
-
35
-	protected $mapping;
36
-	protected $serverroot;
37
-	protected $thirdpartyroot;
38
-	protected $webroot;
39
-
40
-	protected $resources = [];
41
-
42
-	/** @var \OCP\ILogger */
43
-	protected $logger;
44
-
45
-	/**
46
-	 * @param \OCP\ILogger $logger
47
-	 * @param string $theme
48
-	 * @param array $core_map
49
-	 * @param array $party_map
50
-	 */
51
-	public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) {
52
-		$this->logger = $logger;
53
-		$this->theme = $theme;
54
-		$this->mapping = $core_map + $party_map;
55
-		$this->serverroot = key($core_map);
56
-		$this->thirdpartyroot = key($party_map);
57
-		$this->webroot = $this->mapping[$this->serverroot];
58
-	}
59
-
60
-	/**
61
-	 * @param string $resource
62
-	 */
63
-	abstract public function doFind($resource);
64
-
65
-	/**
66
-	 * @param string $resource
67
-	 */
68
-	abstract public function doFindTheme($resource);
69
-
70
-	/**
71
-	 * Finds the resources and adds them to the list
72
-	 *
73
-	 * @param array $resources
74
-	 */
75
-	public function find($resources) {
76
-		foreach ($resources as $resource) {
77
-			try {
78
-				$this->doFind($resource);
79
-			} catch (ResourceNotFoundException $e) {
80
-				$resourceApp = substr($resource, 0, strpos($resource, '/'));
81
-				$this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
82
-			}
83
-		}
84
-		if (!empty($this->theme)) {
85
-			foreach ($resources as $resource) {
86
-				try {
87
-					$this->doFindTheme($resource);
88
-				} catch (ResourceNotFoundException $e) {
89
-					$resourceApp = substr($resource, 0, strpos($resource, '/'));
90
-					$this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
91
-				}
92
-			}
93
-		}
94
-	}
95
-
96
-	/**
97
-	 * append the $file resource if exist at $root
98
-	 *
99
-	 * @param string $root path to check
100
-	 * @param string $file the filename
101
-	 * @param string|null $webRoot base for path, default map $root to $webRoot
102
-	 * @return bool True if the resource was found, false otherwise
103
-	 */
104
-	protected function appendIfExist($root, $file, $webRoot = null) {
105
-		if (is_file($root.'/'.$file)) {
106
-			$this->append($root, $file, $webRoot, false);
107
-			return true;
108
-		}
109
-		return false;
110
-	}
111
-
112
-	/**
113
-	 * Attempt to find the webRoot
114
-	 *
115
-	 * traverse the potential web roots upwards in the path
116
-	 *
117
-	 * example:
118
-	 *   - root: /srv/www/apps/myapp
119
-	 *   - available mappings: ['/srv/www']
120
-	 *
121
-	 * First we check if a mapping for /srv/www/apps/myapp is available,
122
-	 * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
123
-	 * valid web root
124
-	 *
125
-	 * @param string $root
126
-	 * @return string|null The web root or null on failure
127
-	 */
128
-	protected function findWebRoot($root) {
129
-		$webRoot = null;
130
-		$tmpRoot = $root;
131
-
132
-		while ($webRoot === null) {
133
-			if (isset($this->mapping[$tmpRoot])) {
134
-				$webRoot = $this->mapping[$tmpRoot];
135
-				break;
136
-			}
137
-
138
-			if ($tmpRoot === '/') {
139
-				break;
140
-			}
141
-
142
-			$tmpRoot = dirname($tmpRoot);
143
-		}
144
-
145
-		if ($webRoot === null) {
146
-			$realpath = realpath($root);
147
-
148
-			if ($realpath && ($realpath !== $root)) {
149
-				return $this->findWebRoot($realpath);
150
-			}
151
-		}
152
-
153
-		return $webRoot;
154
-	}
155
-
156
-	/**
157
-	 * append the $file resource at $root
158
-	 *
159
-	 * @param string $root path to check
160
-	 * @param string $file the filename
161
-	 * @param string|null $webRoot base for path, default map $root to $webRoot
162
-	 * @param bool $throw Throw an exception, when the route does not exist
163
-	 * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
164
-	 */
165
-	protected function append($root, $file, $webRoot = null, $throw = true) {
166
-
167
-		if (!is_string($root)) {
168
-			if ($throw) {
169
-				throw new ResourceNotFoundException($file, $webRoot);
170
-			}
171
-			return;
172
-		}
173
-
174
-		if (!$webRoot) {
175
-			$webRoot = $this->findWebRoot($root);
176
-
177
-			if ($webRoot === null) {
178
-				$webRoot = '';
179
-				$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
180
-					'app' => 'lib',
181
-					'root' => $root,
182
-					'file' => $file,
183
-					'webRoot' => $webRoot,
184
-					'throw' => $throw ? 'true' : 'false'
185
-				]);
186
-			}
187
-		}
188
-		$this->resources[] = [$root, $webRoot, $file];
189
-
190
-		if ($throw && !is_file($root . '/' . $file)) {
191
-			throw new ResourceNotFoundException($file, $webRoot);
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * Returns the list of all resources that should be loaded
197
-	 * @return array
198
-	 */
199
-	public function getResources() {
200
-		return $this->resources;
201
-	}
33
+    protected $theme;
34
+
35
+    protected $mapping;
36
+    protected $serverroot;
37
+    protected $thirdpartyroot;
38
+    protected $webroot;
39
+
40
+    protected $resources = [];
41
+
42
+    /** @var \OCP\ILogger */
43
+    protected $logger;
44
+
45
+    /**
46
+     * @param \OCP\ILogger $logger
47
+     * @param string $theme
48
+     * @param array $core_map
49
+     * @param array $party_map
50
+     */
51
+    public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) {
52
+        $this->logger = $logger;
53
+        $this->theme = $theme;
54
+        $this->mapping = $core_map + $party_map;
55
+        $this->serverroot = key($core_map);
56
+        $this->thirdpartyroot = key($party_map);
57
+        $this->webroot = $this->mapping[$this->serverroot];
58
+    }
59
+
60
+    /**
61
+     * @param string $resource
62
+     */
63
+    abstract public function doFind($resource);
64
+
65
+    /**
66
+     * @param string $resource
67
+     */
68
+    abstract public function doFindTheme($resource);
69
+
70
+    /**
71
+     * Finds the resources and adds them to the list
72
+     *
73
+     * @param array $resources
74
+     */
75
+    public function find($resources) {
76
+        foreach ($resources as $resource) {
77
+            try {
78
+                $this->doFind($resource);
79
+            } catch (ResourceNotFoundException $e) {
80
+                $resourceApp = substr($resource, 0, strpos($resource, '/'));
81
+                $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
82
+            }
83
+        }
84
+        if (!empty($this->theme)) {
85
+            foreach ($resources as $resource) {
86
+                try {
87
+                    $this->doFindTheme($resource);
88
+                } catch (ResourceNotFoundException $e) {
89
+                    $resourceApp = substr($resource, 0, strpos($resource, '/'));
90
+                    $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
91
+                }
92
+            }
93
+        }
94
+    }
95
+
96
+    /**
97
+     * append the $file resource if exist at $root
98
+     *
99
+     * @param string $root path to check
100
+     * @param string $file the filename
101
+     * @param string|null $webRoot base for path, default map $root to $webRoot
102
+     * @return bool True if the resource was found, false otherwise
103
+     */
104
+    protected function appendIfExist($root, $file, $webRoot = null) {
105
+        if (is_file($root.'/'.$file)) {
106
+            $this->append($root, $file, $webRoot, false);
107
+            return true;
108
+        }
109
+        return false;
110
+    }
111
+
112
+    /**
113
+     * Attempt to find the webRoot
114
+     *
115
+     * traverse the potential web roots upwards in the path
116
+     *
117
+     * example:
118
+     *   - root: /srv/www/apps/myapp
119
+     *   - available mappings: ['/srv/www']
120
+     *
121
+     * First we check if a mapping for /srv/www/apps/myapp is available,
122
+     * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
123
+     * valid web root
124
+     *
125
+     * @param string $root
126
+     * @return string|null The web root or null on failure
127
+     */
128
+    protected function findWebRoot($root) {
129
+        $webRoot = null;
130
+        $tmpRoot = $root;
131
+
132
+        while ($webRoot === null) {
133
+            if (isset($this->mapping[$tmpRoot])) {
134
+                $webRoot = $this->mapping[$tmpRoot];
135
+                break;
136
+            }
137
+
138
+            if ($tmpRoot === '/') {
139
+                break;
140
+            }
141
+
142
+            $tmpRoot = dirname($tmpRoot);
143
+        }
144
+
145
+        if ($webRoot === null) {
146
+            $realpath = realpath($root);
147
+
148
+            if ($realpath && ($realpath !== $root)) {
149
+                return $this->findWebRoot($realpath);
150
+            }
151
+        }
152
+
153
+        return $webRoot;
154
+    }
155
+
156
+    /**
157
+     * append the $file resource at $root
158
+     *
159
+     * @param string $root path to check
160
+     * @param string $file the filename
161
+     * @param string|null $webRoot base for path, default map $root to $webRoot
162
+     * @param bool $throw Throw an exception, when the route does not exist
163
+     * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
164
+     */
165
+    protected function append($root, $file, $webRoot = null, $throw = true) {
166
+
167
+        if (!is_string($root)) {
168
+            if ($throw) {
169
+                throw new ResourceNotFoundException($file, $webRoot);
170
+            }
171
+            return;
172
+        }
173
+
174
+        if (!$webRoot) {
175
+            $webRoot = $this->findWebRoot($root);
176
+
177
+            if ($webRoot === null) {
178
+                $webRoot = '';
179
+                $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
180
+                    'app' => 'lib',
181
+                    'root' => $root,
182
+                    'file' => $file,
183
+                    'webRoot' => $webRoot,
184
+                    'throw' => $throw ? 'true' : 'false'
185
+                ]);
186
+            }
187
+        }
188
+        $this->resources[] = [$root, $webRoot, $file];
189
+
190
+        if ($throw && !is_file($root . '/' . $file)) {
191
+            throw new ResourceNotFoundException($file, $webRoot);
192
+        }
193
+    }
194
+
195
+    /**
196
+     * Returns the list of all resources that should be loaded
197
+     * @return array
198
+     */
199
+    public function getResources() {
200
+        return $this->resources;
201
+    }
202 202
 }
Please login to merge, or discard this patch.
lib/private/Encryption/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 		// always add owner to the list of users with access to the file
74 74
 		$userIds = [$owner];
75 75
 
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
76
+		if (!$this->util->isFile($owner.'/'.$ownerPath)) {
77 77
 			return ['users' => $userIds, 'public' => false];
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -33,95 +33,95 @@
 block discarded – undo
33 33
 
34 34
 class File implements \OCP\Encryption\IFile {
35 35
 
36
-	/** @var Util */
37
-	protected $util;
38
-
39
-	/** @var IRootFolder */
40
-	private $rootFolder;
41
-
42
-	/** @var IManager */
43
-	private $shareManager;
44
-
45
-	/**
46
-	 * cache results of already checked folders
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $cache;
51
-
52
-	public function __construct(Util $util,
53
-								IRootFolder $rootFolder,
54
-								IManager $shareManager) {
55
-		$this->util = $util;
56
-		$this->cache = new CappedMemoryCache();
57
-		$this->rootFolder = $rootFolder;
58
-		$this->shareManager = $shareManager;
59
-	}
60
-
61
-
62
-	/**
63
-	 * get list of users with access to the file
64
-	 *
65
-	 * @param string $path to the file
66
-	 * @return array  ['users' => $uniqueUserIds, 'public' => $public]
67
-	 */
68
-	public function getAccessList($path) {
69
-
70
-		// Make sure that a share key is generated for the owner too
71
-		list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
72
-
73
-		// always add owner to the list of users with access to the file
74
-		$userIds = [$owner];
75
-
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
77
-			return ['users' => $userIds, 'public' => false];
78
-		}
79
-
80
-		$ownerPath = substr($ownerPath, strlen('/files'));
81
-		$userFolder = $this->rootFolder->getUserFolder($owner);
82
-		try {
83
-			$file = $userFolder->get($ownerPath);
84
-		} catch (NotFoundException $e) {
85
-			$file = null;
86
-		}
87
-		$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
88
-
89
-		// first get the shares for the parent and cache the result so that we don't
90
-		// need to check all parents for every file
91
-		$parent = dirname($ownerPath);
92
-		$parentNode = $userFolder->get($parent);
93
-		if (isset($this->cache[$parent])) {
94
-			$resultForParents = $this->cache[$parent];
95
-		} else {
96
-			$resultForParents = $this->shareManager->getAccessList($parentNode);
97
-			$this->cache[$parent] = $resultForParents;
98
-		}
99
-		$userIds = array_merge($userIds, $resultForParents['users']);
100
-		$public = $resultForParents['public'] || $resultForParents['remote'];
101
-
102
-
103
-		// Find out who, if anyone, is sharing the file
104
-		if ($file !== null) {
105
-			$resultForFile = $this->shareManager->getAccessList($file, false);
106
-			$userIds = array_merge($userIds, $resultForFile['users']);
107
-			$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
108
-		}
109
-
110
-		// check if it is a group mount
111
-		if (\OCP\App::isEnabled("files_external")) {
112
-			$mounts = \OC_Mount_Config::getSystemMountPoints();
113
-			foreach ($mounts as $mount) {
114
-				if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
115
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
116
-					$userIds = array_merge($userIds, $mountedFor);
117
-				}
118
-			}
119
-		}
120
-
121
-		// Remove duplicate UIDs
122
-		$uniqueUserIds = array_unique($userIds);
123
-
124
-		return ['users' => $uniqueUserIds, 'public' => $public];
125
-	}
36
+    /** @var Util */
37
+    protected $util;
38
+
39
+    /** @var IRootFolder */
40
+    private $rootFolder;
41
+
42
+    /** @var IManager */
43
+    private $shareManager;
44
+
45
+    /**
46
+     * cache results of already checked folders
47
+     *
48
+     * @var array
49
+     */
50
+    protected $cache;
51
+
52
+    public function __construct(Util $util,
53
+                                IRootFolder $rootFolder,
54
+                                IManager $shareManager) {
55
+        $this->util = $util;
56
+        $this->cache = new CappedMemoryCache();
57
+        $this->rootFolder = $rootFolder;
58
+        $this->shareManager = $shareManager;
59
+    }
60
+
61
+
62
+    /**
63
+     * get list of users with access to the file
64
+     *
65
+     * @param string $path to the file
66
+     * @return array  ['users' => $uniqueUserIds, 'public' => $public]
67
+     */
68
+    public function getAccessList($path) {
69
+
70
+        // Make sure that a share key is generated for the owner too
71
+        list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
72
+
73
+        // always add owner to the list of users with access to the file
74
+        $userIds = [$owner];
75
+
76
+        if (!$this->util->isFile($owner . '/' . $ownerPath)) {
77
+            return ['users' => $userIds, 'public' => false];
78
+        }
79
+
80
+        $ownerPath = substr($ownerPath, strlen('/files'));
81
+        $userFolder = $this->rootFolder->getUserFolder($owner);
82
+        try {
83
+            $file = $userFolder->get($ownerPath);
84
+        } catch (NotFoundException $e) {
85
+            $file = null;
86
+        }
87
+        $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
88
+
89
+        // first get the shares for the parent and cache the result so that we don't
90
+        // need to check all parents for every file
91
+        $parent = dirname($ownerPath);
92
+        $parentNode = $userFolder->get($parent);
93
+        if (isset($this->cache[$parent])) {
94
+            $resultForParents = $this->cache[$parent];
95
+        } else {
96
+            $resultForParents = $this->shareManager->getAccessList($parentNode);
97
+            $this->cache[$parent] = $resultForParents;
98
+        }
99
+        $userIds = array_merge($userIds, $resultForParents['users']);
100
+        $public = $resultForParents['public'] || $resultForParents['remote'];
101
+
102
+
103
+        // Find out who, if anyone, is sharing the file
104
+        if ($file !== null) {
105
+            $resultForFile = $this->shareManager->getAccessList($file, false);
106
+            $userIds = array_merge($userIds, $resultForFile['users']);
107
+            $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
108
+        }
109
+
110
+        // check if it is a group mount
111
+        if (\OCP\App::isEnabled("files_external")) {
112
+            $mounts = \OC_Mount_Config::getSystemMountPoints();
113
+            foreach ($mounts as $mount) {
114
+                if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
115
+                    $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
116
+                    $userIds = array_merge($userIds, $mountedFor);
117
+                }
118
+            }
119
+        }
120
+
121
+        // Remove duplicate UIDs
122
+        $uniqueUserIds = array_unique($userIds);
123
+
124
+        return ['users' => $uniqueUserIds, 'public' => $public];
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
Middleware/Security/Exceptions/StrictCookieMissingException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
  * @package OC\AppFramework\Middleware\Security\Exceptions
33 33
  */
34 34
 class StrictCookieMissingException extends SecurityException {
35
-	public function __construct() {
36
-		parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
-	}
35
+    public function __construct() {
36
+        parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/PublicCalendarObject.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@
 block discarded – undo
23 23
 
24 24
 class PublicCalendarObject extends CalendarObject {
25 25
 
26
-	/**
27
-	 * public calendars are always shared
28
-	 * @return bool
29
-	 */
30
-	protected function isShared() {
31
-		return true;
32
-	}
26
+    /**
27
+     * public calendars are always shared
28
+     * @return bool
29
+     */
30
+    protected function isShared() {
31
+        return true;
32
+    }
33 33
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/UserStoragesController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@
 block discarded – undo
197 197
 		} catch (NotFoundException $e) {
198 198
 			return new DataResponse(
199 199
 				[
200
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
200
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', [$id])
201 201
 				],
202 202
 				Http::STATUS_NOT_FOUND
203 203
 			);
Please login to merge, or discard this patch.
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -44,185 +44,185 @@
 block discarded – undo
44 44
  * User storages controller
45 45
  */
46 46
 class UserStoragesController extends StoragesController {
47
-	/**
48
-	 * @var IUserSession
49
-	 */
50
-	private $userSession;
51
-
52
-	/**
53
-	 * Creates a new user storages controller.
54
-	 *
55
-	 * @param string $AppName application name
56
-	 * @param IRequest $request request object
57
-	 * @param IL10N $l10n l10n service
58
-	 * @param UserStoragesService $userStoragesService storage service
59
-	 * @param IUserSession $userSession
60
-	 * @param ILogger $logger
61
-	 */
62
-	public function __construct(
63
-		$AppName,
64
-		IRequest $request,
65
-		IL10N $l10n,
66
-		UserStoragesService $userStoragesService,
67
-		IUserSession $userSession,
68
-		ILogger $logger
69
-	) {
70
-		parent::__construct(
71
-			$AppName,
72
-			$request,
73
-			$l10n,
74
-			$userStoragesService,
75
-			$logger
76
-		);
77
-		$this->userSession = $userSession;
78
-	}
79
-
80
-	protected function manipulateStorageConfig(StorageConfig $storage) {
81
-		/** @var AuthMechanism */
82
-		$authMechanism = $storage->getAuthMechanism();
83
-		$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
84
-		/** @var Backend */
85
-		$backend = $storage->getBackend();
86
-		$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
87
-	}
88
-
89
-	/**
90
-	 * Get all storage entries
91
-	 *
92
-	 * @NoAdminRequired
93
-	 *
94
-	 * @return DataResponse
95
-	 */
96
-	public function index() {
97
-		return parent::index();
98
-	}
99
-
100
-	/**
101
-	 * Return storage
102
-	 *
103
-	 * @NoAdminRequired
104
-	 *
105
-	 * {@inheritdoc}
106
-	 */
107
-	public function show($id, $testOnly = true) {
108
-		return parent::show($id, $testOnly);
109
-	}
110
-
111
-	/**
112
-	 * Create an external storage entry.
113
-	 *
114
-	 * @param string $mountPoint storage mount point
115
-	 * @param string $backend backend identifier
116
-	 * @param string $authMechanism authentication mechanism identifier
117
-	 * @param array $backendOptions backend-specific options
118
-	 * @param array $mountOptions backend-specific mount options
119
-	 *
120
-	 * @return DataResponse
121
-	 *
122
-	 * @NoAdminRequired
123
-	 */
124
-	public function create(
125
-		$mountPoint,
126
-		$backend,
127
-		$authMechanism,
128
-		$backendOptions,
129
-		$mountOptions
130
-	) {
131
-		$newStorage = $this->createStorage(
132
-			$mountPoint,
133
-			$backend,
134
-			$authMechanism,
135
-			$backendOptions,
136
-			$mountOptions
137
-		);
138
-		if ($newStorage instanceOf DataResponse) {
139
-			return $newStorage;
140
-		}
141
-
142
-		$response = $this->validate($newStorage);
143
-		if (!empty($response)) {
144
-			return $response;
145
-		}
146
-
147
-		$newStorage = $this->service->addStorage($newStorage);
148
-		$this->updateStorageStatus($newStorage);
149
-
150
-		return new DataResponse(
151
-			$this->formatStorageForUI($newStorage),
152
-			Http::STATUS_CREATED
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Update an external storage entry.
158
-	 *
159
-	 * @param int $id storage id
160
-	 * @param string $mountPoint storage mount point
161
-	 * @param string $backend backend identifier
162
-	 * @param string $authMechanism authentication mechanism identifier
163
-	 * @param array $backendOptions backend-specific options
164
-	 * @param array $mountOptions backend-specific mount options
165
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
166
-	 *
167
-	 * @return DataResponse
168
-	 *
169
-	 * @NoAdminRequired
170
-	 */
171
-	public function update(
172
-		$id,
173
-		$mountPoint,
174
-		$backend,
175
-		$authMechanism,
176
-		$backendOptions,
177
-		$mountOptions,
178
-		$testOnly = true
179
-	) {
180
-		$storage = $this->createStorage(
181
-			$mountPoint,
182
-			$backend,
183
-			$authMechanism,
184
-			$backendOptions,
185
-			$mountOptions
186
-		);
187
-		if ($storage instanceOf DataResponse) {
188
-			return $storage;
189
-		}
190
-		$storage->setId($id);
191
-
192
-		$response = $this->validate($storage);
193
-		if (!empty($response)) {
194
-			return $response;
195
-		}
196
-
197
-		try {
198
-			$storage = $this->service->updateStorage($storage);
199
-		} catch (NotFoundException $e) {
200
-			return new DataResponse(
201
-				[
202
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
203
-				],
204
-				Http::STATUS_NOT_FOUND
205
-			);
206
-		}
207
-
208
-		$this->updateStorageStatus($storage, $testOnly);
209
-
210
-		return new DataResponse(
211
-			$this->formatStorageForUI($storage),
212
-			Http::STATUS_OK
213
-		);
214
-
215
-	}
216
-
217
-	/**
218
-	 * Delete storage
219
-	 *
220
-	 * @NoAdminRequired
221
-	 *
222
-	 * {@inheritdoc}
223
-	 */
224
-	public function destroy($id) {
225
-		return parent::destroy($id);
226
-	}
47
+    /**
48
+     * @var IUserSession
49
+     */
50
+    private $userSession;
51
+
52
+    /**
53
+     * Creates a new user storages controller.
54
+     *
55
+     * @param string $AppName application name
56
+     * @param IRequest $request request object
57
+     * @param IL10N $l10n l10n service
58
+     * @param UserStoragesService $userStoragesService storage service
59
+     * @param IUserSession $userSession
60
+     * @param ILogger $logger
61
+     */
62
+    public function __construct(
63
+        $AppName,
64
+        IRequest $request,
65
+        IL10N $l10n,
66
+        UserStoragesService $userStoragesService,
67
+        IUserSession $userSession,
68
+        ILogger $logger
69
+    ) {
70
+        parent::__construct(
71
+            $AppName,
72
+            $request,
73
+            $l10n,
74
+            $userStoragesService,
75
+            $logger
76
+        );
77
+        $this->userSession = $userSession;
78
+    }
79
+
80
+    protected function manipulateStorageConfig(StorageConfig $storage) {
81
+        /** @var AuthMechanism */
82
+        $authMechanism = $storage->getAuthMechanism();
83
+        $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
84
+        /** @var Backend */
85
+        $backend = $storage->getBackend();
86
+        $backend->manipulateStorageConfig($storage, $this->userSession->getUser());
87
+    }
88
+
89
+    /**
90
+     * Get all storage entries
91
+     *
92
+     * @NoAdminRequired
93
+     *
94
+     * @return DataResponse
95
+     */
96
+    public function index() {
97
+        return parent::index();
98
+    }
99
+
100
+    /**
101
+     * Return storage
102
+     *
103
+     * @NoAdminRequired
104
+     *
105
+     * {@inheritdoc}
106
+     */
107
+    public function show($id, $testOnly = true) {
108
+        return parent::show($id, $testOnly);
109
+    }
110
+
111
+    /**
112
+     * Create an external storage entry.
113
+     *
114
+     * @param string $mountPoint storage mount point
115
+     * @param string $backend backend identifier
116
+     * @param string $authMechanism authentication mechanism identifier
117
+     * @param array $backendOptions backend-specific options
118
+     * @param array $mountOptions backend-specific mount options
119
+     *
120
+     * @return DataResponse
121
+     *
122
+     * @NoAdminRequired
123
+     */
124
+    public function create(
125
+        $mountPoint,
126
+        $backend,
127
+        $authMechanism,
128
+        $backendOptions,
129
+        $mountOptions
130
+    ) {
131
+        $newStorage = $this->createStorage(
132
+            $mountPoint,
133
+            $backend,
134
+            $authMechanism,
135
+            $backendOptions,
136
+            $mountOptions
137
+        );
138
+        if ($newStorage instanceOf DataResponse) {
139
+            return $newStorage;
140
+        }
141
+
142
+        $response = $this->validate($newStorage);
143
+        if (!empty($response)) {
144
+            return $response;
145
+        }
146
+
147
+        $newStorage = $this->service->addStorage($newStorage);
148
+        $this->updateStorageStatus($newStorage);
149
+
150
+        return new DataResponse(
151
+            $this->formatStorageForUI($newStorage),
152
+            Http::STATUS_CREATED
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Update an external storage entry.
158
+     *
159
+     * @param int $id storage id
160
+     * @param string $mountPoint storage mount point
161
+     * @param string $backend backend identifier
162
+     * @param string $authMechanism authentication mechanism identifier
163
+     * @param array $backendOptions backend-specific options
164
+     * @param array $mountOptions backend-specific mount options
165
+     * @param bool $testOnly whether to storage should only test the connection or do more things
166
+     *
167
+     * @return DataResponse
168
+     *
169
+     * @NoAdminRequired
170
+     */
171
+    public function update(
172
+        $id,
173
+        $mountPoint,
174
+        $backend,
175
+        $authMechanism,
176
+        $backendOptions,
177
+        $mountOptions,
178
+        $testOnly = true
179
+    ) {
180
+        $storage = $this->createStorage(
181
+            $mountPoint,
182
+            $backend,
183
+            $authMechanism,
184
+            $backendOptions,
185
+            $mountOptions
186
+        );
187
+        if ($storage instanceOf DataResponse) {
188
+            return $storage;
189
+        }
190
+        $storage->setId($id);
191
+
192
+        $response = $this->validate($storage);
193
+        if (!empty($response)) {
194
+            return $response;
195
+        }
196
+
197
+        try {
198
+            $storage = $this->service->updateStorage($storage);
199
+        } catch (NotFoundException $e) {
200
+            return new DataResponse(
201
+                [
202
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
203
+                ],
204
+                Http::STATUS_NOT_FOUND
205
+            );
206
+        }
207
+
208
+        $this->updateStorageStatus($storage, $testOnly);
209
+
210
+        return new DataResponse(
211
+            $this->formatStorageForUI($storage),
212
+            Http::STATUS_OK
213
+        );
214
+
215
+    }
216
+
217
+    /**
218
+     * Delete storage
219
+     *
220
+     * @NoAdminRequired
221
+     *
222
+     * {@inheritdoc}
223
+     */
224
+    public function destroy($id) {
225
+        return parent::destroy($id);
226
+    }
227 227
 
228 228
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/UserGlobalStoragesController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		} catch (NotFoundException $e) {
123 123
 			return new DataResponse(
124 124
 				[
125
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
125
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', [$id])
126 126
 				],
127 127
 				Http::STATUS_NOT_FOUND
128 128
 			);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			} else {
163 163
 				return new DataResponse(
164 164
 					[
165
-						'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', [$id])
165
+						'message' => (string) $this->l10n->t('Storage with ID "%d" is not user editable', [$id])
166 166
 					],
167 167
 					Http::STATUS_FORBIDDEN
168 168
 				);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		} catch (NotFoundException $e) {
171 171
 			return new DataResponse(
172 172
 				[
173
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
173
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', [$id])
174 174
 				],
175 175
 				Http::STATUS_NOT_FOUND
176 176
 			);
Please login to merge, or discard this patch.
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -45,165 +45,165 @@
 block discarded – undo
45 45
  * User global storages controller
46 46
  */
47 47
 class UserGlobalStoragesController extends StoragesController {
48
-	/**
49
-	 * @var IUserSession
50
-	 */
51
-	private $userSession;
52
-
53
-	/**
54
-	 * Creates a new user global storages controller.
55
-	 *
56
-	 * @param string $AppName application name
57
-	 * @param IRequest $request request object
58
-	 * @param IL10N $l10n l10n service
59
-	 * @param UserGlobalStoragesService $userGlobalStoragesService storage service
60
-	 * @param IUserSession $userSession
61
-	 */
62
-	public function __construct(
63
-		$AppName,
64
-		IRequest $request,
65
-		IL10N $l10n,
66
-		UserGlobalStoragesService $userGlobalStoragesService,
67
-		IUserSession $userSession,
68
-		ILogger $logger
69
-	) {
70
-		parent::__construct(
71
-			$AppName,
72
-			$request,
73
-			$l10n,
74
-			$userGlobalStoragesService,
75
-			$logger
76
-		);
77
-		$this->userSession = $userSession;
78
-	}
79
-
80
-	/**
81
-	 * Get all storage entries
82
-	 *
83
-	 * @return DataResponse
84
-	 *
85
-	 * @NoAdminRequired
86
-	 */
87
-	public function index() {
88
-		$storages = $this->formatStoragesForUI($this->service->getUniqueStorages());
89
-
90
-		// remove configuration data, this must be kept private
91
-		foreach ($storages as $storage) {
92
-			$this->sanitizeStorage($storage);
93
-		}
94
-
95
-		return new DataResponse(
96
-			$storages,
97
-			Http::STATUS_OK
98
-		);
99
-	}
100
-
101
-	protected function manipulateStorageConfig(StorageConfig $storage) {
102
-		/** @var AuthMechanism */
103
-		$authMechanism = $storage->getAuthMechanism();
104
-		$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
105
-		/** @var Backend */
106
-		$backend = $storage->getBackend();
107
-		$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
108
-	}
109
-
110
-	/**
111
-	 * Get an external storage entry.
112
-	 *
113
-	 * @param int $id storage id
114
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
115
-	 * @return DataResponse
116
-	 *
117
-	 * @NoAdminRequired
118
-	 */
119
-	public function show($id, $testOnly = true) {
120
-		try {
121
-			$storage = $this->service->getStorage($id);
122
-
123
-			$this->updateStorageStatus($storage, $testOnly);
124
-		} catch (NotFoundException $e) {
125
-			return new DataResponse(
126
-				[
127
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
128
-				],
129
-				Http::STATUS_NOT_FOUND
130
-			);
131
-		}
132
-
133
-		$this->sanitizeStorage($storage);
134
-
135
-		return new DataResponse(
136
-			$this->formatStorageForUI($storage),
137
-			Http::STATUS_OK
138
-		);
139
-	}
140
-
141
-	/**
142
-	 * Update an external storage entry.
143
-	 * Only allows setting user provided backend fields
144
-	 *
145
-	 * @param int $id storage id
146
-	 * @param array $backendOptions backend-specific options
147
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
148
-	 *
149
-	 * @return DataResponse
150
-	 *
151
-	 * @NoAdminRequired
152
-	 */
153
-	public function update(
154
-		$id,
155
-		$backendOptions,
156
-		$testOnly = true
157
-	) {
158
-		try {
159
-			$storage = $this->service->getStorage($id);
160
-			$authMechanism = $storage->getAuthMechanism();
161
-			if ($authMechanism instanceof IUserProvided || $authMechanism instanceof  UserGlobalAuth) {
162
-				$authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
163
-				$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
164
-			} else {
165
-				return new DataResponse(
166
-					[
167
-						'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', [$id])
168
-					],
169
-					Http::STATUS_FORBIDDEN
170
-				);
171
-			}
172
-		} catch (NotFoundException $e) {
173
-			return new DataResponse(
174
-				[
175
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
176
-				],
177
-				Http::STATUS_NOT_FOUND
178
-			);
179
-		}
180
-
181
-		$this->updateStorageStatus($storage, $testOnly);
182
-		$this->sanitizeStorage($storage);
183
-
184
-		return new DataResponse(
185
-			$this->formatStorageForUI($storage),
186
-			Http::STATUS_OK
187
-		);
188
-
189
-	}
190
-
191
-	/**
192
-	 * Remove sensitive data from a StorageConfig before returning it to the user
193
-	 *
194
-	 * @param StorageConfig $storage
195
-	 */
196
-	protected function sanitizeStorage(StorageConfig $storage) {
197
-		$storage->setBackendOptions([]);
198
-		$storage->setMountOptions([]);
199
-
200
-		if ($storage->getAuthMechanism() instanceof IUserProvided) {
201
-			try {
202
-				$storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
203
-			} catch (InsufficientDataForMeaningfulAnswerException $e) {
204
-				// not configured yet
205
-			}
206
-		}
207
-	}
48
+    /**
49
+     * @var IUserSession
50
+     */
51
+    private $userSession;
52
+
53
+    /**
54
+     * Creates a new user global storages controller.
55
+     *
56
+     * @param string $AppName application name
57
+     * @param IRequest $request request object
58
+     * @param IL10N $l10n l10n service
59
+     * @param UserGlobalStoragesService $userGlobalStoragesService storage service
60
+     * @param IUserSession $userSession
61
+     */
62
+    public function __construct(
63
+        $AppName,
64
+        IRequest $request,
65
+        IL10N $l10n,
66
+        UserGlobalStoragesService $userGlobalStoragesService,
67
+        IUserSession $userSession,
68
+        ILogger $logger
69
+    ) {
70
+        parent::__construct(
71
+            $AppName,
72
+            $request,
73
+            $l10n,
74
+            $userGlobalStoragesService,
75
+            $logger
76
+        );
77
+        $this->userSession = $userSession;
78
+    }
79
+
80
+    /**
81
+     * Get all storage entries
82
+     *
83
+     * @return DataResponse
84
+     *
85
+     * @NoAdminRequired
86
+     */
87
+    public function index() {
88
+        $storages = $this->formatStoragesForUI($this->service->getUniqueStorages());
89
+
90
+        // remove configuration data, this must be kept private
91
+        foreach ($storages as $storage) {
92
+            $this->sanitizeStorage($storage);
93
+        }
94
+
95
+        return new DataResponse(
96
+            $storages,
97
+            Http::STATUS_OK
98
+        );
99
+    }
100
+
101
+    protected function manipulateStorageConfig(StorageConfig $storage) {
102
+        /** @var AuthMechanism */
103
+        $authMechanism = $storage->getAuthMechanism();
104
+        $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
105
+        /** @var Backend */
106
+        $backend = $storage->getBackend();
107
+        $backend->manipulateStorageConfig($storage, $this->userSession->getUser());
108
+    }
109
+
110
+    /**
111
+     * Get an external storage entry.
112
+     *
113
+     * @param int $id storage id
114
+     * @param bool $testOnly whether to storage should only test the connection or do more things
115
+     * @return DataResponse
116
+     *
117
+     * @NoAdminRequired
118
+     */
119
+    public function show($id, $testOnly = true) {
120
+        try {
121
+            $storage = $this->service->getStorage($id);
122
+
123
+            $this->updateStorageStatus($storage, $testOnly);
124
+        } catch (NotFoundException $e) {
125
+            return new DataResponse(
126
+                [
127
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
128
+                ],
129
+                Http::STATUS_NOT_FOUND
130
+            );
131
+        }
132
+
133
+        $this->sanitizeStorage($storage);
134
+
135
+        return new DataResponse(
136
+            $this->formatStorageForUI($storage),
137
+            Http::STATUS_OK
138
+        );
139
+    }
140
+
141
+    /**
142
+     * Update an external storage entry.
143
+     * Only allows setting user provided backend fields
144
+     *
145
+     * @param int $id storage id
146
+     * @param array $backendOptions backend-specific options
147
+     * @param bool $testOnly whether to storage should only test the connection or do more things
148
+     *
149
+     * @return DataResponse
150
+     *
151
+     * @NoAdminRequired
152
+     */
153
+    public function update(
154
+        $id,
155
+        $backendOptions,
156
+        $testOnly = true
157
+    ) {
158
+        try {
159
+            $storage = $this->service->getStorage($id);
160
+            $authMechanism = $storage->getAuthMechanism();
161
+            if ($authMechanism instanceof IUserProvided || $authMechanism instanceof  UserGlobalAuth) {
162
+                $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
163
+                $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
164
+            } else {
165
+                return new DataResponse(
166
+                    [
167
+                        'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', [$id])
168
+                    ],
169
+                    Http::STATUS_FORBIDDEN
170
+                );
171
+            }
172
+        } catch (NotFoundException $e) {
173
+            return new DataResponse(
174
+                [
175
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
176
+                ],
177
+                Http::STATUS_NOT_FOUND
178
+            );
179
+        }
180
+
181
+        $this->updateStorageStatus($storage, $testOnly);
182
+        $this->sanitizeStorage($storage);
183
+
184
+        return new DataResponse(
185
+            $this->formatStorageForUI($storage),
186
+            Http::STATUS_OK
187
+        );
188
+
189
+    }
190
+
191
+    /**
192
+     * Remove sensitive data from a StorageConfig before returning it to the user
193
+     *
194
+     * @param StorageConfig $storage
195
+     */
196
+    protected function sanitizeStorage(StorageConfig $storage) {
197
+        $storage->setBackendOptions([]);
198
+        $storage->setMountOptions([]);
199
+
200
+        if ($storage->getAuthMechanism() instanceof IUserProvided) {
201
+            try {
202
+                $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
203
+            } catch (InsufficientDataForMeaningfulAnswerException $e) {
204
+                // not configured yet
205
+            }
206
+        }
207
+    }
208 208
 
209 209
 }
Please login to merge, or discard this patch.