@@ -24,12 +24,12 @@ |
||
24 | 24 | namespace OC\Hooks; |
25 | 25 | |
26 | 26 | class PublicEmitter extends BasicEmitter { |
27 | - /** |
|
28 | - * @param string $scope |
|
29 | - * @param string $method |
|
30 | - * @param array $arguments optional |
|
31 | - */ |
|
32 | - public function emit($scope, $method, array $arguments = array()) { |
|
33 | - parent::emit($scope, $method, $arguments); |
|
34 | - } |
|
27 | + /** |
|
28 | + * @param string $scope |
|
29 | + * @param string $method |
|
30 | + * @param array $arguments optional |
|
31 | + */ |
|
32 | + public function emit($scope, $method, array $arguments = array()) { |
|
33 | + parent::emit($scope, $method, $arguments); |
|
34 | + } |
|
35 | 35 | } |
@@ -24,5 +24,5 @@ |
||
24 | 24 | namespace OC\Hooks; |
25 | 25 | |
26 | 26 | abstract class BasicEmitter implements Emitter { |
27 | - use EmitterTrait; |
|
27 | + use EmitterTrait; |
|
28 | 28 | } |
@@ -24,8 +24,8 @@ |
||
24 | 24 | namespace OC\Hooks; |
25 | 25 | |
26 | 26 | abstract class LegacyEmitter extends BasicEmitter { |
27 | - protected function emit($scope, $method, array $arguments = array()) { |
|
28 | - \OC_Hook::emit($scope, $method, $arguments); |
|
29 | - parent::emit($scope, $method, $arguments); |
|
30 | - } |
|
27 | + protected function emit($scope, $method, array $arguments = array()) { |
|
28 | + \OC_Hook::emit($scope, $method, $arguments); |
|
29 | + parent::emit($scope, $method, $arguments); |
|
30 | + } |
|
31 | 31 | } |
@@ -32,19 +32,19 @@ |
||
32 | 32 | * @package OC\Hooks |
33 | 33 | */ |
34 | 34 | interface Emitter { |
35 | - /** |
|
36 | - * @param string $scope |
|
37 | - * @param string $method |
|
38 | - * @param callable $callback |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function listen($scope, $method, callable $callback); |
|
35 | + /** |
|
36 | + * @param string $scope |
|
37 | + * @param string $method |
|
38 | + * @param callable $callback |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function listen($scope, $method, callable $callback); |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $scope optional |
|
45 | - * @param string $method optional |
|
46 | - * @param callable $callback optional |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function removeListener($scope = null, $method = null, callable $callback = null); |
|
43 | + /** |
|
44 | + * @param string $scope optional |
|
45 | + * @param string $method optional |
|
46 | + * @param callable $callback optional |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function removeListener($scope = null, $method = null, callable $callback = null); |
|
50 | 50 | } |
@@ -24,80 +24,80 @@ |
||
24 | 24 | |
25 | 25 | trait EmitterTrait { |
26 | 26 | |
27 | - /** |
|
28 | - * @var (callable[])[] $listeners |
|
29 | - */ |
|
30 | - protected $listeners = array(); |
|
27 | + /** |
|
28 | + * @var (callable[])[] $listeners |
|
29 | + */ |
|
30 | + protected $listeners = array(); |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param string $scope |
|
34 | - * @param string $method |
|
35 | - * @param callable $callback |
|
36 | - */ |
|
37 | - public function listen($scope, $method, callable $callback) { |
|
38 | - $eventName = $scope . '::' . $method; |
|
39 | - if (!isset($this->listeners[$eventName])) { |
|
40 | - $this->listeners[$eventName] = array(); |
|
41 | - } |
|
42 | - if (array_search($callback, $this->listeners[$eventName], true) === false) { |
|
43 | - $this->listeners[$eventName][] = $callback; |
|
44 | - } |
|
45 | - } |
|
32 | + /** |
|
33 | + * @param string $scope |
|
34 | + * @param string $method |
|
35 | + * @param callable $callback |
|
36 | + */ |
|
37 | + public function listen($scope, $method, callable $callback) { |
|
38 | + $eventName = $scope . '::' . $method; |
|
39 | + if (!isset($this->listeners[$eventName])) { |
|
40 | + $this->listeners[$eventName] = array(); |
|
41 | + } |
|
42 | + if (array_search($callback, $this->listeners[$eventName], true) === false) { |
|
43 | + $this->listeners[$eventName][] = $callback; |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $scope optional |
|
49 | - * @param string $method optional |
|
50 | - * @param callable $callback optional |
|
51 | - */ |
|
52 | - public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
53 | - $names = array(); |
|
54 | - $allNames = array_keys($this->listeners); |
|
55 | - if ($scope and $method) { |
|
56 | - $name = $scope . '::' . $method; |
|
57 | - if (isset($this->listeners[$name])) { |
|
58 | - $names[] = $name; |
|
59 | - } |
|
60 | - } elseif ($scope) { |
|
61 | - foreach ($allNames as $name) { |
|
62 | - $parts = explode('::', $name, 2); |
|
63 | - if ($parts[0] == $scope) { |
|
64 | - $names[] = $name; |
|
65 | - } |
|
66 | - } |
|
67 | - } elseif ($method) { |
|
68 | - foreach ($allNames as $name) { |
|
69 | - $parts = explode('::', $name, 2); |
|
70 | - if ($parts[1] == $method) { |
|
71 | - $names[] = $name; |
|
72 | - } |
|
73 | - } |
|
74 | - } else { |
|
75 | - $names = $allNames; |
|
76 | - } |
|
47 | + /** |
|
48 | + * @param string $scope optional |
|
49 | + * @param string $method optional |
|
50 | + * @param callable $callback optional |
|
51 | + */ |
|
52 | + public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
53 | + $names = array(); |
|
54 | + $allNames = array_keys($this->listeners); |
|
55 | + if ($scope and $method) { |
|
56 | + $name = $scope . '::' . $method; |
|
57 | + if (isset($this->listeners[$name])) { |
|
58 | + $names[] = $name; |
|
59 | + } |
|
60 | + } elseif ($scope) { |
|
61 | + foreach ($allNames as $name) { |
|
62 | + $parts = explode('::', $name, 2); |
|
63 | + if ($parts[0] == $scope) { |
|
64 | + $names[] = $name; |
|
65 | + } |
|
66 | + } |
|
67 | + } elseif ($method) { |
|
68 | + foreach ($allNames as $name) { |
|
69 | + $parts = explode('::', $name, 2); |
|
70 | + if ($parts[1] == $method) { |
|
71 | + $names[] = $name; |
|
72 | + } |
|
73 | + } |
|
74 | + } else { |
|
75 | + $names = $allNames; |
|
76 | + } |
|
77 | 77 | |
78 | - foreach ($names as $name) { |
|
79 | - if ($callback) { |
|
80 | - $index = array_search($callback, $this->listeners[$name], true); |
|
81 | - if ($index !== false) { |
|
82 | - unset($this->listeners[$name][$index]); |
|
83 | - } |
|
84 | - } else { |
|
85 | - $this->listeners[$name] = array(); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
78 | + foreach ($names as $name) { |
|
79 | + if ($callback) { |
|
80 | + $index = array_search($callback, $this->listeners[$name], true); |
|
81 | + if ($index !== false) { |
|
82 | + unset($this->listeners[$name][$index]); |
|
83 | + } |
|
84 | + } else { |
|
85 | + $this->listeners[$name] = array(); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param string $scope |
|
92 | - * @param string $method |
|
93 | - * @param array $arguments optional |
|
94 | - */ |
|
95 | - protected function emit($scope, $method, array $arguments = array()) { |
|
96 | - $eventName = $scope . '::' . $method; |
|
97 | - if (isset($this->listeners[$eventName])) { |
|
98 | - foreach ($this->listeners[$eventName] as $callback) { |
|
99 | - call_user_func_array($callback, $arguments); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
90 | + /** |
|
91 | + * @param string $scope |
|
92 | + * @param string $method |
|
93 | + * @param array $arguments optional |
|
94 | + */ |
|
95 | + protected function emit($scope, $method, array $arguments = array()) { |
|
96 | + $eventName = $scope . '::' . $method; |
|
97 | + if (isset($this->listeners[$eventName])) { |
|
98 | + foreach ($this->listeners[$eventName] as $callback) { |
|
99 | + call_user_func_array($callback, $arguments); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | 103 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param callable $callback |
36 | 36 | */ |
37 | 37 | public function listen($scope, $method, callable $callback) { |
38 | - $eventName = $scope . '::' . $method; |
|
38 | + $eventName = $scope.'::'.$method; |
|
39 | 39 | if (!isset($this->listeners[$eventName])) { |
40 | 40 | $this->listeners[$eventName] = array(); |
41 | 41 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $names = array(); |
54 | 54 | $allNames = array_keys($this->listeners); |
55 | 55 | if ($scope and $method) { |
56 | - $name = $scope . '::' . $method; |
|
56 | + $name = $scope.'::'.$method; |
|
57 | 57 | if (isset($this->listeners[$name])) { |
58 | 58 | $names[] = $name; |
59 | 59 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param array $arguments optional |
94 | 94 | */ |
95 | 95 | protected function emit($scope, $method, array $arguments = array()) { |
96 | - $eventName = $scope . '::' . $method; |
|
96 | + $eventName = $scope.'::'.$method; |
|
97 | 97 | if (isset($this->listeners[$eventName])) { |
98 | 98 | foreach ($this->listeners[$eventName] as $callback) { |
99 | 99 | call_user_func_array($callback, $arguments); |
@@ -43,314 +43,314 @@ |
||
43 | 43 | * @package OC |
44 | 44 | */ |
45 | 45 | class OCSClient { |
46 | - /** @var IClientService */ |
|
47 | - private $httpClientService; |
|
48 | - /** @var IConfig */ |
|
49 | - private $config; |
|
50 | - /** @var ILogger */ |
|
51 | - private $logger; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param IClientService $httpClientService |
|
55 | - * @param IConfig $config |
|
56 | - * @param ILogger $logger |
|
57 | - */ |
|
58 | - public function __construct(IClientService $httpClientService, |
|
59 | - IConfig $config, |
|
60 | - ILogger $logger) { |
|
61 | - $this->httpClientService = $httpClientService; |
|
62 | - $this->config = $config; |
|
63 | - $this->logger = $logger; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Returns whether the AppStore is enabled (i.e. because the AppStore is disabled for EE) |
|
68 | - * |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function isAppStoreEnabled() { |
|
72 | - // For a regular edition default to true, all others default to false |
|
73 | - $default = false; |
|
74 | - if (\OC_Util::getEditionString() === '') { |
|
75 | - $default = true; |
|
76 | - } |
|
77 | - |
|
78 | - return $this->config->getSystemValue('appstoreenabled', $default) === true; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Get the url of the OCS AppStore server. |
|
83 | - * |
|
84 | - * @return string of the AppStore server |
|
85 | - */ |
|
86 | - private function getAppStoreUrl() { |
|
87 | - return $this->config->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1'); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $body |
|
92 | - * @param string $action |
|
93 | - * @return null|\SimpleXMLElement |
|
94 | - */ |
|
95 | - private function loadData($body, $action) { |
|
96 | - $loadEntities = libxml_disable_entity_loader(true); |
|
97 | - $data = @simplexml_load_string($body); |
|
98 | - libxml_disable_entity_loader($loadEntities); |
|
99 | - |
|
100 | - if($data === false) { |
|
101 | - libxml_clear_errors(); |
|
102 | - $this->logger->error( |
|
103 | - sprintf('Could not get %s, content was no valid XML', $action), |
|
104 | - [ |
|
105 | - 'app' => 'core', |
|
106 | - ] |
|
107 | - ); |
|
108 | - return null; |
|
109 | - } |
|
110 | - |
|
111 | - return $data; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Get all the categories from the OCS server |
|
116 | - * |
|
117 | - * @param array $targetVersion The target ownCloud version |
|
118 | - * @return array|null an array of category ids or null |
|
119 | - * @note returns NULL if config value appstoreenabled is set to false |
|
120 | - * This function returns a list of all the application categories on the OCS server |
|
121 | - */ |
|
122 | - public function getCategories(array $targetVersion) { |
|
123 | - if (!$this->isAppStoreEnabled()) { |
|
124 | - return null; |
|
125 | - } |
|
126 | - |
|
127 | - $client = $this->httpClientService->newClient(); |
|
128 | - try { |
|
129 | - $response = $client->get( |
|
130 | - $this->getAppStoreUrl() . '/content/categories', |
|
131 | - [ |
|
132 | - 'timeout' => 5, |
|
133 | - 'query' => [ |
|
134 | - 'version' => implode('x', $targetVersion), |
|
135 | - ], |
|
136 | - ] |
|
137 | - ); |
|
138 | - } catch(\Exception $e) { |
|
139 | - $this->logger->error( |
|
140 | - sprintf('Could not get categories: %s', $e->getMessage()), |
|
141 | - [ |
|
142 | - 'app' => 'core', |
|
143 | - ] |
|
144 | - ); |
|
145 | - return null; |
|
146 | - } |
|
147 | - |
|
148 | - $data = $this->loadData($response->getBody(), 'categories'); |
|
149 | - if($data === null) { |
|
150 | - return null; |
|
151 | - } |
|
152 | - |
|
153 | - $tmp = $data->data; |
|
154 | - $cats = []; |
|
155 | - |
|
156 | - foreach ($tmp->category as $value) { |
|
157 | - $id = (int)$value->id; |
|
158 | - $name = (string)$value->name; |
|
159 | - $cats[$id] = $name; |
|
160 | - } |
|
161 | - |
|
162 | - return $cats; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get all the applications from the OCS server |
|
167 | - * @param array $categories |
|
168 | - * @param int $page |
|
169 | - * @param string $filter |
|
170 | - * @param array $targetVersion The target ownCloud version |
|
171 | - * @return array An array of application data |
|
172 | - */ |
|
173 | - public function getApplications(array $categories, $page, $filter, array $targetVersion) { |
|
174 | - if (!$this->isAppStoreEnabled()) { |
|
175 | - return []; |
|
176 | - } |
|
177 | - |
|
178 | - $client = $this->httpClientService->newClient(); |
|
179 | - try { |
|
180 | - $response = $client->get( |
|
181 | - $this->getAppStoreUrl() . '/content/data', |
|
182 | - [ |
|
183 | - 'timeout' => 5, |
|
184 | - 'query' => [ |
|
185 | - 'version' => implode('x', $targetVersion), |
|
186 | - 'filter' => $filter, |
|
187 | - 'categories' => implode('x', $categories), |
|
188 | - 'sortmode' => 'new', |
|
189 | - 'page' => $page, |
|
190 | - 'pagesize' => 100, |
|
191 | - 'approved' => $filter |
|
192 | - ], |
|
193 | - ] |
|
194 | - ); |
|
195 | - } catch(\Exception $e) { |
|
196 | - $this->logger->error( |
|
197 | - sprintf('Could not get applications: %s', $e->getMessage()), |
|
198 | - [ |
|
199 | - 'app' => 'core', |
|
200 | - ] |
|
201 | - ); |
|
202 | - return []; |
|
203 | - } |
|
204 | - |
|
205 | - $data = $this->loadData($response->getBody(), 'applications'); |
|
206 | - if($data === null) { |
|
207 | - return []; |
|
208 | - } |
|
209 | - |
|
210 | - $tmp = $data->data->content; |
|
211 | - $tmpCount = count($tmp); |
|
212 | - |
|
213 | - $apps = []; |
|
214 | - for ($i = 0; $i < $tmpCount; $i++) { |
|
215 | - $app = []; |
|
216 | - $app['id'] = (string)$tmp[$i]->id; |
|
217 | - $app['name'] = (string)$tmp[$i]->name; |
|
218 | - $app['label'] = (string)$tmp[$i]->label; |
|
219 | - $app['version'] = (string)$tmp[$i]->version; |
|
220 | - $app['type'] = (string)$tmp[$i]->typeid; |
|
221 | - $app['typename'] = (string)$tmp[$i]->typename; |
|
222 | - $app['personid'] = (string)$tmp[$i]->personid; |
|
223 | - $app['profilepage'] = (string)$tmp[$i]->profilepage; |
|
224 | - $app['license'] = (string)$tmp[$i]->license; |
|
225 | - $app['detailpage'] = (string)$tmp[$i]->detailpage; |
|
226 | - $app['preview'] = (string)$tmp[$i]->smallpreviewpic1; |
|
227 | - $app['preview-full'] = (string)$tmp[$i]->previewpic1; |
|
228 | - $app['changed'] = strtotime($tmp[$i]->changed); |
|
229 | - $app['description'] = (string)$tmp[$i]->description; |
|
230 | - $app['score'] = (string)$tmp[$i]->score; |
|
231 | - $app['downloads'] = (int)$tmp[$i]->downloads; |
|
232 | - $app['level'] = (int)$tmp[$i]->approved; |
|
233 | - |
|
234 | - $apps[] = $app; |
|
235 | - } |
|
236 | - |
|
237 | - return $apps; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Get an the applications from the OCS server |
|
243 | - * |
|
244 | - * @param string $id |
|
245 | - * @param array $targetVersion The target ownCloud version |
|
246 | - * @return array|null an array of application data or null |
|
247 | - * |
|
248 | - * This function returns an applications from the OCS server |
|
249 | - */ |
|
250 | - public function getApplication($id, array $targetVersion) { |
|
251 | - if (!$this->isAppStoreEnabled()) { |
|
252 | - return null; |
|
253 | - } |
|
254 | - |
|
255 | - $client = $this->httpClientService->newClient(); |
|
256 | - try { |
|
257 | - $response = $client->get( |
|
258 | - $this->getAppStoreUrl() . '/content/data/' . urlencode($id), |
|
259 | - [ |
|
260 | - 'timeout' => 5, |
|
261 | - 'query' => [ |
|
262 | - 'version' => implode('x', $targetVersion), |
|
263 | - ], |
|
264 | - ] |
|
265 | - ); |
|
266 | - } catch(\Exception $e) { |
|
267 | - $this->logger->error( |
|
268 | - sprintf('Could not get application: %s', $e->getMessage()), |
|
269 | - [ |
|
270 | - 'app' => 'core', |
|
271 | - ] |
|
272 | - ); |
|
273 | - return null; |
|
274 | - } |
|
275 | - |
|
276 | - $data = $this->loadData($response->getBody(), 'application'); |
|
277 | - if($data === null) { |
|
278 | - return null; |
|
279 | - } |
|
280 | - |
|
281 | - $tmp = $data->data->content; |
|
282 | - if (is_null($tmp)) { |
|
283 | - \OCP\Util::writeLog('core', 'No update found at the Nextcloud appstore for app ' . $id, \OCP\Util::DEBUG); |
|
284 | - return null; |
|
285 | - } |
|
286 | - |
|
287 | - $app = []; |
|
288 | - $app['id'] = (int)$id; |
|
289 | - $app['name'] = (string)$tmp->name; |
|
290 | - $app['version'] = (string)$tmp->version; |
|
291 | - $app['type'] = (string)$tmp->typeid; |
|
292 | - $app['label'] = (string)$tmp->label; |
|
293 | - $app['typename'] = (string)$tmp->typename; |
|
294 | - $app['personid'] = (string)$tmp->personid; |
|
295 | - $app['profilepage'] = (string)$tmp->profilepage; |
|
296 | - $app['detailpage'] = (string)$tmp->detailpage; |
|
297 | - $app['preview1'] = (string)$tmp->smallpreviewpic1; |
|
298 | - $app['preview2'] = (string)$tmp->smallpreviewpic2; |
|
299 | - $app['preview3'] = (string)$tmp->smallpreviewpic3; |
|
300 | - $app['changed'] = strtotime($tmp->changed); |
|
301 | - $app['description'] = (string)$tmp->description; |
|
302 | - $app['detailpage'] = (string)$tmp->detailpage; |
|
303 | - $app['score'] = (int)$tmp->score; |
|
304 | - $app['level'] = (int)$tmp->approved; |
|
305 | - |
|
306 | - return $app; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get the download url for an application from the OCS server |
|
311 | - * @param string $id |
|
312 | - * @param array $targetVersion The target ownCloud version |
|
313 | - * @return array|null an array of application data or null |
|
314 | - */ |
|
315 | - public function getApplicationDownload($id, array $targetVersion) { |
|
316 | - if (!$this->isAppStoreEnabled()) { |
|
317 | - return null; |
|
318 | - } |
|
319 | - $url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1'; |
|
320 | - $client = $this->httpClientService->newClient(); |
|
321 | - try { |
|
322 | - $response = $client->get( |
|
323 | - $url, |
|
324 | - [ |
|
325 | - 'timeout' => 5, |
|
326 | - 'query' => [ |
|
327 | - 'version' => implode('x', $targetVersion), |
|
328 | - ], |
|
329 | - ] |
|
330 | - ); |
|
331 | - } catch(\Exception $e) { |
|
332 | - $this->logger->error( |
|
333 | - sprintf('Could not get application download URL: %s', $e->getMessage()), |
|
334 | - [ |
|
335 | - 'app' => 'core', |
|
336 | - ] |
|
337 | - ); |
|
338 | - return null; |
|
339 | - } |
|
340 | - |
|
341 | - $data = $this->loadData($response->getBody(), 'application download URL'); |
|
342 | - if($data === null) { |
|
343 | - return null; |
|
344 | - } |
|
345 | - |
|
346 | - $tmp = $data->data->content; |
|
347 | - $app = []; |
|
348 | - if (isset($tmp->downloadlink)) { |
|
349 | - $app['downloadlink'] = (string)$tmp->downloadlink; |
|
350 | - } else { |
|
351 | - $app['downloadlink'] = ''; |
|
352 | - } |
|
353 | - return $app; |
|
354 | - } |
|
46 | + /** @var IClientService */ |
|
47 | + private $httpClientService; |
|
48 | + /** @var IConfig */ |
|
49 | + private $config; |
|
50 | + /** @var ILogger */ |
|
51 | + private $logger; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param IClientService $httpClientService |
|
55 | + * @param IConfig $config |
|
56 | + * @param ILogger $logger |
|
57 | + */ |
|
58 | + public function __construct(IClientService $httpClientService, |
|
59 | + IConfig $config, |
|
60 | + ILogger $logger) { |
|
61 | + $this->httpClientService = $httpClientService; |
|
62 | + $this->config = $config; |
|
63 | + $this->logger = $logger; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Returns whether the AppStore is enabled (i.e. because the AppStore is disabled for EE) |
|
68 | + * |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function isAppStoreEnabled() { |
|
72 | + // For a regular edition default to true, all others default to false |
|
73 | + $default = false; |
|
74 | + if (\OC_Util::getEditionString() === '') { |
|
75 | + $default = true; |
|
76 | + } |
|
77 | + |
|
78 | + return $this->config->getSystemValue('appstoreenabled', $default) === true; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Get the url of the OCS AppStore server. |
|
83 | + * |
|
84 | + * @return string of the AppStore server |
|
85 | + */ |
|
86 | + private function getAppStoreUrl() { |
|
87 | + return $this->config->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1'); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $body |
|
92 | + * @param string $action |
|
93 | + * @return null|\SimpleXMLElement |
|
94 | + */ |
|
95 | + private function loadData($body, $action) { |
|
96 | + $loadEntities = libxml_disable_entity_loader(true); |
|
97 | + $data = @simplexml_load_string($body); |
|
98 | + libxml_disable_entity_loader($loadEntities); |
|
99 | + |
|
100 | + if($data === false) { |
|
101 | + libxml_clear_errors(); |
|
102 | + $this->logger->error( |
|
103 | + sprintf('Could not get %s, content was no valid XML', $action), |
|
104 | + [ |
|
105 | + 'app' => 'core', |
|
106 | + ] |
|
107 | + ); |
|
108 | + return null; |
|
109 | + } |
|
110 | + |
|
111 | + return $data; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Get all the categories from the OCS server |
|
116 | + * |
|
117 | + * @param array $targetVersion The target ownCloud version |
|
118 | + * @return array|null an array of category ids or null |
|
119 | + * @note returns NULL if config value appstoreenabled is set to false |
|
120 | + * This function returns a list of all the application categories on the OCS server |
|
121 | + */ |
|
122 | + public function getCategories(array $targetVersion) { |
|
123 | + if (!$this->isAppStoreEnabled()) { |
|
124 | + return null; |
|
125 | + } |
|
126 | + |
|
127 | + $client = $this->httpClientService->newClient(); |
|
128 | + try { |
|
129 | + $response = $client->get( |
|
130 | + $this->getAppStoreUrl() . '/content/categories', |
|
131 | + [ |
|
132 | + 'timeout' => 5, |
|
133 | + 'query' => [ |
|
134 | + 'version' => implode('x', $targetVersion), |
|
135 | + ], |
|
136 | + ] |
|
137 | + ); |
|
138 | + } catch(\Exception $e) { |
|
139 | + $this->logger->error( |
|
140 | + sprintf('Could not get categories: %s', $e->getMessage()), |
|
141 | + [ |
|
142 | + 'app' => 'core', |
|
143 | + ] |
|
144 | + ); |
|
145 | + return null; |
|
146 | + } |
|
147 | + |
|
148 | + $data = $this->loadData($response->getBody(), 'categories'); |
|
149 | + if($data === null) { |
|
150 | + return null; |
|
151 | + } |
|
152 | + |
|
153 | + $tmp = $data->data; |
|
154 | + $cats = []; |
|
155 | + |
|
156 | + foreach ($tmp->category as $value) { |
|
157 | + $id = (int)$value->id; |
|
158 | + $name = (string)$value->name; |
|
159 | + $cats[$id] = $name; |
|
160 | + } |
|
161 | + |
|
162 | + return $cats; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get all the applications from the OCS server |
|
167 | + * @param array $categories |
|
168 | + * @param int $page |
|
169 | + * @param string $filter |
|
170 | + * @param array $targetVersion The target ownCloud version |
|
171 | + * @return array An array of application data |
|
172 | + */ |
|
173 | + public function getApplications(array $categories, $page, $filter, array $targetVersion) { |
|
174 | + if (!$this->isAppStoreEnabled()) { |
|
175 | + return []; |
|
176 | + } |
|
177 | + |
|
178 | + $client = $this->httpClientService->newClient(); |
|
179 | + try { |
|
180 | + $response = $client->get( |
|
181 | + $this->getAppStoreUrl() . '/content/data', |
|
182 | + [ |
|
183 | + 'timeout' => 5, |
|
184 | + 'query' => [ |
|
185 | + 'version' => implode('x', $targetVersion), |
|
186 | + 'filter' => $filter, |
|
187 | + 'categories' => implode('x', $categories), |
|
188 | + 'sortmode' => 'new', |
|
189 | + 'page' => $page, |
|
190 | + 'pagesize' => 100, |
|
191 | + 'approved' => $filter |
|
192 | + ], |
|
193 | + ] |
|
194 | + ); |
|
195 | + } catch(\Exception $e) { |
|
196 | + $this->logger->error( |
|
197 | + sprintf('Could not get applications: %s', $e->getMessage()), |
|
198 | + [ |
|
199 | + 'app' => 'core', |
|
200 | + ] |
|
201 | + ); |
|
202 | + return []; |
|
203 | + } |
|
204 | + |
|
205 | + $data = $this->loadData($response->getBody(), 'applications'); |
|
206 | + if($data === null) { |
|
207 | + return []; |
|
208 | + } |
|
209 | + |
|
210 | + $tmp = $data->data->content; |
|
211 | + $tmpCount = count($tmp); |
|
212 | + |
|
213 | + $apps = []; |
|
214 | + for ($i = 0; $i < $tmpCount; $i++) { |
|
215 | + $app = []; |
|
216 | + $app['id'] = (string)$tmp[$i]->id; |
|
217 | + $app['name'] = (string)$tmp[$i]->name; |
|
218 | + $app['label'] = (string)$tmp[$i]->label; |
|
219 | + $app['version'] = (string)$tmp[$i]->version; |
|
220 | + $app['type'] = (string)$tmp[$i]->typeid; |
|
221 | + $app['typename'] = (string)$tmp[$i]->typename; |
|
222 | + $app['personid'] = (string)$tmp[$i]->personid; |
|
223 | + $app['profilepage'] = (string)$tmp[$i]->profilepage; |
|
224 | + $app['license'] = (string)$tmp[$i]->license; |
|
225 | + $app['detailpage'] = (string)$tmp[$i]->detailpage; |
|
226 | + $app['preview'] = (string)$tmp[$i]->smallpreviewpic1; |
|
227 | + $app['preview-full'] = (string)$tmp[$i]->previewpic1; |
|
228 | + $app['changed'] = strtotime($tmp[$i]->changed); |
|
229 | + $app['description'] = (string)$tmp[$i]->description; |
|
230 | + $app['score'] = (string)$tmp[$i]->score; |
|
231 | + $app['downloads'] = (int)$tmp[$i]->downloads; |
|
232 | + $app['level'] = (int)$tmp[$i]->approved; |
|
233 | + |
|
234 | + $apps[] = $app; |
|
235 | + } |
|
236 | + |
|
237 | + return $apps; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Get an the applications from the OCS server |
|
243 | + * |
|
244 | + * @param string $id |
|
245 | + * @param array $targetVersion The target ownCloud version |
|
246 | + * @return array|null an array of application data or null |
|
247 | + * |
|
248 | + * This function returns an applications from the OCS server |
|
249 | + */ |
|
250 | + public function getApplication($id, array $targetVersion) { |
|
251 | + if (!$this->isAppStoreEnabled()) { |
|
252 | + return null; |
|
253 | + } |
|
254 | + |
|
255 | + $client = $this->httpClientService->newClient(); |
|
256 | + try { |
|
257 | + $response = $client->get( |
|
258 | + $this->getAppStoreUrl() . '/content/data/' . urlencode($id), |
|
259 | + [ |
|
260 | + 'timeout' => 5, |
|
261 | + 'query' => [ |
|
262 | + 'version' => implode('x', $targetVersion), |
|
263 | + ], |
|
264 | + ] |
|
265 | + ); |
|
266 | + } catch(\Exception $e) { |
|
267 | + $this->logger->error( |
|
268 | + sprintf('Could not get application: %s', $e->getMessage()), |
|
269 | + [ |
|
270 | + 'app' => 'core', |
|
271 | + ] |
|
272 | + ); |
|
273 | + return null; |
|
274 | + } |
|
275 | + |
|
276 | + $data = $this->loadData($response->getBody(), 'application'); |
|
277 | + if($data === null) { |
|
278 | + return null; |
|
279 | + } |
|
280 | + |
|
281 | + $tmp = $data->data->content; |
|
282 | + if (is_null($tmp)) { |
|
283 | + \OCP\Util::writeLog('core', 'No update found at the Nextcloud appstore for app ' . $id, \OCP\Util::DEBUG); |
|
284 | + return null; |
|
285 | + } |
|
286 | + |
|
287 | + $app = []; |
|
288 | + $app['id'] = (int)$id; |
|
289 | + $app['name'] = (string)$tmp->name; |
|
290 | + $app['version'] = (string)$tmp->version; |
|
291 | + $app['type'] = (string)$tmp->typeid; |
|
292 | + $app['label'] = (string)$tmp->label; |
|
293 | + $app['typename'] = (string)$tmp->typename; |
|
294 | + $app['personid'] = (string)$tmp->personid; |
|
295 | + $app['profilepage'] = (string)$tmp->profilepage; |
|
296 | + $app['detailpage'] = (string)$tmp->detailpage; |
|
297 | + $app['preview1'] = (string)$tmp->smallpreviewpic1; |
|
298 | + $app['preview2'] = (string)$tmp->smallpreviewpic2; |
|
299 | + $app['preview3'] = (string)$tmp->smallpreviewpic3; |
|
300 | + $app['changed'] = strtotime($tmp->changed); |
|
301 | + $app['description'] = (string)$tmp->description; |
|
302 | + $app['detailpage'] = (string)$tmp->detailpage; |
|
303 | + $app['score'] = (int)$tmp->score; |
|
304 | + $app['level'] = (int)$tmp->approved; |
|
305 | + |
|
306 | + return $app; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get the download url for an application from the OCS server |
|
311 | + * @param string $id |
|
312 | + * @param array $targetVersion The target ownCloud version |
|
313 | + * @return array|null an array of application data or null |
|
314 | + */ |
|
315 | + public function getApplicationDownload($id, array $targetVersion) { |
|
316 | + if (!$this->isAppStoreEnabled()) { |
|
317 | + return null; |
|
318 | + } |
|
319 | + $url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1'; |
|
320 | + $client = $this->httpClientService->newClient(); |
|
321 | + try { |
|
322 | + $response = $client->get( |
|
323 | + $url, |
|
324 | + [ |
|
325 | + 'timeout' => 5, |
|
326 | + 'query' => [ |
|
327 | + 'version' => implode('x', $targetVersion), |
|
328 | + ], |
|
329 | + ] |
|
330 | + ); |
|
331 | + } catch(\Exception $e) { |
|
332 | + $this->logger->error( |
|
333 | + sprintf('Could not get application download URL: %s', $e->getMessage()), |
|
334 | + [ |
|
335 | + 'app' => 'core', |
|
336 | + ] |
|
337 | + ); |
|
338 | + return null; |
|
339 | + } |
|
340 | + |
|
341 | + $data = $this->loadData($response->getBody(), 'application download URL'); |
|
342 | + if($data === null) { |
|
343 | + return null; |
|
344 | + } |
|
345 | + |
|
346 | + $tmp = $data->data->content; |
|
347 | + $app = []; |
|
348 | + if (isset($tmp->downloadlink)) { |
|
349 | + $app['downloadlink'] = (string)$tmp->downloadlink; |
|
350 | + } else { |
|
351 | + $app['downloadlink'] = ''; |
|
352 | + } |
|
353 | + return $app; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $data = @simplexml_load_string($body); |
98 | 98 | libxml_disable_entity_loader($loadEntities); |
99 | 99 | |
100 | - if($data === false) { |
|
100 | + if ($data === false) { |
|
101 | 101 | libxml_clear_errors(); |
102 | 102 | $this->logger->error( |
103 | 103 | sprintf('Could not get %s, content was no valid XML', $action), |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $client = $this->httpClientService->newClient(); |
128 | 128 | try { |
129 | 129 | $response = $client->get( |
130 | - $this->getAppStoreUrl() . '/content/categories', |
|
130 | + $this->getAppStoreUrl().'/content/categories', |
|
131 | 131 | [ |
132 | 132 | 'timeout' => 5, |
133 | 133 | 'query' => [ |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ], |
136 | 136 | ] |
137 | 137 | ); |
138 | - } catch(\Exception $e) { |
|
138 | + } catch (\Exception $e) { |
|
139 | 139 | $this->logger->error( |
140 | 140 | sprintf('Could not get categories: %s', $e->getMessage()), |
141 | 141 | [ |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | $data = $this->loadData($response->getBody(), 'categories'); |
149 | - if($data === null) { |
|
149 | + if ($data === null) { |
|
150 | 150 | return null; |
151 | 151 | } |
152 | 152 | |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | $cats = []; |
155 | 155 | |
156 | 156 | foreach ($tmp->category as $value) { |
157 | - $id = (int)$value->id; |
|
158 | - $name = (string)$value->name; |
|
157 | + $id = (int) $value->id; |
|
158 | + $name = (string) $value->name; |
|
159 | 159 | $cats[$id] = $name; |
160 | 160 | } |
161 | 161 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $client = $this->httpClientService->newClient(); |
179 | 179 | try { |
180 | 180 | $response = $client->get( |
181 | - $this->getAppStoreUrl() . '/content/data', |
|
181 | + $this->getAppStoreUrl().'/content/data', |
|
182 | 182 | [ |
183 | 183 | 'timeout' => 5, |
184 | 184 | 'query' => [ |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | ], |
193 | 193 | ] |
194 | 194 | ); |
195 | - } catch(\Exception $e) { |
|
195 | + } catch (\Exception $e) { |
|
196 | 196 | $this->logger->error( |
197 | 197 | sprintf('Could not get applications: %s', $e->getMessage()), |
198 | 198 | [ |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | $data = $this->loadData($response->getBody(), 'applications'); |
206 | - if($data === null) { |
|
206 | + if ($data === null) { |
|
207 | 207 | return []; |
208 | 208 | } |
209 | 209 | |
@@ -213,23 +213,23 @@ discard block |
||
213 | 213 | $apps = []; |
214 | 214 | for ($i = 0; $i < $tmpCount; $i++) { |
215 | 215 | $app = []; |
216 | - $app['id'] = (string)$tmp[$i]->id; |
|
217 | - $app['name'] = (string)$tmp[$i]->name; |
|
218 | - $app['label'] = (string)$tmp[$i]->label; |
|
219 | - $app['version'] = (string)$tmp[$i]->version; |
|
220 | - $app['type'] = (string)$tmp[$i]->typeid; |
|
221 | - $app['typename'] = (string)$tmp[$i]->typename; |
|
222 | - $app['personid'] = (string)$tmp[$i]->personid; |
|
223 | - $app['profilepage'] = (string)$tmp[$i]->profilepage; |
|
224 | - $app['license'] = (string)$tmp[$i]->license; |
|
225 | - $app['detailpage'] = (string)$tmp[$i]->detailpage; |
|
226 | - $app['preview'] = (string)$tmp[$i]->smallpreviewpic1; |
|
227 | - $app['preview-full'] = (string)$tmp[$i]->previewpic1; |
|
216 | + $app['id'] = (string) $tmp[$i]->id; |
|
217 | + $app['name'] = (string) $tmp[$i]->name; |
|
218 | + $app['label'] = (string) $tmp[$i]->label; |
|
219 | + $app['version'] = (string) $tmp[$i]->version; |
|
220 | + $app['type'] = (string) $tmp[$i]->typeid; |
|
221 | + $app['typename'] = (string) $tmp[$i]->typename; |
|
222 | + $app['personid'] = (string) $tmp[$i]->personid; |
|
223 | + $app['profilepage'] = (string) $tmp[$i]->profilepage; |
|
224 | + $app['license'] = (string) $tmp[$i]->license; |
|
225 | + $app['detailpage'] = (string) $tmp[$i]->detailpage; |
|
226 | + $app['preview'] = (string) $tmp[$i]->smallpreviewpic1; |
|
227 | + $app['preview-full'] = (string) $tmp[$i]->previewpic1; |
|
228 | 228 | $app['changed'] = strtotime($tmp[$i]->changed); |
229 | - $app['description'] = (string)$tmp[$i]->description; |
|
230 | - $app['score'] = (string)$tmp[$i]->score; |
|
231 | - $app['downloads'] = (int)$tmp[$i]->downloads; |
|
232 | - $app['level'] = (int)$tmp[$i]->approved; |
|
229 | + $app['description'] = (string) $tmp[$i]->description; |
|
230 | + $app['score'] = (string) $tmp[$i]->score; |
|
231 | + $app['downloads'] = (int) $tmp[$i]->downloads; |
|
232 | + $app['level'] = (int) $tmp[$i]->approved; |
|
233 | 233 | |
234 | 234 | $apps[] = $app; |
235 | 235 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $client = $this->httpClientService->newClient(); |
256 | 256 | try { |
257 | 257 | $response = $client->get( |
258 | - $this->getAppStoreUrl() . '/content/data/' . urlencode($id), |
|
258 | + $this->getAppStoreUrl().'/content/data/'.urlencode($id), |
|
259 | 259 | [ |
260 | 260 | 'timeout' => 5, |
261 | 261 | 'query' => [ |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | ], |
264 | 264 | ] |
265 | 265 | ); |
266 | - } catch(\Exception $e) { |
|
266 | + } catch (\Exception $e) { |
|
267 | 267 | $this->logger->error( |
268 | 268 | sprintf('Could not get application: %s', $e->getMessage()), |
269 | 269 | [ |
@@ -274,34 +274,34 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | $data = $this->loadData($response->getBody(), 'application'); |
277 | - if($data === null) { |
|
277 | + if ($data === null) { |
|
278 | 278 | return null; |
279 | 279 | } |
280 | 280 | |
281 | 281 | $tmp = $data->data->content; |
282 | 282 | if (is_null($tmp)) { |
283 | - \OCP\Util::writeLog('core', 'No update found at the Nextcloud appstore for app ' . $id, \OCP\Util::DEBUG); |
|
283 | + \OCP\Util::writeLog('core', 'No update found at the Nextcloud appstore for app '.$id, \OCP\Util::DEBUG); |
|
284 | 284 | return null; |
285 | 285 | } |
286 | 286 | |
287 | 287 | $app = []; |
288 | - $app['id'] = (int)$id; |
|
289 | - $app['name'] = (string)$tmp->name; |
|
290 | - $app['version'] = (string)$tmp->version; |
|
291 | - $app['type'] = (string)$tmp->typeid; |
|
292 | - $app['label'] = (string)$tmp->label; |
|
293 | - $app['typename'] = (string)$tmp->typename; |
|
294 | - $app['personid'] = (string)$tmp->personid; |
|
295 | - $app['profilepage'] = (string)$tmp->profilepage; |
|
296 | - $app['detailpage'] = (string)$tmp->detailpage; |
|
297 | - $app['preview1'] = (string)$tmp->smallpreviewpic1; |
|
298 | - $app['preview2'] = (string)$tmp->smallpreviewpic2; |
|
299 | - $app['preview3'] = (string)$tmp->smallpreviewpic3; |
|
288 | + $app['id'] = (int) $id; |
|
289 | + $app['name'] = (string) $tmp->name; |
|
290 | + $app['version'] = (string) $tmp->version; |
|
291 | + $app['type'] = (string) $tmp->typeid; |
|
292 | + $app['label'] = (string) $tmp->label; |
|
293 | + $app['typename'] = (string) $tmp->typename; |
|
294 | + $app['personid'] = (string) $tmp->personid; |
|
295 | + $app['profilepage'] = (string) $tmp->profilepage; |
|
296 | + $app['detailpage'] = (string) $tmp->detailpage; |
|
297 | + $app['preview1'] = (string) $tmp->smallpreviewpic1; |
|
298 | + $app['preview2'] = (string) $tmp->smallpreviewpic2; |
|
299 | + $app['preview3'] = (string) $tmp->smallpreviewpic3; |
|
300 | 300 | $app['changed'] = strtotime($tmp->changed); |
301 | - $app['description'] = (string)$tmp->description; |
|
302 | - $app['detailpage'] = (string)$tmp->detailpage; |
|
303 | - $app['score'] = (int)$tmp->score; |
|
304 | - $app['level'] = (int)$tmp->approved; |
|
301 | + $app['description'] = (string) $tmp->description; |
|
302 | + $app['detailpage'] = (string) $tmp->detailpage; |
|
303 | + $app['score'] = (int) $tmp->score; |
|
304 | + $app['level'] = (int) $tmp->approved; |
|
305 | 305 | |
306 | 306 | return $app; |
307 | 307 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | if (!$this->isAppStoreEnabled()) { |
317 | 317 | return null; |
318 | 318 | } |
319 | - $url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1'; |
|
319 | + $url = $this->getAppStoreUrl().'/content/download/'.urlencode($id).'/1'; |
|
320 | 320 | $client = $this->httpClientService->newClient(); |
321 | 321 | try { |
322 | 322 | $response = $client->get( |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | ], |
329 | 329 | ] |
330 | 330 | ); |
331 | - } catch(\Exception $e) { |
|
331 | + } catch (\Exception $e) { |
|
332 | 332 | $this->logger->error( |
333 | 333 | sprintf('Could not get application download URL: %s', $e->getMessage()), |
334 | 334 | [ |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | $data = $this->loadData($response->getBody(), 'application download URL'); |
342 | - if($data === null) { |
|
342 | + if ($data === null) { |
|
343 | 343 | return null; |
344 | 344 | } |
345 | 345 | |
346 | 346 | $tmp = $data->data->content; |
347 | 347 | $app = []; |
348 | 348 | if (isset($tmp->downloadlink)) { |
349 | - $app['downloadlink'] = (string)$tmp->downloadlink; |
|
349 | + $app['downloadlink'] = (string) $tmp->downloadlink; |
|
350 | 350 | } else { |
351 | 351 | $app['downloadlink'] = ''; |
352 | 352 | } |
@@ -37,252 +37,252 @@ |
||
37 | 37 | * database. |
38 | 38 | */ |
39 | 39 | class AppConfig implements IAppConfig { |
40 | - /** |
|
41 | - * @var \OCP\IDBConnection $conn |
|
42 | - */ |
|
43 | - protected $conn; |
|
44 | - |
|
45 | - private $cache = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * @param IDBConnection $conn |
|
49 | - */ |
|
50 | - public function __construct(IDBConnection $conn) { |
|
51 | - $this->conn = $conn; |
|
52 | - $this->configLoaded = false; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $app |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - private function getAppValues($app) { |
|
60 | - $this->loadConfigValues(); |
|
61 | - |
|
62 | - if (isset($this->cache[$app])) { |
|
63 | - return $this->cache[$app]; |
|
64 | - } |
|
65 | - |
|
66 | - return []; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get all apps using the config |
|
71 | - * |
|
72 | - * @return array an array of app ids |
|
73 | - * |
|
74 | - * This function returns a list of all apps that have at least one |
|
75 | - * entry in the appconfig table. |
|
76 | - */ |
|
77 | - public function getApps() { |
|
78 | - $this->loadConfigValues(); |
|
79 | - |
|
80 | - return $this->getSortedKeys($this->cache); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get the available keys for an app |
|
85 | - * |
|
86 | - * @param string $app the app we are looking for |
|
87 | - * @return array an array of key names |
|
88 | - * |
|
89 | - * This function gets all keys of an app. Please note that the values are |
|
90 | - * not returned. |
|
91 | - */ |
|
92 | - public function getKeys($app) { |
|
93 | - $this->loadConfigValues(); |
|
94 | - |
|
95 | - if (isset($this->cache[$app])) { |
|
96 | - return $this->getSortedKeys($this->cache[$app]); |
|
97 | - } |
|
98 | - |
|
99 | - return []; |
|
100 | - } |
|
101 | - |
|
102 | - public function getSortedKeys($data) { |
|
103 | - $keys = array_keys($data); |
|
104 | - sort($keys); |
|
105 | - return $keys; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets the config value |
|
110 | - * |
|
111 | - * @param string $app app |
|
112 | - * @param string $key key |
|
113 | - * @param string $default = null, default value if the key does not exist |
|
114 | - * @return string the value or $default |
|
115 | - * |
|
116 | - * This function gets a value from the appconfig table. If the key does |
|
117 | - * not exist the default value will be returned |
|
118 | - */ |
|
119 | - public function getValue($app, $key, $default = null) { |
|
120 | - $this->loadConfigValues(); |
|
121 | - |
|
122 | - if ($this->hasKey($app, $key)) { |
|
123 | - return $this->cache[$app][$key]; |
|
124 | - } |
|
125 | - |
|
126 | - return $default; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * check if a key is set in the appconfig |
|
131 | - * |
|
132 | - * @param string $app |
|
133 | - * @param string $key |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function hasKey($app, $key) { |
|
137 | - $this->loadConfigValues(); |
|
138 | - |
|
139 | - return isset($this->cache[$app][$key]); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Sets a value. If the key did not exist before it will be created. |
|
144 | - * |
|
145 | - * @param string $app app |
|
146 | - * @param string $key key |
|
147 | - * @param string $value value |
|
148 | - * @return bool True if the value was inserted or updated, false if the value was the same |
|
149 | - */ |
|
150 | - public function setValue($app, $key, $value) { |
|
151 | - if (!$this->hasKey($app, $key)) { |
|
152 | - $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
153 | - 'appid' => $app, |
|
154 | - 'configkey' => $key, |
|
155 | - 'configvalue' => $value, |
|
156 | - ], [ |
|
157 | - 'appid', |
|
158 | - 'configkey', |
|
159 | - ]); |
|
160 | - |
|
161 | - if ($inserted) { |
|
162 | - if (!isset($this->cache[$app])) { |
|
163 | - $this->cache[$app] = []; |
|
164 | - } |
|
165 | - |
|
166 | - $this->cache[$app][$key] = $value; |
|
167 | - return true; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - $sql = $this->conn->getQueryBuilder(); |
|
172 | - $sql->update('appconfig') |
|
173 | - ->set('configvalue', $sql->createParameter('configvalue')) |
|
174 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
175 | - ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
176 | - ->setParameter('configvalue', $value) |
|
177 | - ->setParameter('app', $app) |
|
178 | - ->setParameter('configkey', $key); |
|
179 | - |
|
180 | - /* |
|
40 | + /** |
|
41 | + * @var \OCP\IDBConnection $conn |
|
42 | + */ |
|
43 | + protected $conn; |
|
44 | + |
|
45 | + private $cache = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * @param IDBConnection $conn |
|
49 | + */ |
|
50 | + public function __construct(IDBConnection $conn) { |
|
51 | + $this->conn = $conn; |
|
52 | + $this->configLoaded = false; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $app |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + private function getAppValues($app) { |
|
60 | + $this->loadConfigValues(); |
|
61 | + |
|
62 | + if (isset($this->cache[$app])) { |
|
63 | + return $this->cache[$app]; |
|
64 | + } |
|
65 | + |
|
66 | + return []; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get all apps using the config |
|
71 | + * |
|
72 | + * @return array an array of app ids |
|
73 | + * |
|
74 | + * This function returns a list of all apps that have at least one |
|
75 | + * entry in the appconfig table. |
|
76 | + */ |
|
77 | + public function getApps() { |
|
78 | + $this->loadConfigValues(); |
|
79 | + |
|
80 | + return $this->getSortedKeys($this->cache); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get the available keys for an app |
|
85 | + * |
|
86 | + * @param string $app the app we are looking for |
|
87 | + * @return array an array of key names |
|
88 | + * |
|
89 | + * This function gets all keys of an app. Please note that the values are |
|
90 | + * not returned. |
|
91 | + */ |
|
92 | + public function getKeys($app) { |
|
93 | + $this->loadConfigValues(); |
|
94 | + |
|
95 | + if (isset($this->cache[$app])) { |
|
96 | + return $this->getSortedKeys($this->cache[$app]); |
|
97 | + } |
|
98 | + |
|
99 | + return []; |
|
100 | + } |
|
101 | + |
|
102 | + public function getSortedKeys($data) { |
|
103 | + $keys = array_keys($data); |
|
104 | + sort($keys); |
|
105 | + return $keys; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets the config value |
|
110 | + * |
|
111 | + * @param string $app app |
|
112 | + * @param string $key key |
|
113 | + * @param string $default = null, default value if the key does not exist |
|
114 | + * @return string the value or $default |
|
115 | + * |
|
116 | + * This function gets a value from the appconfig table. If the key does |
|
117 | + * not exist the default value will be returned |
|
118 | + */ |
|
119 | + public function getValue($app, $key, $default = null) { |
|
120 | + $this->loadConfigValues(); |
|
121 | + |
|
122 | + if ($this->hasKey($app, $key)) { |
|
123 | + return $this->cache[$app][$key]; |
|
124 | + } |
|
125 | + |
|
126 | + return $default; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * check if a key is set in the appconfig |
|
131 | + * |
|
132 | + * @param string $app |
|
133 | + * @param string $key |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function hasKey($app, $key) { |
|
137 | + $this->loadConfigValues(); |
|
138 | + |
|
139 | + return isset($this->cache[$app][$key]); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Sets a value. If the key did not exist before it will be created. |
|
144 | + * |
|
145 | + * @param string $app app |
|
146 | + * @param string $key key |
|
147 | + * @param string $value value |
|
148 | + * @return bool True if the value was inserted or updated, false if the value was the same |
|
149 | + */ |
|
150 | + public function setValue($app, $key, $value) { |
|
151 | + if (!$this->hasKey($app, $key)) { |
|
152 | + $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
153 | + 'appid' => $app, |
|
154 | + 'configkey' => $key, |
|
155 | + 'configvalue' => $value, |
|
156 | + ], [ |
|
157 | + 'appid', |
|
158 | + 'configkey', |
|
159 | + ]); |
|
160 | + |
|
161 | + if ($inserted) { |
|
162 | + if (!isset($this->cache[$app])) { |
|
163 | + $this->cache[$app] = []; |
|
164 | + } |
|
165 | + |
|
166 | + $this->cache[$app][$key] = $value; |
|
167 | + return true; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + $sql = $this->conn->getQueryBuilder(); |
|
172 | + $sql->update('appconfig') |
|
173 | + ->set('configvalue', $sql->createParameter('configvalue')) |
|
174 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
175 | + ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
176 | + ->setParameter('configvalue', $value) |
|
177 | + ->setParameter('app', $app) |
|
178 | + ->setParameter('configkey', $key); |
|
179 | + |
|
180 | + /* |
|
181 | 181 | * Only limit to the existing value for non-Oracle DBs: |
182 | 182 | * http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286 |
183 | 183 | * > Large objects (LOBs) are not supported in comparison conditions. |
184 | 184 | */ |
185 | - if (!($this->conn instanceof \OC\DB\OracleConnection)) { |
|
186 | - // Only update the value when it is not the same |
|
187 | - $sql->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue'))) |
|
188 | - ->setParameter('configvalue', $value); |
|
189 | - } |
|
190 | - |
|
191 | - $changedRow = (bool) $sql->execute(); |
|
192 | - |
|
193 | - $this->cache[$app][$key] = $value; |
|
194 | - |
|
195 | - return $changedRow; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Deletes a key |
|
200 | - * |
|
201 | - * @param string $app app |
|
202 | - * @param string $key key |
|
203 | - * @return boolean|null |
|
204 | - */ |
|
205 | - public function deleteKey($app, $key) { |
|
206 | - $this->loadConfigValues(); |
|
207 | - |
|
208 | - $sql = $this->conn->getQueryBuilder(); |
|
209 | - $sql->delete('appconfig') |
|
210 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
211 | - ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
212 | - ->setParameter('app', $app) |
|
213 | - ->setParameter('configkey', $key); |
|
214 | - $sql->execute(); |
|
215 | - |
|
216 | - unset($this->cache[$app][$key]); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Remove app from appconfig |
|
221 | - * |
|
222 | - * @param string $app app |
|
223 | - * @return boolean|null |
|
224 | - * |
|
225 | - * Removes all keys in appconfig belonging to the app. |
|
226 | - */ |
|
227 | - public function deleteApp($app) { |
|
228 | - $this->loadConfigValues(); |
|
229 | - |
|
230 | - $sql = $this->conn->getQueryBuilder(); |
|
231 | - $sql->delete('appconfig') |
|
232 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
233 | - ->setParameter('app', $app); |
|
234 | - $sql->execute(); |
|
235 | - |
|
236 | - unset($this->cache[$app]); |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
241 | - * |
|
242 | - * @param string|false $app |
|
243 | - * @param string|false $key |
|
244 | - * @return array|false |
|
245 | - */ |
|
246 | - public function getValues($app, $key) { |
|
247 | - if (($app !== false) === ($key !== false)) { |
|
248 | - return false; |
|
249 | - } |
|
250 | - |
|
251 | - if ($key === false) { |
|
252 | - return $this->getAppValues($app); |
|
253 | - } else { |
|
254 | - $appIds = $this->getApps(); |
|
255 | - $values = array_map(function($appId) use ($key) { |
|
256 | - return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
257 | - }, $appIds); |
|
258 | - $result = array_combine($appIds, $values); |
|
259 | - |
|
260 | - return array_filter($result); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Load all the app config values |
|
266 | - */ |
|
267 | - protected function loadConfigValues() { |
|
268 | - if ($this->configLoaded) return; |
|
269 | - |
|
270 | - $this->cache = []; |
|
271 | - |
|
272 | - $sql = $this->conn->getQueryBuilder(); |
|
273 | - $sql->select('*') |
|
274 | - ->from('appconfig'); |
|
275 | - $result = $sql->execute(); |
|
276 | - |
|
277 | - while ($row = $result->fetch()) { |
|
278 | - if (!isset($this->cache[$row['appid']])) { |
|
279 | - $this->cache[$row['appid']] = []; |
|
280 | - } |
|
281 | - |
|
282 | - $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
283 | - } |
|
284 | - $result->closeCursor(); |
|
285 | - |
|
286 | - $this->configLoaded = true; |
|
287 | - } |
|
185 | + if (!($this->conn instanceof \OC\DB\OracleConnection)) { |
|
186 | + // Only update the value when it is not the same |
|
187 | + $sql->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue'))) |
|
188 | + ->setParameter('configvalue', $value); |
|
189 | + } |
|
190 | + |
|
191 | + $changedRow = (bool) $sql->execute(); |
|
192 | + |
|
193 | + $this->cache[$app][$key] = $value; |
|
194 | + |
|
195 | + return $changedRow; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Deletes a key |
|
200 | + * |
|
201 | + * @param string $app app |
|
202 | + * @param string $key key |
|
203 | + * @return boolean|null |
|
204 | + */ |
|
205 | + public function deleteKey($app, $key) { |
|
206 | + $this->loadConfigValues(); |
|
207 | + |
|
208 | + $sql = $this->conn->getQueryBuilder(); |
|
209 | + $sql->delete('appconfig') |
|
210 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
211 | + ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
212 | + ->setParameter('app', $app) |
|
213 | + ->setParameter('configkey', $key); |
|
214 | + $sql->execute(); |
|
215 | + |
|
216 | + unset($this->cache[$app][$key]); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Remove app from appconfig |
|
221 | + * |
|
222 | + * @param string $app app |
|
223 | + * @return boolean|null |
|
224 | + * |
|
225 | + * Removes all keys in appconfig belonging to the app. |
|
226 | + */ |
|
227 | + public function deleteApp($app) { |
|
228 | + $this->loadConfigValues(); |
|
229 | + |
|
230 | + $sql = $this->conn->getQueryBuilder(); |
|
231 | + $sql->delete('appconfig') |
|
232 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
233 | + ->setParameter('app', $app); |
|
234 | + $sql->execute(); |
|
235 | + |
|
236 | + unset($this->cache[$app]); |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
241 | + * |
|
242 | + * @param string|false $app |
|
243 | + * @param string|false $key |
|
244 | + * @return array|false |
|
245 | + */ |
|
246 | + public function getValues($app, $key) { |
|
247 | + if (($app !== false) === ($key !== false)) { |
|
248 | + return false; |
|
249 | + } |
|
250 | + |
|
251 | + if ($key === false) { |
|
252 | + return $this->getAppValues($app); |
|
253 | + } else { |
|
254 | + $appIds = $this->getApps(); |
|
255 | + $values = array_map(function($appId) use ($key) { |
|
256 | + return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
257 | + }, $appIds); |
|
258 | + $result = array_combine($appIds, $values); |
|
259 | + |
|
260 | + return array_filter($result); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Load all the app config values |
|
266 | + */ |
|
267 | + protected function loadConfigValues() { |
|
268 | + if ($this->configLoaded) return; |
|
269 | + |
|
270 | + $this->cache = []; |
|
271 | + |
|
272 | + $sql = $this->conn->getQueryBuilder(); |
|
273 | + $sql->select('*') |
|
274 | + ->from('appconfig'); |
|
275 | + $result = $sql->execute(); |
|
276 | + |
|
277 | + while ($row = $result->fetch()) { |
|
278 | + if (!isset($this->cache[$row['appid']])) { |
|
279 | + $this->cache[$row['appid']] = []; |
|
280 | + } |
|
281 | + |
|
282 | + $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
283 | + } |
|
284 | + $result->closeCursor(); |
|
285 | + |
|
286 | + $this->configLoaded = true; |
|
287 | + } |
|
288 | 288 | } |
@@ -265,7 +265,9 @@ |
||
265 | 265 | * Load all the app config values |
266 | 266 | */ |
267 | 267 | protected function loadConfigValues() { |
268 | - if ($this->configLoaded) return; |
|
268 | + if ($this->configLoaded) { |
|
269 | + return; |
|
270 | + } |
|
269 | 271 | |
270 | 272 | $this->cache = []; |
271 | 273 |
@@ -24,23 +24,23 @@ |
||
24 | 24 | namespace OC\Template; |
25 | 25 | |
26 | 26 | class ResourceNotFoundException extends \LogicException { |
27 | - protected $resource; |
|
28 | - protected $webPath; |
|
27 | + protected $resource; |
|
28 | + protected $webPath; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $resource |
|
32 | - * @param string $webPath |
|
33 | - */ |
|
34 | - public function __construct($resource, $webPath) { |
|
35 | - parent::__construct('Resource not found'); |
|
36 | - $this->resource = $resource; |
|
37 | - $this->webPath = $webPath; |
|
38 | - } |
|
30 | + /** |
|
31 | + * @param string $resource |
|
32 | + * @param string $webPath |
|
33 | + */ |
|
34 | + public function __construct($resource, $webPath) { |
|
35 | + parent::__construct('Resource not found'); |
|
36 | + $this->resource = $resource; |
|
37 | + $this->webPath = $webPath; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function getResourcePath() { |
|
44 | - return $this->webPath . '/' . $this->resource; |
|
45 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function getResourcePath() { |
|
44 | + return $this->webPath . '/' . $this->resource; |
|
45 | + } |
|
46 | 46 | } |
@@ -41,6 +41,6 @@ |
||
41 | 41 | * @return string |
42 | 42 | */ |
43 | 43 | public function getResourcePath() { |
44 | - return $this->webPath . '/' . $this->resource; |
|
44 | + return $this->webPath.'/'.$this->resource; |
|
45 | 45 | } |
46 | 46 | } |
@@ -27,110 +27,110 @@ |
||
27 | 27 | namespace OC\Template; |
28 | 28 | |
29 | 29 | abstract class ResourceLocator { |
30 | - protected $theme; |
|
30 | + protected $theme; |
|
31 | 31 | |
32 | - protected $mapping; |
|
33 | - protected $serverroot; |
|
34 | - protected $thirdpartyroot; |
|
35 | - protected $webroot; |
|
32 | + protected $mapping; |
|
33 | + protected $serverroot; |
|
34 | + protected $thirdpartyroot; |
|
35 | + protected $webroot; |
|
36 | 36 | |
37 | - protected $resources = array(); |
|
37 | + protected $resources = array(); |
|
38 | 38 | |
39 | - /** @var \OCP\ILogger */ |
|
40 | - protected $logger; |
|
39 | + /** @var \OCP\ILogger */ |
|
40 | + protected $logger; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param \OCP\ILogger $logger |
|
44 | - * @param string $theme |
|
45 | - * @param array $core_map |
|
46 | - * @param array $party_map |
|
47 | - */ |
|
48 | - public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
49 | - $this->logger = $logger; |
|
50 | - $this->theme = $theme; |
|
51 | - $this->mapping = $core_map + $party_map; |
|
52 | - $this->serverroot = key($core_map); |
|
53 | - $this->thirdpartyroot = key($party_map); |
|
54 | - $this->webroot = $this->mapping[$this->serverroot]; |
|
55 | - } |
|
42 | + /** |
|
43 | + * @param \OCP\ILogger $logger |
|
44 | + * @param string $theme |
|
45 | + * @param array $core_map |
|
46 | + * @param array $party_map |
|
47 | + */ |
|
48 | + public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
49 | + $this->logger = $logger; |
|
50 | + $this->theme = $theme; |
|
51 | + $this->mapping = $core_map + $party_map; |
|
52 | + $this->serverroot = key($core_map); |
|
53 | + $this->thirdpartyroot = key($party_map); |
|
54 | + $this->webroot = $this->mapping[$this->serverroot]; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param string $resource |
|
59 | - */ |
|
60 | - abstract public function doFind($resource); |
|
57 | + /** |
|
58 | + * @param string $resource |
|
59 | + */ |
|
60 | + abstract public function doFind($resource); |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $resource |
|
64 | - */ |
|
65 | - abstract public function doFindTheme($resource); |
|
62 | + /** |
|
63 | + * @param string $resource |
|
64 | + */ |
|
65 | + abstract public function doFindTheme($resource); |
|
66 | 66 | |
67 | - /** |
|
68 | - * Finds the resources and adds them to the list |
|
69 | - * |
|
70 | - * @param array $resources |
|
71 | - */ |
|
72 | - public function find($resources) { |
|
73 | - foreach ($resources as $resource) { |
|
74 | - try { |
|
75 | - $this->doFind($resource); |
|
76 | - } catch (ResourceNotFoundException $e) { |
|
77 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
78 | - $this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
79 | - } |
|
80 | - } |
|
81 | - if (!empty($this->theme)) { |
|
82 | - foreach ($resources as $resource) { |
|
83 | - try { |
|
84 | - $this->doFindTheme($resource); |
|
85 | - } catch (ResourceNotFoundException $e) { |
|
86 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
87 | - $this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
67 | + /** |
|
68 | + * Finds the resources and adds them to the list |
|
69 | + * |
|
70 | + * @param array $resources |
|
71 | + */ |
|
72 | + public function find($resources) { |
|
73 | + foreach ($resources as $resource) { |
|
74 | + try { |
|
75 | + $this->doFind($resource); |
|
76 | + } catch (ResourceNotFoundException $e) { |
|
77 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
78 | + $this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
79 | + } |
|
80 | + } |
|
81 | + if (!empty($this->theme)) { |
|
82 | + foreach ($resources as $resource) { |
|
83 | + try { |
|
84 | + $this->doFindTheme($resource); |
|
85 | + } catch (ResourceNotFoundException $e) { |
|
86 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
87 | + $this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * append the $file resource if exist at $root |
|
95 | - * |
|
96 | - * @param string $root path to check |
|
97 | - * @param string $file the filename |
|
98 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
99 | - * @return bool True if the resource was found, false otherwise |
|
100 | - */ |
|
101 | - protected function appendIfExist($root, $file, $webRoot = null) { |
|
102 | - if (is_file($root.'/'.$file)) { |
|
103 | - $this->append($root, $file, $webRoot, false); |
|
104 | - return true; |
|
105 | - } |
|
106 | - return false; |
|
107 | - } |
|
93 | + /** |
|
94 | + * append the $file resource if exist at $root |
|
95 | + * |
|
96 | + * @param string $root path to check |
|
97 | + * @param string $file the filename |
|
98 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
99 | + * @return bool True if the resource was found, false otherwise |
|
100 | + */ |
|
101 | + protected function appendIfExist($root, $file, $webRoot = null) { |
|
102 | + if (is_file($root.'/'.$file)) { |
|
103 | + $this->append($root, $file, $webRoot, false); |
|
104 | + return true; |
|
105 | + } |
|
106 | + return false; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * append the $file resource at $root |
|
111 | - * |
|
112 | - * @param string $root path to check |
|
113 | - * @param string $file the filename |
|
114 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
115 | - * @param bool $throw Throw an exception, when the route does not exist |
|
116 | - * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
117 | - */ |
|
118 | - protected function append($root, $file, $webRoot = null, $throw = true) { |
|
119 | - if (!$webRoot) { |
|
120 | - $webRoot = $this->mapping[$root]; |
|
121 | - } |
|
122 | - $this->resources[] = array($root, $webRoot, $file); |
|
109 | + /** |
|
110 | + * append the $file resource at $root |
|
111 | + * |
|
112 | + * @param string $root path to check |
|
113 | + * @param string $file the filename |
|
114 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
115 | + * @param bool $throw Throw an exception, when the route does not exist |
|
116 | + * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
117 | + */ |
|
118 | + protected function append($root, $file, $webRoot = null, $throw = true) { |
|
119 | + if (!$webRoot) { |
|
120 | + $webRoot = $this->mapping[$root]; |
|
121 | + } |
|
122 | + $this->resources[] = array($root, $webRoot, $file); |
|
123 | 123 | |
124 | - if ($throw && !is_file($root . '/' . $file)) { |
|
125 | - throw new ResourceNotFoundException($file, $webRoot); |
|
126 | - } |
|
127 | - } |
|
124 | + if ($throw && !is_file($root . '/' . $file)) { |
|
125 | + throw new ResourceNotFoundException($file, $webRoot); |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Returns the list of all resources that should be loaded |
|
131 | - * @return array |
|
132 | - */ |
|
133 | - public function getResources() { |
|
134 | - return $this->resources; |
|
135 | - } |
|
129 | + /** |
|
130 | + * Returns the list of all resources that should be loaded |
|
131 | + * @return array |
|
132 | + */ |
|
133 | + public function getResources() { |
|
134 | + return $this->resources; |
|
135 | + } |
|
136 | 136 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->doFind($resource); |
76 | 76 | } catch (ResourceNotFoundException $e) { |
77 | 77 | $resourceApp = substr($resource, 0, strpos($resource, '/')); |
78 | - $this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
78 | + $this->logger->error('Could not find resource file "'.$e->getResourcePath().'"', ['app' => $resourceApp]); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | if (!empty($this->theme)) { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $this->doFindTheme($resource); |
85 | 85 | } catch (ResourceNotFoundException $e) { |
86 | 86 | $resourceApp = substr($resource, 0, strpos($resource, '/')); |
87 | - $this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
87 | + $this->logger->error('Could not find resource file "'.$e->getResourcePath().'"', ['app' => $resourceApp]); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | $this->resources[] = array($root, $webRoot, $file); |
123 | 123 | |
124 | - if ($throw && !is_file($root . '/' . $file)) { |
|
124 | + if ($throw && !is_file($root.'/'.$file)) { |
|
125 | 125 | throw new ResourceNotFoundException($file, $webRoot); |
126 | 126 | } |
127 | 127 | } |