@@ -33,90 +33,90 @@ |
||
33 | 33 | */ |
34 | 34 | class RepairInvalidShares implements IRepairStep { |
35 | 35 | |
36 | - const CHUNK_SIZE = 200; |
|
37 | - |
|
38 | - /** @var \OCP\IConfig */ |
|
39 | - protected $config; |
|
40 | - |
|
41 | - /** @var \OCP\IDBConnection */ |
|
42 | - protected $connection; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param \OCP\IConfig $config |
|
46 | - * @param \OCP\IDBConnection $connection |
|
47 | - */ |
|
48 | - public function __construct($config, $connection) { |
|
49 | - $this->connection = $connection; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
52 | - |
|
53 | - public function getName() { |
|
54 | - return 'Repair invalid shares'; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Adjust file share permissions |
|
59 | - * @suppress SqlInjectionChecker |
|
60 | - */ |
|
61 | - private function adjustFileSharePermissions(IOutput $out) { |
|
62 | - $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
63 | - $builder = $this->connection->getQueryBuilder(); |
|
64 | - |
|
65 | - $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
66 | - $builder |
|
67 | - ->update('share') |
|
68 | - ->set('permissions', $permsFunc) |
|
69 | - ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
70 | - ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
71 | - |
|
72 | - $updatedEntries = $builder->execute(); |
|
73 | - if ($updatedEntries > 0) { |
|
74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Remove shares where the parent share does not exist anymore |
|
80 | - */ |
|
81 | - private function removeSharesNonExistingParent(IOutput $out) { |
|
82 | - $deletedEntries = 0; |
|
83 | - |
|
84 | - $query = $this->connection->getQueryBuilder(); |
|
85 | - $query->select('s1.parent') |
|
86 | - ->from('share', 's1') |
|
87 | - ->where($query->expr()->isNotNull('s1.parent')) |
|
88 | - ->andWhere($query->expr()->isNull('s2.id')) |
|
89 | - ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
90 | - ->groupBy('s1.parent') |
|
91 | - ->setMaxResults(self::CHUNK_SIZE); |
|
92 | - |
|
93 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
94 | - $deleteQuery->delete('share') |
|
95 | - ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
96 | - |
|
97 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
98 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
99 | - $deletedInLastChunk = 0; |
|
100 | - $result = $query->execute(); |
|
101 | - while ($row = $result->fetch()) { |
|
102 | - $deletedInLastChunk++; |
|
103 | - $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
104 | - ->execute(); |
|
105 | - } |
|
106 | - $result->closeCursor(); |
|
107 | - } |
|
108 | - |
|
109 | - if ($deletedEntries) { |
|
110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - public function run(IOutput $out) { |
|
115 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
116 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
117 | - $this->adjustFileSharePermissions($out); |
|
118 | - } |
|
119 | - |
|
120 | - $this->removeSharesNonExistingParent($out); |
|
121 | - } |
|
36 | + const CHUNK_SIZE = 200; |
|
37 | + |
|
38 | + /** @var \OCP\IConfig */ |
|
39 | + protected $config; |
|
40 | + |
|
41 | + /** @var \OCP\IDBConnection */ |
|
42 | + protected $connection; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param \OCP\IConfig $config |
|
46 | + * @param \OCP\IDBConnection $connection |
|
47 | + */ |
|
48 | + public function __construct($config, $connection) { |
|
49 | + $this->connection = $connection; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | + |
|
53 | + public function getName() { |
|
54 | + return 'Repair invalid shares'; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Adjust file share permissions |
|
59 | + * @suppress SqlInjectionChecker |
|
60 | + */ |
|
61 | + private function adjustFileSharePermissions(IOutput $out) { |
|
62 | + $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
63 | + $builder = $this->connection->getQueryBuilder(); |
|
64 | + |
|
65 | + $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
66 | + $builder |
|
67 | + ->update('share') |
|
68 | + ->set('permissions', $permsFunc) |
|
69 | + ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
70 | + ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
71 | + |
|
72 | + $updatedEntries = $builder->execute(); |
|
73 | + if ($updatedEntries > 0) { |
|
74 | + $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Remove shares where the parent share does not exist anymore |
|
80 | + */ |
|
81 | + private function removeSharesNonExistingParent(IOutput $out) { |
|
82 | + $deletedEntries = 0; |
|
83 | + |
|
84 | + $query = $this->connection->getQueryBuilder(); |
|
85 | + $query->select('s1.parent') |
|
86 | + ->from('share', 's1') |
|
87 | + ->where($query->expr()->isNotNull('s1.parent')) |
|
88 | + ->andWhere($query->expr()->isNull('s2.id')) |
|
89 | + ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
90 | + ->groupBy('s1.parent') |
|
91 | + ->setMaxResults(self::CHUNK_SIZE); |
|
92 | + |
|
93 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
94 | + $deleteQuery->delete('share') |
|
95 | + ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
96 | + |
|
97 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
98 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
99 | + $deletedInLastChunk = 0; |
|
100 | + $result = $query->execute(); |
|
101 | + while ($row = $result->fetch()) { |
|
102 | + $deletedInLastChunk++; |
|
103 | + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
104 | + ->execute(); |
|
105 | + } |
|
106 | + $result->closeCursor(); |
|
107 | + } |
|
108 | + |
|
109 | + if ($deletedEntries) { |
|
110 | + $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + public function run(IOutput $out) { |
|
115 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
116 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
117 | + $this->adjustFileSharePermissions($out); |
|
118 | + } |
|
119 | + |
|
120 | + $this->removeSharesNonExistingParent($out); |
|
121 | + } |
|
122 | 122 | } |
@@ -45,337 +45,337 @@ |
||
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 | } |
@@ -34,156 +34,156 @@ |
||
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 | } |
@@ -25,18 +25,18 @@ |
||
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 | } |
@@ -29,39 +29,39 @@ |
||
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 | } |
@@ -39,208 +39,208 @@ |
||
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 | } |
@@ -33,12 +33,12 @@ |
||
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 | } |
@@ -33,111 +33,111 @@ |
||
33 | 33 | namespace OC\Archive; |
34 | 34 | |
35 | 35 | abstract class Archive { |
36 | - /** |
|
37 | - * @param $source |
|
38 | - */ |
|
39 | - public abstract function __construct($source); |
|
40 | - /** |
|
41 | - * add an empty folder to the archive |
|
42 | - * @param string $path |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public abstract function addFolder($path); |
|
46 | - /** |
|
47 | - * add a file to the archive |
|
48 | - * @param string $path |
|
49 | - * @param string $source either a local file or string data |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public abstract function addFile($path, $source=''); |
|
53 | - /** |
|
54 | - * rename a file or folder in the archive |
|
55 | - * @param string $source |
|
56 | - * @param string $dest |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public abstract function rename($source, $dest); |
|
60 | - /** |
|
61 | - * get the uncompressed size of a file in the archive |
|
62 | - * @param string $path |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public abstract function filesize($path); |
|
66 | - /** |
|
67 | - * get the last modified time of a file in the archive |
|
68 | - * @param string $path |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public abstract function mtime($path); |
|
72 | - /** |
|
73 | - * get the files in a folder |
|
74 | - * @param string $path |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public abstract function getFolder($path); |
|
78 | - /** |
|
79 | - * get all files in the archive |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public abstract function getFiles(); |
|
83 | - /** |
|
84 | - * get the content of a file |
|
85 | - * @param string $path |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public abstract function getFile($path); |
|
89 | - /** |
|
90 | - * extract a single file from the archive |
|
91 | - * @param string $path |
|
92 | - * @param string $dest |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public abstract function extractFile($path, $dest); |
|
96 | - /** |
|
97 | - * extract the archive |
|
98 | - * @param string $dest |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public abstract function extract($dest); |
|
102 | - /** |
|
103 | - * check if a file or folder exists in the archive |
|
104 | - * @param string $path |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public abstract function fileExists($path); |
|
108 | - /** |
|
109 | - * remove a file or folder from the archive |
|
110 | - * @param string $path |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public abstract function remove($path); |
|
114 | - /** |
|
115 | - * get a file handler |
|
116 | - * @param string $path |
|
117 | - * @param string $mode |
|
118 | - * @return resource |
|
119 | - */ |
|
120 | - public abstract function getStream($path, $mode); |
|
121 | - /** |
|
122 | - * add a folder and all its content |
|
123 | - * @param string $path |
|
124 | - * @param string $source |
|
125 | - * @return boolean|null |
|
126 | - */ |
|
127 | - public function addRecursive($path, $source) { |
|
128 | - $dh = opendir($source); |
|
129 | - if(is_resource($dh)) { |
|
130 | - $this->addFolder($path); |
|
131 | - while (($file = readdir($dh)) !== false) { |
|
132 | - if($file === '.' || $file === '..') { |
|
133 | - continue; |
|
134 | - } |
|
135 | - if(is_dir($source.'/'.$file)) { |
|
136 | - $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
137 | - }else{ |
|
138 | - $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
36 | + /** |
|
37 | + * @param $source |
|
38 | + */ |
|
39 | + public abstract function __construct($source); |
|
40 | + /** |
|
41 | + * add an empty folder to the archive |
|
42 | + * @param string $path |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public abstract function addFolder($path); |
|
46 | + /** |
|
47 | + * add a file to the archive |
|
48 | + * @param string $path |
|
49 | + * @param string $source either a local file or string data |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public abstract function addFile($path, $source=''); |
|
53 | + /** |
|
54 | + * rename a file or folder in the archive |
|
55 | + * @param string $source |
|
56 | + * @param string $dest |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public abstract function rename($source, $dest); |
|
60 | + /** |
|
61 | + * get the uncompressed size of a file in the archive |
|
62 | + * @param string $path |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public abstract function filesize($path); |
|
66 | + /** |
|
67 | + * get the last modified time of a file in the archive |
|
68 | + * @param string $path |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public abstract function mtime($path); |
|
72 | + /** |
|
73 | + * get the files in a folder |
|
74 | + * @param string $path |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public abstract function getFolder($path); |
|
78 | + /** |
|
79 | + * get all files in the archive |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public abstract function getFiles(); |
|
83 | + /** |
|
84 | + * get the content of a file |
|
85 | + * @param string $path |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public abstract function getFile($path); |
|
89 | + /** |
|
90 | + * extract a single file from the archive |
|
91 | + * @param string $path |
|
92 | + * @param string $dest |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public abstract function extractFile($path, $dest); |
|
96 | + /** |
|
97 | + * extract the archive |
|
98 | + * @param string $dest |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public abstract function extract($dest); |
|
102 | + /** |
|
103 | + * check if a file or folder exists in the archive |
|
104 | + * @param string $path |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public abstract function fileExists($path); |
|
108 | + /** |
|
109 | + * remove a file or folder from the archive |
|
110 | + * @param string $path |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public abstract function remove($path); |
|
114 | + /** |
|
115 | + * get a file handler |
|
116 | + * @param string $path |
|
117 | + * @param string $mode |
|
118 | + * @return resource |
|
119 | + */ |
|
120 | + public abstract function getStream($path, $mode); |
|
121 | + /** |
|
122 | + * add a folder and all its content |
|
123 | + * @param string $path |
|
124 | + * @param string $source |
|
125 | + * @return boolean|null |
|
126 | + */ |
|
127 | + public function addRecursive($path, $source) { |
|
128 | + $dh = opendir($source); |
|
129 | + if(is_resource($dh)) { |
|
130 | + $this->addFolder($path); |
|
131 | + while (($file = readdir($dh)) !== false) { |
|
132 | + if($file === '.' || $file === '..') { |
|
133 | + continue; |
|
134 | + } |
|
135 | + if(is_dir($source.'/'.$file)) { |
|
136 | + $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
137 | + }else{ |
|
138 | + $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | 143 | } |
@@ -32,45 +32,45 @@ |
||
32 | 32 | */ |
33 | 33 | class File extends \OCP\Search\Provider { |
34 | 34 | |
35 | - /** |
|
36 | - * Search for files and folders matching the given query |
|
37 | - * @param string $query |
|
38 | - * @return \OCP\Search\Result |
|
39 | - */ |
|
40 | - public function search($query) { |
|
41 | - $files = Filesystem::search($query); |
|
42 | - $results = array(); |
|
43 | - // edit results |
|
44 | - foreach ($files as $fileData) { |
|
45 | - // skip versions |
|
46 | - if (strpos($fileData['path'], '_versions') === 0) { |
|
47 | - continue; |
|
48 | - } |
|
49 | - // skip top-level folder |
|
50 | - if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
51 | - continue; |
|
52 | - } |
|
53 | - // create audio result |
|
54 | - if($fileData['mimepart'] === 'audio'){ |
|
55 | - $result = new \OC\Search\Result\Audio($fileData); |
|
56 | - } |
|
57 | - // create image result |
|
58 | - elseif($fileData['mimepart'] === 'image'){ |
|
59 | - $result = new \OC\Search\Result\Image($fileData); |
|
60 | - } |
|
61 | - // create folder result |
|
62 | - elseif($fileData['mimetype'] === 'httpd/unix-directory'){ |
|
63 | - $result = new \OC\Search\Result\Folder($fileData); |
|
64 | - } |
|
65 | - // or create file result |
|
66 | - else{ |
|
67 | - $result = new \OC\Search\Result\File($fileData); |
|
68 | - } |
|
69 | - // add to results |
|
70 | - $results[] = $result; |
|
71 | - } |
|
72 | - // return |
|
73 | - return $results; |
|
74 | - } |
|
35 | + /** |
|
36 | + * Search for files and folders matching the given query |
|
37 | + * @param string $query |
|
38 | + * @return \OCP\Search\Result |
|
39 | + */ |
|
40 | + public function search($query) { |
|
41 | + $files = Filesystem::search($query); |
|
42 | + $results = array(); |
|
43 | + // edit results |
|
44 | + foreach ($files as $fileData) { |
|
45 | + // skip versions |
|
46 | + if (strpos($fileData['path'], '_versions') === 0) { |
|
47 | + continue; |
|
48 | + } |
|
49 | + // skip top-level folder |
|
50 | + if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
51 | + continue; |
|
52 | + } |
|
53 | + // create audio result |
|
54 | + if($fileData['mimepart'] === 'audio'){ |
|
55 | + $result = new \OC\Search\Result\Audio($fileData); |
|
56 | + } |
|
57 | + // create image result |
|
58 | + elseif($fileData['mimepart'] === 'image'){ |
|
59 | + $result = new \OC\Search\Result\Image($fileData); |
|
60 | + } |
|
61 | + // create folder result |
|
62 | + elseif($fileData['mimetype'] === 'httpd/unix-directory'){ |
|
63 | + $result = new \OC\Search\Result\Folder($fileData); |
|
64 | + } |
|
65 | + // or create file result |
|
66 | + else{ |
|
67 | + $result = new \OC\Search\Result\File($fileData); |
|
68 | + } |
|
69 | + // add to results |
|
70 | + $results[] = $result; |
|
71 | + } |
|
72 | + // return |
|
73 | + return $results; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |