@@ -412,7 +412,7 @@ |
||
412 | 412 | $appDir = OC_App::getInstallPath() . '/' . $appId; |
413 | 413 | OC_Helper::rmdirr($appDir); |
414 | 414 | return true; |
415 | - }else{ |
|
415 | + } else{ |
|
416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
417 | 417 | |
418 | 418 | return false; |
@@ -420,7 +420,7 @@ |
||
420 | 420 | |
421 | 421 | /** |
422 | 422 | * Check if app has been installed from git |
423 | - * @param string $name name of the application to remove |
|
423 | + * @param string $appId |
|
424 | 424 | * @return boolean |
425 | 425 | * |
426 | 426 | * The function will check if the path contains a .git folder |
@@ -52,554 +52,554 @@ |
||
52 | 52 | * This class provides the functionality needed to install, update and remove apps |
53 | 53 | */ |
54 | 54 | class Installer { |
55 | - /** @var AppFetcher */ |
|
56 | - private $appFetcher; |
|
57 | - /** @var IClientService */ |
|
58 | - private $clientService; |
|
59 | - /** @var ITempManager */ |
|
60 | - private $tempManager; |
|
61 | - /** @var ILogger */ |
|
62 | - private $logger; |
|
63 | - /** @var IConfig */ |
|
64 | - private $config; |
|
65 | - /** @var array - for caching the result of app fetcher */ |
|
66 | - private $apps = null; |
|
67 | - /** @var bool|null - for caching the result of the ready status */ |
|
68 | - private $isInstanceReadyForUpdates = null; |
|
69 | - |
|
70 | - /** |
|
71 | - * @param AppFetcher $appFetcher |
|
72 | - * @param IClientService $clientService |
|
73 | - * @param ITempManager $tempManager |
|
74 | - * @param ILogger $logger |
|
75 | - * @param IConfig $config |
|
76 | - */ |
|
77 | - public function __construct(AppFetcher $appFetcher, |
|
78 | - IClientService $clientService, |
|
79 | - ITempManager $tempManager, |
|
80 | - ILogger $logger, |
|
81 | - IConfig $config) { |
|
82 | - $this->appFetcher = $appFetcher; |
|
83 | - $this->clientService = $clientService; |
|
84 | - $this->tempManager = $tempManager; |
|
85 | - $this->logger = $logger; |
|
86 | - $this->config = $config; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Installs an app that is located in one of the app folders already |
|
91 | - * |
|
92 | - * @param string $appId App to install |
|
93 | - * @throws \Exception |
|
94 | - * @return string app ID |
|
95 | - */ |
|
96 | - public function installApp($appId) { |
|
97 | - $app = \OC_App::findAppInDirectories($appId); |
|
98 | - if($app === false) { |
|
99 | - throw new \Exception('App not found in any app directory'); |
|
100 | - } |
|
101 | - |
|
102 | - $basedir = $app['path'].'/'.$appId; |
|
103 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
104 | - |
|
105 | - $l = \OC::$server->getL10N('core'); |
|
106 | - |
|
107 | - if(!is_array($info)) { |
|
108 | - throw new \Exception( |
|
109 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
110 | - [$appId] |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - $version = implode('.', \OCP\Util::getVersion()); |
|
116 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
117 | - throw new \Exception( |
|
118 | - // TODO $l |
|
119 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
120 | - [$info['name']] |
|
121 | - ) |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - // check for required dependencies |
|
126 | - \OC_App::checkAppDependencies($this->config, $l, $info); |
|
127 | - \OC_App::registerAutoloading($appId, $basedir); |
|
128 | - |
|
129 | - //install the database |
|
130 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
131 | - if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
132 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
133 | - } else { |
|
134 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
135 | - } |
|
136 | - } else { |
|
137 | - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
138 | - $ms->migrate(); |
|
139 | - } |
|
140 | - |
|
141 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
142 | - |
|
143 | - //run appinfo/install.php |
|
144 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
145 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
146 | - } |
|
147 | - |
|
148 | - $appData = OC_App::getAppInfo($appId); |
|
149 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
150 | - |
|
151 | - //set the installed version |
|
152 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
153 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
154 | - |
|
155 | - //set remote/public handlers |
|
156 | - foreach($info['remote'] as $name=>$path) { |
|
157 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
158 | - } |
|
159 | - foreach($info['public'] as $name=>$path) { |
|
160 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
161 | - } |
|
162 | - |
|
163 | - OC_App::setAppTypes($info['id']); |
|
164 | - |
|
165 | - return $info['id']; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Updates the specified app from the appstore |
|
170 | - * |
|
171 | - * @param string $appId |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function updateAppstoreApp($appId) { |
|
175 | - if($this->isUpdateAvailable($appId)) { |
|
176 | - try { |
|
177 | - $this->downloadApp($appId); |
|
178 | - } catch (\Exception $e) { |
|
179 | - $this->logger->logException($e, [ |
|
180 | - 'level' => \OCP\Util::ERROR, |
|
181 | - 'app' => 'core', |
|
182 | - ]); |
|
183 | - return false; |
|
184 | - } |
|
185 | - return OC_App::updateApp($appId); |
|
186 | - } |
|
187 | - |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Downloads an app and puts it into the app directory |
|
193 | - * |
|
194 | - * @param string $appId |
|
195 | - * |
|
196 | - * @throws \Exception If the installation was not successful |
|
197 | - */ |
|
198 | - public function downloadApp($appId) { |
|
199 | - $appId = strtolower($appId); |
|
200 | - |
|
201 | - $apps = $this->appFetcher->get(); |
|
202 | - foreach($apps as $app) { |
|
203 | - if($app['id'] === $appId) { |
|
204 | - // Load the certificate |
|
205 | - $certificate = new X509(); |
|
206 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
207 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
208 | - |
|
209 | - // Verify if the certificate has been revoked |
|
210 | - $crl = new X509(); |
|
211 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
212 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
213 | - if($crl->validateSignature() !== true) { |
|
214 | - throw new \Exception('Could not validate CRL signature'); |
|
215 | - } |
|
216 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
217 | - $revoked = $crl->getRevoked($csn); |
|
218 | - if ($revoked !== false) { |
|
219 | - throw new \Exception( |
|
220 | - sprintf( |
|
221 | - 'Certificate "%s" has been revoked', |
|
222 | - $csn |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
228 | - if($certificate->validateSignature() !== true) { |
|
229 | - throw new \Exception( |
|
230 | - sprintf( |
|
231 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
232 | - $appId |
|
233 | - ) |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - // Verify if the certificate is issued for the requested app id |
|
238 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
239 | - if(!isset($certInfo['subject']['CN'])) { |
|
240 | - throw new \Exception( |
|
241 | - sprintf( |
|
242 | - 'App with id %s has a cert with no CN', |
|
243 | - $appId |
|
244 | - ) |
|
245 | - ); |
|
246 | - } |
|
247 | - if($certInfo['subject']['CN'] !== $appId) { |
|
248 | - throw new \Exception( |
|
249 | - sprintf( |
|
250 | - 'App with id %s has a cert issued to %s', |
|
251 | - $appId, |
|
252 | - $certInfo['subject']['CN'] |
|
253 | - ) |
|
254 | - ); |
|
255 | - } |
|
256 | - |
|
257 | - // Download the release |
|
258 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
259 | - $client = $this->clientService->newClient(); |
|
260 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
261 | - |
|
262 | - // Check if the signature actually matches the downloaded content |
|
263 | - $certificate = openssl_get_publickey($app['certificate']); |
|
264 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
265 | - openssl_free_key($certificate); |
|
266 | - |
|
267 | - if($verified === true) { |
|
268 | - // Seems to match, let's proceed |
|
269 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
270 | - $archive = new TAR($tempFile); |
|
271 | - |
|
272 | - if($archive) { |
|
273 | - if (!$archive->extract($extractDir)) { |
|
274 | - throw new \Exception( |
|
275 | - sprintf( |
|
276 | - 'Could not extract app %s', |
|
277 | - $appId |
|
278 | - ) |
|
279 | - ); |
|
280 | - } |
|
281 | - $allFiles = scandir($extractDir); |
|
282 | - $folders = array_diff($allFiles, ['.', '..']); |
|
283 | - $folders = array_values($folders); |
|
284 | - |
|
285 | - if(count($folders) > 1) { |
|
286 | - throw new \Exception( |
|
287 | - sprintf( |
|
288 | - 'Extracted app %s has more than 1 folder', |
|
289 | - $appId |
|
290 | - ) |
|
291 | - ); |
|
292 | - } |
|
293 | - |
|
294 | - // Check if appinfo/info.xml has the same app ID as well |
|
295 | - $loadEntities = libxml_disable_entity_loader(false); |
|
296 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
297 | - libxml_disable_entity_loader($loadEntities); |
|
298 | - if((string)$xml->id !== $appId) { |
|
299 | - throw new \Exception( |
|
300 | - sprintf( |
|
301 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
302 | - $appId, |
|
303 | - (string)$xml->id |
|
304 | - ) |
|
305 | - ); |
|
306 | - } |
|
307 | - |
|
308 | - // Check if the version is lower than before |
|
309 | - $currentVersion = OC_App::getAppVersion($appId); |
|
310 | - $newVersion = (string)$xml->version; |
|
311 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
312 | - throw new \Exception( |
|
313 | - sprintf( |
|
314 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
315 | - $appId, |
|
316 | - $currentVersion, |
|
317 | - $newVersion |
|
318 | - ) |
|
319 | - ); |
|
320 | - } |
|
321 | - |
|
322 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
323 | - // Remove old app with the ID if existent |
|
324 | - OC_Helper::rmdirr($baseDir); |
|
325 | - // Move to app folder |
|
326 | - if(@mkdir($baseDir)) { |
|
327 | - $extractDir .= '/' . $folders[0]; |
|
328 | - OC_Helper::copyr($extractDir, $baseDir); |
|
329 | - } |
|
330 | - OC_Helper::copyr($extractDir, $baseDir); |
|
331 | - OC_Helper::rmdirr($extractDir); |
|
332 | - return; |
|
333 | - } else { |
|
334 | - throw new \Exception( |
|
335 | - sprintf( |
|
336 | - 'Could not extract app with ID %s to %s', |
|
337 | - $appId, |
|
338 | - $extractDir |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - } else { |
|
343 | - // Signature does not match |
|
344 | - throw new \Exception( |
|
345 | - sprintf( |
|
346 | - 'App with id %s has invalid signature', |
|
347 | - $appId |
|
348 | - ) |
|
349 | - ); |
|
350 | - } |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - throw new \Exception( |
|
355 | - sprintf( |
|
356 | - 'Could not download app %s', |
|
357 | - $appId |
|
358 | - ) |
|
359 | - ); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Check if an update for the app is available |
|
364 | - * |
|
365 | - * @param string $appId |
|
366 | - * @return string|false false or the version number of the update |
|
367 | - */ |
|
368 | - public function isUpdateAvailable($appId) { |
|
369 | - if ($this->isInstanceReadyForUpdates === null) { |
|
370 | - $installPath = OC_App::getInstallPath(); |
|
371 | - if ($installPath === false || $installPath === null) { |
|
372 | - $this->isInstanceReadyForUpdates = false; |
|
373 | - } else { |
|
374 | - $this->isInstanceReadyForUpdates = true; |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - if ($this->isInstanceReadyForUpdates === false) { |
|
379 | - return false; |
|
380 | - } |
|
381 | - |
|
382 | - if ($this->isInstalledFromGit($appId) === true) { |
|
383 | - return false; |
|
384 | - } |
|
385 | - |
|
386 | - if ($this->apps === null) { |
|
387 | - $this->apps = $this->appFetcher->get(); |
|
388 | - } |
|
389 | - |
|
390 | - foreach($this->apps as $app) { |
|
391 | - if($app['id'] === $appId) { |
|
392 | - $currentVersion = OC_App::getAppVersion($appId); |
|
393 | - $newestVersion = $app['releases'][0]['version']; |
|
394 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
395 | - return $newestVersion; |
|
396 | - } else { |
|
397 | - return false; |
|
398 | - } |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - return false; |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Check if app has been installed from git |
|
407 | - * @param string $name name of the application to remove |
|
408 | - * @return boolean |
|
409 | - * |
|
410 | - * The function will check if the path contains a .git folder |
|
411 | - */ |
|
412 | - private function isInstalledFromGit($appId) { |
|
413 | - $app = \OC_App::findAppInDirectories($appId); |
|
414 | - if($app === false) { |
|
415 | - return false; |
|
416 | - } |
|
417 | - $basedir = $app['path'].'/'.$appId; |
|
418 | - return file_exists($basedir.'/.git/'); |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Check if app is already downloaded |
|
423 | - * @param string $name name of the application to remove |
|
424 | - * @return boolean |
|
425 | - * |
|
426 | - * The function will check if the app is already downloaded in the apps repository |
|
427 | - */ |
|
428 | - public function isDownloaded($name) { |
|
429 | - foreach(\OC::$APPSROOTS as $dir) { |
|
430 | - $dirToTest = $dir['path']; |
|
431 | - $dirToTest .= '/'; |
|
432 | - $dirToTest .= $name; |
|
433 | - $dirToTest .= '/'; |
|
434 | - |
|
435 | - if (is_dir($dirToTest)) { |
|
436 | - return true; |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - return false; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Removes an app |
|
445 | - * @param string $appId ID of the application to remove |
|
446 | - * @return boolean |
|
447 | - * |
|
448 | - * |
|
449 | - * This function works as follows |
|
450 | - * -# call uninstall repair steps |
|
451 | - * -# removing the files |
|
452 | - * |
|
453 | - * The function will not delete preferences, tables and the configuration, |
|
454 | - * this has to be done by the function oc_app_uninstall(). |
|
455 | - */ |
|
456 | - public function removeApp($appId) { |
|
457 | - if($this->isDownloaded( $appId )) { |
|
458 | - if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
459 | - return false; |
|
460 | - } |
|
461 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
462 | - OC_Helper::rmdirr($appDir); |
|
463 | - return true; |
|
464 | - }else{ |
|
465 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
466 | - |
|
467 | - return false; |
|
468 | - } |
|
469 | - |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Installs the app within the bundle and marks the bundle as installed |
|
474 | - * |
|
475 | - * @param Bundle $bundle |
|
476 | - * @throws \Exception If app could not get installed |
|
477 | - */ |
|
478 | - public function installAppBundle(Bundle $bundle) { |
|
479 | - $appIds = $bundle->getAppIdentifiers(); |
|
480 | - foreach($appIds as $appId) { |
|
481 | - if(!$this->isDownloaded($appId)) { |
|
482 | - $this->downloadApp($appId); |
|
483 | - } |
|
484 | - $this->installApp($appId); |
|
485 | - $app = new OC_App(); |
|
486 | - $app->enable($appId); |
|
487 | - } |
|
488 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
489 | - $bundles[] = $bundle->getIdentifier(); |
|
490 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Installs shipped apps |
|
495 | - * |
|
496 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
497 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
498 | - * working ownCloud at the end instead of an aborted update. |
|
499 | - * @return array Array of error messages (appid => Exception) |
|
500 | - */ |
|
501 | - public static function installShippedApps($softErrors = false) { |
|
502 | - $appManager = \OC::$server->getAppManager(); |
|
503 | - $config = \OC::$server->getConfig(); |
|
504 | - $errors = []; |
|
505 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
506 | - if($dir = opendir( $app_dir['path'] )) { |
|
507 | - while( false !== ( $filename = readdir( $dir ))) { |
|
508 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
509 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
510 | - if($config->getAppValue($filename, "installed_version", null) === null) { |
|
511 | - $info=OC_App::getAppInfo($filename); |
|
512 | - $enabled = isset($info['default_enable']); |
|
513 | - if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
|
514 | - && $config->getAppValue($filename, 'enabled') !== 'no') { |
|
515 | - if ($softErrors) { |
|
516 | - try { |
|
517 | - Installer::installShippedApp($filename); |
|
518 | - } catch (HintException $e) { |
|
519 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
520 | - $errors[$filename] = $e; |
|
521 | - continue; |
|
522 | - } |
|
523 | - throw $e; |
|
524 | - } |
|
525 | - } else { |
|
526 | - Installer::installShippedApp($filename); |
|
527 | - } |
|
528 | - $config->setAppValue($filename, 'enabled', 'yes'); |
|
529 | - } |
|
530 | - } |
|
531 | - } |
|
532 | - } |
|
533 | - } |
|
534 | - closedir( $dir ); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - return $errors; |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * install an app already placed in the app folder |
|
543 | - * @param string $app id of the app to install |
|
544 | - * @return integer |
|
545 | - */ |
|
546 | - public static function installShippedApp($app) { |
|
547 | - //install the database |
|
548 | - $appPath = OC_App::getAppPath($app); |
|
549 | - \OC_App::registerAutoloading($app, $appPath); |
|
550 | - |
|
551 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
552 | - try { |
|
553 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
554 | - } catch (TableExistsException $e) { |
|
555 | - throw new HintException( |
|
556 | - 'Failed to enable app ' . $app, |
|
557 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
558 | - 0, $e |
|
559 | - ); |
|
560 | - } |
|
561 | - } else { |
|
562 | - $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
563 | - $ms->migrate(); |
|
564 | - } |
|
565 | - |
|
566 | - //run appinfo/install.php |
|
567 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
568 | - |
|
569 | - $info = OC_App::getAppInfo($app); |
|
570 | - if (is_null($info)) { |
|
571 | - return false; |
|
572 | - } |
|
573 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
574 | - |
|
575 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
576 | - |
|
577 | - $config = \OC::$server->getConfig(); |
|
578 | - |
|
579 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
580 | - if (array_key_exists('ocsid', $info)) { |
|
581 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
582 | - } |
|
583 | - |
|
584 | - //set remote/public handlers |
|
585 | - foreach($info['remote'] as $name=>$path) { |
|
586 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
587 | - } |
|
588 | - foreach($info['public'] as $name=>$path) { |
|
589 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
590 | - } |
|
591 | - |
|
592 | - OC_App::setAppTypes($info['id']); |
|
593 | - |
|
594 | - return $info['id']; |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * @param string $script |
|
599 | - */ |
|
600 | - private static function includeAppScript($script) { |
|
601 | - if ( file_exists($script) ){ |
|
602 | - include $script; |
|
603 | - } |
|
604 | - } |
|
55 | + /** @var AppFetcher */ |
|
56 | + private $appFetcher; |
|
57 | + /** @var IClientService */ |
|
58 | + private $clientService; |
|
59 | + /** @var ITempManager */ |
|
60 | + private $tempManager; |
|
61 | + /** @var ILogger */ |
|
62 | + private $logger; |
|
63 | + /** @var IConfig */ |
|
64 | + private $config; |
|
65 | + /** @var array - for caching the result of app fetcher */ |
|
66 | + private $apps = null; |
|
67 | + /** @var bool|null - for caching the result of the ready status */ |
|
68 | + private $isInstanceReadyForUpdates = null; |
|
69 | + |
|
70 | + /** |
|
71 | + * @param AppFetcher $appFetcher |
|
72 | + * @param IClientService $clientService |
|
73 | + * @param ITempManager $tempManager |
|
74 | + * @param ILogger $logger |
|
75 | + * @param IConfig $config |
|
76 | + */ |
|
77 | + public function __construct(AppFetcher $appFetcher, |
|
78 | + IClientService $clientService, |
|
79 | + ITempManager $tempManager, |
|
80 | + ILogger $logger, |
|
81 | + IConfig $config) { |
|
82 | + $this->appFetcher = $appFetcher; |
|
83 | + $this->clientService = $clientService; |
|
84 | + $this->tempManager = $tempManager; |
|
85 | + $this->logger = $logger; |
|
86 | + $this->config = $config; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Installs an app that is located in one of the app folders already |
|
91 | + * |
|
92 | + * @param string $appId App to install |
|
93 | + * @throws \Exception |
|
94 | + * @return string app ID |
|
95 | + */ |
|
96 | + public function installApp($appId) { |
|
97 | + $app = \OC_App::findAppInDirectories($appId); |
|
98 | + if($app === false) { |
|
99 | + throw new \Exception('App not found in any app directory'); |
|
100 | + } |
|
101 | + |
|
102 | + $basedir = $app['path'].'/'.$appId; |
|
103 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
104 | + |
|
105 | + $l = \OC::$server->getL10N('core'); |
|
106 | + |
|
107 | + if(!is_array($info)) { |
|
108 | + throw new \Exception( |
|
109 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
110 | + [$appId] |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + $version = implode('.', \OCP\Util::getVersion()); |
|
116 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
117 | + throw new \Exception( |
|
118 | + // TODO $l |
|
119 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
120 | + [$info['name']] |
|
121 | + ) |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + // check for required dependencies |
|
126 | + \OC_App::checkAppDependencies($this->config, $l, $info); |
|
127 | + \OC_App::registerAutoloading($appId, $basedir); |
|
128 | + |
|
129 | + //install the database |
|
130 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
131 | + if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
132 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
133 | + } else { |
|
134 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
135 | + } |
|
136 | + } else { |
|
137 | + $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
138 | + $ms->migrate(); |
|
139 | + } |
|
140 | + |
|
141 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
142 | + |
|
143 | + //run appinfo/install.php |
|
144 | + if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
145 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
146 | + } |
|
147 | + |
|
148 | + $appData = OC_App::getAppInfo($appId); |
|
149 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
150 | + |
|
151 | + //set the installed version |
|
152 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
153 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
154 | + |
|
155 | + //set remote/public handlers |
|
156 | + foreach($info['remote'] as $name=>$path) { |
|
157 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
158 | + } |
|
159 | + foreach($info['public'] as $name=>$path) { |
|
160 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
161 | + } |
|
162 | + |
|
163 | + OC_App::setAppTypes($info['id']); |
|
164 | + |
|
165 | + return $info['id']; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Updates the specified app from the appstore |
|
170 | + * |
|
171 | + * @param string $appId |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function updateAppstoreApp($appId) { |
|
175 | + if($this->isUpdateAvailable($appId)) { |
|
176 | + try { |
|
177 | + $this->downloadApp($appId); |
|
178 | + } catch (\Exception $e) { |
|
179 | + $this->logger->logException($e, [ |
|
180 | + 'level' => \OCP\Util::ERROR, |
|
181 | + 'app' => 'core', |
|
182 | + ]); |
|
183 | + return false; |
|
184 | + } |
|
185 | + return OC_App::updateApp($appId); |
|
186 | + } |
|
187 | + |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Downloads an app and puts it into the app directory |
|
193 | + * |
|
194 | + * @param string $appId |
|
195 | + * |
|
196 | + * @throws \Exception If the installation was not successful |
|
197 | + */ |
|
198 | + public function downloadApp($appId) { |
|
199 | + $appId = strtolower($appId); |
|
200 | + |
|
201 | + $apps = $this->appFetcher->get(); |
|
202 | + foreach($apps as $app) { |
|
203 | + if($app['id'] === $appId) { |
|
204 | + // Load the certificate |
|
205 | + $certificate = new X509(); |
|
206 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
207 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
208 | + |
|
209 | + // Verify if the certificate has been revoked |
|
210 | + $crl = new X509(); |
|
211 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
212 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
213 | + if($crl->validateSignature() !== true) { |
|
214 | + throw new \Exception('Could not validate CRL signature'); |
|
215 | + } |
|
216 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
217 | + $revoked = $crl->getRevoked($csn); |
|
218 | + if ($revoked !== false) { |
|
219 | + throw new \Exception( |
|
220 | + sprintf( |
|
221 | + 'Certificate "%s" has been revoked', |
|
222 | + $csn |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
228 | + if($certificate->validateSignature() !== true) { |
|
229 | + throw new \Exception( |
|
230 | + sprintf( |
|
231 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
232 | + $appId |
|
233 | + ) |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + // Verify if the certificate is issued for the requested app id |
|
238 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
239 | + if(!isset($certInfo['subject']['CN'])) { |
|
240 | + throw new \Exception( |
|
241 | + sprintf( |
|
242 | + 'App with id %s has a cert with no CN', |
|
243 | + $appId |
|
244 | + ) |
|
245 | + ); |
|
246 | + } |
|
247 | + if($certInfo['subject']['CN'] !== $appId) { |
|
248 | + throw new \Exception( |
|
249 | + sprintf( |
|
250 | + 'App with id %s has a cert issued to %s', |
|
251 | + $appId, |
|
252 | + $certInfo['subject']['CN'] |
|
253 | + ) |
|
254 | + ); |
|
255 | + } |
|
256 | + |
|
257 | + // Download the release |
|
258 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
259 | + $client = $this->clientService->newClient(); |
|
260 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
261 | + |
|
262 | + // Check if the signature actually matches the downloaded content |
|
263 | + $certificate = openssl_get_publickey($app['certificate']); |
|
264 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
265 | + openssl_free_key($certificate); |
|
266 | + |
|
267 | + if($verified === true) { |
|
268 | + // Seems to match, let's proceed |
|
269 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
270 | + $archive = new TAR($tempFile); |
|
271 | + |
|
272 | + if($archive) { |
|
273 | + if (!$archive->extract($extractDir)) { |
|
274 | + throw new \Exception( |
|
275 | + sprintf( |
|
276 | + 'Could not extract app %s', |
|
277 | + $appId |
|
278 | + ) |
|
279 | + ); |
|
280 | + } |
|
281 | + $allFiles = scandir($extractDir); |
|
282 | + $folders = array_diff($allFiles, ['.', '..']); |
|
283 | + $folders = array_values($folders); |
|
284 | + |
|
285 | + if(count($folders) > 1) { |
|
286 | + throw new \Exception( |
|
287 | + sprintf( |
|
288 | + 'Extracted app %s has more than 1 folder', |
|
289 | + $appId |
|
290 | + ) |
|
291 | + ); |
|
292 | + } |
|
293 | + |
|
294 | + // Check if appinfo/info.xml has the same app ID as well |
|
295 | + $loadEntities = libxml_disable_entity_loader(false); |
|
296 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
297 | + libxml_disable_entity_loader($loadEntities); |
|
298 | + if((string)$xml->id !== $appId) { |
|
299 | + throw new \Exception( |
|
300 | + sprintf( |
|
301 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
302 | + $appId, |
|
303 | + (string)$xml->id |
|
304 | + ) |
|
305 | + ); |
|
306 | + } |
|
307 | + |
|
308 | + // Check if the version is lower than before |
|
309 | + $currentVersion = OC_App::getAppVersion($appId); |
|
310 | + $newVersion = (string)$xml->version; |
|
311 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
312 | + throw new \Exception( |
|
313 | + sprintf( |
|
314 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
315 | + $appId, |
|
316 | + $currentVersion, |
|
317 | + $newVersion |
|
318 | + ) |
|
319 | + ); |
|
320 | + } |
|
321 | + |
|
322 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
323 | + // Remove old app with the ID if existent |
|
324 | + OC_Helper::rmdirr($baseDir); |
|
325 | + // Move to app folder |
|
326 | + if(@mkdir($baseDir)) { |
|
327 | + $extractDir .= '/' . $folders[0]; |
|
328 | + OC_Helper::copyr($extractDir, $baseDir); |
|
329 | + } |
|
330 | + OC_Helper::copyr($extractDir, $baseDir); |
|
331 | + OC_Helper::rmdirr($extractDir); |
|
332 | + return; |
|
333 | + } else { |
|
334 | + throw new \Exception( |
|
335 | + sprintf( |
|
336 | + 'Could not extract app with ID %s to %s', |
|
337 | + $appId, |
|
338 | + $extractDir |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + } else { |
|
343 | + // Signature does not match |
|
344 | + throw new \Exception( |
|
345 | + sprintf( |
|
346 | + 'App with id %s has invalid signature', |
|
347 | + $appId |
|
348 | + ) |
|
349 | + ); |
|
350 | + } |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + throw new \Exception( |
|
355 | + sprintf( |
|
356 | + 'Could not download app %s', |
|
357 | + $appId |
|
358 | + ) |
|
359 | + ); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Check if an update for the app is available |
|
364 | + * |
|
365 | + * @param string $appId |
|
366 | + * @return string|false false or the version number of the update |
|
367 | + */ |
|
368 | + public function isUpdateAvailable($appId) { |
|
369 | + if ($this->isInstanceReadyForUpdates === null) { |
|
370 | + $installPath = OC_App::getInstallPath(); |
|
371 | + if ($installPath === false || $installPath === null) { |
|
372 | + $this->isInstanceReadyForUpdates = false; |
|
373 | + } else { |
|
374 | + $this->isInstanceReadyForUpdates = true; |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + if ($this->isInstanceReadyForUpdates === false) { |
|
379 | + return false; |
|
380 | + } |
|
381 | + |
|
382 | + if ($this->isInstalledFromGit($appId) === true) { |
|
383 | + return false; |
|
384 | + } |
|
385 | + |
|
386 | + if ($this->apps === null) { |
|
387 | + $this->apps = $this->appFetcher->get(); |
|
388 | + } |
|
389 | + |
|
390 | + foreach($this->apps as $app) { |
|
391 | + if($app['id'] === $appId) { |
|
392 | + $currentVersion = OC_App::getAppVersion($appId); |
|
393 | + $newestVersion = $app['releases'][0]['version']; |
|
394 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
395 | + return $newestVersion; |
|
396 | + } else { |
|
397 | + return false; |
|
398 | + } |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + return false; |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Check if app has been installed from git |
|
407 | + * @param string $name name of the application to remove |
|
408 | + * @return boolean |
|
409 | + * |
|
410 | + * The function will check if the path contains a .git folder |
|
411 | + */ |
|
412 | + private function isInstalledFromGit($appId) { |
|
413 | + $app = \OC_App::findAppInDirectories($appId); |
|
414 | + if($app === false) { |
|
415 | + return false; |
|
416 | + } |
|
417 | + $basedir = $app['path'].'/'.$appId; |
|
418 | + return file_exists($basedir.'/.git/'); |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * Check if app is already downloaded |
|
423 | + * @param string $name name of the application to remove |
|
424 | + * @return boolean |
|
425 | + * |
|
426 | + * The function will check if the app is already downloaded in the apps repository |
|
427 | + */ |
|
428 | + public function isDownloaded($name) { |
|
429 | + foreach(\OC::$APPSROOTS as $dir) { |
|
430 | + $dirToTest = $dir['path']; |
|
431 | + $dirToTest .= '/'; |
|
432 | + $dirToTest .= $name; |
|
433 | + $dirToTest .= '/'; |
|
434 | + |
|
435 | + if (is_dir($dirToTest)) { |
|
436 | + return true; |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + return false; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Removes an app |
|
445 | + * @param string $appId ID of the application to remove |
|
446 | + * @return boolean |
|
447 | + * |
|
448 | + * |
|
449 | + * This function works as follows |
|
450 | + * -# call uninstall repair steps |
|
451 | + * -# removing the files |
|
452 | + * |
|
453 | + * The function will not delete preferences, tables and the configuration, |
|
454 | + * this has to be done by the function oc_app_uninstall(). |
|
455 | + */ |
|
456 | + public function removeApp($appId) { |
|
457 | + if($this->isDownloaded( $appId )) { |
|
458 | + if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
459 | + return false; |
|
460 | + } |
|
461 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
462 | + OC_Helper::rmdirr($appDir); |
|
463 | + return true; |
|
464 | + }else{ |
|
465 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
466 | + |
|
467 | + return false; |
|
468 | + } |
|
469 | + |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Installs the app within the bundle and marks the bundle as installed |
|
474 | + * |
|
475 | + * @param Bundle $bundle |
|
476 | + * @throws \Exception If app could not get installed |
|
477 | + */ |
|
478 | + public function installAppBundle(Bundle $bundle) { |
|
479 | + $appIds = $bundle->getAppIdentifiers(); |
|
480 | + foreach($appIds as $appId) { |
|
481 | + if(!$this->isDownloaded($appId)) { |
|
482 | + $this->downloadApp($appId); |
|
483 | + } |
|
484 | + $this->installApp($appId); |
|
485 | + $app = new OC_App(); |
|
486 | + $app->enable($appId); |
|
487 | + } |
|
488 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
489 | + $bundles[] = $bundle->getIdentifier(); |
|
490 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Installs shipped apps |
|
495 | + * |
|
496 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
497 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
498 | + * working ownCloud at the end instead of an aborted update. |
|
499 | + * @return array Array of error messages (appid => Exception) |
|
500 | + */ |
|
501 | + public static function installShippedApps($softErrors = false) { |
|
502 | + $appManager = \OC::$server->getAppManager(); |
|
503 | + $config = \OC::$server->getConfig(); |
|
504 | + $errors = []; |
|
505 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
506 | + if($dir = opendir( $app_dir['path'] )) { |
|
507 | + while( false !== ( $filename = readdir( $dir ))) { |
|
508 | + if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
509 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
510 | + if($config->getAppValue($filename, "installed_version", null) === null) { |
|
511 | + $info=OC_App::getAppInfo($filename); |
|
512 | + $enabled = isset($info['default_enable']); |
|
513 | + if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
|
514 | + && $config->getAppValue($filename, 'enabled') !== 'no') { |
|
515 | + if ($softErrors) { |
|
516 | + try { |
|
517 | + Installer::installShippedApp($filename); |
|
518 | + } catch (HintException $e) { |
|
519 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
520 | + $errors[$filename] = $e; |
|
521 | + continue; |
|
522 | + } |
|
523 | + throw $e; |
|
524 | + } |
|
525 | + } else { |
|
526 | + Installer::installShippedApp($filename); |
|
527 | + } |
|
528 | + $config->setAppValue($filename, 'enabled', 'yes'); |
|
529 | + } |
|
530 | + } |
|
531 | + } |
|
532 | + } |
|
533 | + } |
|
534 | + closedir( $dir ); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + return $errors; |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * install an app already placed in the app folder |
|
543 | + * @param string $app id of the app to install |
|
544 | + * @return integer |
|
545 | + */ |
|
546 | + public static function installShippedApp($app) { |
|
547 | + //install the database |
|
548 | + $appPath = OC_App::getAppPath($app); |
|
549 | + \OC_App::registerAutoloading($app, $appPath); |
|
550 | + |
|
551 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
552 | + try { |
|
553 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
554 | + } catch (TableExistsException $e) { |
|
555 | + throw new HintException( |
|
556 | + 'Failed to enable app ' . $app, |
|
557 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
558 | + 0, $e |
|
559 | + ); |
|
560 | + } |
|
561 | + } else { |
|
562 | + $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
563 | + $ms->migrate(); |
|
564 | + } |
|
565 | + |
|
566 | + //run appinfo/install.php |
|
567 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
568 | + |
|
569 | + $info = OC_App::getAppInfo($app); |
|
570 | + if (is_null($info)) { |
|
571 | + return false; |
|
572 | + } |
|
573 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
574 | + |
|
575 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
576 | + |
|
577 | + $config = \OC::$server->getConfig(); |
|
578 | + |
|
579 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
580 | + if (array_key_exists('ocsid', $info)) { |
|
581 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
582 | + } |
|
583 | + |
|
584 | + //set remote/public handlers |
|
585 | + foreach($info['remote'] as $name=>$path) { |
|
586 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
587 | + } |
|
588 | + foreach($info['public'] as $name=>$path) { |
|
589 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
590 | + } |
|
591 | + |
|
592 | + OC_App::setAppTypes($info['id']); |
|
593 | + |
|
594 | + return $info['id']; |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * @param string $script |
|
599 | + */ |
|
600 | + private static function includeAppScript($script) { |
|
601 | + if ( file_exists($script) ){ |
|
602 | + include $script; |
|
603 | + } |
|
604 | + } |
|
605 | 605 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function installApp($appId) { |
97 | 97 | $app = \OC_App::findAppInDirectories($appId); |
98 | - if($app === false) { |
|
98 | + if ($app === false) { |
|
99 | 99 | throw new \Exception('App not found in any app directory'); |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | $l = \OC::$server->getL10N('core'); |
106 | 106 | |
107 | - if(!is_array($info)) { |
|
107 | + if (!is_array($info)) { |
|
108 | 108 | throw new \Exception( |
109 | 109 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
110 | 110 | [$appId] |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | \OC_App::registerAutoloading($appId, $basedir); |
128 | 128 | |
129 | 129 | //install the database |
130 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
130 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
131 | 131 | if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
132 | 132 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
133 | 133 | } else { |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
142 | 142 | |
143 | 143 | //run appinfo/install.php |
144 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
145 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
144 | + if (!isset($data['noinstall']) or $data['noinstall'] == false) { |
|
145 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $appData = OC_App::getAppInfo($appId); |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
154 | 154 | |
155 | 155 | //set remote/public handlers |
156 | - foreach($info['remote'] as $name=>$path) { |
|
156 | + foreach ($info['remote'] as $name=>$path) { |
|
157 | 157 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
158 | 158 | } |
159 | - foreach($info['public'] as $name=>$path) { |
|
159 | + foreach ($info['public'] as $name=>$path) { |
|
160 | 160 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
161 | 161 | } |
162 | 162 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @return bool |
173 | 173 | */ |
174 | 174 | public function updateAppstoreApp($appId) { |
175 | - if($this->isUpdateAvailable($appId)) { |
|
175 | + if ($this->isUpdateAvailable($appId)) { |
|
176 | 176 | try { |
177 | 177 | $this->downloadApp($appId); |
178 | 178 | } catch (\Exception $e) { |
@@ -199,18 +199,18 @@ discard block |
||
199 | 199 | $appId = strtolower($appId); |
200 | 200 | |
201 | 201 | $apps = $this->appFetcher->get(); |
202 | - foreach($apps as $app) { |
|
203 | - if($app['id'] === $appId) { |
|
202 | + foreach ($apps as $app) { |
|
203 | + if ($app['id'] === $appId) { |
|
204 | 204 | // Load the certificate |
205 | 205 | $certificate = new X509(); |
206 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
206 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
207 | 207 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
208 | 208 | |
209 | 209 | // Verify if the certificate has been revoked |
210 | 210 | $crl = new X509(); |
211 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
212 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
213 | - if($crl->validateSignature() !== true) { |
|
211 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
212 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
213 | + if ($crl->validateSignature() !== true) { |
|
214 | 214 | throw new \Exception('Could not validate CRL signature'); |
215 | 215 | } |
216 | 216 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | |
227 | 227 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
228 | - if($certificate->validateSignature() !== true) { |
|
228 | + if ($certificate->validateSignature() !== true) { |
|
229 | 229 | throw new \Exception( |
230 | 230 | sprintf( |
231 | 231 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | // Verify if the certificate is issued for the requested app id |
238 | 238 | $certInfo = openssl_x509_parse($app['certificate']); |
239 | - if(!isset($certInfo['subject']['CN'])) { |
|
239 | + if (!isset($certInfo['subject']['CN'])) { |
|
240 | 240 | throw new \Exception( |
241 | 241 | sprintf( |
242 | 242 | 'App with id %s has a cert with no CN', |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | ) |
245 | 245 | ); |
246 | 246 | } |
247 | - if($certInfo['subject']['CN'] !== $appId) { |
|
247 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
248 | 248 | throw new \Exception( |
249 | 249 | sprintf( |
250 | 250 | 'App with id %s has a cert issued to %s', |
@@ -261,15 +261,15 @@ discard block |
||
261 | 261 | |
262 | 262 | // Check if the signature actually matches the downloaded content |
263 | 263 | $certificate = openssl_get_publickey($app['certificate']); |
264 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
264 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
265 | 265 | openssl_free_key($certificate); |
266 | 266 | |
267 | - if($verified === true) { |
|
267 | + if ($verified === true) { |
|
268 | 268 | // Seems to match, let's proceed |
269 | 269 | $extractDir = $this->tempManager->getTemporaryFolder(); |
270 | 270 | $archive = new TAR($tempFile); |
271 | 271 | |
272 | - if($archive) { |
|
272 | + if ($archive) { |
|
273 | 273 | if (!$archive->extract($extractDir)) { |
274 | 274 | throw new \Exception( |
275 | 275 | sprintf( |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $folders = array_diff($allFiles, ['.', '..']); |
283 | 283 | $folders = array_values($folders); |
284 | 284 | |
285 | - if(count($folders) > 1) { |
|
285 | + if (count($folders) > 1) { |
|
286 | 286 | throw new \Exception( |
287 | 287 | sprintf( |
288 | 288 | 'Extracted app %s has more than 1 folder', |
@@ -293,22 +293,22 @@ discard block |
||
293 | 293 | |
294 | 294 | // Check if appinfo/info.xml has the same app ID as well |
295 | 295 | $loadEntities = libxml_disable_entity_loader(false); |
296 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
296 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
297 | 297 | libxml_disable_entity_loader($loadEntities); |
298 | - if((string)$xml->id !== $appId) { |
|
298 | + if ((string) $xml->id !== $appId) { |
|
299 | 299 | throw new \Exception( |
300 | 300 | sprintf( |
301 | 301 | 'App for id %s has a wrong app ID in info.xml: %s', |
302 | 302 | $appId, |
303 | - (string)$xml->id |
|
303 | + (string) $xml->id |
|
304 | 304 | ) |
305 | 305 | ); |
306 | 306 | } |
307 | 307 | |
308 | 308 | // Check if the version is lower than before |
309 | 309 | $currentVersion = OC_App::getAppVersion($appId); |
310 | - $newVersion = (string)$xml->version; |
|
311 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
310 | + $newVersion = (string) $xml->version; |
|
311 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
312 | 312 | throw new \Exception( |
313 | 313 | sprintf( |
314 | 314 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -319,12 +319,12 @@ discard block |
||
319 | 319 | ); |
320 | 320 | } |
321 | 321 | |
322 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
322 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
323 | 323 | // Remove old app with the ID if existent |
324 | 324 | OC_Helper::rmdirr($baseDir); |
325 | 325 | // Move to app folder |
326 | - if(@mkdir($baseDir)) { |
|
327 | - $extractDir .= '/' . $folders[0]; |
|
326 | + if (@mkdir($baseDir)) { |
|
327 | + $extractDir .= '/'.$folders[0]; |
|
328 | 328 | OC_Helper::copyr($extractDir, $baseDir); |
329 | 329 | } |
330 | 330 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | $this->apps = $this->appFetcher->get(); |
388 | 388 | } |
389 | 389 | |
390 | - foreach($this->apps as $app) { |
|
391 | - if($app['id'] === $appId) { |
|
390 | + foreach ($this->apps as $app) { |
|
391 | + if ($app['id'] === $appId) { |
|
392 | 392 | $currentVersion = OC_App::getAppVersion($appId); |
393 | 393 | $newestVersion = $app['releases'][0]['version']; |
394 | 394 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | */ |
412 | 412 | private function isInstalledFromGit($appId) { |
413 | 413 | $app = \OC_App::findAppInDirectories($appId); |
414 | - if($app === false) { |
|
414 | + if ($app === false) { |
|
415 | 415 | return false; |
416 | 416 | } |
417 | 417 | $basedir = $app['path'].'/'.$appId; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * The function will check if the app is already downloaded in the apps repository |
427 | 427 | */ |
428 | 428 | public function isDownloaded($name) { |
429 | - foreach(\OC::$APPSROOTS as $dir) { |
|
429 | + foreach (\OC::$APPSROOTS as $dir) { |
|
430 | 430 | $dirToTest = $dir['path']; |
431 | 431 | $dirToTest .= '/'; |
432 | 432 | $dirToTest .= $name; |
@@ -454,14 +454,14 @@ discard block |
||
454 | 454 | * this has to be done by the function oc_app_uninstall(). |
455 | 455 | */ |
456 | 456 | public function removeApp($appId) { |
457 | - if($this->isDownloaded( $appId )) { |
|
457 | + if ($this->isDownloaded($appId)) { |
|
458 | 458 | if (\OC::$server->getAppManager()->isShipped($appId)) { |
459 | 459 | return false; |
460 | 460 | } |
461 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
461 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
462 | 462 | OC_Helper::rmdirr($appDir); |
463 | 463 | return true; |
464 | - }else{ |
|
464 | + } else { |
|
465 | 465 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
466 | 466 | |
467 | 467 | return false; |
@@ -477,8 +477,8 @@ discard block |
||
477 | 477 | */ |
478 | 478 | public function installAppBundle(Bundle $bundle) { |
479 | 479 | $appIds = $bundle->getAppIdentifiers(); |
480 | - foreach($appIds as $appId) { |
|
481 | - if(!$this->isDownloaded($appId)) { |
|
480 | + foreach ($appIds as $appId) { |
|
481 | + if (!$this->isDownloaded($appId)) { |
|
482 | 482 | $this->downloadApp($appId); |
483 | 483 | } |
484 | 484 | $this->installApp($appId); |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | $appManager = \OC::$server->getAppManager(); |
503 | 503 | $config = \OC::$server->getConfig(); |
504 | 504 | $errors = []; |
505 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
506 | - if($dir = opendir( $app_dir['path'] )) { |
|
507 | - while( false !== ( $filename = readdir( $dir ))) { |
|
508 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
509 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
510 | - if($config->getAppValue($filename, "installed_version", null) === null) { |
|
511 | - $info=OC_App::getAppInfo($filename); |
|
505 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
506 | + if ($dir = opendir($app_dir['path'])) { |
|
507 | + while (false !== ($filename = readdir($dir))) { |
|
508 | + if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { |
|
509 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
510 | + if ($config->getAppValue($filename, "installed_version", null) === null) { |
|
511 | + $info = OC_App::getAppInfo($filename); |
|
512 | 512 | $enabled = isset($info['default_enable']); |
513 | 513 | if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
514 | 514 | && $config->getAppValue($filename, 'enabled') !== 'no') { |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | } |
532 | 532 | } |
533 | 533 | } |
534 | - closedir( $dir ); |
|
534 | + closedir($dir); |
|
535 | 535 | } |
536 | 536 | } |
537 | 537 | |
@@ -548,12 +548,12 @@ discard block |
||
548 | 548 | $appPath = OC_App::getAppPath($app); |
549 | 549 | \OC_App::registerAutoloading($app, $appPath); |
550 | 550 | |
551 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
551 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
552 | 552 | try { |
553 | 553 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
554 | 554 | } catch (TableExistsException $e) { |
555 | 555 | throw new HintException( |
556 | - 'Failed to enable app ' . $app, |
|
556 | + 'Failed to enable app '.$app, |
|
557 | 557 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
558 | 558 | 0, $e |
559 | 559 | ); |
@@ -582,10 +582,10 @@ discard block |
||
582 | 582 | } |
583 | 583 | |
584 | 584 | //set remote/public handlers |
585 | - foreach($info['remote'] as $name=>$path) { |
|
585 | + foreach ($info['remote'] as $name=>$path) { |
|
586 | 586 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
587 | 587 | } |
588 | - foreach($info['public'] as $name=>$path) { |
|
588 | + foreach ($info['public'] as $name=>$path) { |
|
589 | 589 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
590 | 590 | } |
591 | 591 | |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @param string $script |
599 | 599 | */ |
600 | 600 | private static function includeAppScript($script) { |
601 | - if ( file_exists($script) ){ |
|
601 | + if (file_exists($script)) { |
|
602 | 602 | include $script; |
603 | 603 | } |
604 | 604 | } |
@@ -134,7 +134,7 @@ |
||
134 | 134 | } |
135 | 135 | if(is_dir($source.'/'.$file)) { |
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else{ |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |
@@ -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 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $source either a local file or string data |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public abstract function addFile($path, $source=''); |
|
52 | + public abstract function addFile($path, $source = ''); |
|
53 | 53 | /** |
54 | 54 | * rename a file or folder in the archive |
55 | 55 | * @param string $source |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function addRecursive($path, $source) { |
128 | 128 | $dh = opendir($source); |
129 | - if(is_resource($dh)) { |
|
129 | + if (is_resource($dh)) { |
|
130 | 130 | $this->addFolder($path); |
131 | 131 | while (($file = readdir($dh)) !== false) { |
132 | - if($file === '.' || $file === '..') { |
|
132 | + if ($file === '.' || $file === '..') { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - if(is_dir($source.'/'.$file)) { |
|
135 | + if (is_dir($source.'/'.$file)) { |
|
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else { |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |
@@ -25,14 +25,14 @@ |
||
25 | 25 | namespace OC; |
26 | 26 | |
27 | 27 | class NaturalSort_DefaultCollator { |
28 | - public function compare($a, $b) { |
|
29 | - $result = strcasecmp($a, $b); |
|
30 | - if ($result === 0) { |
|
31 | - if ($a === $b) { |
|
32 | - return 0; |
|
33 | - } |
|
34 | - return ($a > $b) ? -1 : 1; |
|
35 | - } |
|
36 | - return ($result < 0) ? -1 : 1; |
|
37 | - } |
|
28 | + public function compare($a, $b) { |
|
29 | + $result = strcasecmp($a, $b); |
|
30 | + if ($result === 0) { |
|
31 | + if ($a === $b) { |
|
32 | + return 0; |
|
33 | + } |
|
34 | + return ($a > $b) ? -1 : 1; |
|
35 | + } |
|
36 | + return ($result < 0) ? -1 : 1; |
|
37 | + } |
|
38 | 38 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | parent::__construct( 'core', 'layout.user' ); |
62 | 62 | if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
63 | 63 | $this->assign('bodyid', 'body-settings'); |
64 | - }else{ |
|
64 | + } else{ |
|
65 | 65 | $this->assign('bodyid', 'body-user'); |
66 | 66 | } |
67 | 67 |
@@ -45,285 +45,285 @@ |
||
45 | 45 | |
46 | 46 | class TemplateLayout extends \OC_Template { |
47 | 47 | |
48 | - private static $versionHash = ''; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var \OCP\IConfig |
|
52 | - */ |
|
53 | - private $config; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $renderAs |
|
57 | - * @param string $appId application id |
|
58 | - */ |
|
59 | - public function __construct( $renderAs, $appId = '' ) { |
|
60 | - |
|
61 | - // yes - should be injected .... |
|
62 | - $this->config = \OC::$server->getConfig(); |
|
63 | - |
|
64 | - |
|
65 | - // Decide which page we show |
|
66 | - if($renderAs == 'user') { |
|
67 | - parent::__construct( 'core', 'layout.user' ); |
|
68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
69 | - $this->assign('bodyid', 'body-settings'); |
|
70 | - }else{ |
|
71 | - $this->assign('bodyid', 'body-user'); |
|
72 | - } |
|
73 | - |
|
74 | - // Code integrity notification |
|
75 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
78 | - } |
|
79 | - |
|
80 | - // Add navigation entry |
|
81 | - $this->assign( 'application', ''); |
|
82 | - $this->assign( 'appid', $appId ); |
|
83 | - $navigation = \OC::$server->getNavigationManager()->getAll(); |
|
84 | - $this->assign( 'navigation', $navigation); |
|
85 | - $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
|
86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | - foreach($navigation as $entry) { |
|
88 | - if ($entry['active']) { |
|
89 | - $this->assign( 'application', $entry['name'] ); |
|
90 | - break; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - foreach($settingsNavigation as $entry) { |
|
95 | - if ($entry['active']) { |
|
96 | - $this->assign( 'application', $entry['name'] ); |
|
97 | - break; |
|
98 | - } |
|
99 | - } |
|
100 | - $userDisplayName = \OC_User::getDisplayName(); |
|
101 | - $this->assign('user_displayname', $userDisplayName); |
|
102 | - $this->assign('user_uid', \OC_User::getUser()); |
|
103 | - |
|
104 | - if (\OC_User::getUser() === false) { |
|
105 | - $this->assign('userAvatarSet', false); |
|
106 | - } else { |
|
107 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
108 | - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
109 | - } |
|
110 | - |
|
111 | - // check if app menu icons should be inverted |
|
112 | - try { |
|
113 | - /** @var \OCA\Theming\Util $util */ |
|
114 | - $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
115 | - $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
116 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
117 | - $this->assign('themingInvertMenu', false); |
|
118 | - } |
|
119 | - |
|
120 | - } else if ($renderAs == 'error') { |
|
121 | - parent::__construct('core', 'layout.guest', '', false); |
|
122 | - $this->assign('bodyid', 'body-login'); |
|
123 | - } else if ($renderAs == 'guest') { |
|
124 | - parent::__construct('core', 'layout.guest'); |
|
125 | - $this->assign('bodyid', 'body-login'); |
|
126 | - } else if ($renderAs == 'public') { |
|
127 | - parent::__construct('core', 'layout.public'); |
|
128 | - $this->assign( 'appid', $appId ); |
|
129 | - $this->assign('bodyid', 'body-public'); |
|
130 | - } else { |
|
131 | - parent::__construct('core', 'layout.base'); |
|
132 | - |
|
133 | - } |
|
134 | - // Send the language to our layouts |
|
135 | - $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
136 | - $lang = str_replace('_', '-', $lang); |
|
137 | - $this->assign('language', $lang); |
|
138 | - |
|
139 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
140 | - if (empty(self::$versionHash)) { |
|
141 | - $v = \OC_App::getAppVersions(); |
|
142 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
143 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
144 | - } |
|
145 | - } else { |
|
146 | - self::$versionHash = md5('not installed'); |
|
147 | - } |
|
148 | - |
|
149 | - // Add the js files |
|
150 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
151 | - $this->assign('jsfiles', array()); |
|
152 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
153 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
154 | - $jsConfigHelper = new JSConfigHelper( |
|
155 | - \OC::$server->getL10N('lib'), |
|
156 | - \OC::$server->query(Defaults::class), |
|
157 | - \OC::$server->getAppManager(), |
|
158 | - \OC::$server->getSession(), |
|
159 | - \OC::$server->getUserSession()->getUser(), |
|
160 | - $this->config, |
|
161 | - \OC::$server->getGroupManager(), |
|
162 | - \OC::$server->getIniWrapper(), |
|
163 | - \OC::$server->getURLGenerator(), |
|
164 | - \OC::$server->getCapabilitiesManager() |
|
165 | - ); |
|
166 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
167 | - } else { |
|
168 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
169 | - } |
|
170 | - } |
|
171 | - foreach($jsFiles as $info) { |
|
172 | - $web = $info[1]; |
|
173 | - $file = $info[2]; |
|
174 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
175 | - } |
|
176 | - |
|
177 | - try { |
|
178 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
179 | - } catch (\Exception $e) { |
|
180 | - $pathInfo = ''; |
|
181 | - } |
|
182 | - |
|
183 | - // Do not initialise scss appdata until we have a fully installed instance |
|
184 | - // Do not load scss for update, errors, installation or login page |
|
185 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
186 | - && !\OCP\Util::needUpgrade() |
|
187 | - && $pathInfo !== '' |
|
188 | - && !preg_match('/^\/login/', $pathInfo) |
|
189 | - && $renderAs !== 'error' && $renderAs !== 'guest' |
|
190 | - ) { |
|
191 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
192 | - } else { |
|
193 | - // If we ignore the scss compiler, |
|
194 | - // we need to load the guest css fallback |
|
195 | - \OC_Util::addStyle('guest'); |
|
196 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
197 | - } |
|
198 | - |
|
199 | - $this->assign('cssfiles', array()); |
|
200 | - $this->assign('printcssfiles', []); |
|
201 | - $this->assign('versionHash', self::$versionHash); |
|
202 | - foreach($cssFiles as $info) { |
|
203 | - $web = $info[1]; |
|
204 | - $file = $info[2]; |
|
205 | - |
|
206 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
207 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
208 | - } else { |
|
209 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param string $path |
|
216 | - * @param string $file |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
220 | - if ($this->config->getSystemValue('debug', false)) { |
|
221 | - // allows chrome workspace mapping in debug mode |
|
222 | - return ""; |
|
223 | - } |
|
224 | - $themingSuffix = ''; |
|
225 | - $v = []; |
|
226 | - |
|
227 | - if ($this->config->getSystemValue('installed', false)) { |
|
228 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
229 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
230 | - } |
|
231 | - $v = \OC_App::getAppVersions(); |
|
232 | - } |
|
233 | - |
|
234 | - // Try the webroot path for a match |
|
235 | - if ($path !== false && $path !== '') { |
|
236 | - $appName = $this->getAppNamefromPath($path); |
|
237 | - if(array_key_exists($appName, $v)) { |
|
238 | - $appVersion = $v[$appName]; |
|
239 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
240 | - } |
|
241 | - } |
|
242 | - // fallback to the file path instead |
|
243 | - if ($file !== false && $file !== '') { |
|
244 | - $appName = $this->getAppNamefromPath($file); |
|
245 | - if(array_key_exists($appName, $v)) { |
|
246 | - $appVersion = $v[$appName]; |
|
247 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * @param array $styles |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
259 | - // Read the selected theme from the config file |
|
260 | - $theme = \OC_Util::getTheme(); |
|
261 | - |
|
262 | - if($compileScss) { |
|
263 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
264 | - } else { |
|
265 | - $SCSSCacher = null; |
|
266 | - } |
|
267 | - |
|
268 | - $locator = new \OC\Template\CSSResourceLocator( |
|
269 | - \OC::$server->getLogger(), |
|
270 | - $theme, |
|
271 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
272 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
273 | - $SCSSCacher |
|
274 | - ); |
|
275 | - $locator->find($styles); |
|
276 | - return $locator->getResources(); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @param string $path |
|
281 | - * @return string|boolean |
|
282 | - */ |
|
283 | - public function getAppNamefromPath($path) { |
|
284 | - if ($path !== '' && is_string($path)) { |
|
285 | - $pathParts = explode('/', $path); |
|
286 | - if ($pathParts[0] === 'css') { |
|
287 | - // This is a scss request |
|
288 | - return $pathParts[1]; |
|
289 | - } |
|
290 | - return end($pathParts); |
|
291 | - } |
|
292 | - return false; |
|
293 | - |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * @param array $scripts |
|
298 | - * @return array |
|
299 | - */ |
|
300 | - static public function findJavascriptFiles($scripts) { |
|
301 | - // Read the selected theme from the config file |
|
302 | - $theme = \OC_Util::getTheme(); |
|
303 | - |
|
304 | - $locator = new \OC\Template\JSResourceLocator( |
|
305 | - \OC::$server->getLogger(), |
|
306 | - $theme, |
|
307 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
308 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
309 | - \OC::$server->query(JSCombiner::class) |
|
310 | - ); |
|
311 | - $locator->find($scripts); |
|
312 | - return $locator->getResources(); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
317 | - * @param string $filePath Absolute path |
|
318 | - * @return string Relative path |
|
319 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
320 | - */ |
|
321 | - public static function convertToRelativePath($filePath) { |
|
322 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
323 | - if(count($relativePath) !== 2) { |
|
324 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
325 | - } |
|
326 | - |
|
327 | - return $relativePath[1]; |
|
328 | - } |
|
48 | + private static $versionHash = ''; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var \OCP\IConfig |
|
52 | + */ |
|
53 | + private $config; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $renderAs |
|
57 | + * @param string $appId application id |
|
58 | + */ |
|
59 | + public function __construct( $renderAs, $appId = '' ) { |
|
60 | + |
|
61 | + // yes - should be injected .... |
|
62 | + $this->config = \OC::$server->getConfig(); |
|
63 | + |
|
64 | + |
|
65 | + // Decide which page we show |
|
66 | + if($renderAs == 'user') { |
|
67 | + parent::__construct( 'core', 'layout.user' ); |
|
68 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
69 | + $this->assign('bodyid', 'body-settings'); |
|
70 | + }else{ |
|
71 | + $this->assign('bodyid', 'body-user'); |
|
72 | + } |
|
73 | + |
|
74 | + // Code integrity notification |
|
75 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
76 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
78 | + } |
|
79 | + |
|
80 | + // Add navigation entry |
|
81 | + $this->assign( 'application', ''); |
|
82 | + $this->assign( 'appid', $appId ); |
|
83 | + $navigation = \OC::$server->getNavigationManager()->getAll(); |
|
84 | + $this->assign( 'navigation', $navigation); |
|
85 | + $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
|
86 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | + foreach($navigation as $entry) { |
|
88 | + if ($entry['active']) { |
|
89 | + $this->assign( 'application', $entry['name'] ); |
|
90 | + break; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + foreach($settingsNavigation as $entry) { |
|
95 | + if ($entry['active']) { |
|
96 | + $this->assign( 'application', $entry['name'] ); |
|
97 | + break; |
|
98 | + } |
|
99 | + } |
|
100 | + $userDisplayName = \OC_User::getDisplayName(); |
|
101 | + $this->assign('user_displayname', $userDisplayName); |
|
102 | + $this->assign('user_uid', \OC_User::getUser()); |
|
103 | + |
|
104 | + if (\OC_User::getUser() === false) { |
|
105 | + $this->assign('userAvatarSet', false); |
|
106 | + } else { |
|
107 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
108 | + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
109 | + } |
|
110 | + |
|
111 | + // check if app menu icons should be inverted |
|
112 | + try { |
|
113 | + /** @var \OCA\Theming\Util $util */ |
|
114 | + $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
115 | + $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
116 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
117 | + $this->assign('themingInvertMenu', false); |
|
118 | + } |
|
119 | + |
|
120 | + } else if ($renderAs == 'error') { |
|
121 | + parent::__construct('core', 'layout.guest', '', false); |
|
122 | + $this->assign('bodyid', 'body-login'); |
|
123 | + } else if ($renderAs == 'guest') { |
|
124 | + parent::__construct('core', 'layout.guest'); |
|
125 | + $this->assign('bodyid', 'body-login'); |
|
126 | + } else if ($renderAs == 'public') { |
|
127 | + parent::__construct('core', 'layout.public'); |
|
128 | + $this->assign( 'appid', $appId ); |
|
129 | + $this->assign('bodyid', 'body-public'); |
|
130 | + } else { |
|
131 | + parent::__construct('core', 'layout.base'); |
|
132 | + |
|
133 | + } |
|
134 | + // Send the language to our layouts |
|
135 | + $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
136 | + $lang = str_replace('_', '-', $lang); |
|
137 | + $this->assign('language', $lang); |
|
138 | + |
|
139 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
140 | + if (empty(self::$versionHash)) { |
|
141 | + $v = \OC_App::getAppVersions(); |
|
142 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
143 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
144 | + } |
|
145 | + } else { |
|
146 | + self::$versionHash = md5('not installed'); |
|
147 | + } |
|
148 | + |
|
149 | + // Add the js files |
|
150 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
151 | + $this->assign('jsfiles', array()); |
|
152 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
153 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
154 | + $jsConfigHelper = new JSConfigHelper( |
|
155 | + \OC::$server->getL10N('lib'), |
|
156 | + \OC::$server->query(Defaults::class), |
|
157 | + \OC::$server->getAppManager(), |
|
158 | + \OC::$server->getSession(), |
|
159 | + \OC::$server->getUserSession()->getUser(), |
|
160 | + $this->config, |
|
161 | + \OC::$server->getGroupManager(), |
|
162 | + \OC::$server->getIniWrapper(), |
|
163 | + \OC::$server->getURLGenerator(), |
|
164 | + \OC::$server->getCapabilitiesManager() |
|
165 | + ); |
|
166 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
167 | + } else { |
|
168 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
169 | + } |
|
170 | + } |
|
171 | + foreach($jsFiles as $info) { |
|
172 | + $web = $info[1]; |
|
173 | + $file = $info[2]; |
|
174 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
175 | + } |
|
176 | + |
|
177 | + try { |
|
178 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
179 | + } catch (\Exception $e) { |
|
180 | + $pathInfo = ''; |
|
181 | + } |
|
182 | + |
|
183 | + // Do not initialise scss appdata until we have a fully installed instance |
|
184 | + // Do not load scss for update, errors, installation or login page |
|
185 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
186 | + && !\OCP\Util::needUpgrade() |
|
187 | + && $pathInfo !== '' |
|
188 | + && !preg_match('/^\/login/', $pathInfo) |
|
189 | + && $renderAs !== 'error' && $renderAs !== 'guest' |
|
190 | + ) { |
|
191 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
192 | + } else { |
|
193 | + // If we ignore the scss compiler, |
|
194 | + // we need to load the guest css fallback |
|
195 | + \OC_Util::addStyle('guest'); |
|
196 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
197 | + } |
|
198 | + |
|
199 | + $this->assign('cssfiles', array()); |
|
200 | + $this->assign('printcssfiles', []); |
|
201 | + $this->assign('versionHash', self::$versionHash); |
|
202 | + foreach($cssFiles as $info) { |
|
203 | + $web = $info[1]; |
|
204 | + $file = $info[2]; |
|
205 | + |
|
206 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
207 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
208 | + } else { |
|
209 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param string $path |
|
216 | + * @param string $file |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
220 | + if ($this->config->getSystemValue('debug', false)) { |
|
221 | + // allows chrome workspace mapping in debug mode |
|
222 | + return ""; |
|
223 | + } |
|
224 | + $themingSuffix = ''; |
|
225 | + $v = []; |
|
226 | + |
|
227 | + if ($this->config->getSystemValue('installed', false)) { |
|
228 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
229 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
230 | + } |
|
231 | + $v = \OC_App::getAppVersions(); |
|
232 | + } |
|
233 | + |
|
234 | + // Try the webroot path for a match |
|
235 | + if ($path !== false && $path !== '') { |
|
236 | + $appName = $this->getAppNamefromPath($path); |
|
237 | + if(array_key_exists($appName, $v)) { |
|
238 | + $appVersion = $v[$appName]; |
|
239 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
240 | + } |
|
241 | + } |
|
242 | + // fallback to the file path instead |
|
243 | + if ($file !== false && $file !== '') { |
|
244 | + $appName = $this->getAppNamefromPath($file); |
|
245 | + if(array_key_exists($appName, $v)) { |
|
246 | + $appVersion = $v[$appName]; |
|
247 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * @param array $styles |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
259 | + // Read the selected theme from the config file |
|
260 | + $theme = \OC_Util::getTheme(); |
|
261 | + |
|
262 | + if($compileScss) { |
|
263 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
264 | + } else { |
|
265 | + $SCSSCacher = null; |
|
266 | + } |
|
267 | + |
|
268 | + $locator = new \OC\Template\CSSResourceLocator( |
|
269 | + \OC::$server->getLogger(), |
|
270 | + $theme, |
|
271 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
272 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
273 | + $SCSSCacher |
|
274 | + ); |
|
275 | + $locator->find($styles); |
|
276 | + return $locator->getResources(); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @param string $path |
|
281 | + * @return string|boolean |
|
282 | + */ |
|
283 | + public function getAppNamefromPath($path) { |
|
284 | + if ($path !== '' && is_string($path)) { |
|
285 | + $pathParts = explode('/', $path); |
|
286 | + if ($pathParts[0] === 'css') { |
|
287 | + // This is a scss request |
|
288 | + return $pathParts[1]; |
|
289 | + } |
|
290 | + return end($pathParts); |
|
291 | + } |
|
292 | + return false; |
|
293 | + |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * @param array $scripts |
|
298 | + * @return array |
|
299 | + */ |
|
300 | + static public function findJavascriptFiles($scripts) { |
|
301 | + // Read the selected theme from the config file |
|
302 | + $theme = \OC_Util::getTheme(); |
|
303 | + |
|
304 | + $locator = new \OC\Template\JSResourceLocator( |
|
305 | + \OC::$server->getLogger(), |
|
306 | + $theme, |
|
307 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
308 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
309 | + \OC::$server->query(JSCombiner::class) |
|
310 | + ); |
|
311 | + $locator->find($scripts); |
|
312 | + return $locator->getResources(); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
317 | + * @param string $filePath Absolute path |
|
318 | + * @return string Relative path |
|
319 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
320 | + */ |
|
321 | + public static function convertToRelativePath($filePath) { |
|
322 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
323 | + if(count($relativePath) !== 2) { |
|
324 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
325 | + } |
|
326 | + |
|
327 | + return $relativePath[1]; |
|
328 | + } |
|
329 | 329 | } |
@@ -56,44 +56,44 @@ discard block |
||
56 | 56 | * @param string $renderAs |
57 | 57 | * @param string $appId application id |
58 | 58 | */ |
59 | - public function __construct( $renderAs, $appId = '' ) { |
|
59 | + public function __construct($renderAs, $appId = '') { |
|
60 | 60 | |
61 | 61 | // yes - should be injected .... |
62 | 62 | $this->config = \OC::$server->getConfig(); |
63 | 63 | |
64 | 64 | |
65 | 65 | // Decide which page we show |
66 | - if($renderAs == 'user') { |
|
67 | - parent::__construct( 'core', 'layout.user' ); |
|
68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
66 | + if ($renderAs == 'user') { |
|
67 | + parent::__construct('core', 'layout.user'); |
|
68 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
69 | 69 | $this->assign('bodyid', 'body-settings'); |
70 | - }else{ |
|
70 | + } else { |
|
71 | 71 | $this->assign('bodyid', 'body-user'); |
72 | 72 | } |
73 | 73 | |
74 | 74 | // Code integrity notification |
75 | 75 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
76 | + if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | 77 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Add navigation entry |
81 | - $this->assign( 'application', ''); |
|
82 | - $this->assign( 'appid', $appId ); |
|
81 | + $this->assign('application', ''); |
|
82 | + $this->assign('appid', $appId); |
|
83 | 83 | $navigation = \OC::$server->getNavigationManager()->getAll(); |
84 | - $this->assign( 'navigation', $navigation); |
|
84 | + $this->assign('navigation', $navigation); |
|
85 | 85 | $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | - foreach($navigation as $entry) { |
|
86 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
87 | + foreach ($navigation as $entry) { |
|
88 | 88 | if ($entry['active']) { |
89 | - $this->assign( 'application', $entry['name'] ); |
|
89 | + $this->assign('application', $entry['name']); |
|
90 | 90 | break; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - foreach($settingsNavigation as $entry) { |
|
94 | + foreach ($settingsNavigation as $entry) { |
|
95 | 95 | if ($entry['active']) { |
96 | - $this->assign( 'application', $entry['name'] ); |
|
96 | + $this->assign('application', $entry['name']); |
|
97 | 97 | break; |
98 | 98 | } |
99 | 99 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $this->assign('bodyid', 'body-login'); |
126 | 126 | } else if ($renderAs == 'public') { |
127 | 127 | parent::__construct('core', 'layout.public'); |
128 | - $this->assign( 'appid', $appId ); |
|
128 | + $this->assign('appid', $appId); |
|
129 | 129 | $this->assign('bodyid', 'body-public'); |
130 | 130 | } else { |
131 | 131 | parent::__construct('core', 'layout.base'); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $lang = str_replace('_', '-', $lang); |
137 | 137 | $this->assign('language', $lang); |
138 | 138 | |
139 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
139 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
140 | 140 | if (empty(self::$versionHash)) { |
141 | 141 | $v = \OC_App::getAppVersions(); |
142 | 142 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
169 | 169 | } |
170 | 170 | } |
171 | - foreach($jsFiles as $info) { |
|
171 | + foreach ($jsFiles as $info) { |
|
172 | 172 | $web = $info[1]; |
173 | 173 | $file = $info[2]; |
174 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
174 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | try { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | // Do not initialise scss appdata until we have a fully installed instance |
184 | 184 | // Do not load scss for update, errors, installation or login page |
185 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
185 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
186 | 186 | && !\OCP\Util::needUpgrade() |
187 | 187 | && $pathInfo !== '' |
188 | 188 | && !preg_match('/^\/login/', $pathInfo) |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | $this->assign('cssfiles', array()); |
200 | 200 | $this->assign('printcssfiles', []); |
201 | 201 | $this->assign('versionHash', self::$versionHash); |
202 | - foreach($cssFiles as $info) { |
|
202 | + foreach ($cssFiles as $info) { |
|
203 | 203 | $web = $info[1]; |
204 | 204 | $file = $info[2]; |
205 | 205 | |
206 | 206 | if (substr($file, -strlen('print.css')) === 'print.css') { |
207 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
207 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
208 | 208 | } else { |
209 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
209 | + $this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix($web, $file)); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | if ($this->config->getSystemValue('installed', false)) { |
228 | 228 | if (\OC::$server->getAppManager()->isInstalled('theming')) { |
229 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
229 | + $themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
230 | 230 | } |
231 | 231 | $v = \OC_App::getAppVersions(); |
232 | 232 | } |
@@ -234,21 +234,21 @@ discard block |
||
234 | 234 | // Try the webroot path for a match |
235 | 235 | if ($path !== false && $path !== '') { |
236 | 236 | $appName = $this->getAppNamefromPath($path); |
237 | - if(array_key_exists($appName, $v)) { |
|
237 | + if (array_key_exists($appName, $v)) { |
|
238 | 238 | $appVersion = $v[$appName]; |
239 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
239 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | // fallback to the file path instead |
243 | 243 | if ($file !== false && $file !== '') { |
244 | 244 | $appName = $this->getAppNamefromPath($file); |
245 | - if(array_key_exists($appName, $v)) { |
|
245 | + if (array_key_exists($appName, $v)) { |
|
246 | 246 | $appVersion = $v[$appName]; |
247 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
247 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
251 | + return '?v='.self::$versionHash.$themingSuffix; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | // Read the selected theme from the config file |
260 | 260 | $theme = \OC_Util::getTheme(); |
261 | 261 | |
262 | - if($compileScss) { |
|
262 | + if ($compileScss) { |
|
263 | 263 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
264 | 264 | } else { |
265 | 265 | $SCSSCacher = null; |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | $locator = new \OC\Template\CSSResourceLocator( |
269 | 269 | \OC::$server->getLogger(), |
270 | 270 | $theme, |
271 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
272 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
271 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
272 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
273 | 273 | $SCSSCacher |
274 | 274 | ); |
275 | 275 | $locator->find($styles); |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | $locator = new \OC\Template\JSResourceLocator( |
305 | 305 | \OC::$server->getLogger(), |
306 | 306 | $theme, |
307 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
308 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
307 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
308 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
309 | 309 | \OC::$server->query(JSCombiner::class) |
310 | 310 | ); |
311 | 311 | $locator->find($scripts); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public static function convertToRelativePath($filePath) { |
322 | 322 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
323 | - if(count($relativePath) !== 2) { |
|
323 | + if (count($relativePath) !== 2) { |
|
324 | 324 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
325 | 325 | } |
326 | 326 |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function execute($jobList, ILogger $logger = null) { |
59 | 59 | // add an interval of 15 mins |
60 | - $this->setInterval(15*60); |
|
60 | + $this->setInterval(15 * 60); |
|
61 | 61 | |
62 | 62 | $this->jobList = $jobList; |
63 | 63 | $this->logger = $logger; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | try { |
91 | 91 | $repair->addStep($step); |
92 | 92 | } catch (\Exception $ex) { |
93 | - $this->logger->logException($ex,[ |
|
93 | + $this->logger->logException($ex, [ |
|
94 | 94 | 'app' => 'migration' |
95 | 95 | ]); |
96 | 96 |
@@ -37,81 +37,81 @@ |
||
37 | 37 | */ |
38 | 38 | class BackgroundRepair extends TimedJob { |
39 | 39 | |
40 | - /** @var IJobList */ |
|
41 | - private $jobList; |
|
40 | + /** @var IJobList */ |
|
41 | + private $jobList; |
|
42 | 42 | |
43 | - /** @var ILogger */ |
|
44 | - private $logger; |
|
43 | + /** @var ILogger */ |
|
44 | + private $logger; |
|
45 | 45 | |
46 | - /** @var EventDispatcher */ |
|
47 | - private $dispatcher; |
|
46 | + /** @var EventDispatcher */ |
|
47 | + private $dispatcher; |
|
48 | 48 | |
49 | - public function setDispatcher(EventDispatcher $dispatcher) { |
|
50 | - $this->dispatcher = $dispatcher; |
|
51 | - } |
|
52 | - /** |
|
53 | - * run the job, then remove it from the job list |
|
54 | - * |
|
55 | - * @param JobList $jobList |
|
56 | - * @param ILogger|null $logger |
|
57 | - */ |
|
58 | - public function execute($jobList, ILogger $logger = null) { |
|
59 | - // add an interval of 15 mins |
|
60 | - $this->setInterval(15*60); |
|
49 | + public function setDispatcher(EventDispatcher $dispatcher) { |
|
50 | + $this->dispatcher = $dispatcher; |
|
51 | + } |
|
52 | + /** |
|
53 | + * run the job, then remove it from the job list |
|
54 | + * |
|
55 | + * @param JobList $jobList |
|
56 | + * @param ILogger|null $logger |
|
57 | + */ |
|
58 | + public function execute($jobList, ILogger $logger = null) { |
|
59 | + // add an interval of 15 mins |
|
60 | + $this->setInterval(15*60); |
|
61 | 61 | |
62 | - $this->jobList = $jobList; |
|
63 | - $this->logger = $logger; |
|
64 | - parent::execute($jobList, $logger); |
|
65 | - } |
|
62 | + $this->jobList = $jobList; |
|
63 | + $this->logger = $logger; |
|
64 | + parent::execute($jobList, $logger); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param array $argument |
|
69 | - * @throws \Exception |
|
70 | - * @throws \OC\NeedsUpdateException |
|
71 | - */ |
|
72 | - protected function run($argument) { |
|
73 | - if (!isset($argument['app']) || !isset($argument['step'])) { |
|
74 | - // remove the job - we can never execute it |
|
75 | - $this->jobList->remove($this, $this->argument); |
|
76 | - return; |
|
77 | - } |
|
78 | - $app = $argument['app']; |
|
67 | + /** |
|
68 | + * @param array $argument |
|
69 | + * @throws \Exception |
|
70 | + * @throws \OC\NeedsUpdateException |
|
71 | + */ |
|
72 | + protected function run($argument) { |
|
73 | + if (!isset($argument['app']) || !isset($argument['step'])) { |
|
74 | + // remove the job - we can never execute it |
|
75 | + $this->jobList->remove($this, $this->argument); |
|
76 | + return; |
|
77 | + } |
|
78 | + $app = $argument['app']; |
|
79 | 79 | |
80 | - try { |
|
81 | - $this->loadApp($app); |
|
82 | - } catch (NeedsUpdateException $ex) { |
|
83 | - // as long as the app is not yet done with it's offline migration |
|
84 | - // we better not start with the live migration |
|
85 | - return; |
|
86 | - } |
|
80 | + try { |
|
81 | + $this->loadApp($app); |
|
82 | + } catch (NeedsUpdateException $ex) { |
|
83 | + // as long as the app is not yet done with it's offline migration |
|
84 | + // we better not start with the live migration |
|
85 | + return; |
|
86 | + } |
|
87 | 87 | |
88 | - $step = $argument['step']; |
|
89 | - $repair = new Repair([], $this->dispatcher); |
|
90 | - try { |
|
91 | - $repair->addStep($step); |
|
92 | - } catch (\Exception $ex) { |
|
93 | - $this->logger->logException($ex,[ |
|
94 | - 'app' => 'migration' |
|
95 | - ]); |
|
88 | + $step = $argument['step']; |
|
89 | + $repair = new Repair([], $this->dispatcher); |
|
90 | + try { |
|
91 | + $repair->addStep($step); |
|
92 | + } catch (\Exception $ex) { |
|
93 | + $this->logger->logException($ex,[ |
|
94 | + 'app' => 'migration' |
|
95 | + ]); |
|
96 | 96 | |
97 | - // remove the job - we can never execute it |
|
98 | - $this->jobList->remove($this, $this->argument); |
|
99 | - return; |
|
100 | - } |
|
97 | + // remove the job - we can never execute it |
|
98 | + $this->jobList->remove($this, $this->argument); |
|
99 | + return; |
|
100 | + } |
|
101 | 101 | |
102 | - // execute the repair step |
|
103 | - $repair->run(); |
|
102 | + // execute the repair step |
|
103 | + $repair->run(); |
|
104 | 104 | |
105 | - // remove the job once executed successfully |
|
106 | - $this->jobList->remove($this, $this->argument); |
|
107 | - } |
|
105 | + // remove the job once executed successfully |
|
106 | + $this->jobList->remove($this, $this->argument); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @codeCoverageIgnore |
|
111 | - * @param $app |
|
112 | - * @throws NeedsUpdateException |
|
113 | - */ |
|
114 | - protected function loadApp($app) { |
|
115 | - OC_App::loadApp($app); |
|
116 | - } |
|
109 | + /** |
|
110 | + * @codeCoverageIgnore |
|
111 | + * @param $app |
|
112 | + * @throws NeedsUpdateException |
|
113 | + */ |
|
114 | + protected function loadApp($app) { |
|
115 | + OC_App::loadApp($app); |
|
116 | + } |
|
117 | 117 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | if ($command instanceof ICommand) { |
56 | 56 | // ensure the command can be serialized |
57 | 57 | $serialized = serialize($command); |
58 | - if(strlen($serialized) > 4000) { |
|
58 | + if (strlen($serialized) > 4000) { |
|
59 | 59 | throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
60 | 60 | } |
61 | 61 | $unserialized = unserialize($serialized); |
@@ -26,48 +26,48 @@ |
||
26 | 26 | use OCP\Command\ICommand; |
27 | 27 | |
28 | 28 | class QueueBus implements IBus { |
29 | - /** |
|
30 | - * @var ICommand[]|callable[] |
|
31 | - */ |
|
32 | - private $queue = []; |
|
29 | + /** |
|
30 | + * @var ICommand[]|callable[] |
|
31 | + */ |
|
32 | + private $queue = []; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Schedule a command to be fired |
|
36 | - * |
|
37 | - * @param \OCP\Command\ICommand | callable $command |
|
38 | - */ |
|
39 | - public function push($command) { |
|
40 | - $this->queue[] = $command; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Schedule a command to be fired |
|
36 | + * |
|
37 | + * @param \OCP\Command\ICommand | callable $command |
|
38 | + */ |
|
39 | + public function push($command) { |
|
40 | + $this->queue[] = $command; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Require all commands using a trait to be run synchronous |
|
45 | - * |
|
46 | - * @param string $trait |
|
47 | - */ |
|
48 | - public function requireSync($trait) { |
|
49 | - } |
|
43 | + /** |
|
44 | + * Require all commands using a trait to be run synchronous |
|
45 | + * |
|
46 | + * @param string $trait |
|
47 | + */ |
|
48 | + public function requireSync($trait) { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param \OCP\Command\ICommand | callable $command |
|
53 | - */ |
|
54 | - private function runCommand($command) { |
|
55 | - if ($command instanceof ICommand) { |
|
56 | - // ensure the command can be serialized |
|
57 | - $serialized = serialize($command); |
|
58 | - if(strlen($serialized) > 4000) { |
|
59 | - throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
60 | - } |
|
61 | - $unserialized = unserialize($serialized); |
|
62 | - $unserialized->handle(); |
|
63 | - } else { |
|
64 | - $command(); |
|
65 | - } |
|
66 | - } |
|
51 | + /** |
|
52 | + * @param \OCP\Command\ICommand | callable $command |
|
53 | + */ |
|
54 | + private function runCommand($command) { |
|
55 | + if ($command instanceof ICommand) { |
|
56 | + // ensure the command can be serialized |
|
57 | + $serialized = serialize($command); |
|
58 | + if(strlen($serialized) > 4000) { |
|
59 | + throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
60 | + } |
|
61 | + $unserialized = unserialize($serialized); |
|
62 | + $unserialized->handle(); |
|
63 | + } else { |
|
64 | + $command(); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - public function run() { |
|
69 | - while ($command = array_shift($this->queue)) { |
|
70 | - $this->runCommand($command); |
|
71 | - } |
|
72 | - } |
|
68 | + public function run() { |
|
69 | + while ($command = array_shift($this->queue)) { |
|
70 | + $this->runCommand($command); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | use OC\BackgroundJob\QueuedJob; |
26 | 26 | |
27 | 27 | class CallableJob extends QueuedJob { |
28 | - protected function run($serializedCallable) { |
|
29 | - $callable = unserialize($serializedCallable); |
|
30 | - if (is_callable($callable)) { |
|
31 | - $callable(); |
|
32 | - } else { |
|
33 | - throw new \InvalidArgumentException('Invalid serialized callable'); |
|
34 | - } |
|
35 | - } |
|
28 | + protected function run($serializedCallable) { |
|
29 | + $callable = unserialize($serializedCallable); |
|
30 | + if (is_callable($callable)) { |
|
31 | + $callable(); |
|
32 | + } else { |
|
33 | + throw new \InvalidArgumentException('Invalid serialized callable'); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | use SuperClosure\Serializer; |
27 | 27 | |
28 | 28 | class ClosureJob extends QueuedJob { |
29 | - protected function run($serializedCallable) { |
|
30 | - $serializer = new Serializer(); |
|
31 | - $callable = $serializer->unserialize($serializedCallable); |
|
32 | - if (is_callable($callable)) { |
|
33 | - $callable(); |
|
34 | - } else { |
|
35 | - throw new \InvalidArgumentException('Invalid serialized callable'); |
|
36 | - } |
|
37 | - } |
|
29 | + protected function run($serializedCallable) { |
|
30 | + $serializer = new Serializer(); |
|
31 | + $callable = $serializer->unserialize($serializedCallable); |
|
32 | + if (is_callable($callable)) { |
|
33 | + $callable(); |
|
34 | + } else { |
|
35 | + throw new \InvalidArgumentException('Invalid serialized callable'); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | use OCP\IUser; |
26 | 26 | |
27 | 27 | trait FileAccess { |
28 | - protected function setupFS(IUser $user){ |
|
29 | - \OC_Util::setupFS($user->getUID()); |
|
30 | - } |
|
28 | + protected function setupFS(IUser $user){ |
|
29 | + \OC_Util::setupFS($user->getUID()); |
|
30 | + } |
|
31 | 31 | |
32 | - protected function getUserFolder(IUser $user) { |
|
33 | - $this->setupFS($user); |
|
34 | - return \OC::$server->getUserFolder($user->getUID()); |
|
35 | - } |
|
32 | + protected function getUserFolder(IUser $user) { |
|
33 | + $this->setupFS($user); |
|
34 | + return \OC::$server->getUserFolder($user->getUID()); |
|
35 | + } |
|
36 | 36 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | use OCP\IUser; |
26 | 26 | |
27 | 27 | trait FileAccess { |
28 | - protected function setupFS(IUser $user){ |
|
28 | + protected function setupFS(IUser $user) { |
|
29 | 29 | \OC_Util::setupFS($user->getUID()); |
30 | 30 | } |
31 | 31 |