Completed
Push — master ( eba447...1a7516 )
by Blizzz
18:31
created
lib/private/Files/Cache/Propagator.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -30,161 +30,161 @@
 block discarded – undo
30 30
  * Propagate etags and mtimes within the storage
31 31
  */
32 32
 class Propagator implements IPropagator {
33
-	private $inBatch = false;
34
-
35
-	private $batch = [];
36
-
37
-	/**
38
-	 * @var \OC\Files\Storage\Storage
39
-	 */
40
-	protected $storage;
41
-
42
-	/**
43
-	 * @var IDBConnection
44
-	 */
45
-	private $connection;
46
-
47
-	/**
48
-	 * @param \OC\Files\Storage\Storage $storage
49
-	 * @param IDBConnection $connection
50
-	 */
51
-	public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection) {
52
-		$this->storage = $storage;
53
-		$this->connection = $connection;
54
-	}
55
-
56
-
57
-	/**
58
-	 * @param string $internalPath
59
-	 * @param int $time
60
-	 * @param int $sizeDifference number of bytes the file has grown
61
-	 * @suppress SqlInjectionChecker
62
-	 */
63
-	public function propagateChange($internalPath, $time, $sizeDifference = 0) {
64
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
65
-
66
-		$parents = $this->getParents($internalPath);
67
-
68
-		if ($this->inBatch) {
69
-			foreach ($parents as $parent) {
70
-				$this->addToBatch($parent, $time, $sizeDifference);
71
-			}
72
-			return;
73
-		}
74
-
75
-		$parentHashes = array_map('md5', $parents);
76
-		$etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
77
-
78
-		$builder = $this->connection->getQueryBuilder();
79
-		$hashParams = array_map(function ($hash) use ($builder) {
80
-			return $builder->expr()->literal($hash);
81
-		}, $parentHashes);
82
-
83
-		$builder->update('filecache')
84
-			->set('mtime', $builder->createFunction('GREATEST(`mtime`, ' . $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT) . ')'))
85
-			->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR))
86
-			->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
87
-			->andWhere($builder->expr()->in('path_hash', $hashParams));
88
-
89
-		$builder->execute();
90
-
91
-		if ($sizeDifference !== 0) {
92
-			// we need to do size separably so we can ignore entries with uncalculated size
93
-			$builder = $this->connection->getQueryBuilder();
94
-			$builder->update('filecache')
95
-				->set('size', $builder->createFunction('`size` + ' . $builder->createNamedParameter($sizeDifference)))
96
-				->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
97
-				->andWhere($builder->expr()->in('path_hash', $hashParams))
98
-				->andWhere($builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
99
-		}
100
-
101
-		$builder->execute();
102
-	}
103
-
104
-	protected function getParents($path) {
105
-		$parts = explode('/', $path);
106
-		$parent = '';
107
-		$parents = [];
108
-		foreach ($parts as $part) {
109
-			$parents[] = $parent;
110
-			$parent = trim($parent . '/' . $part, '/');
111
-		}
112
-		return $parents;
113
-	}
114
-
115
-	/**
116
-	 * Mark the beginning of a propagation batch
117
-	 *
118
-	 * Note that not all cache setups support propagation in which case this will be a noop
119
-	 *
120
-	 * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent
121
-	 * before the batch is committed.
122
-	 */
123
-	public function beginBatch() {
124
-		$this->inBatch = true;
125
-	}
126
-
127
-	private function addToBatch($internalPath, $time, $sizeDifference) {
128
-		if (!isset($this->batch[$internalPath])) {
129
-			$this->batch[$internalPath] = [
130
-				'hash' => md5($internalPath),
131
-				'time' => $time,
132
-				'size' => $sizeDifference
133
-			];
134
-		} else {
135
-			$this->batch[$internalPath]['size'] += $sizeDifference;
136
-			if ($time > $this->batch[$internalPath]['time']) {
137
-				$this->batch[$internalPath]['time'] = $time;
138
-			}
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Commit the active propagation batch
144
-	 * @suppress SqlInjectionChecker
145
-	 */
146
-	public function commitBatch() {
147
-		if (!$this->inBatch) {
148
-			throw new \BadMethodCallException('Not in batch');
149
-		}
150
-		$this->inBatch = false;
151
-
152
-		$this->connection->beginTransaction();
153
-
154
-		$query = $this->connection->getQueryBuilder();
155
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
156
-
157
-		$query->update('filecache')
158
-			->set('mtime', $query->createFunction('GREATEST(`mtime`, ' . $query->createParameter('time') . ')'))
159
-			->set('etag', $query->expr()->literal(uniqid()))
160
-			->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
161
-			->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
162
-
163
-		$sizeQuery = $this->connection->getQueryBuilder();
164
-		$sizeQuery->update('filecache')
165
-			->set('size', $sizeQuery->createFunction('`size` + ' . $sizeQuery->createParameter('size')))
166
-			->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
167
-			->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')))
168
-			->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
169
-
170
-		foreach ($this->batch as $item) {
171
-			$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
172
-			$query->setParameter('hash', $item['hash']);
173
-
174
-			$query->execute();
175
-
176
-			if ($item['size']) {
177
-				$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
178
-				$sizeQuery->setParameter('hash', $item['hash']);
179
-
180
-				$sizeQuery->execute();
181
-			}
182
-		}
183
-
184
-		$this->batch = [];
185
-
186
-		$this->connection->commit();
187
-	}
33
+    private $inBatch = false;
34
+
35
+    private $batch = [];
36
+
37
+    /**
38
+     * @var \OC\Files\Storage\Storage
39
+     */
40
+    protected $storage;
41
+
42
+    /**
43
+     * @var IDBConnection
44
+     */
45
+    private $connection;
46
+
47
+    /**
48
+     * @param \OC\Files\Storage\Storage $storage
49
+     * @param IDBConnection $connection
50
+     */
51
+    public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection) {
52
+        $this->storage = $storage;
53
+        $this->connection = $connection;
54
+    }
55
+
56
+
57
+    /**
58
+     * @param string $internalPath
59
+     * @param int $time
60
+     * @param int $sizeDifference number of bytes the file has grown
61
+     * @suppress SqlInjectionChecker
62
+     */
63
+    public function propagateChange($internalPath, $time, $sizeDifference = 0) {
64
+        $storageId = (int)$this->storage->getStorageCache()->getNumericId();
65
+
66
+        $parents = $this->getParents($internalPath);
67
+
68
+        if ($this->inBatch) {
69
+            foreach ($parents as $parent) {
70
+                $this->addToBatch($parent, $time, $sizeDifference);
71
+            }
72
+            return;
73
+        }
74
+
75
+        $parentHashes = array_map('md5', $parents);
76
+        $etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
77
+
78
+        $builder = $this->connection->getQueryBuilder();
79
+        $hashParams = array_map(function ($hash) use ($builder) {
80
+            return $builder->expr()->literal($hash);
81
+        }, $parentHashes);
82
+
83
+        $builder->update('filecache')
84
+            ->set('mtime', $builder->createFunction('GREATEST(`mtime`, ' . $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT) . ')'))
85
+            ->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR))
86
+            ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
87
+            ->andWhere($builder->expr()->in('path_hash', $hashParams));
88
+
89
+        $builder->execute();
90
+
91
+        if ($sizeDifference !== 0) {
92
+            // we need to do size separably so we can ignore entries with uncalculated size
93
+            $builder = $this->connection->getQueryBuilder();
94
+            $builder->update('filecache')
95
+                ->set('size', $builder->createFunction('`size` + ' . $builder->createNamedParameter($sizeDifference)))
96
+                ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
97
+                ->andWhere($builder->expr()->in('path_hash', $hashParams))
98
+                ->andWhere($builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
99
+        }
100
+
101
+        $builder->execute();
102
+    }
103
+
104
+    protected function getParents($path) {
105
+        $parts = explode('/', $path);
106
+        $parent = '';
107
+        $parents = [];
108
+        foreach ($parts as $part) {
109
+            $parents[] = $parent;
110
+            $parent = trim($parent . '/' . $part, '/');
111
+        }
112
+        return $parents;
113
+    }
114
+
115
+    /**
116
+     * Mark the beginning of a propagation batch
117
+     *
118
+     * Note that not all cache setups support propagation in which case this will be a noop
119
+     *
120
+     * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent
121
+     * before the batch is committed.
122
+     */
123
+    public function beginBatch() {
124
+        $this->inBatch = true;
125
+    }
126
+
127
+    private function addToBatch($internalPath, $time, $sizeDifference) {
128
+        if (!isset($this->batch[$internalPath])) {
129
+            $this->batch[$internalPath] = [
130
+                'hash' => md5($internalPath),
131
+                'time' => $time,
132
+                'size' => $sizeDifference
133
+            ];
134
+        } else {
135
+            $this->batch[$internalPath]['size'] += $sizeDifference;
136
+            if ($time > $this->batch[$internalPath]['time']) {
137
+                $this->batch[$internalPath]['time'] = $time;
138
+            }
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Commit the active propagation batch
144
+     * @suppress SqlInjectionChecker
145
+     */
146
+    public function commitBatch() {
147
+        if (!$this->inBatch) {
148
+            throw new \BadMethodCallException('Not in batch');
149
+        }
150
+        $this->inBatch = false;
151
+
152
+        $this->connection->beginTransaction();
153
+
154
+        $query = $this->connection->getQueryBuilder();
155
+        $storageId = (int)$this->storage->getStorageCache()->getNumericId();
156
+
157
+        $query->update('filecache')
158
+            ->set('mtime', $query->createFunction('GREATEST(`mtime`, ' . $query->createParameter('time') . ')'))
159
+            ->set('etag', $query->expr()->literal(uniqid()))
160
+            ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
161
+            ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
162
+
163
+        $sizeQuery = $this->connection->getQueryBuilder();
164
+        $sizeQuery->update('filecache')
165
+            ->set('size', $sizeQuery->createFunction('`size` + ' . $sizeQuery->createParameter('size')))
166
+            ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
167
+            ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')))
168
+            ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
169
+
170
+        foreach ($this->batch as $item) {
171
+            $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
172
+            $query->setParameter('hash', $item['hash']);
173
+
174
+            $query->execute();
175
+
176
+            if ($item['size']) {
177
+                $sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
178
+                $sizeQuery->setParameter('hash', $item['hash']);
179
+
180
+                $sizeQuery->execute();
181
+            }
182
+        }
183
+
184
+        $this->batch = [];
185
+
186
+        $this->connection->commit();
187
+    }
188 188
 
189 189
 
190 190
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @suppress SqlInjectionChecker
62 62
 	 */
63 63
 	public function propagateChange($internalPath, $time, $sizeDifference = 0) {
64
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
64
+		$storageId = (int) $this->storage->getStorageCache()->getNumericId();
65 65
 
66 66
 		$parents = $this->getParents($internalPath);
67 67
 
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 		$etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
77 77
 
78 78
 		$builder = $this->connection->getQueryBuilder();
79
-		$hashParams = array_map(function ($hash) use ($builder) {
79
+		$hashParams = array_map(function($hash) use ($builder) {
80 80
 			return $builder->expr()->literal($hash);
81 81
 		}, $parentHashes);
82 82
 
83 83
 		$builder->update('filecache')
84
-			->set('mtime', $builder->createFunction('GREATEST(`mtime`, ' . $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT) . ')'))
84
+			->set('mtime', $builder->createFunction('GREATEST(`mtime`, '.$builder->createNamedParameter((int) $time, IQueryBuilder::PARAM_INT).')'))
85 85
 			->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR))
86 86
 			->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
87 87
 			->andWhere($builder->expr()->in('path_hash', $hashParams));
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			// we need to do size separably so we can ignore entries with uncalculated size
93 93
 			$builder = $this->connection->getQueryBuilder();
94 94
 			$builder->update('filecache')
95
-				->set('size', $builder->createFunction('`size` + ' . $builder->createNamedParameter($sizeDifference)))
95
+				->set('size', $builder->createFunction('`size` + '.$builder->createNamedParameter($sizeDifference)))
96 96
 				->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
97 97
 				->andWhere($builder->expr()->in('path_hash', $hashParams))
98 98
 				->andWhere($builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		$parents = [];
108 108
 		foreach ($parts as $part) {
109 109
 			$parents[] = $parent;
110
-			$parent = trim($parent . '/' . $part, '/');
110
+			$parent = trim($parent.'/'.$part, '/');
111 111
 		}
112 112
 		return $parents;
113 113
 	}
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
 		$this->connection->beginTransaction();
153 153
 
154 154
 		$query = $this->connection->getQueryBuilder();
155
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
155
+		$storageId = (int) $this->storage->getStorageCache()->getNumericId();
156 156
 
157 157
 		$query->update('filecache')
158
-			->set('mtime', $query->createFunction('GREATEST(`mtime`, ' . $query->createParameter('time') . ')'))
158
+			->set('mtime', $query->createFunction('GREATEST(`mtime`, '.$query->createParameter('time').')'))
159 159
 			->set('etag', $query->expr()->literal(uniqid()))
160 160
 			->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
161 161
 			->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
162 162
 
163 163
 		$sizeQuery = $this->connection->getQueryBuilder();
164 164
 		$sizeQuery->update('filecache')
165
-			->set('size', $sizeQuery->createFunction('`size` + ' . $sizeQuery->createParameter('size')))
165
+			->set('size', $sizeQuery->createFunction('`size` + '.$sizeQuery->createParameter('size')))
166 166
 			->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
167 167
 			->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')))
168 168
 			->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
Please login to merge, or discard this patch.
lib/private/Route/Router.php 2 patches
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -45,337 +45,337 @@
 block discarded – undo
45 45
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
46 46
 
47 47
 class Router implements IRouter {
48
-	/** @var RouteCollection[] */
49
-	protected $collections = [];
50
-	/** @var null|RouteCollection */
51
-	protected $collection = null;
52
-	/** @var null|string */
53
-	protected $collectionName = null;
54
-	/** @var null|RouteCollection */
55
-	protected $root = null;
56
-	/** @var null|UrlGenerator */
57
-	protected $generator = null;
58
-	/** @var string[] */
59
-	protected $routingFiles;
60
-	/** @var bool */
61
-	protected $loaded = false;
62
-	/** @var array */
63
-	protected $loadedApps = [];
64
-	/** @var ILogger */
65
-	protected $logger;
66
-	/** @var RequestContext */
67
-	protected $context;
48
+    /** @var RouteCollection[] */
49
+    protected $collections = [];
50
+    /** @var null|RouteCollection */
51
+    protected $collection = null;
52
+    /** @var null|string */
53
+    protected $collectionName = null;
54
+    /** @var null|RouteCollection */
55
+    protected $root = null;
56
+    /** @var null|UrlGenerator */
57
+    protected $generator = null;
58
+    /** @var string[] */
59
+    protected $routingFiles;
60
+    /** @var bool */
61
+    protected $loaded = false;
62
+    /** @var array */
63
+    protected $loadedApps = [];
64
+    /** @var ILogger */
65
+    protected $logger;
66
+    /** @var RequestContext */
67
+    protected $context;
68 68
 
69
-	/**
70
-	 * @param ILogger $logger
71
-	 */
72
-	public function __construct(ILogger $logger) {
73
-		$this->logger = $logger;
74
-		$baseUrl = \OC::$WEBROOT;
75
-		if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
76
-			$baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
77
-		}
78
-		if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
79
-			$method = $_SERVER['REQUEST_METHOD'];
80
-		} else {
81
-			$method = 'GET';
82
-		}
83
-		$request = \OC::$server->getRequest();
84
-		$host = $request->getServerHost();
85
-		$schema = $request->getServerProtocol();
86
-		$this->context = new RequestContext($baseUrl, $method, $host, $schema);
87
-		// TODO cache
88
-		$this->root = $this->getCollection('root');
89
-	}
69
+    /**
70
+     * @param ILogger $logger
71
+     */
72
+    public function __construct(ILogger $logger) {
73
+        $this->logger = $logger;
74
+        $baseUrl = \OC::$WEBROOT;
75
+        if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
76
+            $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
77
+        }
78
+        if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
79
+            $method = $_SERVER['REQUEST_METHOD'];
80
+        } else {
81
+            $method = 'GET';
82
+        }
83
+        $request = \OC::$server->getRequest();
84
+        $host = $request->getServerHost();
85
+        $schema = $request->getServerProtocol();
86
+        $this->context = new RequestContext($baseUrl, $method, $host, $schema);
87
+        // TODO cache
88
+        $this->root = $this->getCollection('root');
89
+    }
90 90
 
91
-	/**
92
-	 * Get the files to load the routes from
93
-	 *
94
-	 * @return string[]
95
-	 */
96
-	public function getRoutingFiles() {
97
-		if (!isset($this->routingFiles)) {
98
-			$this->routingFiles = [];
99
-			foreach (\OC_APP::getEnabledApps() as $app) {
100
-				$appPath = \OC_App::getAppPath($app);
101
-				if($appPath !== false) {
102
-					$file = $appPath . '/appinfo/routes.php';
103
-					if (file_exists($file)) {
104
-						$this->routingFiles[$app] = $file;
105
-					}
106
-				}
107
-			}
108
-		}
109
-		return $this->routingFiles;
110
-	}
91
+    /**
92
+     * Get the files to load the routes from
93
+     *
94
+     * @return string[]
95
+     */
96
+    public function getRoutingFiles() {
97
+        if (!isset($this->routingFiles)) {
98
+            $this->routingFiles = [];
99
+            foreach (\OC_APP::getEnabledApps() as $app) {
100
+                $appPath = \OC_App::getAppPath($app);
101
+                if($appPath !== false) {
102
+                    $file = $appPath . '/appinfo/routes.php';
103
+                    if (file_exists($file)) {
104
+                        $this->routingFiles[$app] = $file;
105
+                    }
106
+                }
107
+            }
108
+        }
109
+        return $this->routingFiles;
110
+    }
111 111
 
112
-	/**
113
-	 * Loads the routes
114
-	 *
115
-	 * @param null|string $app
116
-	 */
117
-	public function loadRoutes($app = null) {
118
-		if(is_string($app)) {
119
-			$app = \OC_App::cleanAppId($app);
120
-		}
112
+    /**
113
+     * Loads the routes
114
+     *
115
+     * @param null|string $app
116
+     */
117
+    public function loadRoutes($app = null) {
118
+        if(is_string($app)) {
119
+            $app = \OC_App::cleanAppId($app);
120
+        }
121 121
 
122
-		$requestedApp = $app;
123
-		if ($this->loaded) {
124
-			return;
125
-		}
126
-		if (is_null($app)) {
127
-			$this->loaded = true;
128
-			$routingFiles = $this->getRoutingFiles();
129
-		} else {
130
-			if (isset($this->loadedApps[$app])) {
131
-				return;
132
-			}
133
-			$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
134
-			if ($file !== false && file_exists($file)) {
135
-				$routingFiles = [$app => $file];
136
-			} else {
137
-				$routingFiles = [];
138
-			}
139
-		}
140
-		\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
141
-		foreach ($routingFiles as $app => $file) {
142
-			if (!isset($this->loadedApps[$app])) {
143
-				if (!\OC_App::isAppLoaded($app)) {
144
-					// app MUST be loaded before app routes
145
-					// try again next time loadRoutes() is called
146
-					$this->loaded = false;
147
-					continue;
148
-				}
149
-				$this->loadedApps[$app] = true;
150
-				$this->useCollection($app);
151
-				$this->requireRouteFile($file, $app);
152
-				$collection = $this->getCollection($app);
153
-				$collection->addPrefix('/apps/' . $app);
154
-				$this->root->addCollection($collection);
122
+        $requestedApp = $app;
123
+        if ($this->loaded) {
124
+            return;
125
+        }
126
+        if (is_null($app)) {
127
+            $this->loaded = true;
128
+            $routingFiles = $this->getRoutingFiles();
129
+        } else {
130
+            if (isset($this->loadedApps[$app])) {
131
+                return;
132
+            }
133
+            $file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
134
+            if ($file !== false && file_exists($file)) {
135
+                $routingFiles = [$app => $file];
136
+            } else {
137
+                $routingFiles = [];
138
+            }
139
+        }
140
+        \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
141
+        foreach ($routingFiles as $app => $file) {
142
+            if (!isset($this->loadedApps[$app])) {
143
+                if (!\OC_App::isAppLoaded($app)) {
144
+                    // app MUST be loaded before app routes
145
+                    // try again next time loadRoutes() is called
146
+                    $this->loaded = false;
147
+                    continue;
148
+                }
149
+                $this->loadedApps[$app] = true;
150
+                $this->useCollection($app);
151
+                $this->requireRouteFile($file, $app);
152
+                $collection = $this->getCollection($app);
153
+                $collection->addPrefix('/apps/' . $app);
154
+                $this->root->addCollection($collection);
155 155
 
156
-				// Also add the OCS collection
157
-				$collection = $this->getCollection($app.'.ocs');
158
-				$collection->addPrefix('/ocsapp');
159
-				$this->root->addCollection($collection);
160
-			}
161
-		}
162
-		if (!isset($this->loadedApps['core'])) {
163
-			$this->loadedApps['core'] = true;
164
-			$this->useCollection('root');
165
-			require_once __DIR__ . '/../../../settings/routes.php';
166
-			require_once __DIR__ . '/../../../core/routes.php';
156
+                // Also add the OCS collection
157
+                $collection = $this->getCollection($app.'.ocs');
158
+                $collection->addPrefix('/ocsapp');
159
+                $this->root->addCollection($collection);
160
+            }
161
+        }
162
+        if (!isset($this->loadedApps['core'])) {
163
+            $this->loadedApps['core'] = true;
164
+            $this->useCollection('root');
165
+            require_once __DIR__ . '/../../../settings/routes.php';
166
+            require_once __DIR__ . '/../../../core/routes.php';
167 167
 
168
-			// Also add the OCS collection
169
-			$collection = $this->getCollection('root.ocs');
170
-			$collection->addPrefix('/ocsapp');
171
-			$this->root->addCollection($collection);
172
-		}
173
-		if ($this->loaded) {
174
-			$collection = $this->getCollection('ocs');
175
-			$collection->addPrefix('/ocs');
176
-			$this->root->addCollection($collection);
177
-		}
178
-		\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
179
-	}
168
+            // Also add the OCS collection
169
+            $collection = $this->getCollection('root.ocs');
170
+            $collection->addPrefix('/ocsapp');
171
+            $this->root->addCollection($collection);
172
+        }
173
+        if ($this->loaded) {
174
+            $collection = $this->getCollection('ocs');
175
+            $collection->addPrefix('/ocs');
176
+            $this->root->addCollection($collection);
177
+        }
178
+        \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
179
+    }
180 180
 
181
-	/**
182
-	 * @return string
183
-	 * @deprecated
184
-	 */
185
-	public function getCacheKey() {
186
-		return '';
187
-	}
181
+    /**
182
+     * @return string
183
+     * @deprecated
184
+     */
185
+    public function getCacheKey() {
186
+        return '';
187
+    }
188 188
 
189
-	/**
190
-	 * @param string $name
191
-	 * @return \Symfony\Component\Routing\RouteCollection
192
-	 */
193
-	protected function getCollection($name) {
194
-		if (!isset($this->collections[$name])) {
195
-			$this->collections[$name] = new RouteCollection();
196
-		}
197
-		return $this->collections[$name];
198
-	}
189
+    /**
190
+     * @param string $name
191
+     * @return \Symfony\Component\Routing\RouteCollection
192
+     */
193
+    protected function getCollection($name) {
194
+        if (!isset($this->collections[$name])) {
195
+            $this->collections[$name] = new RouteCollection();
196
+        }
197
+        return $this->collections[$name];
198
+    }
199 199
 
200
-	/**
201
-	 * Sets the collection to use for adding routes
202
-	 *
203
-	 * @param string $name Name of the collection to use.
204
-	 * @return void
205
-	 */
206
-	public function useCollection($name) {
207
-		$this->collection = $this->getCollection($name);
208
-		$this->collectionName = $name;
209
-	}
200
+    /**
201
+     * Sets the collection to use for adding routes
202
+     *
203
+     * @param string $name Name of the collection to use.
204
+     * @return void
205
+     */
206
+    public function useCollection($name) {
207
+        $this->collection = $this->getCollection($name);
208
+        $this->collectionName = $name;
209
+    }
210 210
 
211
-	/**
212
-	 * returns the current collection name in use for adding routes
213
-	 *
214
-	 * @return string the collection name
215
-	 */
216
-	public function getCurrentCollection() {
217
-		return $this->collectionName;
218
-	}
211
+    /**
212
+     * returns the current collection name in use for adding routes
213
+     *
214
+     * @return string the collection name
215
+     */
216
+    public function getCurrentCollection() {
217
+        return $this->collectionName;
218
+    }
219 219
 
220 220
 
221
-	/**
222
-	 * Create a \OC\Route\Route.
223
-	 *
224
-	 * @param string $name Name of the route to create.
225
-	 * @param string $pattern The pattern to match
226
-	 * @param array $defaults An array of default parameter values
227
-	 * @param array $requirements An array of requirements for parameters (regexes)
228
-	 * @return \OC\Route\Route
229
-	 */
230
-	public function create($name,
231
-						   $pattern,
232
-						   array $defaults = [],
233
-						   array $requirements = []) {
234
-		$route = new Route($pattern, $defaults, $requirements);
235
-		$this->collection->add($name, $route);
236
-		return $route;
237
-	}
221
+    /**
222
+     * Create a \OC\Route\Route.
223
+     *
224
+     * @param string $name Name of the route to create.
225
+     * @param string $pattern The pattern to match
226
+     * @param array $defaults An array of default parameter values
227
+     * @param array $requirements An array of requirements for parameters (regexes)
228
+     * @return \OC\Route\Route
229
+     */
230
+    public function create($name,
231
+                            $pattern,
232
+                            array $defaults = [],
233
+                            array $requirements = []) {
234
+        $route = new Route($pattern, $defaults, $requirements);
235
+        $this->collection->add($name, $route);
236
+        return $route;
237
+    }
238 238
 
239
-	/**
240
-	 * Find the route matching $url
241
-	 *
242
-	 * @param string $url The url to find
243
-	 * @throws \Exception
244
-	 * @return void
245
-	 */
246
-	public function match($url) {
247
-		if (substr($url, 0, 6) === '/apps/') {
248
-			// empty string / 'apps' / $app / rest of the route
249
-			list(, , $app,) = explode('/', $url, 4);
239
+    /**
240
+     * Find the route matching $url
241
+     *
242
+     * @param string $url The url to find
243
+     * @throws \Exception
244
+     * @return void
245
+     */
246
+    public function match($url) {
247
+        if (substr($url, 0, 6) === '/apps/') {
248
+            // empty string / 'apps' / $app / rest of the route
249
+            list(, , $app,) = explode('/', $url, 4);
250 250
 
251
-			$app = \OC_App::cleanAppId($app);
252
-			\OC::$REQUESTEDAPP = $app;
253
-			$this->loadRoutes($app);
254
-		} else if (substr($url, 0, 13) === '/ocsapp/apps/') {
255
-			// empty string / 'ocsapp' / 'apps' / $app / rest of the route
256
-			list(, , , $app,) = explode('/', $url, 5);
251
+            $app = \OC_App::cleanAppId($app);
252
+            \OC::$REQUESTEDAPP = $app;
253
+            $this->loadRoutes($app);
254
+        } else if (substr($url, 0, 13) === '/ocsapp/apps/') {
255
+            // empty string / 'ocsapp' / 'apps' / $app / rest of the route
256
+            list(, , , $app,) = explode('/', $url, 5);
257 257
 
258
-			$app = \OC_App::cleanAppId($app);
259
-			\OC::$REQUESTEDAPP = $app;
260
-			$this->loadRoutes($app);
261
-		} else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
262
-			\OC::$REQUESTEDAPP = $url;
263
-			if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) {
264
-				\OC_App::loadApps();
265
-			}
266
-			$this->loadRoutes('core');
267
-		} else {
268
-			$this->loadRoutes();
269
-		}
258
+            $app = \OC_App::cleanAppId($app);
259
+            \OC::$REQUESTEDAPP = $app;
260
+            $this->loadRoutes($app);
261
+        } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
262
+            \OC::$REQUESTEDAPP = $url;
263
+            if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) {
264
+                \OC_App::loadApps();
265
+            }
266
+            $this->loadRoutes('core');
267
+        } else {
268
+            $this->loadRoutes();
269
+        }
270 270
 
271
-		$matcher = new UrlMatcher($this->root, $this->context);
272
-		try {
273
-			$parameters = $matcher->match($url);
274
-		} catch (ResourceNotFoundException $e) {
275
-			if (substr($url, -1) !== '/') {
276
-				// We allow links to apps/files? for backwards compatibility reasons
277
-				// However, since Symfony does not allow empty route names, the route
278
-				// we need to match is '/', so we need to append the '/' here.
279
-				try {
280
-					$parameters = $matcher->match($url . '/');
281
-				} catch (ResourceNotFoundException $newException) {
282
-					// If we still didn't match a route, we throw the original exception
283
-					throw $e;
284
-				}
285
-			} else {
286
-				throw $e;
287
-			}
288
-		}
271
+        $matcher = new UrlMatcher($this->root, $this->context);
272
+        try {
273
+            $parameters = $matcher->match($url);
274
+        } catch (ResourceNotFoundException $e) {
275
+            if (substr($url, -1) !== '/') {
276
+                // We allow links to apps/files? for backwards compatibility reasons
277
+                // However, since Symfony does not allow empty route names, the route
278
+                // we need to match is '/', so we need to append the '/' here.
279
+                try {
280
+                    $parameters = $matcher->match($url . '/');
281
+                } catch (ResourceNotFoundException $newException) {
282
+                    // If we still didn't match a route, we throw the original exception
283
+                    throw $e;
284
+                }
285
+            } else {
286
+                throw $e;
287
+            }
288
+        }
289 289
 
290
-		\OC::$server->getEventLogger()->start('run_route', 'Run route');
291
-		if (isset($parameters['action'])) {
292
-			$action = $parameters['action'];
293
-			if (!is_callable($action)) {
294
-				throw new \Exception('not a callable action');
295
-			}
296
-			unset($parameters['action']);
297
-			call_user_func($action, $parameters);
298
-		} elseif (isset($parameters['file'])) {
299
-			include $parameters['file'];
300
-		} else {
301
-			throw new \Exception('no action available');
302
-		}
303
-		\OC::$server->getEventLogger()->end('run_route');
304
-	}
290
+        \OC::$server->getEventLogger()->start('run_route', 'Run route');
291
+        if (isset($parameters['action'])) {
292
+            $action = $parameters['action'];
293
+            if (!is_callable($action)) {
294
+                throw new \Exception('not a callable action');
295
+            }
296
+            unset($parameters['action']);
297
+            call_user_func($action, $parameters);
298
+        } elseif (isset($parameters['file'])) {
299
+            include $parameters['file'];
300
+        } else {
301
+            throw new \Exception('no action available');
302
+        }
303
+        \OC::$server->getEventLogger()->end('run_route');
304
+    }
305 305
 
306
-	/**
307
-	 * Get the url generator
308
-	 *
309
-	 * @return \Symfony\Component\Routing\Generator\UrlGenerator
310
-	 *
311
-	 */
312
-	public function getGenerator() {
313
-		if (null !== $this->generator) {
314
-			return $this->generator;
315
-		}
306
+    /**
307
+     * Get the url generator
308
+     *
309
+     * @return \Symfony\Component\Routing\Generator\UrlGenerator
310
+     *
311
+     */
312
+    public function getGenerator() {
313
+        if (null !== $this->generator) {
314
+            return $this->generator;
315
+        }
316 316
 
317
-		return $this->generator = new UrlGenerator($this->root, $this->context);
318
-	}
317
+        return $this->generator = new UrlGenerator($this->root, $this->context);
318
+    }
319 319
 
320
-	/**
321
-	 * Generate url based on $name and $parameters
322
-	 *
323
-	 * @param string $name Name of the route to use.
324
-	 * @param array $parameters Parameters for the route
325
-	 * @param bool $absolute
326
-	 * @return string
327
-	 */
328
-	public function generate($name,
329
-							 $parameters = [],
330
-							 $absolute = false) {
331
-		$this->loadRoutes();
332
-		try {
333
-			$referenceType = UrlGenerator::ABSOLUTE_URL;
334
-			if ($absolute === false) {
335
-				$referenceType = UrlGenerator::ABSOLUTE_PATH;
336
-			}
337
-			return $this->getGenerator()->generate($name, $parameters, $referenceType);
338
-		} catch (RouteNotFoundException $e) {
339
-			$this->logger->logException($e);
340
-			return '';
341
-		}
342
-	}
320
+    /**
321
+     * Generate url based on $name and $parameters
322
+     *
323
+     * @param string $name Name of the route to use.
324
+     * @param array $parameters Parameters for the route
325
+     * @param bool $absolute
326
+     * @return string
327
+     */
328
+    public function generate($name,
329
+                                $parameters = [],
330
+                                $absolute = false) {
331
+        $this->loadRoutes();
332
+        try {
333
+            $referenceType = UrlGenerator::ABSOLUTE_URL;
334
+            if ($absolute === false) {
335
+                $referenceType = UrlGenerator::ABSOLUTE_PATH;
336
+            }
337
+            return $this->getGenerator()->generate($name, $parameters, $referenceType);
338
+        } catch (RouteNotFoundException $e) {
339
+            $this->logger->logException($e);
340
+            return '';
341
+        }
342
+    }
343 343
 
344
-	/**
345
-	 * To isolate the variable scope used inside the $file it is required in it's own method
346
-	 *
347
-	 * @param string $file the route file location to include
348
-	 * @param string $appName
349
-	 */
350
-	private function requireRouteFile($file, $appName) {
351
-		$this->setupRoutes(include_once $file, $appName);
352
-	}
344
+    /**
345
+     * To isolate the variable scope used inside the $file it is required in it's own method
346
+     *
347
+     * @param string $file the route file location to include
348
+     * @param string $appName
349
+     */
350
+    private function requireRouteFile($file, $appName) {
351
+        $this->setupRoutes(include_once $file, $appName);
352
+    }
353 353
 
354 354
 
355
-	/**
356
-	 * If a routes.php file returns an array, try to set up the application and
357
-	 * register the routes for the app. The application class will be chosen by
358
-	 * camelcasing the appname, e.g.: my_app will be turned into
359
-	 * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default
360
-	 * App will be intialized. This makes it optional to ship an
361
-	 * appinfo/application.php by using the built in query resolver
362
-	 *
363
-	 * @param array $routes the application routes
364
-	 * @param string $appName the name of the app.
365
-	 */
366
-	private function setupRoutes($routes, $appName) {
367
-		if (is_array($routes)) {
368
-			$appNameSpace = App::buildAppNamespace($appName);
355
+    /**
356
+     * If a routes.php file returns an array, try to set up the application and
357
+     * register the routes for the app. The application class will be chosen by
358
+     * camelcasing the appname, e.g.: my_app will be turned into
359
+     * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default
360
+     * App will be intialized. This makes it optional to ship an
361
+     * appinfo/application.php by using the built in query resolver
362
+     *
363
+     * @param array $routes the application routes
364
+     * @param string $appName the name of the app.
365
+     */
366
+    private function setupRoutes($routes, $appName) {
367
+        if (is_array($routes)) {
368
+            $appNameSpace = App::buildAppNamespace($appName);
369 369
 
370
-			$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
370
+            $applicationClassName = $appNameSpace . '\\AppInfo\\Application';
371 371
 
372
-			if (class_exists($applicationClassName)) {
373
-				$application = new $applicationClassName();
374
-			} else {
375
-				$application = new App($appName);
376
-			}
372
+            if (class_exists($applicationClassName)) {
373
+                $application = new $applicationClassName();
374
+            } else {
375
+                $application = new App($appName);
376
+            }
377 377
 
378
-			$application->registerRoutes($this, $routes);
379
-		}
380
-	}
378
+            $application->registerRoutes($this, $routes);
379
+        }
380
+    }
381 381
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	public function __construct(ILogger $logger) {
73 73
 		$this->logger = $logger;
74 74
 		$baseUrl = \OC::$WEBROOT;
75
-		if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
75
+		if (!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
76 76
 			$baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
77 77
 		}
78 78
 		if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 			$this->routingFiles = [];
99 99
 			foreach (\OC_APP::getEnabledApps() as $app) {
100 100
 				$appPath = \OC_App::getAppPath($app);
101
-				if($appPath !== false) {
102
-					$file = $appPath . '/appinfo/routes.php';
101
+				if ($appPath !== false) {
102
+					$file = $appPath.'/appinfo/routes.php';
103 103
 					if (file_exists($file)) {
104 104
 						$this->routingFiles[$app] = $file;
105 105
 					}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param null|string $app
116 116
 	 */
117 117
 	public function loadRoutes($app = null) {
118
-		if(is_string($app)) {
118
+		if (is_string($app)) {
119 119
 			$app = \OC_App::cleanAppId($app);
120 120
 		}
121 121
 
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 			if (isset($this->loadedApps[$app])) {
131 131
 				return;
132 132
 			}
133
-			$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
133
+			$file = \OC_App::getAppPath($app).'/appinfo/routes.php';
134 134
 			if ($file !== false && file_exists($file)) {
135 135
 				$routingFiles = [$app => $file];
136 136
 			} else {
137 137
 				$routingFiles = [];
138 138
 			}
139 139
 		}
140
-		\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
140
+		\OC::$server->getEventLogger()->start('loadroutes'.$requestedApp, 'Loading Routes');
141 141
 		foreach ($routingFiles as $app => $file) {
142 142
 			if (!isset($this->loadedApps[$app])) {
143 143
 				if (!\OC_App::isAppLoaded($app)) {
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 				$this->useCollection($app);
151 151
 				$this->requireRouteFile($file, $app);
152 152
 				$collection = $this->getCollection($app);
153
-				$collection->addPrefix('/apps/' . $app);
153
+				$collection->addPrefix('/apps/'.$app);
154 154
 				$this->root->addCollection($collection);
155 155
 
156 156
 				// Also add the OCS collection
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 		if (!isset($this->loadedApps['core'])) {
163 163
 			$this->loadedApps['core'] = true;
164 164
 			$this->useCollection('root');
165
-			require_once __DIR__ . '/../../../settings/routes.php';
166
-			require_once __DIR__ . '/../../../core/routes.php';
165
+			require_once __DIR__.'/../../../settings/routes.php';
166
+			require_once __DIR__.'/../../../core/routes.php';
167 167
 
168 168
 			// Also add the OCS collection
169 169
 			$collection = $this->getCollection('root.ocs');
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 			$collection->addPrefix('/ocs');
176 176
 			$this->root->addCollection($collection);
177 177
 		}
178
-		\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
178
+		\OC::$server->getEventLogger()->end('loadroutes'.$requestedApp);
179 179
 	}
180 180
 
181 181
 	/**
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 	public function match($url) {
247 247
 		if (substr($url, 0, 6) === '/apps/') {
248 248
 			// empty string / 'apps' / $app / rest of the route
249
-			list(, , $app,) = explode('/', $url, 4);
249
+			list(,, $app,) = explode('/', $url, 4);
250 250
 
251 251
 			$app = \OC_App::cleanAppId($app);
252 252
 			\OC::$REQUESTEDAPP = $app;
253 253
 			$this->loadRoutes($app);
254 254
 		} else if (substr($url, 0, 13) === '/ocsapp/apps/') {
255 255
 			// empty string / 'ocsapp' / 'apps' / $app / rest of the route
256
-			list(, , , $app,) = explode('/', $url, 5);
256
+			list(,,, $app,) = explode('/', $url, 5);
257 257
 
258 258
 			$app = \OC_App::cleanAppId($app);
259 259
 			\OC::$REQUESTEDAPP = $app;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 				// However, since Symfony does not allow empty route names, the route
278 278
 				// we need to match is '/', so we need to append the '/' here.
279 279
 				try {
280
-					$parameters = $matcher->match($url . '/');
280
+					$parameters = $matcher->match($url.'/');
281 281
 				} catch (ResourceNotFoundException $newException) {
282 282
 					// If we still didn't match a route, we throw the original exception
283 283
 					throw $e;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		if (is_array($routes)) {
368 368
 			$appNameSpace = App::buildAppNamespace($appName);
369 369
 
370
-			$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
370
+			$applicationClassName = $appNameSpace.'\\AppInfo\\Application';
371 371
 
372 372
 			if (class_exists($applicationClassName)) {
373 373
 				$application = new $applicationClassName();
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/RemoteController.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -34,156 +34,156 @@
 block discarded – undo
34 34
 
35 35
 class RemoteController extends OCSController {
36 36
 
37
-	/** @var Manager */
38
-	private $externalManager;
39
-
40
-	/** @var ILogger */
41
-	private $logger;
42
-
43
-	/**
44
-	 * @NoAdminRequired
45
-	 *
46
-	 * Remote constructor.
47
-	 *
48
-	 * @param string $appName
49
-	 * @param IRequest $request
50
-	 * @param Manager $externalManager
51
-	 */
52
-	public function __construct($appName,
53
-								IRequest $request,
54
-								Manager $externalManager,
55
-								ILogger $logger) {
56
-		parent::__construct($appName, $request);
57
-
58
-		$this->externalManager = $externalManager;
59
-		$this->logger = $logger;
60
-	}
61
-
62
-	/**
63
-	 * @NoAdminRequired
64
-	 *
65
-	 * Get list of pending remote shares
66
-	 *
67
-	 * @return DataResponse
68
-	 */
69
-	public function getOpenShares() {
70
-		return new DataResponse($this->externalManager->getOpenShares());
71
-	}
72
-
73
-	/**
74
-	 * @NoAdminRequired
75
-	 *
76
-	 * Accept a remote share
77
-	 *
78
-	 * @param int $id
79
-	 * @return DataResponse
80
-	 * @throws OCSNotFoundException
81
-	 */
82
-	public function acceptShare($id) {
83
-		if ($this->externalManager->acceptShare($id)) {
84
-			return new DataResponse();
85
-		}
86
-
87
-		$this->logger->error('Could not accept federated share with id: ' . $id,
88
-			['app' => 'files_sharing']);
89
-
90
-		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
91
-	}
92
-
93
-	/**
94
-	 * @NoAdminRequired
95
-	 *
96
-	 * Decline a remote share
97
-	 *
98
-	 * @param int $id
99
-	 * @return DataResponse
100
-	 * @throws OCSNotFoundException
101
-	 */
102
-	public function declineShare($id) {
103
-		if ($this->externalManager->declineShare($id)) {
104
-			return new DataResponse();
105
-		}
106
-
107
-		// Make sure the user has no notification for something that does not exist anymore.
108
-		$this->externalManager->processNotification($id);
109
-
110
-		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
111
-	}
112
-
113
-	/**
114
-	 * @param array $share Share with info from the share_external table
115
-	 * @return array enriched share info with data from the filecache
116
-	 */
117
-	private static function extendShareInfo($share) {
118
-		$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
119
-		$info = $view->getFileInfo($share['mountpoint']);
120
-
121
-		$share['mimetype'] = $info->getMimetype();
122
-		$share['mtime'] = $info->getMTime();
123
-		$share['permissions'] = $info->getPermissions();
124
-		$share['type'] = $info->getType();
125
-		$share['file_id'] = $info->getId();
126
-
127
-		return $share;
128
-	}
129
-
130
-	/**
131
-	 * @NoAdminRequired
132
-	 *
133
-	 * List accepted remote shares
134
-	 *
135
-	 * @return DataResponse
136
-	 */
137
-	public function getShares() {
138
-		$shares = $this->externalManager->getAcceptedShares();
139
-		$shares = array_map('self::extendShareInfo', $shares);
140
-
141
-		return new DataResponse($shares);
142
-	}
143
-
144
-	/**
145
-	 * @NoAdminRequired
146
-	 *
147
-	 * Get info of a remote share
148
-	 *
149
-	 * @param int $id
150
-	 * @return DataResponse
151
-	 * @throws OCSNotFoundException
152
-	 */
153
-	public function getShare($id) {
154
-		$shareInfo = $this->externalManager->getShare($id);
155
-
156
-		if ($shareInfo === false) {
157
-			throw new OCSNotFoundException('share does not exist');
158
-		} else {
159
-			$shareInfo = self::extendShareInfo($shareInfo);
160
-			return new DataResponse($shareInfo);
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * @NoAdminRequired
166
-	 *
167
-	 * Unshare a remote share
168
-	 *
169
-	 * @param int $id
170
-	 * @return DataResponse
171
-	 * @throws OCSNotFoundException
172
-	 * @throws OCSForbiddenException
173
-	 */
174
-	public function unshare($id) {
175
-		$shareInfo = $this->externalManager->getShare($id);
176
-
177
-		if ($shareInfo === false) {
178
-			throw new OCSNotFoundException('Share does not exist');
179
-		}
180
-
181
-		$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
182
-
183
-		if ($this->externalManager->removeShare($mountPoint) === true) {
184
-			return new DataResponse();
185
-		} else {
186
-			throw new OCSForbiddenException('Could not unshare');
187
-		}
188
-	}
37
+    /** @var Manager */
38
+    private $externalManager;
39
+
40
+    /** @var ILogger */
41
+    private $logger;
42
+
43
+    /**
44
+     * @NoAdminRequired
45
+     *
46
+     * Remote constructor.
47
+     *
48
+     * @param string $appName
49
+     * @param IRequest $request
50
+     * @param Manager $externalManager
51
+     */
52
+    public function __construct($appName,
53
+                                IRequest $request,
54
+                                Manager $externalManager,
55
+                                ILogger $logger) {
56
+        parent::__construct($appName, $request);
57
+
58
+        $this->externalManager = $externalManager;
59
+        $this->logger = $logger;
60
+    }
61
+
62
+    /**
63
+     * @NoAdminRequired
64
+     *
65
+     * Get list of pending remote shares
66
+     *
67
+     * @return DataResponse
68
+     */
69
+    public function getOpenShares() {
70
+        return new DataResponse($this->externalManager->getOpenShares());
71
+    }
72
+
73
+    /**
74
+     * @NoAdminRequired
75
+     *
76
+     * Accept a remote share
77
+     *
78
+     * @param int $id
79
+     * @return DataResponse
80
+     * @throws OCSNotFoundException
81
+     */
82
+    public function acceptShare($id) {
83
+        if ($this->externalManager->acceptShare($id)) {
84
+            return new DataResponse();
85
+        }
86
+
87
+        $this->logger->error('Could not accept federated share with id: ' . $id,
88
+            ['app' => 'files_sharing']);
89
+
90
+        throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
91
+    }
92
+
93
+    /**
94
+     * @NoAdminRequired
95
+     *
96
+     * Decline a remote share
97
+     *
98
+     * @param int $id
99
+     * @return DataResponse
100
+     * @throws OCSNotFoundException
101
+     */
102
+    public function declineShare($id) {
103
+        if ($this->externalManager->declineShare($id)) {
104
+            return new DataResponse();
105
+        }
106
+
107
+        // Make sure the user has no notification for something that does not exist anymore.
108
+        $this->externalManager->processNotification($id);
109
+
110
+        throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
111
+    }
112
+
113
+    /**
114
+     * @param array $share Share with info from the share_external table
115
+     * @return array enriched share info with data from the filecache
116
+     */
117
+    private static function extendShareInfo($share) {
118
+        $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
119
+        $info = $view->getFileInfo($share['mountpoint']);
120
+
121
+        $share['mimetype'] = $info->getMimetype();
122
+        $share['mtime'] = $info->getMTime();
123
+        $share['permissions'] = $info->getPermissions();
124
+        $share['type'] = $info->getType();
125
+        $share['file_id'] = $info->getId();
126
+
127
+        return $share;
128
+    }
129
+
130
+    /**
131
+     * @NoAdminRequired
132
+     *
133
+     * List accepted remote shares
134
+     *
135
+     * @return DataResponse
136
+     */
137
+    public function getShares() {
138
+        $shares = $this->externalManager->getAcceptedShares();
139
+        $shares = array_map('self::extendShareInfo', $shares);
140
+
141
+        return new DataResponse($shares);
142
+    }
143
+
144
+    /**
145
+     * @NoAdminRequired
146
+     *
147
+     * Get info of a remote share
148
+     *
149
+     * @param int $id
150
+     * @return DataResponse
151
+     * @throws OCSNotFoundException
152
+     */
153
+    public function getShare($id) {
154
+        $shareInfo = $this->externalManager->getShare($id);
155
+
156
+        if ($shareInfo === false) {
157
+            throw new OCSNotFoundException('share does not exist');
158
+        } else {
159
+            $shareInfo = self::extendShareInfo($shareInfo);
160
+            return new DataResponse($shareInfo);
161
+        }
162
+    }
163
+
164
+    /**
165
+     * @NoAdminRequired
166
+     *
167
+     * Unshare a remote share
168
+     *
169
+     * @param int $id
170
+     * @return DataResponse
171
+     * @throws OCSNotFoundException
172
+     * @throws OCSForbiddenException
173
+     */
174
+    public function unshare($id) {
175
+        $shareInfo = $this->externalManager->getShare($id);
176
+
177
+        if ($shareInfo === false) {
178
+            throw new OCSNotFoundException('Share does not exist');
179
+        }
180
+
181
+        $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
182
+
183
+        if ($this->externalManager->removeShare($mountPoint) === true) {
184
+            return new DataResponse();
185
+        } else {
186
+            throw new OCSForbiddenException('Could not unshare');
187
+        }
188
+    }
189 189
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 			return new DataResponse();
85 85
 		}
86 86
 
87
-		$this->logger->error('Could not accept federated share with id: ' . $id,
87
+		$this->logger->error('Could not accept federated share with id: '.$id,
88 88
 			['app' => 'files_sharing']);
89 89
 
90 90
 		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return array enriched share info with data from the filecache
116 116
 	 */
117 117
 	private static function extendShareInfo($share) {
118
-		$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
118
+		$view = new \OC\Files\View('/'.\OC_User::getUser().'/files/');
119 119
 		$info = $view->getFileInfo($share['mountpoint']);
120 120
 
121 121
 		$share['mimetype'] = $info->getMimetype();
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 			throw new OCSNotFoundException('Share does not exist');
179 179
 		}
180 180
 
181
-		$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
181
+		$mountPoint = '/'.\OC_User::getUser().'/files'.$shareInfo['mountpoint'];
182 182
 
183 183
 		if ($this->externalManager->removeShare($mountPoint) === true) {
184 184
 			return new DataResponse();
Please login to merge, or discard this patch.
apps/testing/lib/AppInfo/Application.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,18 +25,18 @@
 block discarded – undo
25 25
 use OCA\Testing\AlternativeHomeUserBackend;
26 26
 
27 27
 class Application extends App {
28
-	public function __construct (array $urlParams = array()) {
29
-		$appName = 'testing';
30
-		parent::__construct($appName, $urlParams);
28
+    public function __construct (array $urlParams = array()) {
29
+        $appName = 'testing';
30
+        parent::__construct($appName, $urlParams);
31 31
 
32
-		$c = $this->getContainer();
33
-		$config = $c->getServer()->getConfig();
34
-		if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') {
35
-			$userManager = $c->getServer()->getUserManager();
32
+        $c = $this->getContainer();
33
+        $config = $c->getServer()->getConfig();
34
+        if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') {
35
+            $userManager = $c->getServer()->getUserManager();
36 36
 
37
-			// replace all user backends with this one
38
-			$userManager->clearBackends();
39
-			$userManager->registerBackend($c->query(AlternativeHomeUserBackend::class));
40
-		}
41
-	}
37
+            // replace all user backends with this one
38
+            $userManager->clearBackends();
39
+            $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class));
40
+        }
41
+    }
42 42
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 use OCA\Testing\AlternativeHomeUserBackend;
26 26
 
27 27
 class Application extends App {
28
-	public function __construct (array $urlParams = array()) {
28
+	public function __construct(array $urlParams = array()) {
29 29
 		$appName = 'testing';
30 30
 		parent::__construct($appName, $urlParams);
31 31
 
Please login to merge, or discard this patch.
apps/testing/lib/Controller/ConfigController.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
 
30 30
 class ConfigController extends OCSController {
31 31
 
32
-	/** @var IConfig */
33
-	private $config;
32
+    /** @var IConfig */
33
+    private $config;
34 34
 
35
-	/**
36
-	 * @param string $appName
37
-	 * @param IRequest $request
38
-	 * @param IConfig $config
39
-	 */
40
-	public function __construct($appName,
41
-								IRequest $request,
42
-								IConfig $config) {
43
-		parent::__construct($appName, $request);
44
-		$this->config = $config;
45
-	}
35
+    /**
36
+     * @param string $appName
37
+     * @param IRequest $request
38
+     * @param IConfig $config
39
+     */
40
+    public function __construct($appName,
41
+                                IRequest $request,
42
+                                IConfig $config) {
43
+        parent::__construct($appName, $request);
44
+        $this->config = $config;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string $appid
49
-	 * @param string $configkey
50
-	 * @param string $value
51
-	 * @return DataResponse
52
-	 */
53
-	public function setAppValue($appid, $configkey, $value) {
54
-		$this->config->setAppValue($appid, $configkey, $value);
55
-		return new DataResponse();
56
-	}
47
+    /**
48
+     * @param string $appid
49
+     * @param string $configkey
50
+     * @param string $value
51
+     * @return DataResponse
52
+     */
53
+    public function setAppValue($appid, $configkey, $value) {
54
+        $this->config->setAppValue($appid, $configkey, $value);
55
+        return new DataResponse();
56
+    }
57 57
 
58
-	/**
59
-	 * @param string $appid
60
-	 * @param string $configkey
61
-	 * @return DataResponse
62
-	 */
63
-	public function deleteAppValue($appid, $configkey) {
64
-		$this->config->deleteAppValue($appid, $configkey);
65
-		return new DataResponse();
66
-	}
58
+    /**
59
+     * @param string $appid
60
+     * @param string $configkey
61
+     * @return DataResponse
62
+     */
63
+    public function deleteAppValue($appid, $configkey) {
64
+        $this->config->deleteAppValue($appid, $configkey);
65
+        return new DataResponse();
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/testing/lib/Controller/LockingController.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -39,208 +39,208 @@
 block discarded – undo
39 39
 
40 40
 class LockingController extends OCSController {
41 41
 
42
-	/** @var ILockingProvider */
43
-	protected $lockingProvider;
44
-
45
-	/** @var FakeDBLockingProvider */
46
-	protected $fakeDBLockingProvider;
47
-
48
-	/** @var IDBConnection */
49
-	protected $connection;
50
-
51
-	/** @var IConfig */
52
-	protected $config;
53
-
54
-	/** @var IRootFolder */
55
-	protected $rootFolder;
56
-
57
-	/**
58
-	 * @param string $appName
59
-	 * @param IRequest $request
60
-	 * @param ILockingProvider $lockingProvider
61
-	 * @param FakeDBLockingProvider $fakeDBLockingProvider
62
-	 * @param IDBConnection $connection
63
-	 * @param IConfig $config
64
-	 * @param IRootFolder $rootFolder
65
-	 */
66
-	public function __construct($appName,
67
-								IRequest $request,
68
-								ILockingProvider $lockingProvider,
69
-								FakeDBLockingProvider $fakeDBLockingProvider,
70
-								IDBConnection $connection,
71
-								IConfig $config,
72
-								IRootFolder $rootFolder) {
73
-		parent::__construct($appName, $request);
74
-
75
-		$this->lockingProvider = $lockingProvider;
76
-		$this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
-		$this->connection = $connection;
78
-		$this->config = $config;
79
-		$this->rootFolder = $rootFolder;
80
-	}
81
-
82
-	/**
83
-	 * @return ILockingProvider
84
-	 * @throws \RuntimeException
85
-	 */
86
-	protected function getLockingProvider() {
87
-		if ($this->lockingProvider instanceof DBLockingProvider) {
88
-			return $this->fakeDBLockingProvider;
89
-		}
90
-		throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
-	}
92
-
93
-	/**
94
-	 * @param string $user
95
-	 * @param string $path
96
-	 * @return string
97
-	 * @throws NotFoundException
98
-	 */
99
-	protected function getPath($user, $path) {
100
-		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
-	}
103
-
104
-	/**
105
-	 * @return DataResponse
106
-	 * @throws OCSException
107
-	 */
108
-	public function isLockingEnabled() {
109
-		try {
110
-			$this->getLockingProvider();
111
-			return new DataResponse();
112
-		} catch (\RuntimeException $e) {
113
-			throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @param int $type
119
-	 * @param string $user
120
-	 * @param string $path
121
-	 * @return DataResponse
122
-	 * @throws OCSException
123
-	 */
124
-	public function acquireLock($type, $user, $path) {
125
-		try {
126
-			$path = $this->getPath($user, $path);
127
-		} catch (NoUserException $e) {
128
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
-		} catch (NotFoundException $e) {
130
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
-		}
132
-
133
-		$lockingProvider = $this->getLockingProvider();
134
-
135
-		try {
136
-			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
138
-			return new DataResponse();
139
-		} catch (LockedException $e) {
140
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
141
-		}
142
-	}
143
-
144
-	/**
145
-	 * @param int $type
146
-	 * @param string $user
147
-	 * @param string $path
148
-	 * @return DataResponse
149
-	 * @throws OCSException
150
-	 */
151
-	public function changeLock($type, $user, $path) {
152
-		try {
153
-			$path = $this->getPath($user, $path);
154
-		} catch (NoUserException $e) {
155
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
-		} catch (NotFoundException $e) {
157
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
-		}
159
-
160
-		$lockingProvider = $this->getLockingProvider();
161
-
162
-		try {
163
-			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
165
-			return new DataResponse();
166
-		} catch (LockedException $e) {
167
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
168
-		}
169
-	}
170
-
171
-	/**
172
-	 * @param int $type
173
-	 * @param string $user
174
-	 * @param string $path
175
-	 * @return DataResponse
176
-	 * @throws OCSException
177
-	 */
178
-	public function releaseLock($type, $user, $path) {
179
-		try {
180
-			$path = $this->getPath($user, $path);
181
-		} catch (NoUserException $e) {
182
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
-		} catch (NotFoundException $e) {
184
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
-		}
186
-
187
-		$lockingProvider = $this->getLockingProvider();
188
-
189
-		try {
190
-			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
192
-			return new DataResponse();
193
-		} catch (LockedException $e) {
194
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * @param int $type
200
-	 * @param string $user
201
-	 * @param string $path
202
-	 * @return DataResponse
203
-	 * @throws OCSException
204
-	 */
205
-	public function isLocked($type, $user, $path) {
206
-		try {
207
-			$path = $this->getPath($user, $path);
208
-		} catch (NoUserException $e) {
209
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
-		} catch (NotFoundException $e) {
211
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
-		}
213
-
214
-		$lockingProvider = $this->getLockingProvider();
215
-
216
-		if ($lockingProvider->isLocked($path, $type)) {
217
-			return new DataResponse();
218
-		}
219
-
220
-		throw new OCSException('', Http::STATUS_LOCKED);
221
-	}
222
-
223
-	/**
224
-	 * @param int $type
225
-	 * @return DataResponse
226
-	 */
227
-	public function releaseAll($type = null) {
228
-		$lockingProvider = $this->getLockingProvider();
229
-
230
-		foreach ($this->config->getAppKeys('testing') as $lock) {
231
-			if (strpos($lock, 'locking_') === 0) {
232
-				$path = substr($lock, strlen('locking_'));
233
-
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
-				} else {
239
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
-				}
241
-			}
242
-		}
243
-
244
-		return new DataResponse();
245
-	}
42
+    /** @var ILockingProvider */
43
+    protected $lockingProvider;
44
+
45
+    /** @var FakeDBLockingProvider */
46
+    protected $fakeDBLockingProvider;
47
+
48
+    /** @var IDBConnection */
49
+    protected $connection;
50
+
51
+    /** @var IConfig */
52
+    protected $config;
53
+
54
+    /** @var IRootFolder */
55
+    protected $rootFolder;
56
+
57
+    /**
58
+     * @param string $appName
59
+     * @param IRequest $request
60
+     * @param ILockingProvider $lockingProvider
61
+     * @param FakeDBLockingProvider $fakeDBLockingProvider
62
+     * @param IDBConnection $connection
63
+     * @param IConfig $config
64
+     * @param IRootFolder $rootFolder
65
+     */
66
+    public function __construct($appName,
67
+                                IRequest $request,
68
+                                ILockingProvider $lockingProvider,
69
+                                FakeDBLockingProvider $fakeDBLockingProvider,
70
+                                IDBConnection $connection,
71
+                                IConfig $config,
72
+                                IRootFolder $rootFolder) {
73
+        parent::__construct($appName, $request);
74
+
75
+        $this->lockingProvider = $lockingProvider;
76
+        $this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
+        $this->connection = $connection;
78
+        $this->config = $config;
79
+        $this->rootFolder = $rootFolder;
80
+    }
81
+
82
+    /**
83
+     * @return ILockingProvider
84
+     * @throws \RuntimeException
85
+     */
86
+    protected function getLockingProvider() {
87
+        if ($this->lockingProvider instanceof DBLockingProvider) {
88
+            return $this->fakeDBLockingProvider;
89
+        }
90
+        throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
+    }
92
+
93
+    /**
94
+     * @param string $user
95
+     * @param string $path
96
+     * @return string
97
+     * @throws NotFoundException
98
+     */
99
+    protected function getPath($user, $path) {
100
+        $node = $this->rootFolder->getUserFolder($user)->get($path);
101
+        return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
+    }
103
+
104
+    /**
105
+     * @return DataResponse
106
+     * @throws OCSException
107
+     */
108
+    public function isLockingEnabled() {
109
+        try {
110
+            $this->getLockingProvider();
111
+            return new DataResponse();
112
+        } catch (\RuntimeException $e) {
113
+            throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @param int $type
119
+     * @param string $user
120
+     * @param string $path
121
+     * @return DataResponse
122
+     * @throws OCSException
123
+     */
124
+    public function acquireLock($type, $user, $path) {
125
+        try {
126
+            $path = $this->getPath($user, $path);
127
+        } catch (NoUserException $e) {
128
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
+        } catch (NotFoundException $e) {
130
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
+        }
132
+
133
+        $lockingProvider = $this->getLockingProvider();
134
+
135
+        try {
136
+            $lockingProvider->acquireLock($path, $type);
137
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
138
+            return new DataResponse();
139
+        } catch (LockedException $e) {
140
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
141
+        }
142
+    }
143
+
144
+    /**
145
+     * @param int $type
146
+     * @param string $user
147
+     * @param string $path
148
+     * @return DataResponse
149
+     * @throws OCSException
150
+     */
151
+    public function changeLock($type, $user, $path) {
152
+        try {
153
+            $path = $this->getPath($user, $path);
154
+        } catch (NoUserException $e) {
155
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
+        } catch (NotFoundException $e) {
157
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
+        }
159
+
160
+        $lockingProvider = $this->getLockingProvider();
161
+
162
+        try {
163
+            $lockingProvider->changeLock($path, $type);
164
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
165
+            return new DataResponse();
166
+        } catch (LockedException $e) {
167
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
168
+        }
169
+    }
170
+
171
+    /**
172
+     * @param int $type
173
+     * @param string $user
174
+     * @param string $path
175
+     * @return DataResponse
176
+     * @throws OCSException
177
+     */
178
+    public function releaseLock($type, $user, $path) {
179
+        try {
180
+            $path = $this->getPath($user, $path);
181
+        } catch (NoUserException $e) {
182
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
+        } catch (NotFoundException $e) {
184
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
+        }
186
+
187
+        $lockingProvider = $this->getLockingProvider();
188
+
189
+        try {
190
+            $lockingProvider->releaseLock($path, $type);
191
+            $this->config->deleteAppValue('testing', 'locking_' . $path);
192
+            return new DataResponse();
193
+        } catch (LockedException $e) {
194
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
195
+        }
196
+    }
197
+
198
+    /**
199
+     * @param int $type
200
+     * @param string $user
201
+     * @param string $path
202
+     * @return DataResponse
203
+     * @throws OCSException
204
+     */
205
+    public function isLocked($type, $user, $path) {
206
+        try {
207
+            $path = $this->getPath($user, $path);
208
+        } catch (NoUserException $e) {
209
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
+        } catch (NotFoundException $e) {
211
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
+        }
213
+
214
+        $lockingProvider = $this->getLockingProvider();
215
+
216
+        if ($lockingProvider->isLocked($path, $type)) {
217
+            return new DataResponse();
218
+        }
219
+
220
+        throw new OCSException('', Http::STATUS_LOCKED);
221
+    }
222
+
223
+    /**
224
+     * @param int $type
225
+     * @return DataResponse
226
+     */
227
+    public function releaseAll($type = null) {
228
+        $lockingProvider = $this->getLockingProvider();
229
+
230
+        foreach ($this->config->getAppKeys('testing') as $lock) {
231
+            if (strpos($lock, 'locking_') === 0) {
232
+                $path = substr($lock, strlen('locking_'));
233
+
234
+                if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
+                } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
+                } else {
239
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
+                }
241
+            }
242
+        }
243
+
244
+        return new DataResponse();
245
+    }
246 246
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	protected function getPath($user, $path) {
100 100
 		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
101
+		return 'files/'.md5($node->getStorage()->getId().'::'.trim($node->getInternalPath(), '/'));
102 102
 	}
103 103
 
104 104
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 		try {
136 136
 			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
137
+			$this->config->setAppValue('testing', 'locking_'.$path, $type);
138 138
 			return new DataResponse();
139 139
 		} catch (LockedException $e) {
140 140
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 
162 162
 		try {
163 163
 			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
164
+			$this->config->setAppValue('testing', 'locking_'.$path, $type);
165 165
 			return new DataResponse();
166 166
 		} catch (LockedException $e) {
167 167
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		try {
190 190
 			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
191
+			$this->config->deleteAppValue('testing', 'locking_'.$path);
192 192
 			return new DataResponse();
193 193
 		} catch (LockedException $e) {
194 194
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 			if (strpos($lock, 'locking_') === 0) {
232 232
 				$path = substr($lock, strlen('locking_'));
233 233
 
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
234
+				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235 235
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
236
+				} else if ($type === ILockingProvider::LOCK_SHARED && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237 237
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238 238
 				} else {
239 239
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
Please login to merge, or discard this patch.
lib/public/Files/ObjectStore/IObjectStore.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -30,33 +30,33 @@
 block discarded – undo
30 30
  */
31 31
 interface IObjectStore {
32 32
 
33
-	/**
34
-	 * @return string the container or bucket name where objects are stored
35
-	 * @since 7.0.0
36
-	 */
37
-	public function getStorageId();
33
+    /**
34
+     * @return string the container or bucket name where objects are stored
35
+     * @since 7.0.0
36
+     */
37
+    public function getStorageId();
38 38
 
39
-	/**
40
-	 * @param string $urn the unified resource name used to identify the object
41
-	 * @return resource stream with the read data
42
-	 * @throws \Exception when something goes wrong, message will be logged
43
-	 * @since 7.0.0
44
-	 */
45
-	public function readObject($urn);
39
+    /**
40
+     * @param string $urn the unified resource name used to identify the object
41
+     * @return resource stream with the read data
42
+     * @throws \Exception when something goes wrong, message will be logged
43
+     * @since 7.0.0
44
+     */
45
+    public function readObject($urn);
46 46
 
47
-	/**
48
-	 * @param string $urn the unified resource name used to identify the object
49
-	 * @param resource $stream stream with the data to write
50
-	 * @throws \Exception when something goes wrong, message will be logged
51
-	 * @since 7.0.0
52
-	 */
53
-	public function writeObject($urn, $stream);
47
+    /**
48
+     * @param string $urn the unified resource name used to identify the object
49
+     * @param resource $stream stream with the data to write
50
+     * @throws \Exception when something goes wrong, message will be logged
51
+     * @since 7.0.0
52
+     */
53
+    public function writeObject($urn, $stream);
54 54
 
55
-	/**
56
-	 * @param string $urn the unified resource name used to identify the object
57
-	 * @return void
58
-	 * @throws \Exception when something goes wrong, message will be logged
59
-	 * @since 7.0.0
60
-	 */
61
-	public function deleteObject($urn);
55
+    /**
56
+     * @param string $urn the unified resource name used to identify the object
57
+     * @return void
58
+     * @throws \Exception when something goes wrong, message will be logged
59
+     * @since 7.0.0
60
+     */
61
+    public function deleteObject($urn);
62 62
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/ICallbackResponse.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@
 block discarded – undo
33 33
  */
34 34
 interface ICallbackResponse {
35 35
 
36
-	/**
37
-	 * Outputs the content that should be printed
38
-	 *
39
-	 * @param IOutput $output a small wrapper that handles output
40
-	 * @since 8.1.0
41
-	 */
42
-	public function callback(IOutput $output);
36
+    /**
37
+     * Outputs the content that should be printed
38
+     *
39
+     * @param IOutput $output a small wrapper that handles output
40
+     * @since 8.1.0
41
+     */
42
+    public function callback(IOutput $output);
43 43
 
44 44
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/DataDisplayResponse.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	 * @param array $headers additional key value based headers
47 47
 	 * @since 8.1.0
48 48
 	 */
49
-	public function __construct($data='', $statusCode=Http::STATUS_OK,
50
-	                            $headers=[]) {
49
+	public function __construct($data = '', $statusCode = Http::STATUS_OK,
50
+	                            $headers = []) {
51 51
 		$this->data = $data;
52 52
 		$this->setStatus($statusCode);
53 53
 		$this->setHeaders(array_merge($this->getHeaders(), $headers));
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * @return DataDisplayResponse Reference to this object
71 71
 	 * @since 8.1.0
72 72
 	 */
73
-	public function setData($data){
73
+	public function setData($data) {
74 74
 		$this->data = $data;
75 75
 
76 76
 		return $this;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 * @return string the data
83 83
 	 * @since 8.1.0
84 84
 	 */
85
-	public function getData(){
85
+	public function getData() {
86 86
 		return $this->data;
87 87
 	}
88 88
 
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -33,57 +33,57 @@
 block discarded – undo
33 33
  */
34 34
 class DataDisplayResponse extends Response {
35 35
 
36
-	/**
37
-	 * response data
38
-	 * @var string
39
-	 */
40
-	protected $data;
36
+    /**
37
+     * response data
38
+     * @var string
39
+     */
40
+    protected $data;
41 41
 
42 42
 
43
-	/**
44
-	 * @param string $data the data to display
45
-	 * @param int $statusCode the Http status code, defaults to 200
46
-	 * @param array $headers additional key value based headers
47
-	 * @since 8.1.0
48
-	 */
49
-	public function __construct($data='', $statusCode=Http::STATUS_OK,
50
-	                            $headers=[]) {
51
-		$this->data = $data;
52
-		$this->setStatus($statusCode);
53
-		$this->setHeaders(array_merge($this->getHeaders(), $headers));
54
-		$this->addHeader('Content-Disposition', 'inline; filename=""');
55
-	}
43
+    /**
44
+     * @param string $data the data to display
45
+     * @param int $statusCode the Http status code, defaults to 200
46
+     * @param array $headers additional key value based headers
47
+     * @since 8.1.0
48
+     */
49
+    public function __construct($data='', $statusCode=Http::STATUS_OK,
50
+                                $headers=[]) {
51
+        $this->data = $data;
52
+        $this->setStatus($statusCode);
53
+        $this->setHeaders(array_merge($this->getHeaders(), $headers));
54
+        $this->addHeader('Content-Disposition', 'inline; filename=""');
55
+    }
56 56
 
57
-	/**
58
-	 * Outputs data. No processing is done.
59
-	 * @return string
60
-	 * @since 8.1.0
61
-	 */
62
-	public function render() {
63
-		return $this->data;
64
-	}
57
+    /**
58
+     * Outputs data. No processing is done.
59
+     * @return string
60
+     * @since 8.1.0
61
+     */
62
+    public function render() {
63
+        return $this->data;
64
+    }
65 65
 
66 66
 
67
-	/**
68
-	 * Sets values in the data
69
-	 * @param string $data the data to display
70
-	 * @return DataDisplayResponse Reference to this object
71
-	 * @since 8.1.0
72
-	 */
73
-	public function setData($data){
74
-		$this->data = $data;
67
+    /**
68
+     * Sets values in the data
69
+     * @param string $data the data to display
70
+     * @return DataDisplayResponse Reference to this object
71
+     * @since 8.1.0
72
+     */
73
+    public function setData($data){
74
+        $this->data = $data;
75 75
 
76
-		return $this;
77
-	}
76
+        return $this;
77
+    }
78 78
 
79 79
 
80
-	/**
81
-	 * Used to get the set parameters
82
-	 * @return string the data
83
-	 * @since 8.1.0
84
-	 */
85
-	public function getData(){
86
-		return $this->data;
87
-	}
80
+    /**
81
+     * Used to get the set parameters
82
+     * @return string the data
83
+     * @since 8.1.0
84
+     */
85
+    public function getData(){
86
+        return $this->data;
87
+    }
88 88
 
89 89
 }
Please login to merge, or discard this patch.