@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | <meta charset="utf-8"> |
| 5 | 5 | <title> |
| 6 | 6 | <?php |
| 7 | - p(!empty($_['application'])?$_['application'].' - ':''); |
|
| 7 | + p(!empty($_['application']) ? $_['application'].' - ' : ''); |
|
| 8 | 8 | p($theme->getTitle()); |
| 9 | 9 | ?> |
| 10 | 10 | </title> |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | <meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>"> |
| 15 | 15 | <meta name="apple-mobile-web-app-capable" content="yes"> |
| 16 | 16 | <meta name="apple-mobile-web-app-status-bar-style" content="black"> |
| 17 | - <meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:$theme->getTitle()); ?>"> |
|
| 17 | + <meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files') ? $_['application'] : $theme->getTitle()); ?>"> |
|
| 18 | 18 | <meta name="mobile-web-app-capable" content="yes"> |
| 19 | 19 | <meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>"> |
| 20 | 20 | <link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>"> |
@@ -26,18 +26,18 @@ discard block |
||
| 26 | 26 | <?php print_unescaped($_['inline_ocjs']); ?> |
| 27 | 27 | </script> |
| 28 | 28 | <?php endif; ?> |
| 29 | - <?php foreach($_['cssfiles'] as $cssfile): ?> |
|
| 29 | + <?php foreach ($_['cssfiles'] as $cssfile): ?> |
|
| 30 | 30 | <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>"> |
| 31 | 31 | <?php endforeach; ?> |
| 32 | - <?php foreach($_['printcssfiles'] as $cssfile): ?> |
|
| 32 | + <?php foreach ($_['printcssfiles'] as $cssfile): ?> |
|
| 33 | 33 | <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print"> |
| 34 | 34 | <?php endforeach; ?> |
| 35 | - <?php foreach($_['jsfiles'] as $jsfile): ?> |
|
| 35 | + <?php foreach ($_['jsfiles'] as $jsfile): ?> |
|
| 36 | 36 | <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script> |
| 37 | 37 | <?php endforeach; ?> |
| 38 | 38 | <?php print_unescaped($_['headers']); ?> |
| 39 | 39 | </head> |
| 40 | - <body id="<?php p($_['bodyid']);?>"> |
|
| 40 | + <body id="<?php p($_['bodyid']); ?>"> |
|
| 41 | 41 | <?php include('layout.noscript.warning.php'); ?> |
| 42 | 42 | <div id="notification-container"> |
| 43 | 43 | <div id="notification"></div> |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | <a href="#" class="header-appname-container menutoggle" tabindex="2"> |
| 57 | 57 | <h1 class="header-appname"> |
| 58 | - <?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?> |
|
| 58 | + <?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?> |
|
| 59 | 59 | </h1> |
| 60 | 60 | <div class="icon-caret"></div> |
| 61 | 61 | </a> |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | <a href="<?php print_unescaped($entry['href']); ?>" |
| 67 | 67 | tabindex="3" |
| 68 | 68 | <?php if ($entry['active']): ?> class="active"<?php endif; ?>> |
| 69 | - <img src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" |
|
| 69 | + <img src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" |
|
| 70 | 70 | class="app-icon"/> |
| 71 | 71 | <div class="icon-loading-small-dark" |
| 72 | 72 | style="display:none;"></div> |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | <div id="navigation"> |
| 89 | 89 | <div id="apps"> |
| 90 | 90 | <ul> |
| 91 | - <?php foreach($_['navigation'] as $entry): ?> |
|
| 91 | + <?php foreach ($_['navigation'] as $entry): ?> |
|
| 92 | 92 | <li data-id="<?php p($entry['id']); ?>"> |
| 93 | 93 | <a href="<?php print_unescaped($entry['href']); ?>" tabindex="3" |
| 94 | - <?php if( $entry['active'] ): ?> class="active"<?php endif; ?>> |
|
| 94 | + <?php if ($entry['active']): ?> class="active"<?php endif; ?>> |
|
| 95 | 95 | <svg width="16" height="16" viewBox="0 0 16 16"> |
| 96 | 96 | <defs><filter id="invert-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs> |
| 97 | - <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invert-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon"></image> |
|
| 97 | + <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invert-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" class="app-icon"></image> |
|
| 98 | 98 | </svg> |
| 99 | 99 | <div class="icon-loading-small-dark" style="display:none;"></div> |
| 100 | 100 | <span><?php p($entry['name']); ?></span> |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | <div id="header-right"> |
| 112 | 112 | <form class="searchbox" action="#" method="post" role="search" novalidate> |
| 113 | 113 | <label for="searchbox" class="hidden-visually"> |
| 114 | - <?php p($l->t('Search'));?> |
|
| 114 | + <?php p($l->t('Search')); ?> |
|
| 115 | 115 | </label> |
| 116 | 116 | <input id="searchbox" type="search" name="query" |
| 117 | 117 | value="" required |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | <div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>"> |
| 124 | 124 | <?php if ($_['userAvatarSet']): ?> |
| 125 | 125 | <img alt="" width="32" height="32" |
| 126 | - src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>" |
|
| 127 | - srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']]));?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']]));?> 4x" |
|
| 126 | + src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>" |
|
| 127 | + srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']])); ?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']])); ?> 4x" |
|
| 128 | 128 | > |
| 129 | 129 | <?php endif; ?> |
| 130 | 130 | </div> |
@@ -132,11 +132,11 @@ discard block |
||
| 132 | 132 | </div> |
| 133 | 133 | <div id="expanddiv"> |
| 134 | 134 | <ul> |
| 135 | - <?php foreach($_['settingsnavigation'] as $entry):?> |
|
| 135 | + <?php foreach ($_['settingsnavigation'] as $entry):?> |
|
| 136 | 136 | <li> |
| 137 | 137 | <a href="<?php print_unescaped($entry['href']); ?>" |
| 138 | - <?php if( $entry["active"] ): ?> class="active"<?php endif; ?>> |
|
| 139 | - <img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"> |
|
| 138 | + <?php if ($entry["active"]): ?> class="active"<?php endif; ?>> |
|
| 139 | + <img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"> |
|
| 140 | 140 | <?php p($entry['name']) ?> |
| 141 | 141 | </a> |
| 142 | 142 | </li> |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | $apps = self::getEnabledApps(); |
| 112 | 112 | |
| 113 | 113 | // Add each apps' folder as allowed class path |
| 114 | - foreach($apps as $app) { |
|
| 114 | + foreach ($apps as $app) { |
|
| 115 | 115 | $path = self::getAppPath($app); |
| 116 | - if($path !== false) { |
|
| 116 | + if ($path !== false) { |
|
| 117 | 117 | self::registerAutoloading($app, $path); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -138,15 +138,15 @@ discard block |
||
| 138 | 138 | public static function loadApp($app) { |
| 139 | 139 | self::$loadedApps[] = $app; |
| 140 | 140 | $appPath = self::getAppPath($app); |
| 141 | - if($appPath === false) { |
|
| 141 | + if ($appPath === false) { |
|
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // in case someone calls loadApp() directly |
| 146 | 146 | self::registerAutoloading($app, $appPath); |
| 147 | 147 | |
| 148 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
| 149 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 148 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
| 149 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
| 150 | 150 | self::requireAppFile($app); |
| 151 | 151 | if (self::isType($app, array('authentication'))) { |
| 152 | 152 | // since authentication apps affect the "is app enabled for group" check, |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // enabled for groups |
| 156 | 156 | self::$enabledAppsCache = array(); |
| 157 | 157 | } |
| 158 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 158 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $info = self::getAppInfo($app); |
@@ -182,17 +182,17 @@ discard block |
||
| 182 | 182 | * @param string $path |
| 183 | 183 | */ |
| 184 | 184 | public static function registerAutoloading($app, $path) { |
| 185 | - $key = $app . '-' . $path; |
|
| 186 | - if(isset(self::$alreadyRegistered[$key])) { |
|
| 185 | + $key = $app.'-'.$path; |
|
| 186 | + if (isset(self::$alreadyRegistered[$key])) { |
|
| 187 | 187 | return; |
| 188 | 188 | } |
| 189 | 189 | self::$alreadyRegistered[$key] = true; |
| 190 | 190 | // Register on PSR-4 composer autoloader |
| 191 | 191 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
| 192 | 192 | \OC::$server->registerNamespace($app, $appNamespace); |
| 193 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 193 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
| 194 | 194 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
| 195 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 195 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Register on legacy autoloader |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | private static function requireAppFile($app) { |
| 208 | 208 | try { |
| 209 | 209 | // encapsulated here to avoid variable scope conflicts |
| 210 | - require_once $app . '/appinfo/app.php'; |
|
| 210 | + require_once $app.'/appinfo/app.php'; |
|
| 211 | 211 | } catch (Error $ex) { |
| 212 | 212 | \OC::$server->getLogger()->logException($ex); |
| 213 | 213 | $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public static function setAppTypes($app) { |
| 263 | 263 | $appData = self::getAppInfo($app); |
| 264 | - if(!is_array($appData)) { |
|
| 264 | + if (!is_array($appData)) { |
|
| 265 | 265 | return; |
| 266 | 266 | } |
| 267 | 267 | |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | } else { |
| 326 | 326 | $apps = $appManager->getEnabledAppsForUser($user); |
| 327 | 327 | } |
| 328 | - $apps = array_filter($apps, function ($app) { |
|
| 329 | - return $app !== 'files';//we add this manually |
|
| 328 | + $apps = array_filter($apps, function($app) { |
|
| 329 | + return $app !== 'files'; //we add this manually |
|
| 330 | 330 | }); |
| 331 | 331 | sort($apps); |
| 332 | 332 | array_unshift($apps, 'files'); |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | ); |
| 371 | 371 | $isDownloaded = $installer->isDownloaded($appId); |
| 372 | 372 | |
| 373 | - if(!$isDownloaded) { |
|
| 373 | + if (!$isDownloaded) { |
|
| 374 | 374 | $installer->downloadApp($appId); |
| 375 | 375 | } |
| 376 | 376 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $info = self::getAppInfo($appId); |
| 411 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 411 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 412 | 412 | $appPath = self::getAppPath($appId); |
| 413 | 413 | self::registerAutoloading($appId, $appPath); |
| 414 | 414 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | */ |
| 512 | 512 | public static function findAppInDirectories($appId) { |
| 513 | 513 | $sanitizedAppId = self::cleanAppId($appId); |
| 514 | - if($sanitizedAppId !== $appId) { |
|
| 514 | + if ($sanitizedAppId !== $appId) { |
|
| 515 | 515 | return false; |
| 516 | 516 | } |
| 517 | 517 | static $app_dir = array(); |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | |
| 523 | 523 | $possibleApps = array(); |
| 524 | 524 | foreach (OC::$APPSROOTS as $dir) { |
| 525 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 525 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
| 526 | 526 | $possibleApps[] = $dir; |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | if (($dir = self::findAppInDirectories($appId)) != false) { |
| 566 | - return $dir['path'] . '/' . $appId; |
|
| 566 | + return $dir['path'].'/'.$appId; |
|
| 567 | 567 | } |
| 568 | 568 | return false; |
| 569 | 569 | } |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | */ |
| 578 | 578 | public static function getAppWebPath($appId) { |
| 579 | 579 | if (($dir = self::findAppInDirectories($appId)) != false) { |
| 580 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 580 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
| 581 | 581 | } |
| 582 | 582 | return false; |
| 583 | 583 | } |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * @return string |
| 591 | 591 | */ |
| 592 | 592 | public static function getAppVersion($appId, $useCache = true) { |
| 593 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
| 593 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
| 594 | 594 | return self::$appVersion[$appId]; |
| 595 | 595 | } |
| 596 | 596 | |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | * @return string |
| 607 | 607 | */ |
| 608 | 608 | public static function getAppVersionByPath($path) { |
| 609 | - $infoFile = $path . '/appinfo/info.xml'; |
|
| 609 | + $infoFile = $path.'/appinfo/info.xml'; |
|
| 610 | 610 | $appData = self::getAppInfo($infoFile, true); |
| 611 | 611 | return isset($appData['version']) ? $appData['version'] : ''; |
| 612 | 612 | } |
@@ -629,10 +629,10 @@ discard block |
||
| 629 | 629 | return self::$appInfo[$appId]; |
| 630 | 630 | } |
| 631 | 631 | $appPath = self::getAppPath($appId); |
| 632 | - if($appPath === false) { |
|
| 632 | + if ($appPath === false) { |
|
| 633 | 633 | return null; |
| 634 | 634 | } |
| 635 | - $file = $appPath . '/appinfo/info.xml'; |
|
| 635 | + $file = $appPath.'/appinfo/info.xml'; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
@@ -641,9 +641,9 @@ discard block |
||
| 641 | 641 | if (is_array($data)) { |
| 642 | 642 | $data = OC_App::parseAppInfo($data, $lang); |
| 643 | 643 | } |
| 644 | - if(isset($data['ocsid'])) { |
|
| 644 | + if (isset($data['ocsid'])) { |
|
| 645 | 645 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
| 646 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 646 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 647 | 647 | $data['ocsid'] = $storedId; |
| 648 | 648 | } |
| 649 | 649 | } |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | * @param string $page |
| 736 | 736 | */ |
| 737 | 737 | public static function registerAdmin($app, $page) { |
| 738 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 738 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -744,7 +744,7 @@ discard block |
||
| 744 | 744 | * @param string $page |
| 745 | 745 | */ |
| 746 | 746 | public static function registerPersonal($app, $page) { |
| 747 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 747 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | /** |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | |
| 774 | 774 | foreach (OC::$APPSROOTS as $apps_dir) { |
| 775 | 775 | if (!is_readable($apps_dir['path'])) { |
| 776 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 776 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
| 777 | 777 | continue; |
| 778 | 778 | } |
| 779 | 779 | $dh = opendir($apps_dir['path']); |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | if (is_resource($dh)) { |
| 782 | 782 | while (($file = readdir($dh)) !== false) { |
| 783 | 783 | |
| 784 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 784 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
| 785 | 785 | |
| 786 | 786 | $apps[] = $file; |
| 787 | 787 | } |
@@ -811,12 +811,12 @@ discard block |
||
| 811 | 811 | |
| 812 | 812 | $info = OC_App::getAppInfo($app, false, $langCode); |
| 813 | 813 | if (!is_array($info)) { |
| 814 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 814 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
| 815 | 815 | continue; |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | if (!isset($info['name'])) { |
| 819 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 819 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
| 820 | 820 | continue; |
| 821 | 821 | } |
| 822 | 822 | |
@@ -843,13 +843,13 @@ discard block |
||
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | $appPath = self::getAppPath($app); |
| 846 | - if($appPath !== false) { |
|
| 847 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 846 | + if ($appPath !== false) { |
|
| 847 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
| 848 | 848 | if (file_exists($appIcon)) { |
| 849 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
| 849 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app.'.svg'); |
|
| 850 | 850 | $info['previewAsIcon'] = true; |
| 851 | 851 | } else { |
| 852 | - $appIcon = $appPath . '/img/app.svg'; |
|
| 852 | + $appIcon = $appPath.'/img/app.svg'; |
|
| 853 | 853 | if (file_exists($appIcon)) { |
| 854 | 854 | $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
| 855 | 855 | $info['previewAsIcon'] = true; |
@@ -883,9 +883,9 @@ discard block |
||
| 883 | 883 | * @return string|false |
| 884 | 884 | */ |
| 885 | 885 | public static function getInternalAppIdByOcs($ocsID) { |
| 886 | - if(is_numeric($ocsID)) { |
|
| 886 | + if (is_numeric($ocsID)) { |
|
| 887 | 887 | $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
| 888 | - if(array_search($ocsID, $idArray)) { |
|
| 888 | + if (array_search($ocsID, $idArray)) { |
|
| 889 | 889 | return array_search($ocsID, $idArray); |
| 890 | 890 | } |
| 891 | 891 | } |
@@ -989,7 +989,7 @@ discard block |
||
| 989 | 989 | public static function getAppVersions() { |
| 990 | 990 | static $versions; |
| 991 | 991 | |
| 992 | - if(!$versions) { |
|
| 992 | + if (!$versions) { |
|
| 993 | 993 | $appConfig = \OC::$server->getAppConfig(); |
| 994 | 994 | $versions = $appConfig->getValues(false, 'installed_version'); |
| 995 | 995 | } |
@@ -1011,7 +1011,7 @@ discard block |
||
| 1011 | 1011 | if ($app !== false) { |
| 1012 | 1012 | // check if the app is compatible with this version of ownCloud |
| 1013 | 1013 | $info = self::getAppInfo($app); |
| 1014 | - if(!is_array($info)) { |
|
| 1014 | + if (!is_array($info)) { |
|
| 1015 | 1015 | throw new \Exception( |
| 1016 | 1016 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
| 1017 | 1017 | [$info['name']] |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | $config->setAppValue($app, 'ocsid', $appData['id']); |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1039 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 1040 | 1040 | $appPath = self::getAppPath($app); |
| 1041 | 1041 | self::registerAutoloading($app, $appPath); |
| 1042 | 1042 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | |
| 1045 | 1045 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
| 1046 | 1046 | } else { |
| 1047 | - if(empty($appName) ) { |
|
| 1047 | + if (empty($appName)) { |
|
| 1048 | 1048 | throw new \Exception($l->t("No app name specified")); |
| 1049 | 1049 | } else { |
| 1050 | 1050 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1062,24 +1062,24 @@ discard block |
||
| 1062 | 1062 | */ |
| 1063 | 1063 | public static function updateApp($appId) { |
| 1064 | 1064 | $appPath = self::getAppPath($appId); |
| 1065 | - if($appPath === false) { |
|
| 1065 | + if ($appPath === false) { |
|
| 1066 | 1066 | return false; |
| 1067 | 1067 | } |
| 1068 | 1068 | $appData = self::getAppInfo($appId); |
| 1069 | 1069 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
| 1070 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1071 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1070 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
| 1071 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
| 1074 | 1074 | self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
| 1075 | 1075 | unset(self::$appVersion[$appId]); |
| 1076 | 1076 | // run upgrade code |
| 1077 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1077 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
| 1078 | 1078 | self::loadApp($appId); |
| 1079 | - include $appPath . '/appinfo/update.php'; |
|
| 1079 | + include $appPath.'/appinfo/update.php'; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | self::setupBackgroundJobs($appData['background-jobs']); |
| 1082 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1082 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1083 | 1083 | $appPath = self::getAppPath($appId); |
| 1084 | 1084 | self::registerAutoloading($appId, $appPath); |
| 1085 | 1085 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
@@ -1088,14 +1088,14 @@ discard block |
||
| 1088 | 1088 | //set remote/public handlers |
| 1089 | 1089 | if (array_key_exists('ocsid', $appData)) { |
| 1090 | 1090 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
| 1091 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1091 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1092 | 1092 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
| 1093 | 1093 | } |
| 1094 | 1094 | foreach ($appData['remote'] as $name => $path) { |
| 1095 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1095 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | foreach ($appData['public'] as $name => $path) { |
| 1098 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1098 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | self::setAppTypes($appId); |
@@ -1165,17 +1165,17 @@ discard block |
||
| 1165 | 1165 | public static function getStorage($appId) { |
| 1166 | 1166 | if (OC_App::isEnabled($appId)) { //sanity check |
| 1167 | 1167 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
| 1168 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1168 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
| 1169 | 1169 | if (!$view->file_exists($appId)) { |
| 1170 | 1170 | $view->mkdir($appId); |
| 1171 | 1171 | } |
| 1172 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1172 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
| 1173 | 1173 | } else { |
| 1174 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1174 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
| 1175 | 1175 | return false; |
| 1176 | 1176 | } |
| 1177 | 1177 | } else { |
| 1178 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1178 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
| 1179 | 1179 | return false; |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
@@ -1207,9 +1207,9 @@ discard block |
||
| 1207 | 1207 | |
| 1208 | 1208 | if ($attributeLang === $similarLang) { |
| 1209 | 1209 | $similarLangFallback = $option['@value']; |
| 1210 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1210 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
| 1211 | 1211 | if ($similarLangFallback === false) { |
| 1212 | - $similarLangFallback = $option['@value']; |
|
| 1212 | + $similarLangFallback = $option['@value']; |
|
| 1213 | 1213 | } |
| 1214 | 1214 | } |
| 1215 | 1215 | } else { |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
| 1245 | 1245 | } else if (isset($data['description']) && is_string($data['description'])) { |
| 1246 | 1246 | $data['description'] = trim($data['description']); |
| 1247 | - } else { |
|
| 1247 | + } else { |
|
| 1248 | 1248 | $data['description'] = ''; |
| 1249 | 1249 | } |
| 1250 | 1250 | |
@@ -60,1214 +60,1214 @@ |
||
| 60 | 60 | * upgrading and removing apps. |
| 61 | 61 | */ |
| 62 | 62 | class OC_App { |
| 63 | - static private $appVersion = []; |
|
| 64 | - static private $adminForms = array(); |
|
| 65 | - static private $personalForms = array(); |
|
| 66 | - static private $appInfo = array(); |
|
| 67 | - static private $appTypes = array(); |
|
| 68 | - static private $loadedApps = array(); |
|
| 69 | - static private $altLogin = array(); |
|
| 70 | - static private $alreadyRegistered = []; |
|
| 71 | - const officialApp = 200; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * clean the appId |
|
| 75 | - * |
|
| 76 | - * @param string|boolean $app AppId that needs to be cleaned |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public static function cleanAppId($app) { |
|
| 80 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Check if an app is loaded |
|
| 85 | - * |
|
| 86 | - * @param string $app |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - public static function isAppLoaded($app) { |
|
| 90 | - return in_array($app, self::$loadedApps, true); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * loads all apps |
|
| 95 | - * |
|
| 96 | - * @param string[] | string | null $types |
|
| 97 | - * @return bool |
|
| 98 | - * |
|
| 99 | - * This function walks through the ownCloud directory and loads all apps |
|
| 100 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
| 101 | - * exists. |
|
| 102 | - * |
|
| 103 | - * if $types is set, only apps of those types will be loaded |
|
| 104 | - */ |
|
| 105 | - public static function loadApps($types = null) { |
|
| 106 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 107 | - return false; |
|
| 108 | - } |
|
| 109 | - // Load the enabled apps here |
|
| 110 | - $apps = self::getEnabledApps(); |
|
| 111 | - |
|
| 112 | - // Add each apps' folder as allowed class path |
|
| 113 | - foreach($apps as $app) { |
|
| 114 | - $path = self::getAppPath($app); |
|
| 115 | - if($path !== false) { |
|
| 116 | - self::registerAutoloading($app, $path); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // prevent app.php from printing output |
|
| 121 | - ob_start(); |
|
| 122 | - foreach ($apps as $app) { |
|
| 123 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
| 124 | - self::loadApp($app); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - ob_end_clean(); |
|
| 128 | - |
|
| 129 | - return true; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * load a single app |
|
| 134 | - * |
|
| 135 | - * @param string $app |
|
| 136 | - */ |
|
| 137 | - public static function loadApp($app) { |
|
| 138 | - self::$loadedApps[] = $app; |
|
| 139 | - $appPath = self::getAppPath($app); |
|
| 140 | - if($appPath === false) { |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // in case someone calls loadApp() directly |
|
| 145 | - self::registerAutoloading($app, $appPath); |
|
| 146 | - |
|
| 147 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
| 148 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 149 | - self::requireAppFile($app); |
|
| 150 | - if (self::isType($app, array('authentication'))) { |
|
| 151 | - // since authentication apps affect the "is app enabled for group" check, |
|
| 152 | - // the enabled apps cache needs to be cleared to make sure that the |
|
| 153 | - // next time getEnableApps() is called it will also include apps that were |
|
| 154 | - // enabled for groups |
|
| 155 | - self::$enabledAppsCache = array(); |
|
| 156 | - } |
|
| 157 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $info = self::getAppInfo($app); |
|
| 161 | - if (!empty($info['activity']['filters'])) { |
|
| 162 | - foreach ($info['activity']['filters'] as $filter) { |
|
| 163 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - if (!empty($info['activity']['settings'])) { |
|
| 167 | - foreach ($info['activity']['settings'] as $setting) { |
|
| 168 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - if (!empty($info['activity']['providers'])) { |
|
| 172 | - foreach ($info['activity']['providers'] as $provider) { |
|
| 173 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @internal |
|
| 180 | - * @param string $app |
|
| 181 | - * @param string $path |
|
| 182 | - */ |
|
| 183 | - public static function registerAutoloading($app, $path) { |
|
| 184 | - $key = $app . '-' . $path; |
|
| 185 | - if(isset(self::$alreadyRegistered[$key])) { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - self::$alreadyRegistered[$key] = true; |
|
| 189 | - // Register on PSR-4 composer autoloader |
|
| 190 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
| 191 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
| 192 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 193 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
| 194 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // Register on legacy autoloader |
|
| 198 | - \OC::$loader->addValidRoot($path); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Load app.php from the given app |
|
| 203 | - * |
|
| 204 | - * @param string $app app name |
|
| 205 | - */ |
|
| 206 | - private static function requireAppFile($app) { |
|
| 207 | - try { |
|
| 208 | - // encapsulated here to avoid variable scope conflicts |
|
| 209 | - require_once $app . '/appinfo/app.php'; |
|
| 210 | - } catch (Error $ex) { |
|
| 211 | - \OC::$server->getLogger()->logException($ex); |
|
| 212 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
| 213 | - if (!in_array($app, $blacklist)) { |
|
| 214 | - self::disable($app); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * check if an app is of a specific type |
|
| 221 | - * |
|
| 222 | - * @param string $app |
|
| 223 | - * @param string|array $types |
|
| 224 | - * @return bool |
|
| 225 | - */ |
|
| 226 | - public static function isType($app, $types) { |
|
| 227 | - if (is_string($types)) { |
|
| 228 | - $types = array($types); |
|
| 229 | - } |
|
| 230 | - $appTypes = self::getAppTypes($app); |
|
| 231 | - foreach ($types as $type) { |
|
| 232 | - if (array_search($type, $appTypes) !== false) { |
|
| 233 | - return true; |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * get the types of an app |
|
| 241 | - * |
|
| 242 | - * @param string $app |
|
| 243 | - * @return array |
|
| 244 | - */ |
|
| 245 | - private static function getAppTypes($app) { |
|
| 246 | - //load the cache |
|
| 247 | - if (count(self::$appTypes) == 0) { |
|
| 248 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - if (isset(self::$appTypes[$app])) { |
|
| 252 | - return explode(',', self::$appTypes[$app]); |
|
| 253 | - } else { |
|
| 254 | - return array(); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * read app types from info.xml and cache them in the database |
|
| 260 | - */ |
|
| 261 | - public static function setAppTypes($app) { |
|
| 262 | - $appData = self::getAppInfo($app); |
|
| 263 | - if(!is_array($appData)) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if (isset($appData['types'])) { |
|
| 268 | - $appTypes = implode(',', $appData['types']); |
|
| 269 | - } else { |
|
| 270 | - $appTypes = ''; |
|
| 271 | - $appData['types'] = []; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
| 275 | - |
|
| 276 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
| 277 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
| 278 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
| 279 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * check if app is shipped |
|
| 286 | - * |
|
| 287 | - * @param string $appId the id of the app to check |
|
| 288 | - * @return bool |
|
| 289 | - * |
|
| 290 | - * Check if an app that is installed is a shipped app or installed from the appstore. |
|
| 291 | - */ |
|
| 292 | - public static function isShipped($appId) { |
|
| 293 | - return \OC::$server->getAppManager()->isShipped($appId); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * get all enabled apps |
|
| 298 | - */ |
|
| 299 | - protected static $enabledAppsCache = array(); |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Returns apps enabled for the current user. |
|
| 303 | - * |
|
| 304 | - * @param bool $forceRefresh whether to refresh the cache |
|
| 305 | - * @param bool $all whether to return apps for all users, not only the |
|
| 306 | - * currently logged in one |
|
| 307 | - * @return string[] |
|
| 308 | - */ |
|
| 309 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
| 310 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 311 | - return array(); |
|
| 312 | - } |
|
| 313 | - // in incognito mode or when logged out, $user will be false, |
|
| 314 | - // which is also the case during an upgrade |
|
| 315 | - $appManager = \OC::$server->getAppManager(); |
|
| 316 | - if ($all) { |
|
| 317 | - $user = null; |
|
| 318 | - } else { |
|
| 319 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if (is_null($user)) { |
|
| 323 | - $apps = $appManager->getInstalledApps(); |
|
| 324 | - } else { |
|
| 325 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
| 326 | - } |
|
| 327 | - $apps = array_filter($apps, function ($app) { |
|
| 328 | - return $app !== 'files';//we add this manually |
|
| 329 | - }); |
|
| 330 | - sort($apps); |
|
| 331 | - array_unshift($apps, 'files'); |
|
| 332 | - return $apps; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * checks whether or not an app is enabled |
|
| 337 | - * |
|
| 338 | - * @param string $app app |
|
| 339 | - * @return bool |
|
| 340 | - * |
|
| 341 | - * This function checks whether or not an app is enabled. |
|
| 342 | - */ |
|
| 343 | - public static function isEnabled($app) { |
|
| 344 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * enables an app |
|
| 349 | - * |
|
| 350 | - * @param string $appId |
|
| 351 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
| 352 | - * @throws \Exception |
|
| 353 | - * @return void |
|
| 354 | - * |
|
| 355 | - * This function set an app as enabled in appconfig. |
|
| 356 | - */ |
|
| 357 | - public function enable($appId, |
|
| 358 | - $groups = null) { |
|
| 359 | - self::$enabledAppsCache = []; // flush |
|
| 360 | - $l = \OC::$server->getL10N('core'); |
|
| 361 | - $config = \OC::$server->getConfig(); |
|
| 362 | - |
|
| 363 | - // Check if app is already downloaded |
|
| 364 | - $installer = new Installer( |
|
| 365 | - \OC::$server->getAppFetcher(), |
|
| 366 | - \OC::$server->getHTTPClientService(), |
|
| 367 | - \OC::$server->getTempManager(), |
|
| 368 | - \OC::$server->getLogger(), |
|
| 369 | - \OC::$server->getConfig() |
|
| 370 | - ); |
|
| 371 | - $isDownloaded = $installer->isDownloaded($appId); |
|
| 372 | - |
|
| 373 | - if(!$isDownloaded) { |
|
| 374 | - $installer->downloadApp($appId); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - if (!Installer::isInstalled($appId)) { |
|
| 378 | - $appId = self::installApp( |
|
| 379 | - $appId, |
|
| 380 | - $config, |
|
| 381 | - $l |
|
| 382 | - ); |
|
| 383 | - $appPath = self::getAppPath($appId); |
|
| 384 | - self::registerAutoloading($appId, $appPath); |
|
| 385 | - $installer->installApp($appId); |
|
| 386 | - } else { |
|
| 387 | - // check for required dependencies |
|
| 388 | - $info = self::getAppInfo($appId); |
|
| 389 | - self::checkAppDependencies($config, $l, $info); |
|
| 390 | - $appPath = self::getAppPath($appId); |
|
| 391 | - self::registerAutoloading($appId, $appPath); |
|
| 392 | - $installer->installApp($appId); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $appManager = \OC::$server->getAppManager(); |
|
| 396 | - if (!is_null($groups)) { |
|
| 397 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 398 | - $groupsList = []; |
|
| 399 | - foreach ($groups as $group) { |
|
| 400 | - $groupItem = $groupManager->get($group); |
|
| 401 | - if ($groupItem instanceof \OCP\IGroup) { |
|
| 402 | - $groupsList[] = $groupManager->get($group); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
| 406 | - } else { |
|
| 407 | - $appManager->enableApp($appId); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - $info = self::getAppInfo($appId); |
|
| 411 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 412 | - $appPath = self::getAppPath($appId); |
|
| 413 | - self::registerAutoloading($appId, $appPath); |
|
| 414 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * @param string $app |
|
| 420 | - * @return bool |
|
| 421 | - */ |
|
| 422 | - public static function removeApp($app) { |
|
| 423 | - if (self::isShipped($app)) { |
|
| 424 | - return false; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - $installer = new Installer( |
|
| 428 | - \OC::$server->getAppFetcher(), |
|
| 429 | - \OC::$server->getHTTPClientService(), |
|
| 430 | - \OC::$server->getTempManager(), |
|
| 431 | - \OC::$server->getLogger(), |
|
| 432 | - \OC::$server->getConfig() |
|
| 433 | - ); |
|
| 434 | - return $installer->removeApp($app); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * This function set an app as disabled in appconfig. |
|
| 439 | - * |
|
| 440 | - * @param string $app app |
|
| 441 | - * @throws Exception |
|
| 442 | - */ |
|
| 443 | - public static function disable($app) { |
|
| 444 | - // flush |
|
| 445 | - self::$enabledAppsCache = array(); |
|
| 446 | - |
|
| 447 | - // run uninstall steps |
|
| 448 | - $appData = OC_App::getAppInfo($app); |
|
| 449 | - if (!is_null($appData)) { |
|
| 450 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // emit disable hook - needed anymore ? |
|
| 454 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
| 455 | - |
|
| 456 | - // finally disable it |
|
| 457 | - $appManager = \OC::$server->getAppManager(); |
|
| 458 | - $appManager->disableApp($app); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - // This is private as well. It simply works, so don't ask for more details |
|
| 462 | - private static function proceedNavigation($list) { |
|
| 463 | - usort($list, function($a, $b) { |
|
| 464 | - if (isset($a['order']) && isset($b['order'])) { |
|
| 465 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 466 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
| 467 | - return isset($a['order']) ? -1 : 1; |
|
| 468 | - } else { |
|
| 469 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 470 | - } |
|
| 471 | - }); |
|
| 472 | - |
|
| 473 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
| 474 | - foreach ($list as $index => &$navEntry) { |
|
| 475 | - if ($navEntry['id'] == $activeApp) { |
|
| 476 | - $navEntry['active'] = true; |
|
| 477 | - } else { |
|
| 478 | - $navEntry['active'] = false; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - unset($navEntry); |
|
| 482 | - |
|
| 483 | - return $list; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Get the path where to install apps |
|
| 488 | - * |
|
| 489 | - * @return string|false |
|
| 490 | - */ |
|
| 491 | - public static function getInstallPath() { |
|
| 492 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
| 493 | - return false; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - foreach (OC::$APPSROOTS as $dir) { |
|
| 497 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
| 498 | - return $dir['path']; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
| 503 | - return null; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * search for an app in all app-directories |
|
| 509 | - * |
|
| 510 | - * @param string $appId |
|
| 511 | - * @return false|string |
|
| 512 | - */ |
|
| 513 | - public static function findAppInDirectories($appId) { |
|
| 514 | - $sanitizedAppId = self::cleanAppId($appId); |
|
| 515 | - if($sanitizedAppId !== $appId) { |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - static $app_dir = array(); |
|
| 519 | - |
|
| 520 | - if (isset($app_dir[$appId])) { |
|
| 521 | - return $app_dir[$appId]; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $possibleApps = array(); |
|
| 525 | - foreach (OC::$APPSROOTS as $dir) { |
|
| 526 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 527 | - $possibleApps[] = $dir; |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - if (empty($possibleApps)) { |
|
| 532 | - return false; |
|
| 533 | - } elseif (count($possibleApps) === 1) { |
|
| 534 | - $dir = array_shift($possibleApps); |
|
| 535 | - $app_dir[$appId] = $dir; |
|
| 536 | - return $dir; |
|
| 537 | - } else { |
|
| 538 | - $versionToLoad = array(); |
|
| 539 | - foreach ($possibleApps as $possibleApp) { |
|
| 540 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
| 541 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
| 542 | - $versionToLoad = array( |
|
| 543 | - 'dir' => $possibleApp, |
|
| 544 | - 'version' => $version, |
|
| 545 | - ); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
| 549 | - return $versionToLoad['dir']; |
|
| 550 | - //TODO - write test |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Get the directory for the given app. |
|
| 556 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 557 | - * |
|
| 558 | - * @param string $appId |
|
| 559 | - * @return string|false |
|
| 560 | - */ |
|
| 561 | - public static function getAppPath($appId) { |
|
| 562 | - if ($appId === null || trim($appId) === '') { |
|
| 563 | - return false; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 567 | - return $dir['path'] . '/' . $appId; |
|
| 568 | - } |
|
| 569 | - return false; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Get the path for the given app on the access |
|
| 574 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 575 | - * |
|
| 576 | - * @param string $appId |
|
| 577 | - * @return string|false |
|
| 578 | - */ |
|
| 579 | - public static function getAppWebPath($appId) { |
|
| 580 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 581 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 582 | - } |
|
| 583 | - return false; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * get the last version of the app from appinfo/info.xml |
|
| 588 | - * |
|
| 589 | - * @param string $appId |
|
| 590 | - * @param bool $useCache |
|
| 591 | - * @return string |
|
| 592 | - */ |
|
| 593 | - public static function getAppVersion($appId, $useCache = true) { |
|
| 594 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
| 595 | - return self::$appVersion[$appId]; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - $file = self::getAppPath($appId); |
|
| 599 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
| 600 | - return self::$appVersion[$appId]; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * get app's version based on it's path |
|
| 605 | - * |
|
| 606 | - * @param string $path |
|
| 607 | - * @return string |
|
| 608 | - */ |
|
| 609 | - public static function getAppVersionByPath($path) { |
|
| 610 | - $infoFile = $path . '/appinfo/info.xml'; |
|
| 611 | - $appData = self::getAppInfo($infoFile, true); |
|
| 612 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Read all app metadata from the info.xml file |
|
| 618 | - * |
|
| 619 | - * @param string $appId id of the app or the path of the info.xml file |
|
| 620 | - * @param bool $path |
|
| 621 | - * @param string $lang |
|
| 622 | - * @return array|null |
|
| 623 | - * @note all data is read from info.xml, not just pre-defined fields |
|
| 624 | - */ |
|
| 625 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
| 626 | - if ($path) { |
|
| 627 | - $file = $appId; |
|
| 628 | - } else { |
|
| 629 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
| 630 | - return self::$appInfo[$appId]; |
|
| 631 | - } |
|
| 632 | - $appPath = self::getAppPath($appId); |
|
| 633 | - if($appPath === false) { |
|
| 634 | - return null; |
|
| 635 | - } |
|
| 636 | - $file = $appPath . '/appinfo/info.xml'; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
| 640 | - $data = $parser->parse($file); |
|
| 641 | - |
|
| 642 | - if (is_array($data)) { |
|
| 643 | - $data = OC_App::parseAppInfo($data, $lang); |
|
| 644 | - } |
|
| 645 | - if(isset($data['ocsid'])) { |
|
| 646 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
| 647 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 648 | - $data['ocsid'] = $storedId; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - if ($lang === null) { |
|
| 653 | - self::$appInfo[$appId] = $data; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - return $data; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Returns the navigation |
|
| 661 | - * |
|
| 662 | - * @return array |
|
| 663 | - * |
|
| 664 | - * This function returns an array containing all entries added. The |
|
| 665 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
| 666 | - * given for each app the following keys exist: |
|
| 667 | - * - active: boolean, signals if the user is on this navigation entry |
|
| 668 | - */ |
|
| 669 | - public static function getNavigation() { |
|
| 670 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
| 671 | - return self::proceedNavigation($entries); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Returns the Settings Navigation |
|
| 676 | - * |
|
| 677 | - * @return string[] |
|
| 678 | - * |
|
| 679 | - * This function returns an array containing all settings pages added. The |
|
| 680 | - * entries are sorted by the key 'order' ascending. |
|
| 681 | - */ |
|
| 682 | - public static function getSettingsNavigation() { |
|
| 683 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
| 684 | - return self::proceedNavigation($entries); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * get the id of loaded app |
|
| 689 | - * |
|
| 690 | - * @return string |
|
| 691 | - */ |
|
| 692 | - public static function getCurrentApp() { |
|
| 693 | - $request = \OC::$server->getRequest(); |
|
| 694 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
| 695 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
| 696 | - if (empty($topFolder)) { |
|
| 697 | - $path_info = $request->getPathInfo(); |
|
| 698 | - if ($path_info) { |
|
| 699 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - if ($topFolder == 'apps') { |
|
| 703 | - $length = strlen($topFolder); |
|
| 704 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
| 705 | - } else { |
|
| 706 | - return $topFolder; |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * @param string $type |
|
| 712 | - * @return array |
|
| 713 | - */ |
|
| 714 | - public static function getForms($type) { |
|
| 715 | - $forms = array(); |
|
| 716 | - switch ($type) { |
|
| 717 | - case 'admin': |
|
| 718 | - $source = self::$adminForms; |
|
| 719 | - break; |
|
| 720 | - case 'personal': |
|
| 721 | - $source = self::$personalForms; |
|
| 722 | - break; |
|
| 723 | - default: |
|
| 724 | - return array(); |
|
| 725 | - } |
|
| 726 | - foreach ($source as $form) { |
|
| 727 | - $forms[] = include $form; |
|
| 728 | - } |
|
| 729 | - return $forms; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * register an admin form to be shown |
|
| 734 | - * |
|
| 735 | - * @param string $app |
|
| 736 | - * @param string $page |
|
| 737 | - */ |
|
| 738 | - public static function registerAdmin($app, $page) { |
|
| 739 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * register a personal form to be shown |
|
| 744 | - * @param string $app |
|
| 745 | - * @param string $page |
|
| 746 | - */ |
|
| 747 | - public static function registerPersonal($app, $page) { |
|
| 748 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * @param array $entry |
|
| 753 | - */ |
|
| 754 | - public static function registerLogIn(array $entry) { |
|
| 755 | - self::$altLogin[] = $entry; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * @return array |
|
| 760 | - */ |
|
| 761 | - public static function getAlternativeLogIns() { |
|
| 762 | - return self::$altLogin; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * get a list of all apps in the apps folder |
|
| 767 | - * |
|
| 768 | - * @return array an array of app names (string IDs) |
|
| 769 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
| 770 | - */ |
|
| 771 | - public static function getAllApps() { |
|
| 772 | - |
|
| 773 | - $apps = array(); |
|
| 774 | - |
|
| 775 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
| 776 | - if (!is_readable($apps_dir['path'])) { |
|
| 777 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 778 | - continue; |
|
| 779 | - } |
|
| 780 | - $dh = opendir($apps_dir['path']); |
|
| 781 | - |
|
| 782 | - if (is_resource($dh)) { |
|
| 783 | - while (($file = readdir($dh)) !== false) { |
|
| 784 | - |
|
| 785 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 786 | - |
|
| 787 | - $apps[] = $file; |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - return $apps; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * List all apps, this is used in apps.php |
|
| 798 | - * |
|
| 799 | - * @return array |
|
| 800 | - */ |
|
| 801 | - public function listAllApps() { |
|
| 802 | - $installedApps = OC_App::getAllApps(); |
|
| 803 | - |
|
| 804 | - //we don't want to show configuration for these |
|
| 805 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
| 806 | - $appList = array(); |
|
| 807 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
| 808 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 809 | - |
|
| 810 | - foreach ($installedApps as $app) { |
|
| 811 | - if (array_search($app, $blacklist) === false) { |
|
| 812 | - |
|
| 813 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
| 814 | - if (!is_array($info)) { |
|
| 815 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 816 | - continue; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - if (!isset($info['name'])) { |
|
| 820 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 821 | - continue; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
| 825 | - $info['groups'] = null; |
|
| 826 | - if ($enabled === 'yes') { |
|
| 827 | - $active = true; |
|
| 828 | - } else if ($enabled === 'no') { |
|
| 829 | - $active = false; |
|
| 830 | - } else { |
|
| 831 | - $active = true; |
|
| 832 | - $info['groups'] = $enabled; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - $info['active'] = $active; |
|
| 836 | - |
|
| 837 | - if (self::isShipped($app)) { |
|
| 838 | - $info['internal'] = true; |
|
| 839 | - $info['level'] = self::officialApp; |
|
| 840 | - $info['removable'] = false; |
|
| 841 | - } else { |
|
| 842 | - $info['internal'] = false; |
|
| 843 | - $info['removable'] = true; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $appPath = self::getAppPath($app); |
|
| 847 | - if($appPath !== false) { |
|
| 848 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 849 | - if (file_exists($appIcon)) { |
|
| 850 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
| 851 | - $info['previewAsIcon'] = true; |
|
| 852 | - } else { |
|
| 853 | - $appIcon = $appPath . '/img/app.svg'; |
|
| 854 | - if (file_exists($appIcon)) { |
|
| 855 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
| 856 | - $info['previewAsIcon'] = true; |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - // fix documentation |
|
| 861 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
| 862 | - foreach ($info['documentation'] as $key => $url) { |
|
| 863 | - // If it is not an absolute URL we assume it is a key |
|
| 864 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
| 865 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
| 866 | - $url = $urlGenerator->linkToDocs($url); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - $info['documentation'][$key] = $url; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - $info['version'] = OC_App::getAppVersion($app); |
|
| 874 | - $appList[] = $info; |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - return $appList; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - /** |
|
| 882 | - * Returns the internal app ID or false |
|
| 883 | - * @param string $ocsID |
|
| 884 | - * @return string|false |
|
| 885 | - */ |
|
| 886 | - public static function getInternalAppIdByOcs($ocsID) { |
|
| 887 | - if(is_numeric($ocsID)) { |
|
| 888 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
| 889 | - if(array_search($ocsID, $idArray)) { |
|
| 890 | - return array_search($ocsID, $idArray); |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - return false; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - public static function shouldUpgrade($app) { |
|
| 897 | - $versions = self::getAppVersions(); |
|
| 898 | - $currentVersion = OC_App::getAppVersion($app); |
|
| 899 | - if ($currentVersion && isset($versions[$app])) { |
|
| 900 | - $installedVersion = $versions[$app]; |
|
| 901 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
| 902 | - return true; |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - return false; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Adjust the number of version parts of $version1 to match |
|
| 910 | - * the number of version parts of $version2. |
|
| 911 | - * |
|
| 912 | - * @param string $version1 version to adjust |
|
| 913 | - * @param string $version2 version to take the number of parts from |
|
| 914 | - * @return string shortened $version1 |
|
| 915 | - */ |
|
| 916 | - private static function adjustVersionParts($version1, $version2) { |
|
| 917 | - $version1 = explode('.', $version1); |
|
| 918 | - $version2 = explode('.', $version2); |
|
| 919 | - // reduce $version1 to match the number of parts in $version2 |
|
| 920 | - while (count($version1) > count($version2)) { |
|
| 921 | - array_pop($version1); |
|
| 922 | - } |
|
| 923 | - // if $version1 does not have enough parts, add some |
|
| 924 | - while (count($version1) < count($version2)) { |
|
| 925 | - $version1[] = '0'; |
|
| 926 | - } |
|
| 927 | - return implode('.', $version1); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Check whether the current ownCloud version matches the given |
|
| 932 | - * application's version requirements. |
|
| 933 | - * |
|
| 934 | - * The comparison is made based on the number of parts that the |
|
| 935 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
| 936 | - * app info version is expecting version 6.0, the comparison is |
|
| 937 | - * made on the first two parts of the ownCloud version. |
|
| 938 | - * This means that it's possible to specify "requiremin" => 6 |
|
| 939 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
| 940 | - * |
|
| 941 | - * @param string $ocVersion ownCloud version to check against |
|
| 942 | - * @param array $appInfo app info (from xml) |
|
| 943 | - * |
|
| 944 | - * @return boolean true if compatible, otherwise false |
|
| 945 | - */ |
|
| 946 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
| 947 | - $requireMin = ''; |
|
| 948 | - $requireMax = ''; |
|
| 949 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 950 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
| 951 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 952 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
| 953 | - } else if (isset($appInfo['requiremin'])) { |
|
| 954 | - $requireMin = $appInfo['requiremin']; |
|
| 955 | - } else if (isset($appInfo['require'])) { |
|
| 956 | - $requireMin = $appInfo['require']; |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 960 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
| 961 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 962 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
| 963 | - } else if (isset($appInfo['requiremax'])) { |
|
| 964 | - $requireMax = $appInfo['requiremax']; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - if (is_array($ocVersion)) { |
|
| 968 | - $ocVersion = implode('.', $ocVersion); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - if (!empty($requireMin) |
|
| 972 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
| 973 | - ) { |
|
| 974 | - |
|
| 975 | - return false; |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - if (!empty($requireMax) |
|
| 979 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
| 980 | - ) { |
|
| 981 | - return false; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - return true; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * get the installed version of all apps |
|
| 989 | - */ |
|
| 990 | - public static function getAppVersions() { |
|
| 991 | - static $versions; |
|
| 992 | - |
|
| 993 | - if(!$versions) { |
|
| 994 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 995 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
| 996 | - } |
|
| 997 | - return $versions; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * @param string $app |
|
| 1002 | - * @param \OCP\IConfig $config |
|
| 1003 | - * @param \OCP\IL10N $l |
|
| 1004 | - * @return bool |
|
| 1005 | - * |
|
| 1006 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
| 1007 | - * @throws Exception if no app-name was specified |
|
| 1008 | - */ |
|
| 1009 | - public function installApp($app, |
|
| 1010 | - \OCP\IConfig $config, |
|
| 1011 | - \OCP\IL10N $l) { |
|
| 1012 | - if ($app !== false) { |
|
| 1013 | - // check if the app is compatible with this version of ownCloud |
|
| 1014 | - $info = self::getAppInfo($app); |
|
| 1015 | - if(!is_array($info)) { |
|
| 1016 | - throw new \Exception( |
|
| 1017 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 1018 | - [$info['name']] |
|
| 1019 | - ) |
|
| 1020 | - ); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - $version = \OCP\Util::getVersion(); |
|
| 1024 | - if (!self::isAppCompatible($version, $info)) { |
|
| 1025 | - throw new \Exception( |
|
| 1026 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 1027 | - array($info['name']) |
|
| 1028 | - ) |
|
| 1029 | - ); |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - // check for required dependencies |
|
| 1033 | - self::checkAppDependencies($config, $l, $info); |
|
| 1034 | - |
|
| 1035 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
| 1036 | - if (isset($appData['id'])) { |
|
| 1037 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1041 | - $appPath = self::getAppPath($app); |
|
| 1042 | - self::registerAutoloading($app, $appPath); |
|
| 1043 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
| 1047 | - } else { |
|
| 1048 | - if(empty($appName) ) { |
|
| 1049 | - throw new \Exception($l->t("No app name specified")); |
|
| 1050 | - } else { |
|
| 1051 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - return $app; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * update the database for the app and call the update script |
|
| 1060 | - * |
|
| 1061 | - * @param string $appId |
|
| 1062 | - * @return bool |
|
| 1063 | - */ |
|
| 1064 | - public static function updateApp($appId) { |
|
| 1065 | - $appPath = self::getAppPath($appId); |
|
| 1066 | - if($appPath === false) { |
|
| 1067 | - return false; |
|
| 1068 | - } |
|
| 1069 | - $appData = self::getAppInfo($appId); |
|
| 1070 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
| 1071 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1072 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1073 | - } |
|
| 1074 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
| 1075 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
| 1076 | - unset(self::$appVersion[$appId]); |
|
| 1077 | - // run upgrade code |
|
| 1078 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1079 | - self::loadApp($appId); |
|
| 1080 | - include $appPath . '/appinfo/update.php'; |
|
| 1081 | - } |
|
| 1082 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
| 1083 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1084 | - $appPath = self::getAppPath($appId); |
|
| 1085 | - self::registerAutoloading($appId, $appPath); |
|
| 1086 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - //set remote/public handlers |
|
| 1090 | - if (array_key_exists('ocsid', $appData)) { |
|
| 1091 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
| 1092 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1093 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
| 1094 | - } |
|
| 1095 | - foreach ($appData['remote'] as $name => $path) { |
|
| 1096 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1097 | - } |
|
| 1098 | - foreach ($appData['public'] as $name => $path) { |
|
| 1099 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - self::setAppTypes($appId); |
|
| 1103 | - |
|
| 1104 | - $version = \OC_App::getAppVersion($appId); |
|
| 1105 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
| 1106 | - |
|
| 1107 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
| 1108 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
| 1109 | - )); |
|
| 1110 | - |
|
| 1111 | - return true; |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * @param string $appId |
|
| 1116 | - * @param string[] $steps |
|
| 1117 | - * @throws \OC\NeedsUpdateException |
|
| 1118 | - */ |
|
| 1119 | - public static function executeRepairSteps($appId, array $steps) { |
|
| 1120 | - if (empty($steps)) { |
|
| 1121 | - return; |
|
| 1122 | - } |
|
| 1123 | - // load the app |
|
| 1124 | - self::loadApp($appId); |
|
| 1125 | - |
|
| 1126 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
| 1127 | - |
|
| 1128 | - // load the steps |
|
| 1129 | - $r = new Repair([], $dispatcher); |
|
| 1130 | - foreach ($steps as $step) { |
|
| 1131 | - try { |
|
| 1132 | - $r->addStep($step); |
|
| 1133 | - } catch (Exception $ex) { |
|
| 1134 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
| 1135 | - \OC::$server->getLogger()->logException($ex); |
|
| 1136 | - } |
|
| 1137 | - } |
|
| 1138 | - // run the steps |
|
| 1139 | - $r->run(); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - public static function setupBackgroundJobs(array $jobs) { |
|
| 1143 | - $queue = \OC::$server->getJobList(); |
|
| 1144 | - foreach ($jobs as $job) { |
|
| 1145 | - $queue->add($job); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * @param string $appId |
|
| 1151 | - * @param string[] $steps |
|
| 1152 | - */ |
|
| 1153 | - private static function setupLiveMigrations($appId, array $steps) { |
|
| 1154 | - $queue = \OC::$server->getJobList(); |
|
| 1155 | - foreach ($steps as $step) { |
|
| 1156 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
| 1157 | - 'app' => $appId, |
|
| 1158 | - 'step' => $step]); |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - /** |
|
| 1163 | - * @param string $appId |
|
| 1164 | - * @return \OC\Files\View|false |
|
| 1165 | - */ |
|
| 1166 | - public static function getStorage($appId) { |
|
| 1167 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
| 1168 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1169 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1170 | - if (!$view->file_exists($appId)) { |
|
| 1171 | - $view->mkdir($appId); |
|
| 1172 | - } |
|
| 1173 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1174 | - } else { |
|
| 1175 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1176 | - return false; |
|
| 1177 | - } |
|
| 1178 | - } else { |
|
| 1179 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1180 | - return false; |
|
| 1181 | - } |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - protected static function findBestL10NOption($options, $lang) { |
|
| 1185 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
| 1186 | - |
|
| 1187 | - $lang = strtolower($lang); |
|
| 1188 | - $similarLang = $lang; |
|
| 1189 | - if (strpos($similarLang, '_')) { |
|
| 1190 | - // For "de_DE" we want to find "de" and the other way around |
|
| 1191 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - foreach ($options as $option) { |
|
| 1195 | - if (is_array($option)) { |
|
| 1196 | - if ($fallback === false) { |
|
| 1197 | - $fallback = $option['@value']; |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - if (!isset($option['@attributes']['lang'])) { |
|
| 1201 | - continue; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 1205 | - if ($attributeLang === $lang) { |
|
| 1206 | - return $option['@value']; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - if ($attributeLang === $similarLang) { |
|
| 1210 | - $similarLangFallback = $option['@value']; |
|
| 1211 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1212 | - if ($similarLangFallback === false) { |
|
| 1213 | - $similarLangFallback = $option['@value']; |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - } else { |
|
| 1217 | - $englishFallback = $option; |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - if ($similarLangFallback !== false) { |
|
| 1222 | - return $similarLangFallback; |
|
| 1223 | - } else if ($englishFallback !== false) { |
|
| 1224 | - return $englishFallback; |
|
| 1225 | - } |
|
| 1226 | - return (string) $fallback; |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * parses the app data array and enhanced the 'description' value |
|
| 1231 | - * |
|
| 1232 | - * @param array $data the app data |
|
| 1233 | - * @param string $lang |
|
| 1234 | - * @return array improved app data |
|
| 1235 | - */ |
|
| 1236 | - public static function parseAppInfo(array $data, $lang = null) { |
|
| 1237 | - |
|
| 1238 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
| 1239 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
| 1240 | - } |
|
| 1241 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
| 1242 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
| 1243 | - } |
|
| 1244 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
| 1245 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
| 1246 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
| 1247 | - $data['description'] = trim($data['description']); |
|
| 1248 | - } else { |
|
| 1249 | - $data['description'] = ''; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - return $data; |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - /** |
|
| 1256 | - * @param \OCP\IConfig $config |
|
| 1257 | - * @param \OCP\IL10N $l |
|
| 1258 | - * @param array $info |
|
| 1259 | - * @throws \Exception |
|
| 1260 | - */ |
|
| 1261 | - protected static function checkAppDependencies($config, $l, $info) { |
|
| 1262 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
| 1263 | - $missing = $dependencyAnalyzer->analyze($info); |
|
| 1264 | - if (!empty($missing)) { |
|
| 1265 | - $missingMsg = join(PHP_EOL, $missing); |
|
| 1266 | - throw new \Exception( |
|
| 1267 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
| 1268 | - [$info['name'], $missingMsg] |
|
| 1269 | - ) |
|
| 1270 | - ); |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 63 | + static private $appVersion = []; |
|
| 64 | + static private $adminForms = array(); |
|
| 65 | + static private $personalForms = array(); |
|
| 66 | + static private $appInfo = array(); |
|
| 67 | + static private $appTypes = array(); |
|
| 68 | + static private $loadedApps = array(); |
|
| 69 | + static private $altLogin = array(); |
|
| 70 | + static private $alreadyRegistered = []; |
|
| 71 | + const officialApp = 200; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * clean the appId |
|
| 75 | + * |
|
| 76 | + * @param string|boolean $app AppId that needs to be cleaned |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public static function cleanAppId($app) { |
|
| 80 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Check if an app is loaded |
|
| 85 | + * |
|
| 86 | + * @param string $app |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + public static function isAppLoaded($app) { |
|
| 90 | + return in_array($app, self::$loadedApps, true); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * loads all apps |
|
| 95 | + * |
|
| 96 | + * @param string[] | string | null $types |
|
| 97 | + * @return bool |
|
| 98 | + * |
|
| 99 | + * This function walks through the ownCloud directory and loads all apps |
|
| 100 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
| 101 | + * exists. |
|
| 102 | + * |
|
| 103 | + * if $types is set, only apps of those types will be loaded |
|
| 104 | + */ |
|
| 105 | + public static function loadApps($types = null) { |
|
| 106 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 109 | + // Load the enabled apps here |
|
| 110 | + $apps = self::getEnabledApps(); |
|
| 111 | + |
|
| 112 | + // Add each apps' folder as allowed class path |
|
| 113 | + foreach($apps as $app) { |
|
| 114 | + $path = self::getAppPath($app); |
|
| 115 | + if($path !== false) { |
|
| 116 | + self::registerAutoloading($app, $path); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // prevent app.php from printing output |
|
| 121 | + ob_start(); |
|
| 122 | + foreach ($apps as $app) { |
|
| 123 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
| 124 | + self::loadApp($app); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + ob_end_clean(); |
|
| 128 | + |
|
| 129 | + return true; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * load a single app |
|
| 134 | + * |
|
| 135 | + * @param string $app |
|
| 136 | + */ |
|
| 137 | + public static function loadApp($app) { |
|
| 138 | + self::$loadedApps[] = $app; |
|
| 139 | + $appPath = self::getAppPath($app); |
|
| 140 | + if($appPath === false) { |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // in case someone calls loadApp() directly |
|
| 145 | + self::registerAutoloading($app, $appPath); |
|
| 146 | + |
|
| 147 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
| 148 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 149 | + self::requireAppFile($app); |
|
| 150 | + if (self::isType($app, array('authentication'))) { |
|
| 151 | + // since authentication apps affect the "is app enabled for group" check, |
|
| 152 | + // the enabled apps cache needs to be cleared to make sure that the |
|
| 153 | + // next time getEnableApps() is called it will also include apps that were |
|
| 154 | + // enabled for groups |
|
| 155 | + self::$enabledAppsCache = array(); |
|
| 156 | + } |
|
| 157 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $info = self::getAppInfo($app); |
|
| 161 | + if (!empty($info['activity']['filters'])) { |
|
| 162 | + foreach ($info['activity']['filters'] as $filter) { |
|
| 163 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + if (!empty($info['activity']['settings'])) { |
|
| 167 | + foreach ($info['activity']['settings'] as $setting) { |
|
| 168 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + if (!empty($info['activity']['providers'])) { |
|
| 172 | + foreach ($info['activity']['providers'] as $provider) { |
|
| 173 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @internal |
|
| 180 | + * @param string $app |
|
| 181 | + * @param string $path |
|
| 182 | + */ |
|
| 183 | + public static function registerAutoloading($app, $path) { |
|
| 184 | + $key = $app . '-' . $path; |
|
| 185 | + if(isset(self::$alreadyRegistered[$key])) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + self::$alreadyRegistered[$key] = true; |
|
| 189 | + // Register on PSR-4 composer autoloader |
|
| 190 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
| 191 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
| 192 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 193 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
| 194 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // Register on legacy autoloader |
|
| 198 | + \OC::$loader->addValidRoot($path); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Load app.php from the given app |
|
| 203 | + * |
|
| 204 | + * @param string $app app name |
|
| 205 | + */ |
|
| 206 | + private static function requireAppFile($app) { |
|
| 207 | + try { |
|
| 208 | + // encapsulated here to avoid variable scope conflicts |
|
| 209 | + require_once $app . '/appinfo/app.php'; |
|
| 210 | + } catch (Error $ex) { |
|
| 211 | + \OC::$server->getLogger()->logException($ex); |
|
| 212 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
| 213 | + if (!in_array($app, $blacklist)) { |
|
| 214 | + self::disable($app); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * check if an app is of a specific type |
|
| 221 | + * |
|
| 222 | + * @param string $app |
|
| 223 | + * @param string|array $types |
|
| 224 | + * @return bool |
|
| 225 | + */ |
|
| 226 | + public static function isType($app, $types) { |
|
| 227 | + if (is_string($types)) { |
|
| 228 | + $types = array($types); |
|
| 229 | + } |
|
| 230 | + $appTypes = self::getAppTypes($app); |
|
| 231 | + foreach ($types as $type) { |
|
| 232 | + if (array_search($type, $appTypes) !== false) { |
|
| 233 | + return true; |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * get the types of an app |
|
| 241 | + * |
|
| 242 | + * @param string $app |
|
| 243 | + * @return array |
|
| 244 | + */ |
|
| 245 | + private static function getAppTypes($app) { |
|
| 246 | + //load the cache |
|
| 247 | + if (count(self::$appTypes) == 0) { |
|
| 248 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + if (isset(self::$appTypes[$app])) { |
|
| 252 | + return explode(',', self::$appTypes[$app]); |
|
| 253 | + } else { |
|
| 254 | + return array(); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * read app types from info.xml and cache them in the database |
|
| 260 | + */ |
|
| 261 | + public static function setAppTypes($app) { |
|
| 262 | + $appData = self::getAppInfo($app); |
|
| 263 | + if(!is_array($appData)) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if (isset($appData['types'])) { |
|
| 268 | + $appTypes = implode(',', $appData['types']); |
|
| 269 | + } else { |
|
| 270 | + $appTypes = ''; |
|
| 271 | + $appData['types'] = []; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
| 275 | + |
|
| 276 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
| 277 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
| 278 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
| 279 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * check if app is shipped |
|
| 286 | + * |
|
| 287 | + * @param string $appId the id of the app to check |
|
| 288 | + * @return bool |
|
| 289 | + * |
|
| 290 | + * Check if an app that is installed is a shipped app or installed from the appstore. |
|
| 291 | + */ |
|
| 292 | + public static function isShipped($appId) { |
|
| 293 | + return \OC::$server->getAppManager()->isShipped($appId); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * get all enabled apps |
|
| 298 | + */ |
|
| 299 | + protected static $enabledAppsCache = array(); |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Returns apps enabled for the current user. |
|
| 303 | + * |
|
| 304 | + * @param bool $forceRefresh whether to refresh the cache |
|
| 305 | + * @param bool $all whether to return apps for all users, not only the |
|
| 306 | + * currently logged in one |
|
| 307 | + * @return string[] |
|
| 308 | + */ |
|
| 309 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
| 310 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 311 | + return array(); |
|
| 312 | + } |
|
| 313 | + // in incognito mode or when logged out, $user will be false, |
|
| 314 | + // which is also the case during an upgrade |
|
| 315 | + $appManager = \OC::$server->getAppManager(); |
|
| 316 | + if ($all) { |
|
| 317 | + $user = null; |
|
| 318 | + } else { |
|
| 319 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if (is_null($user)) { |
|
| 323 | + $apps = $appManager->getInstalledApps(); |
|
| 324 | + } else { |
|
| 325 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
| 326 | + } |
|
| 327 | + $apps = array_filter($apps, function ($app) { |
|
| 328 | + return $app !== 'files';//we add this manually |
|
| 329 | + }); |
|
| 330 | + sort($apps); |
|
| 331 | + array_unshift($apps, 'files'); |
|
| 332 | + return $apps; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * checks whether or not an app is enabled |
|
| 337 | + * |
|
| 338 | + * @param string $app app |
|
| 339 | + * @return bool |
|
| 340 | + * |
|
| 341 | + * This function checks whether or not an app is enabled. |
|
| 342 | + */ |
|
| 343 | + public static function isEnabled($app) { |
|
| 344 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * enables an app |
|
| 349 | + * |
|
| 350 | + * @param string $appId |
|
| 351 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
| 352 | + * @throws \Exception |
|
| 353 | + * @return void |
|
| 354 | + * |
|
| 355 | + * This function set an app as enabled in appconfig. |
|
| 356 | + */ |
|
| 357 | + public function enable($appId, |
|
| 358 | + $groups = null) { |
|
| 359 | + self::$enabledAppsCache = []; // flush |
|
| 360 | + $l = \OC::$server->getL10N('core'); |
|
| 361 | + $config = \OC::$server->getConfig(); |
|
| 362 | + |
|
| 363 | + // Check if app is already downloaded |
|
| 364 | + $installer = new Installer( |
|
| 365 | + \OC::$server->getAppFetcher(), |
|
| 366 | + \OC::$server->getHTTPClientService(), |
|
| 367 | + \OC::$server->getTempManager(), |
|
| 368 | + \OC::$server->getLogger(), |
|
| 369 | + \OC::$server->getConfig() |
|
| 370 | + ); |
|
| 371 | + $isDownloaded = $installer->isDownloaded($appId); |
|
| 372 | + |
|
| 373 | + if(!$isDownloaded) { |
|
| 374 | + $installer->downloadApp($appId); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + if (!Installer::isInstalled($appId)) { |
|
| 378 | + $appId = self::installApp( |
|
| 379 | + $appId, |
|
| 380 | + $config, |
|
| 381 | + $l |
|
| 382 | + ); |
|
| 383 | + $appPath = self::getAppPath($appId); |
|
| 384 | + self::registerAutoloading($appId, $appPath); |
|
| 385 | + $installer->installApp($appId); |
|
| 386 | + } else { |
|
| 387 | + // check for required dependencies |
|
| 388 | + $info = self::getAppInfo($appId); |
|
| 389 | + self::checkAppDependencies($config, $l, $info); |
|
| 390 | + $appPath = self::getAppPath($appId); |
|
| 391 | + self::registerAutoloading($appId, $appPath); |
|
| 392 | + $installer->installApp($appId); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $appManager = \OC::$server->getAppManager(); |
|
| 396 | + if (!is_null($groups)) { |
|
| 397 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 398 | + $groupsList = []; |
|
| 399 | + foreach ($groups as $group) { |
|
| 400 | + $groupItem = $groupManager->get($group); |
|
| 401 | + if ($groupItem instanceof \OCP\IGroup) { |
|
| 402 | + $groupsList[] = $groupManager->get($group); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
| 406 | + } else { |
|
| 407 | + $appManager->enableApp($appId); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + $info = self::getAppInfo($appId); |
|
| 411 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 412 | + $appPath = self::getAppPath($appId); |
|
| 413 | + self::registerAutoloading($appId, $appPath); |
|
| 414 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * @param string $app |
|
| 420 | + * @return bool |
|
| 421 | + */ |
|
| 422 | + public static function removeApp($app) { |
|
| 423 | + if (self::isShipped($app)) { |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + $installer = new Installer( |
|
| 428 | + \OC::$server->getAppFetcher(), |
|
| 429 | + \OC::$server->getHTTPClientService(), |
|
| 430 | + \OC::$server->getTempManager(), |
|
| 431 | + \OC::$server->getLogger(), |
|
| 432 | + \OC::$server->getConfig() |
|
| 433 | + ); |
|
| 434 | + return $installer->removeApp($app); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * This function set an app as disabled in appconfig. |
|
| 439 | + * |
|
| 440 | + * @param string $app app |
|
| 441 | + * @throws Exception |
|
| 442 | + */ |
|
| 443 | + public static function disable($app) { |
|
| 444 | + // flush |
|
| 445 | + self::$enabledAppsCache = array(); |
|
| 446 | + |
|
| 447 | + // run uninstall steps |
|
| 448 | + $appData = OC_App::getAppInfo($app); |
|
| 449 | + if (!is_null($appData)) { |
|
| 450 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // emit disable hook - needed anymore ? |
|
| 454 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
| 455 | + |
|
| 456 | + // finally disable it |
|
| 457 | + $appManager = \OC::$server->getAppManager(); |
|
| 458 | + $appManager->disableApp($app); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + // This is private as well. It simply works, so don't ask for more details |
|
| 462 | + private static function proceedNavigation($list) { |
|
| 463 | + usort($list, function($a, $b) { |
|
| 464 | + if (isset($a['order']) && isset($b['order'])) { |
|
| 465 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 466 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
| 467 | + return isset($a['order']) ? -1 : 1; |
|
| 468 | + } else { |
|
| 469 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 470 | + } |
|
| 471 | + }); |
|
| 472 | + |
|
| 473 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
| 474 | + foreach ($list as $index => &$navEntry) { |
|
| 475 | + if ($navEntry['id'] == $activeApp) { |
|
| 476 | + $navEntry['active'] = true; |
|
| 477 | + } else { |
|
| 478 | + $navEntry['active'] = false; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + unset($navEntry); |
|
| 482 | + |
|
| 483 | + return $list; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Get the path where to install apps |
|
| 488 | + * |
|
| 489 | + * @return string|false |
|
| 490 | + */ |
|
| 491 | + public static function getInstallPath() { |
|
| 492 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
| 493 | + return false; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + foreach (OC::$APPSROOTS as $dir) { |
|
| 497 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
| 498 | + return $dir['path']; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
| 503 | + return null; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * search for an app in all app-directories |
|
| 509 | + * |
|
| 510 | + * @param string $appId |
|
| 511 | + * @return false|string |
|
| 512 | + */ |
|
| 513 | + public static function findAppInDirectories($appId) { |
|
| 514 | + $sanitizedAppId = self::cleanAppId($appId); |
|
| 515 | + if($sanitizedAppId !== $appId) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + static $app_dir = array(); |
|
| 519 | + |
|
| 520 | + if (isset($app_dir[$appId])) { |
|
| 521 | + return $app_dir[$appId]; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $possibleApps = array(); |
|
| 525 | + foreach (OC::$APPSROOTS as $dir) { |
|
| 526 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 527 | + $possibleApps[] = $dir; |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + if (empty($possibleApps)) { |
|
| 532 | + return false; |
|
| 533 | + } elseif (count($possibleApps) === 1) { |
|
| 534 | + $dir = array_shift($possibleApps); |
|
| 535 | + $app_dir[$appId] = $dir; |
|
| 536 | + return $dir; |
|
| 537 | + } else { |
|
| 538 | + $versionToLoad = array(); |
|
| 539 | + foreach ($possibleApps as $possibleApp) { |
|
| 540 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
| 541 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
| 542 | + $versionToLoad = array( |
|
| 543 | + 'dir' => $possibleApp, |
|
| 544 | + 'version' => $version, |
|
| 545 | + ); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
| 549 | + return $versionToLoad['dir']; |
|
| 550 | + //TODO - write test |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Get the directory for the given app. |
|
| 556 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 557 | + * |
|
| 558 | + * @param string $appId |
|
| 559 | + * @return string|false |
|
| 560 | + */ |
|
| 561 | + public static function getAppPath($appId) { |
|
| 562 | + if ($appId === null || trim($appId) === '') { |
|
| 563 | + return false; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 567 | + return $dir['path'] . '/' . $appId; |
|
| 568 | + } |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Get the path for the given app on the access |
|
| 574 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 575 | + * |
|
| 576 | + * @param string $appId |
|
| 577 | + * @return string|false |
|
| 578 | + */ |
|
| 579 | + public static function getAppWebPath($appId) { |
|
| 580 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 581 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 582 | + } |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * get the last version of the app from appinfo/info.xml |
|
| 588 | + * |
|
| 589 | + * @param string $appId |
|
| 590 | + * @param bool $useCache |
|
| 591 | + * @return string |
|
| 592 | + */ |
|
| 593 | + public static function getAppVersion($appId, $useCache = true) { |
|
| 594 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
| 595 | + return self::$appVersion[$appId]; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + $file = self::getAppPath($appId); |
|
| 599 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
| 600 | + return self::$appVersion[$appId]; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * get app's version based on it's path |
|
| 605 | + * |
|
| 606 | + * @param string $path |
|
| 607 | + * @return string |
|
| 608 | + */ |
|
| 609 | + public static function getAppVersionByPath($path) { |
|
| 610 | + $infoFile = $path . '/appinfo/info.xml'; |
|
| 611 | + $appData = self::getAppInfo($infoFile, true); |
|
| 612 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Read all app metadata from the info.xml file |
|
| 618 | + * |
|
| 619 | + * @param string $appId id of the app or the path of the info.xml file |
|
| 620 | + * @param bool $path |
|
| 621 | + * @param string $lang |
|
| 622 | + * @return array|null |
|
| 623 | + * @note all data is read from info.xml, not just pre-defined fields |
|
| 624 | + */ |
|
| 625 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
| 626 | + if ($path) { |
|
| 627 | + $file = $appId; |
|
| 628 | + } else { |
|
| 629 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
| 630 | + return self::$appInfo[$appId]; |
|
| 631 | + } |
|
| 632 | + $appPath = self::getAppPath($appId); |
|
| 633 | + if($appPath === false) { |
|
| 634 | + return null; |
|
| 635 | + } |
|
| 636 | + $file = $appPath . '/appinfo/info.xml'; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
| 640 | + $data = $parser->parse($file); |
|
| 641 | + |
|
| 642 | + if (is_array($data)) { |
|
| 643 | + $data = OC_App::parseAppInfo($data, $lang); |
|
| 644 | + } |
|
| 645 | + if(isset($data['ocsid'])) { |
|
| 646 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
| 647 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 648 | + $data['ocsid'] = $storedId; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + if ($lang === null) { |
|
| 653 | + self::$appInfo[$appId] = $data; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + return $data; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Returns the navigation |
|
| 661 | + * |
|
| 662 | + * @return array |
|
| 663 | + * |
|
| 664 | + * This function returns an array containing all entries added. The |
|
| 665 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
| 666 | + * given for each app the following keys exist: |
|
| 667 | + * - active: boolean, signals if the user is on this navigation entry |
|
| 668 | + */ |
|
| 669 | + public static function getNavigation() { |
|
| 670 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
| 671 | + return self::proceedNavigation($entries); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Returns the Settings Navigation |
|
| 676 | + * |
|
| 677 | + * @return string[] |
|
| 678 | + * |
|
| 679 | + * This function returns an array containing all settings pages added. The |
|
| 680 | + * entries are sorted by the key 'order' ascending. |
|
| 681 | + */ |
|
| 682 | + public static function getSettingsNavigation() { |
|
| 683 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
| 684 | + return self::proceedNavigation($entries); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * get the id of loaded app |
|
| 689 | + * |
|
| 690 | + * @return string |
|
| 691 | + */ |
|
| 692 | + public static function getCurrentApp() { |
|
| 693 | + $request = \OC::$server->getRequest(); |
|
| 694 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
| 695 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
| 696 | + if (empty($topFolder)) { |
|
| 697 | + $path_info = $request->getPathInfo(); |
|
| 698 | + if ($path_info) { |
|
| 699 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + if ($topFolder == 'apps') { |
|
| 703 | + $length = strlen($topFolder); |
|
| 704 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
| 705 | + } else { |
|
| 706 | + return $topFolder; |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * @param string $type |
|
| 712 | + * @return array |
|
| 713 | + */ |
|
| 714 | + public static function getForms($type) { |
|
| 715 | + $forms = array(); |
|
| 716 | + switch ($type) { |
|
| 717 | + case 'admin': |
|
| 718 | + $source = self::$adminForms; |
|
| 719 | + break; |
|
| 720 | + case 'personal': |
|
| 721 | + $source = self::$personalForms; |
|
| 722 | + break; |
|
| 723 | + default: |
|
| 724 | + return array(); |
|
| 725 | + } |
|
| 726 | + foreach ($source as $form) { |
|
| 727 | + $forms[] = include $form; |
|
| 728 | + } |
|
| 729 | + return $forms; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * register an admin form to be shown |
|
| 734 | + * |
|
| 735 | + * @param string $app |
|
| 736 | + * @param string $page |
|
| 737 | + */ |
|
| 738 | + public static function registerAdmin($app, $page) { |
|
| 739 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * register a personal form to be shown |
|
| 744 | + * @param string $app |
|
| 745 | + * @param string $page |
|
| 746 | + */ |
|
| 747 | + public static function registerPersonal($app, $page) { |
|
| 748 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * @param array $entry |
|
| 753 | + */ |
|
| 754 | + public static function registerLogIn(array $entry) { |
|
| 755 | + self::$altLogin[] = $entry; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * @return array |
|
| 760 | + */ |
|
| 761 | + public static function getAlternativeLogIns() { |
|
| 762 | + return self::$altLogin; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * get a list of all apps in the apps folder |
|
| 767 | + * |
|
| 768 | + * @return array an array of app names (string IDs) |
|
| 769 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
| 770 | + */ |
|
| 771 | + public static function getAllApps() { |
|
| 772 | + |
|
| 773 | + $apps = array(); |
|
| 774 | + |
|
| 775 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
| 776 | + if (!is_readable($apps_dir['path'])) { |
|
| 777 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 778 | + continue; |
|
| 779 | + } |
|
| 780 | + $dh = opendir($apps_dir['path']); |
|
| 781 | + |
|
| 782 | + if (is_resource($dh)) { |
|
| 783 | + while (($file = readdir($dh)) !== false) { |
|
| 784 | + |
|
| 785 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 786 | + |
|
| 787 | + $apps[] = $file; |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + return $apps; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * List all apps, this is used in apps.php |
|
| 798 | + * |
|
| 799 | + * @return array |
|
| 800 | + */ |
|
| 801 | + public function listAllApps() { |
|
| 802 | + $installedApps = OC_App::getAllApps(); |
|
| 803 | + |
|
| 804 | + //we don't want to show configuration for these |
|
| 805 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
| 806 | + $appList = array(); |
|
| 807 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
| 808 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 809 | + |
|
| 810 | + foreach ($installedApps as $app) { |
|
| 811 | + if (array_search($app, $blacklist) === false) { |
|
| 812 | + |
|
| 813 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
| 814 | + if (!is_array($info)) { |
|
| 815 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 816 | + continue; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + if (!isset($info['name'])) { |
|
| 820 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 821 | + continue; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
| 825 | + $info['groups'] = null; |
|
| 826 | + if ($enabled === 'yes') { |
|
| 827 | + $active = true; |
|
| 828 | + } else if ($enabled === 'no') { |
|
| 829 | + $active = false; |
|
| 830 | + } else { |
|
| 831 | + $active = true; |
|
| 832 | + $info['groups'] = $enabled; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + $info['active'] = $active; |
|
| 836 | + |
|
| 837 | + if (self::isShipped($app)) { |
|
| 838 | + $info['internal'] = true; |
|
| 839 | + $info['level'] = self::officialApp; |
|
| 840 | + $info['removable'] = false; |
|
| 841 | + } else { |
|
| 842 | + $info['internal'] = false; |
|
| 843 | + $info['removable'] = true; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $appPath = self::getAppPath($app); |
|
| 847 | + if($appPath !== false) { |
|
| 848 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 849 | + if (file_exists($appIcon)) { |
|
| 850 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
| 851 | + $info['previewAsIcon'] = true; |
|
| 852 | + } else { |
|
| 853 | + $appIcon = $appPath . '/img/app.svg'; |
|
| 854 | + if (file_exists($appIcon)) { |
|
| 855 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
| 856 | + $info['previewAsIcon'] = true; |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + // fix documentation |
|
| 861 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
| 862 | + foreach ($info['documentation'] as $key => $url) { |
|
| 863 | + // If it is not an absolute URL we assume it is a key |
|
| 864 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
| 865 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
| 866 | + $url = $urlGenerator->linkToDocs($url); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + $info['documentation'][$key] = $url; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + $info['version'] = OC_App::getAppVersion($app); |
|
| 874 | + $appList[] = $info; |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + return $appList; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + /** |
|
| 882 | + * Returns the internal app ID or false |
|
| 883 | + * @param string $ocsID |
|
| 884 | + * @return string|false |
|
| 885 | + */ |
|
| 886 | + public static function getInternalAppIdByOcs($ocsID) { |
|
| 887 | + if(is_numeric($ocsID)) { |
|
| 888 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
| 889 | + if(array_search($ocsID, $idArray)) { |
|
| 890 | + return array_search($ocsID, $idArray); |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + return false; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + public static function shouldUpgrade($app) { |
|
| 897 | + $versions = self::getAppVersions(); |
|
| 898 | + $currentVersion = OC_App::getAppVersion($app); |
|
| 899 | + if ($currentVersion && isset($versions[$app])) { |
|
| 900 | + $installedVersion = $versions[$app]; |
|
| 901 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
| 902 | + return true; |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + return false; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Adjust the number of version parts of $version1 to match |
|
| 910 | + * the number of version parts of $version2. |
|
| 911 | + * |
|
| 912 | + * @param string $version1 version to adjust |
|
| 913 | + * @param string $version2 version to take the number of parts from |
|
| 914 | + * @return string shortened $version1 |
|
| 915 | + */ |
|
| 916 | + private static function adjustVersionParts($version1, $version2) { |
|
| 917 | + $version1 = explode('.', $version1); |
|
| 918 | + $version2 = explode('.', $version2); |
|
| 919 | + // reduce $version1 to match the number of parts in $version2 |
|
| 920 | + while (count($version1) > count($version2)) { |
|
| 921 | + array_pop($version1); |
|
| 922 | + } |
|
| 923 | + // if $version1 does not have enough parts, add some |
|
| 924 | + while (count($version1) < count($version2)) { |
|
| 925 | + $version1[] = '0'; |
|
| 926 | + } |
|
| 927 | + return implode('.', $version1); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Check whether the current ownCloud version matches the given |
|
| 932 | + * application's version requirements. |
|
| 933 | + * |
|
| 934 | + * The comparison is made based on the number of parts that the |
|
| 935 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
| 936 | + * app info version is expecting version 6.0, the comparison is |
|
| 937 | + * made on the first two parts of the ownCloud version. |
|
| 938 | + * This means that it's possible to specify "requiremin" => 6 |
|
| 939 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
| 940 | + * |
|
| 941 | + * @param string $ocVersion ownCloud version to check against |
|
| 942 | + * @param array $appInfo app info (from xml) |
|
| 943 | + * |
|
| 944 | + * @return boolean true if compatible, otherwise false |
|
| 945 | + */ |
|
| 946 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
| 947 | + $requireMin = ''; |
|
| 948 | + $requireMax = ''; |
|
| 949 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 950 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
| 951 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 952 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
| 953 | + } else if (isset($appInfo['requiremin'])) { |
|
| 954 | + $requireMin = $appInfo['requiremin']; |
|
| 955 | + } else if (isset($appInfo['require'])) { |
|
| 956 | + $requireMin = $appInfo['require']; |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 960 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
| 961 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 962 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
| 963 | + } else if (isset($appInfo['requiremax'])) { |
|
| 964 | + $requireMax = $appInfo['requiremax']; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + if (is_array($ocVersion)) { |
|
| 968 | + $ocVersion = implode('.', $ocVersion); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + if (!empty($requireMin) |
|
| 972 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
| 973 | + ) { |
|
| 974 | + |
|
| 975 | + return false; |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + if (!empty($requireMax) |
|
| 979 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
| 980 | + ) { |
|
| 981 | + return false; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + return true; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * get the installed version of all apps |
|
| 989 | + */ |
|
| 990 | + public static function getAppVersions() { |
|
| 991 | + static $versions; |
|
| 992 | + |
|
| 993 | + if(!$versions) { |
|
| 994 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 995 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
| 996 | + } |
|
| 997 | + return $versions; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * @param string $app |
|
| 1002 | + * @param \OCP\IConfig $config |
|
| 1003 | + * @param \OCP\IL10N $l |
|
| 1004 | + * @return bool |
|
| 1005 | + * |
|
| 1006 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
| 1007 | + * @throws Exception if no app-name was specified |
|
| 1008 | + */ |
|
| 1009 | + public function installApp($app, |
|
| 1010 | + \OCP\IConfig $config, |
|
| 1011 | + \OCP\IL10N $l) { |
|
| 1012 | + if ($app !== false) { |
|
| 1013 | + // check if the app is compatible with this version of ownCloud |
|
| 1014 | + $info = self::getAppInfo($app); |
|
| 1015 | + if(!is_array($info)) { |
|
| 1016 | + throw new \Exception( |
|
| 1017 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 1018 | + [$info['name']] |
|
| 1019 | + ) |
|
| 1020 | + ); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + $version = \OCP\Util::getVersion(); |
|
| 1024 | + if (!self::isAppCompatible($version, $info)) { |
|
| 1025 | + throw new \Exception( |
|
| 1026 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 1027 | + array($info['name']) |
|
| 1028 | + ) |
|
| 1029 | + ); |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + // check for required dependencies |
|
| 1033 | + self::checkAppDependencies($config, $l, $info); |
|
| 1034 | + |
|
| 1035 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
| 1036 | + if (isset($appData['id'])) { |
|
| 1037 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1041 | + $appPath = self::getAppPath($app); |
|
| 1042 | + self::registerAutoloading($app, $appPath); |
|
| 1043 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
| 1047 | + } else { |
|
| 1048 | + if(empty($appName) ) { |
|
| 1049 | + throw new \Exception($l->t("No app name specified")); |
|
| 1050 | + } else { |
|
| 1051 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + return $app; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * update the database for the app and call the update script |
|
| 1060 | + * |
|
| 1061 | + * @param string $appId |
|
| 1062 | + * @return bool |
|
| 1063 | + */ |
|
| 1064 | + public static function updateApp($appId) { |
|
| 1065 | + $appPath = self::getAppPath($appId); |
|
| 1066 | + if($appPath === false) { |
|
| 1067 | + return false; |
|
| 1068 | + } |
|
| 1069 | + $appData = self::getAppInfo($appId); |
|
| 1070 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
| 1071 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1072 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1073 | + } |
|
| 1074 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
| 1075 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
| 1076 | + unset(self::$appVersion[$appId]); |
|
| 1077 | + // run upgrade code |
|
| 1078 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1079 | + self::loadApp($appId); |
|
| 1080 | + include $appPath . '/appinfo/update.php'; |
|
| 1081 | + } |
|
| 1082 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
| 1083 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1084 | + $appPath = self::getAppPath($appId); |
|
| 1085 | + self::registerAutoloading($appId, $appPath); |
|
| 1086 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + //set remote/public handlers |
|
| 1090 | + if (array_key_exists('ocsid', $appData)) { |
|
| 1091 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
| 1092 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1093 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
| 1094 | + } |
|
| 1095 | + foreach ($appData['remote'] as $name => $path) { |
|
| 1096 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1097 | + } |
|
| 1098 | + foreach ($appData['public'] as $name => $path) { |
|
| 1099 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + self::setAppTypes($appId); |
|
| 1103 | + |
|
| 1104 | + $version = \OC_App::getAppVersion($appId); |
|
| 1105 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
| 1106 | + |
|
| 1107 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
| 1108 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
| 1109 | + )); |
|
| 1110 | + |
|
| 1111 | + return true; |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * @param string $appId |
|
| 1116 | + * @param string[] $steps |
|
| 1117 | + * @throws \OC\NeedsUpdateException |
|
| 1118 | + */ |
|
| 1119 | + public static function executeRepairSteps($appId, array $steps) { |
|
| 1120 | + if (empty($steps)) { |
|
| 1121 | + return; |
|
| 1122 | + } |
|
| 1123 | + // load the app |
|
| 1124 | + self::loadApp($appId); |
|
| 1125 | + |
|
| 1126 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
| 1127 | + |
|
| 1128 | + // load the steps |
|
| 1129 | + $r = new Repair([], $dispatcher); |
|
| 1130 | + foreach ($steps as $step) { |
|
| 1131 | + try { |
|
| 1132 | + $r->addStep($step); |
|
| 1133 | + } catch (Exception $ex) { |
|
| 1134 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
| 1135 | + \OC::$server->getLogger()->logException($ex); |
|
| 1136 | + } |
|
| 1137 | + } |
|
| 1138 | + // run the steps |
|
| 1139 | + $r->run(); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + public static function setupBackgroundJobs(array $jobs) { |
|
| 1143 | + $queue = \OC::$server->getJobList(); |
|
| 1144 | + foreach ($jobs as $job) { |
|
| 1145 | + $queue->add($job); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * @param string $appId |
|
| 1151 | + * @param string[] $steps |
|
| 1152 | + */ |
|
| 1153 | + private static function setupLiveMigrations($appId, array $steps) { |
|
| 1154 | + $queue = \OC::$server->getJobList(); |
|
| 1155 | + foreach ($steps as $step) { |
|
| 1156 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
| 1157 | + 'app' => $appId, |
|
| 1158 | + 'step' => $step]); |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + /** |
|
| 1163 | + * @param string $appId |
|
| 1164 | + * @return \OC\Files\View|false |
|
| 1165 | + */ |
|
| 1166 | + public static function getStorage($appId) { |
|
| 1167 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
| 1168 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1169 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1170 | + if (!$view->file_exists($appId)) { |
|
| 1171 | + $view->mkdir($appId); |
|
| 1172 | + } |
|
| 1173 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1174 | + } else { |
|
| 1175 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1176 | + return false; |
|
| 1177 | + } |
|
| 1178 | + } else { |
|
| 1179 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1180 | + return false; |
|
| 1181 | + } |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + protected static function findBestL10NOption($options, $lang) { |
|
| 1185 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
| 1186 | + |
|
| 1187 | + $lang = strtolower($lang); |
|
| 1188 | + $similarLang = $lang; |
|
| 1189 | + if (strpos($similarLang, '_')) { |
|
| 1190 | + // For "de_DE" we want to find "de" and the other way around |
|
| 1191 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + foreach ($options as $option) { |
|
| 1195 | + if (is_array($option)) { |
|
| 1196 | + if ($fallback === false) { |
|
| 1197 | + $fallback = $option['@value']; |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + if (!isset($option['@attributes']['lang'])) { |
|
| 1201 | + continue; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 1205 | + if ($attributeLang === $lang) { |
|
| 1206 | + return $option['@value']; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + if ($attributeLang === $similarLang) { |
|
| 1210 | + $similarLangFallback = $option['@value']; |
|
| 1211 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1212 | + if ($similarLangFallback === false) { |
|
| 1213 | + $similarLangFallback = $option['@value']; |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + } else { |
|
| 1217 | + $englishFallback = $option; |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + if ($similarLangFallback !== false) { |
|
| 1222 | + return $similarLangFallback; |
|
| 1223 | + } else if ($englishFallback !== false) { |
|
| 1224 | + return $englishFallback; |
|
| 1225 | + } |
|
| 1226 | + return (string) $fallback; |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * parses the app data array and enhanced the 'description' value |
|
| 1231 | + * |
|
| 1232 | + * @param array $data the app data |
|
| 1233 | + * @param string $lang |
|
| 1234 | + * @return array improved app data |
|
| 1235 | + */ |
|
| 1236 | + public static function parseAppInfo(array $data, $lang = null) { |
|
| 1237 | + |
|
| 1238 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
| 1239 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
| 1240 | + } |
|
| 1241 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
| 1242 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
| 1243 | + } |
|
| 1244 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
| 1245 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
| 1246 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
| 1247 | + $data['description'] = trim($data['description']); |
|
| 1248 | + } else { |
|
| 1249 | + $data['description'] = ''; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + return $data; |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + /** |
|
| 1256 | + * @param \OCP\IConfig $config |
|
| 1257 | + * @param \OCP\IL10N $l |
|
| 1258 | + * @param array $info |
|
| 1259 | + * @throws \Exception |
|
| 1260 | + */ |
|
| 1261 | + protected static function checkAppDependencies($config, $l, $info) { |
|
| 1262 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
| 1263 | + $missing = $dependencyAnalyzer->analyze($info); |
|
| 1264 | + if (!empty($missing)) { |
|
| 1265 | + $missingMsg = join(PHP_EOL, $missing); |
|
| 1266 | + throw new \Exception( |
|
| 1267 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
| 1268 | + [$info['name'], $missingMsg] |
|
| 1269 | + ) |
|
| 1270 | + ); |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | 1273 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function installApp($appId) { |
| 110 | 110 | $app = \OC_App::findAppInDirectories($appId); |
| 111 | - if($app === false) { |
|
| 111 | + if ($app === false) { |
|
| 112 | 112 | throw new \Exception('App not found in any app directory'); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
| 117 | 117 | |
| 118 | 118 | //install the database |
| 119 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 119 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
| 120 | 120 | if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
| 121 | 121 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
| 122 | 122 | } else { |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
| 129 | 129 | |
| 130 | 130 | //run appinfo/install.php |
| 131 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
| 132 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 131 | + if ((!isset($data['noinstall']) or $data['noinstall'] == false)) { |
|
| 132 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $appData = OC_App::getAppInfo($appId); |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
| 141 | 141 | |
| 142 | 142 | //set remote/public handlers |
| 143 | - foreach($info['remote'] as $name=>$path) { |
|
| 143 | + foreach ($info['remote'] as $name=>$path) { |
|
| 144 | 144 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
| 145 | 145 | } |
| 146 | - foreach($info['public'] as $name=>$path) { |
|
| 146 | + foreach ($info['public'] as $name=>$path) { |
|
| 147 | 147 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * Checks whether or not an app is installed, i.e. registered in apps table. |
| 161 | 161 | */ |
| 162 | - public static function isInstalled( $app ) { |
|
| 162 | + public static function isInstalled($app) { |
|
| 163 | 163 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
| 164 | 164 | } |
| 165 | 165 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @return bool |
| 171 | 171 | */ |
| 172 | 172 | public function updateAppstoreApp($appId) { |
| 173 | - if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
| 173 | + if (self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
| 174 | 174 | try { |
| 175 | 175 | $this->downloadApp($appId); |
| 176 | 176 | } catch (\Exception $e) { |
@@ -194,18 +194,18 @@ discard block |
||
| 194 | 194 | $appId = strtolower($appId); |
| 195 | 195 | |
| 196 | 196 | $apps = $this->appFetcher->get(); |
| 197 | - foreach($apps as $app) { |
|
| 198 | - if($app['id'] === $appId) { |
|
| 197 | + foreach ($apps as $app) { |
|
| 198 | + if ($app['id'] === $appId) { |
|
| 199 | 199 | // Load the certificate |
| 200 | 200 | $certificate = new X509(); |
| 201 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 201 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 202 | 202 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
| 203 | 203 | |
| 204 | 204 | // Verify if the certificate has been revoked |
| 205 | 205 | $crl = new X509(); |
| 206 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 207 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 208 | - if($crl->validateSignature() !== true) { |
|
| 206 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 207 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
| 208 | + if ($crl->validateSignature() !== true) { |
|
| 209 | 209 | throw new \Exception('Could not validate CRL signature'); |
| 210 | 210 | } |
| 211 | 211 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
| 223 | - if($certificate->validateSignature() !== true) { |
|
| 223 | + if ($certificate->validateSignature() !== true) { |
|
| 224 | 224 | throw new \Exception( |
| 225 | 225 | sprintf( |
| 226 | 226 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | // Verify if the certificate is issued for the requested app id |
| 233 | 233 | $certInfo = openssl_x509_parse($app['certificate']); |
| 234 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 234 | + if (!isset($certInfo['subject']['CN'])) { |
|
| 235 | 235 | throw new \Exception( |
| 236 | 236 | sprintf( |
| 237 | 237 | 'App with id %s has a cert with no CN', |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | ) |
| 240 | 240 | ); |
| 241 | 241 | } |
| 242 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 242 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
| 243 | 243 | throw new \Exception( |
| 244 | 244 | sprintf( |
| 245 | 245 | 'App with id %s has a cert issued to %s', |
@@ -256,21 +256,21 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | // Check if the signature actually matches the downloaded content |
| 258 | 258 | $certificate = openssl_get_publickey($app['certificate']); |
| 259 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 259 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 260 | 260 | openssl_free_key($certificate); |
| 261 | 261 | |
| 262 | - if($verified === true) { |
|
| 262 | + if ($verified === true) { |
|
| 263 | 263 | // Seems to match, let's proceed |
| 264 | 264 | $extractDir = $this->tempManager->getTemporaryFolder(); |
| 265 | 265 | $archive = new TAR($tempFile); |
| 266 | 266 | |
| 267 | - if($archive) { |
|
| 267 | + if ($archive) { |
|
| 268 | 268 | $archive->extract($extractDir); |
| 269 | 269 | $allFiles = scandir($extractDir); |
| 270 | 270 | $folders = array_diff($allFiles, ['.', '..']); |
| 271 | 271 | $folders = array_values($folders); |
| 272 | 272 | |
| 273 | - if(count($folders) > 1) { |
|
| 273 | + if (count($folders) > 1) { |
|
| 274 | 274 | throw new \Exception( |
| 275 | 275 | sprintf( |
| 276 | 276 | 'Extracted app %s has more than 1 folder', |
@@ -281,22 +281,22 @@ discard block |
||
| 281 | 281 | |
| 282 | 282 | // Check if appinfo/info.xml has the same app ID as well |
| 283 | 283 | $loadEntities = libxml_disable_entity_loader(false); |
| 284 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 284 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
| 285 | 285 | libxml_disable_entity_loader($loadEntities); |
| 286 | - if((string)$xml->id !== $appId) { |
|
| 286 | + if ((string) $xml->id !== $appId) { |
|
| 287 | 287 | throw new \Exception( |
| 288 | 288 | sprintf( |
| 289 | 289 | 'App for id %s has a wrong app ID in info.xml: %s', |
| 290 | 290 | $appId, |
| 291 | - (string)$xml->id |
|
| 291 | + (string) $xml->id |
|
| 292 | 292 | ) |
| 293 | 293 | ); |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | // Check if the version is lower than before |
| 297 | 297 | $currentVersion = OC_App::getAppVersion($appId); |
| 298 | - $newVersion = (string)$xml->version; |
|
| 299 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 298 | + $newVersion = (string) $xml->version; |
|
| 299 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
| 300 | 300 | throw new \Exception( |
| 301 | 301 | sprintf( |
| 302 | 302 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -307,12 +307,12 @@ discard block |
||
| 307 | 307 | ); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 310 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
| 311 | 311 | // Remove old app with the ID if existent |
| 312 | 312 | OC_Helper::rmdirr($baseDir); |
| 313 | 313 | // Move to app folder |
| 314 | - if(@mkdir($baseDir)) { |
|
| 315 | - $extractDir .= '/' . $folders[0]; |
|
| 314 | + if (@mkdir($baseDir)) { |
|
| 315 | + $extractDir .= '/'.$folders[0]; |
|
| 316 | 316 | OC_Helper::copyr($extractDir, $baseDir); |
| 317 | 317 | } |
| 318 | 318 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $apps = $appFetcher->get(); |
| 375 | - foreach($apps as $app) { |
|
| 376 | - if($app['id'] === $appId) { |
|
| 375 | + foreach ($apps as $app) { |
|
| 376 | + if ($app['id'] === $appId) { |
|
| 377 | 377 | $currentVersion = OC_App::getAppVersion($appId); |
| 378 | 378 | $newestVersion = $app['releases'][0]['version']; |
| 379 | 379 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | * The function will check if the app is already downloaded in the apps repository |
| 396 | 396 | */ |
| 397 | 397 | public function isDownloaded($name) { |
| 398 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 398 | + foreach (\OC::$APPSROOTS as $dir) { |
|
| 399 | 399 | $dirToTest = $dir['path']; |
| 400 | 400 | $dirToTest .= '/'; |
| 401 | 401 | $dirToTest .= $name; |
@@ -423,11 +423,11 @@ discard block |
||
| 423 | 423 | * this has to be done by the function oc_app_uninstall(). |
| 424 | 424 | */ |
| 425 | 425 | public function removeApp($appId) { |
| 426 | - if($this->isDownloaded( $appId )) { |
|
| 427 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 426 | + if ($this->isDownloaded($appId)) { |
|
| 427 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
| 428 | 428 | OC_Helper::rmdirr($appDir); |
| 429 | 429 | return true; |
| 430 | - }else{ |
|
| 430 | + } else { |
|
| 431 | 431 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
| 432 | 432 | |
| 433 | 433 | return false; |
@@ -443,8 +443,8 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function installAppBundle(Bundle $bundle) { |
| 445 | 445 | $appIds = $bundle->getAppIdentifiers(); |
| 446 | - foreach($appIds as $appId) { |
|
| 447 | - if(!$this->isDownloaded($appId)) { |
|
| 446 | + foreach ($appIds as $appId) { |
|
| 447 | + if (!$this->isDownloaded($appId)) { |
|
| 448 | 448 | $this->downloadApp($appId); |
| 449 | 449 | } |
| 450 | 450 | $this->installApp($appId); |
@@ -466,13 +466,13 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | public static function installShippedApps($softErrors = false) { |
| 468 | 468 | $errors = []; |
| 469 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 470 | - if($dir = opendir( $app_dir['path'] )) { |
|
| 471 | - while( false !== ( $filename = readdir( $dir ))) { |
|
| 472 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 473 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 474 | - if(!Installer::isInstalled($filename)) { |
|
| 475 | - $info=OC_App::getAppInfo($filename); |
|
| 469 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
| 470 | + if ($dir = opendir($app_dir['path'])) { |
|
| 471 | + while (false !== ($filename = readdir($dir))) { |
|
| 472 | + if (substr($filename, 0, 1) != '.' and is_dir($app_dir['path']."/$filename")) { |
|
| 473 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
| 474 | + if (!Installer::isInstalled($filename)) { |
|
| 475 | + $info = OC_App::getAppInfo($filename); |
|
| 476 | 476 | $enabled = isset($info['default_enable']); |
| 477 | 477 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
| 478 | 478 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | - closedir( $dir ); |
|
| 498 | + closedir($dir); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | |
@@ -510,12 +510,12 @@ discard block |
||
| 510 | 510 | public static function installShippedApp($app) { |
| 511 | 511 | //install the database |
| 512 | 512 | $appPath = OC_App::getAppPath($app); |
| 513 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
| 513 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
| 514 | 514 | try { |
| 515 | 515 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
| 516 | 516 | } catch (TableExistsException $e) { |
| 517 | 517 | throw new HintException( |
| 518 | - 'Failed to enable app ' . $app, |
|
| 518 | + 'Failed to enable app '.$app, |
|
| 519 | 519 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
| 520 | 520 | 0, $e |
| 521 | 521 | ); |
@@ -542,16 +542,16 @@ discard block |
||
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | //set remote/public handlers |
| 545 | - foreach($info['remote'] as $name=>$path) { |
|
| 545 | + foreach ($info['remote'] as $name=>$path) { |
|
| 546 | 546 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
| 547 | 547 | } |
| 548 | - foreach($info['public'] as $name=>$path) { |
|
| 548 | + foreach ($info['public'] as $name=>$path) { |
|
| 549 | 549 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | OC_App::setAppTypes($info['id']); |
| 553 | 553 | |
| 554 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 554 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 555 | 555 | // requires that autoloading was registered for the app, |
| 556 | 556 | // as happens before running the install.php some lines above |
| 557 | 557 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | public static function checkCode($folder) { |
| 569 | 569 | // is the code checker enabled? |
| 570 | - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
| 570 | + if (!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
| 571 | 571 | return true; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | * @param string $script |
| 582 | 582 | */ |
| 583 | 583 | private static function includeAppScript($script) { |
| 584 | - if ( file_exists($script) ){ |
|
| 584 | + if (file_exists($script)) { |
|
| 585 | 585 | include $script; |
| 586 | 586 | } |
| 587 | 587 | } |
@@ -42,7 +42,6 @@ discard block |
||
| 42 | 42 | namespace OC; |
| 43 | 43 | |
| 44 | 44 | use Doctrine\DBAL\Exception\TableExistsException; |
| 45 | -use OC\App\AppManager; |
|
| 46 | 45 | use OC\App\AppStore\Bundles\Bundle; |
| 47 | 46 | use OC\App\AppStore\Fetcher\AppFetcher; |
| 48 | 47 | use OC\App\CodeChecker\CodeChecker; |
@@ -52,7 +51,6 @@ discard block |
||
| 52 | 51 | use OC_App; |
| 53 | 52 | use OC_DB; |
| 54 | 53 | use OC_Helper; |
| 55 | -use OCP\App\IAppManager; |
|
| 56 | 54 | use OCP\Http\Client\IClientService; |
| 57 | 55 | use OCP\IConfig; |
| 58 | 56 | use OCP\ILogger; |
@@ -63,520 +63,520 @@ |
||
| 63 | 63 | * This class provides the functionality needed to install, update and remove apps |
| 64 | 64 | */ |
| 65 | 65 | class Installer { |
| 66 | - /** @var AppFetcher */ |
|
| 67 | - private $appFetcher; |
|
| 68 | - /** @var IClientService */ |
|
| 69 | - private $clientService; |
|
| 70 | - /** @var ITempManager */ |
|
| 71 | - private $tempManager; |
|
| 72 | - /** @var ILogger */ |
|
| 73 | - private $logger; |
|
| 74 | - /** @var IConfig */ |
|
| 75 | - private $config; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param AppFetcher $appFetcher |
|
| 79 | - * @param IClientService $clientService |
|
| 80 | - * @param ITempManager $tempManager |
|
| 81 | - * @param ILogger $logger |
|
| 82 | - * @param IConfig $config |
|
| 83 | - */ |
|
| 84 | - public function __construct(AppFetcher $appFetcher, |
|
| 85 | - IClientService $clientService, |
|
| 86 | - ITempManager $tempManager, |
|
| 87 | - ILogger $logger, |
|
| 88 | - IConfig $config) { |
|
| 89 | - $this->appFetcher = $appFetcher; |
|
| 90 | - $this->clientService = $clientService; |
|
| 91 | - $this->tempManager = $tempManager; |
|
| 92 | - $this->logger = $logger; |
|
| 93 | - $this->config = $config; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Installs an app that is located in one of the app folders already |
|
| 98 | - * |
|
| 99 | - * @param string $appId App to install |
|
| 100 | - * @throws \Exception |
|
| 101 | - * @return integer |
|
| 102 | - */ |
|
| 103 | - public function installApp($appId) { |
|
| 104 | - $app = \OC_App::findAppInDirectories($appId); |
|
| 105 | - if($app === false) { |
|
| 106 | - throw new \Exception('App not found in any app directory'); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $basedir = $app['path'].'/'.$appId; |
|
| 110 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 111 | - |
|
| 112 | - //install the database |
|
| 113 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 114 | - if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
| 115 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 116 | - } else { |
|
| 117 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - \OC_App::registerAutoloading($appId, $basedir); |
|
| 122 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 123 | - |
|
| 124 | - //run appinfo/install.php |
|
| 125 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
| 126 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $appData = OC_App::getAppInfo($appId); |
|
| 130 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 131 | - |
|
| 132 | - //set the installed version |
|
| 133 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 134 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 135 | - |
|
| 136 | - //set remote/public handlers |
|
| 137 | - foreach($info['remote'] as $name=>$path) { |
|
| 138 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 139 | - } |
|
| 140 | - foreach($info['public'] as $name=>$path) { |
|
| 141 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - OC_App::setAppTypes($info['id']); |
|
| 145 | - |
|
| 146 | - return $info['id']; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @brief checks whether or not an app is installed |
|
| 151 | - * @param string $app app |
|
| 152 | - * @returns bool |
|
| 153 | - * |
|
| 154 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
| 155 | - */ |
|
| 156 | - public static function isInstalled( $app ) { |
|
| 157 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Updates the specified app from the appstore |
|
| 162 | - * |
|
| 163 | - * @param string $appId |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - public function updateAppstoreApp($appId) { |
|
| 167 | - if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
| 168 | - try { |
|
| 169 | - $this->downloadApp($appId); |
|
| 170 | - } catch (\Exception $e) { |
|
| 171 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - return OC_App::updateApp($appId); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Downloads an app and puts it into the app directory |
|
| 182 | - * |
|
| 183 | - * @param string $appId |
|
| 184 | - * |
|
| 185 | - * @throws \Exception If the installation was not successful |
|
| 186 | - */ |
|
| 187 | - public function downloadApp($appId) { |
|
| 188 | - $appId = strtolower($appId); |
|
| 189 | - |
|
| 190 | - $apps = $this->appFetcher->get(); |
|
| 191 | - foreach($apps as $app) { |
|
| 192 | - if($app['id'] === $appId) { |
|
| 193 | - // Load the certificate |
|
| 194 | - $certificate = new X509(); |
|
| 195 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 196 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 197 | - |
|
| 198 | - // Verify if the certificate has been revoked |
|
| 199 | - $crl = new X509(); |
|
| 200 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 201 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 202 | - if($crl->validateSignature() !== true) { |
|
| 203 | - throw new \Exception('Could not validate CRL signature'); |
|
| 204 | - } |
|
| 205 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 206 | - $revoked = $crl->getRevoked($csn); |
|
| 207 | - if ($revoked !== false) { |
|
| 208 | - throw new \Exception( |
|
| 209 | - sprintf( |
|
| 210 | - 'Certificate "%s" has been revoked', |
|
| 211 | - $csn |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 217 | - if($certificate->validateSignature() !== true) { |
|
| 218 | - throw new \Exception( |
|
| 219 | - sprintf( |
|
| 220 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 221 | - $appId |
|
| 222 | - ) |
|
| 223 | - ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Verify if the certificate is issued for the requested app id |
|
| 227 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
| 228 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 229 | - throw new \Exception( |
|
| 230 | - sprintf( |
|
| 231 | - 'App with id %s has a cert with no CN', |
|
| 232 | - $appId |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 237 | - throw new \Exception( |
|
| 238 | - sprintf( |
|
| 239 | - 'App with id %s has a cert issued to %s', |
|
| 240 | - $appId, |
|
| 241 | - $certInfo['subject']['CN'] |
|
| 242 | - ) |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // Download the release |
|
| 247 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 248 | - $client = $this->clientService->newClient(); |
|
| 249 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
| 250 | - |
|
| 251 | - // Check if the signature actually matches the downloaded content |
|
| 252 | - $certificate = openssl_get_publickey($app['certificate']); |
|
| 253 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 254 | - openssl_free_key($certificate); |
|
| 255 | - |
|
| 256 | - if($verified === true) { |
|
| 257 | - // Seems to match, let's proceed |
|
| 258 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 259 | - $archive = new TAR($tempFile); |
|
| 260 | - |
|
| 261 | - if($archive) { |
|
| 262 | - $archive->extract($extractDir); |
|
| 263 | - $allFiles = scandir($extractDir); |
|
| 264 | - $folders = array_diff($allFiles, ['.', '..']); |
|
| 265 | - $folders = array_values($folders); |
|
| 266 | - |
|
| 267 | - if(count($folders) > 1) { |
|
| 268 | - throw new \Exception( |
|
| 269 | - sprintf( |
|
| 270 | - 'Extracted app %s has more than 1 folder', |
|
| 271 | - $appId |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // Check if appinfo/info.xml has the same app ID as well |
|
| 277 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 278 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 279 | - libxml_disable_entity_loader($loadEntities); |
|
| 280 | - if((string)$xml->id !== $appId) { |
|
| 281 | - throw new \Exception( |
|
| 282 | - sprintf( |
|
| 283 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 284 | - $appId, |
|
| 285 | - (string)$xml->id |
|
| 286 | - ) |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - // Check if the version is lower than before |
|
| 291 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 292 | - $newVersion = (string)$xml->version; |
|
| 293 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 294 | - throw new \Exception( |
|
| 295 | - sprintf( |
|
| 296 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
| 297 | - $appId, |
|
| 298 | - $currentVersion, |
|
| 299 | - $newVersion |
|
| 300 | - ) |
|
| 301 | - ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 305 | - // Remove old app with the ID if existent |
|
| 306 | - OC_Helper::rmdirr($baseDir); |
|
| 307 | - // Move to app folder |
|
| 308 | - if(@mkdir($baseDir)) { |
|
| 309 | - $extractDir .= '/' . $folders[0]; |
|
| 310 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 311 | - } |
|
| 312 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 313 | - OC_Helper::rmdirr($extractDir); |
|
| 314 | - return; |
|
| 315 | - } else { |
|
| 316 | - throw new \Exception( |
|
| 317 | - sprintf( |
|
| 318 | - 'Could not extract app with ID %s to %s', |
|
| 319 | - $appId, |
|
| 320 | - $extractDir |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - } else { |
|
| 325 | - // Signature does not match |
|
| 326 | - throw new \Exception( |
|
| 327 | - sprintf( |
|
| 328 | - 'App with id %s has invalid signature', |
|
| 329 | - $appId |
|
| 330 | - ) |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - throw new \Exception( |
|
| 337 | - sprintf( |
|
| 338 | - 'Could not download app %s', |
|
| 339 | - $appId |
|
| 340 | - ) |
|
| 341 | - ); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Check if an update for the app is available |
|
| 346 | - * |
|
| 347 | - * @param string $appId |
|
| 348 | - * @param AppFetcher $appFetcher |
|
| 349 | - * @return string|false false or the version number of the update |
|
| 350 | - */ |
|
| 351 | - public static function isUpdateAvailable($appId, |
|
| 352 | - AppFetcher $appFetcher) { |
|
| 353 | - static $isInstanceReadyForUpdates = null; |
|
| 354 | - |
|
| 355 | - if ($isInstanceReadyForUpdates === null) { |
|
| 356 | - $installPath = OC_App::getInstallPath(); |
|
| 357 | - if ($installPath === false || $installPath === null) { |
|
| 358 | - $isInstanceReadyForUpdates = false; |
|
| 359 | - } else { |
|
| 360 | - $isInstanceReadyForUpdates = true; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if ($isInstanceReadyForUpdates === false) { |
|
| 365 | - return false; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - $apps = $appFetcher->get(); |
|
| 369 | - foreach($apps as $app) { |
|
| 370 | - if($app['id'] === $appId) { |
|
| 371 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 372 | - $newestVersion = $app['releases'][0]['version']; |
|
| 373 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
| 374 | - return $newestVersion; |
|
| 375 | - } else { |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - return false; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Check if app is already downloaded |
|
| 386 | - * @param string $name name of the application to remove |
|
| 387 | - * @return boolean |
|
| 388 | - * |
|
| 389 | - * The function will check if the app is already downloaded in the apps repository |
|
| 390 | - */ |
|
| 391 | - public function isDownloaded($name) { |
|
| 392 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 393 | - $dirToTest = $dir['path']; |
|
| 394 | - $dirToTest .= '/'; |
|
| 395 | - $dirToTest .= $name; |
|
| 396 | - $dirToTest .= '/'; |
|
| 397 | - |
|
| 398 | - if (is_dir($dirToTest)) { |
|
| 399 | - return true; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return false; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Removes an app |
|
| 408 | - * @param string $appId ID of the application to remove |
|
| 409 | - * @return boolean |
|
| 410 | - * |
|
| 411 | - * |
|
| 412 | - * This function works as follows |
|
| 413 | - * -# call uninstall repair steps |
|
| 414 | - * -# removing the files |
|
| 415 | - * |
|
| 416 | - * The function will not delete preferences, tables and the configuration, |
|
| 417 | - * this has to be done by the function oc_app_uninstall(). |
|
| 418 | - */ |
|
| 419 | - public function removeApp($appId) { |
|
| 420 | - if($this->isDownloaded( $appId )) { |
|
| 421 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 422 | - OC_Helper::rmdirr($appDir); |
|
| 423 | - return true; |
|
| 424 | - }else{ |
|
| 425 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
| 426 | - |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Installs the app within the bundle and marks the bundle as installed |
|
| 434 | - * |
|
| 435 | - * @param Bundle $bundle |
|
| 436 | - * @throws \Exception If app could not get installed |
|
| 437 | - */ |
|
| 438 | - public function installAppBundle(Bundle $bundle) { |
|
| 439 | - $appIds = $bundle->getAppIdentifiers(); |
|
| 440 | - foreach($appIds as $appId) { |
|
| 441 | - if(!$this->isDownloaded($appId)) { |
|
| 442 | - $this->downloadApp($appId); |
|
| 443 | - } |
|
| 444 | - $this->installApp($appId); |
|
| 445 | - $app = new OC_App(); |
|
| 446 | - $app->enable($appId); |
|
| 447 | - } |
|
| 448 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 449 | - $bundles[] = $bundle->getIdentifier(); |
|
| 450 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Installs shipped apps |
|
| 455 | - * |
|
| 456 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 457 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 458 | - * working ownCloud at the end instead of an aborted update. |
|
| 459 | - * @return array Array of error messages (appid => Exception) |
|
| 460 | - */ |
|
| 461 | - public static function installShippedApps($softErrors = false) { |
|
| 462 | - $errors = []; |
|
| 463 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 464 | - if($dir = opendir( $app_dir['path'] )) { |
|
| 465 | - while( false !== ( $filename = readdir( $dir ))) { |
|
| 466 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 467 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 468 | - if(!Installer::isInstalled($filename)) { |
|
| 469 | - $info=OC_App::getAppInfo($filename); |
|
| 470 | - $enabled = isset($info['default_enable']); |
|
| 471 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
| 472 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
| 473 | - if ($softErrors) { |
|
| 474 | - try { |
|
| 475 | - Installer::installShippedApp($filename); |
|
| 476 | - } catch (HintException $e) { |
|
| 477 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
| 478 | - $errors[$filename] = $e; |
|
| 479 | - continue; |
|
| 480 | - } |
|
| 481 | - throw $e; |
|
| 482 | - } |
|
| 483 | - } else { |
|
| 484 | - Installer::installShippedApp($filename); |
|
| 485 | - } |
|
| 486 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - closedir( $dir ); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $errors; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * install an app already placed in the app folder |
|
| 501 | - * @param string $app id of the app to install |
|
| 502 | - * @return integer |
|
| 503 | - */ |
|
| 504 | - public static function installShippedApp($app) { |
|
| 505 | - //install the database |
|
| 506 | - $appPath = OC_App::getAppPath($app); |
|
| 507 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
| 508 | - try { |
|
| 509 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
| 510 | - } catch (TableExistsException $e) { |
|
| 511 | - throw new HintException( |
|
| 512 | - 'Failed to enable app ' . $app, |
|
| 513 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
|
| 514 | - 0, $e |
|
| 515 | - ); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - //run appinfo/install.php |
|
| 520 | - \OC_App::registerAutoloading($app, $appPath); |
|
| 521 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 522 | - |
|
| 523 | - $info = OC_App::getAppInfo($app); |
|
| 524 | - if (is_null($info)) { |
|
| 525 | - return false; |
|
| 526 | - } |
|
| 527 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 528 | - |
|
| 529 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 530 | - |
|
| 531 | - $config = \OC::$server->getConfig(); |
|
| 532 | - |
|
| 533 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 534 | - if (array_key_exists('ocsid', $info)) { |
|
| 535 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - //set remote/public handlers |
|
| 539 | - foreach($info['remote'] as $name=>$path) { |
|
| 540 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 541 | - } |
|
| 542 | - foreach($info['public'] as $name=>$path) { |
|
| 543 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - OC_App::setAppTypes($info['id']); |
|
| 547 | - |
|
| 548 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 549 | - // requires that autoloading was registered for the app, |
|
| 550 | - // as happens before running the install.php some lines above |
|
| 551 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - return $info['id']; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * check the code of an app with some static code checks |
|
| 559 | - * @param string $folder the folder of the app to check |
|
| 560 | - * @return boolean true for app is o.k. and false for app is not o.k. |
|
| 561 | - */ |
|
| 562 | - public static function checkCode($folder) { |
|
| 563 | - // is the code checker enabled? |
|
| 564 | - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
| 565 | - return true; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); |
|
| 569 | - $errors = $codeChecker->analyseFolder(basename($folder), $folder); |
|
| 570 | - |
|
| 571 | - return empty($errors); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * @param string $script |
|
| 576 | - */ |
|
| 577 | - private static function includeAppScript($script) { |
|
| 578 | - if ( file_exists($script) ){ |
|
| 579 | - include $script; |
|
| 580 | - } |
|
| 581 | - } |
|
| 66 | + /** @var AppFetcher */ |
|
| 67 | + private $appFetcher; |
|
| 68 | + /** @var IClientService */ |
|
| 69 | + private $clientService; |
|
| 70 | + /** @var ITempManager */ |
|
| 71 | + private $tempManager; |
|
| 72 | + /** @var ILogger */ |
|
| 73 | + private $logger; |
|
| 74 | + /** @var IConfig */ |
|
| 75 | + private $config; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param AppFetcher $appFetcher |
|
| 79 | + * @param IClientService $clientService |
|
| 80 | + * @param ITempManager $tempManager |
|
| 81 | + * @param ILogger $logger |
|
| 82 | + * @param IConfig $config |
|
| 83 | + */ |
|
| 84 | + public function __construct(AppFetcher $appFetcher, |
|
| 85 | + IClientService $clientService, |
|
| 86 | + ITempManager $tempManager, |
|
| 87 | + ILogger $logger, |
|
| 88 | + IConfig $config) { |
|
| 89 | + $this->appFetcher = $appFetcher; |
|
| 90 | + $this->clientService = $clientService; |
|
| 91 | + $this->tempManager = $tempManager; |
|
| 92 | + $this->logger = $logger; |
|
| 93 | + $this->config = $config; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Installs an app that is located in one of the app folders already |
|
| 98 | + * |
|
| 99 | + * @param string $appId App to install |
|
| 100 | + * @throws \Exception |
|
| 101 | + * @return integer |
|
| 102 | + */ |
|
| 103 | + public function installApp($appId) { |
|
| 104 | + $app = \OC_App::findAppInDirectories($appId); |
|
| 105 | + if($app === false) { |
|
| 106 | + throw new \Exception('App not found in any app directory'); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $basedir = $app['path'].'/'.$appId; |
|
| 110 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 111 | + |
|
| 112 | + //install the database |
|
| 113 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 114 | + if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
| 115 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 116 | + } else { |
|
| 117 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + \OC_App::registerAutoloading($appId, $basedir); |
|
| 122 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 123 | + |
|
| 124 | + //run appinfo/install.php |
|
| 125 | + if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
| 126 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $appData = OC_App::getAppInfo($appId); |
|
| 130 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 131 | + |
|
| 132 | + //set the installed version |
|
| 133 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 134 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 135 | + |
|
| 136 | + //set remote/public handlers |
|
| 137 | + foreach($info['remote'] as $name=>$path) { |
|
| 138 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 139 | + } |
|
| 140 | + foreach($info['public'] as $name=>$path) { |
|
| 141 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + OC_App::setAppTypes($info['id']); |
|
| 145 | + |
|
| 146 | + return $info['id']; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @brief checks whether or not an app is installed |
|
| 151 | + * @param string $app app |
|
| 152 | + * @returns bool |
|
| 153 | + * |
|
| 154 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
| 155 | + */ |
|
| 156 | + public static function isInstalled( $app ) { |
|
| 157 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Updates the specified app from the appstore |
|
| 162 | + * |
|
| 163 | + * @param string $appId |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + public function updateAppstoreApp($appId) { |
|
| 167 | + if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
| 168 | + try { |
|
| 169 | + $this->downloadApp($appId); |
|
| 170 | + } catch (\Exception $e) { |
|
| 171 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + return OC_App::updateApp($appId); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Downloads an app and puts it into the app directory |
|
| 182 | + * |
|
| 183 | + * @param string $appId |
|
| 184 | + * |
|
| 185 | + * @throws \Exception If the installation was not successful |
|
| 186 | + */ |
|
| 187 | + public function downloadApp($appId) { |
|
| 188 | + $appId = strtolower($appId); |
|
| 189 | + |
|
| 190 | + $apps = $this->appFetcher->get(); |
|
| 191 | + foreach($apps as $app) { |
|
| 192 | + if($app['id'] === $appId) { |
|
| 193 | + // Load the certificate |
|
| 194 | + $certificate = new X509(); |
|
| 195 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 196 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 197 | + |
|
| 198 | + // Verify if the certificate has been revoked |
|
| 199 | + $crl = new X509(); |
|
| 200 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 201 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 202 | + if($crl->validateSignature() !== true) { |
|
| 203 | + throw new \Exception('Could not validate CRL signature'); |
|
| 204 | + } |
|
| 205 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 206 | + $revoked = $crl->getRevoked($csn); |
|
| 207 | + if ($revoked !== false) { |
|
| 208 | + throw new \Exception( |
|
| 209 | + sprintf( |
|
| 210 | + 'Certificate "%s" has been revoked', |
|
| 211 | + $csn |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 217 | + if($certificate->validateSignature() !== true) { |
|
| 218 | + throw new \Exception( |
|
| 219 | + sprintf( |
|
| 220 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 221 | + $appId |
|
| 222 | + ) |
|
| 223 | + ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Verify if the certificate is issued for the requested app id |
|
| 227 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
| 228 | + if(!isset($certInfo['subject']['CN'])) { |
|
| 229 | + throw new \Exception( |
|
| 230 | + sprintf( |
|
| 231 | + 'App with id %s has a cert with no CN', |
|
| 232 | + $appId |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + if($certInfo['subject']['CN'] !== $appId) { |
|
| 237 | + throw new \Exception( |
|
| 238 | + sprintf( |
|
| 239 | + 'App with id %s has a cert issued to %s', |
|
| 240 | + $appId, |
|
| 241 | + $certInfo['subject']['CN'] |
|
| 242 | + ) |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // Download the release |
|
| 247 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 248 | + $client = $this->clientService->newClient(); |
|
| 249 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
| 250 | + |
|
| 251 | + // Check if the signature actually matches the downloaded content |
|
| 252 | + $certificate = openssl_get_publickey($app['certificate']); |
|
| 253 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 254 | + openssl_free_key($certificate); |
|
| 255 | + |
|
| 256 | + if($verified === true) { |
|
| 257 | + // Seems to match, let's proceed |
|
| 258 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 259 | + $archive = new TAR($tempFile); |
|
| 260 | + |
|
| 261 | + if($archive) { |
|
| 262 | + $archive->extract($extractDir); |
|
| 263 | + $allFiles = scandir($extractDir); |
|
| 264 | + $folders = array_diff($allFiles, ['.', '..']); |
|
| 265 | + $folders = array_values($folders); |
|
| 266 | + |
|
| 267 | + if(count($folders) > 1) { |
|
| 268 | + throw new \Exception( |
|
| 269 | + sprintf( |
|
| 270 | + 'Extracted app %s has more than 1 folder', |
|
| 271 | + $appId |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // Check if appinfo/info.xml has the same app ID as well |
|
| 277 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 278 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 279 | + libxml_disable_entity_loader($loadEntities); |
|
| 280 | + if((string)$xml->id !== $appId) { |
|
| 281 | + throw new \Exception( |
|
| 282 | + sprintf( |
|
| 283 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 284 | + $appId, |
|
| 285 | + (string)$xml->id |
|
| 286 | + ) |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + // Check if the version is lower than before |
|
| 291 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 292 | + $newVersion = (string)$xml->version; |
|
| 293 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 294 | + throw new \Exception( |
|
| 295 | + sprintf( |
|
| 296 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
| 297 | + $appId, |
|
| 298 | + $currentVersion, |
|
| 299 | + $newVersion |
|
| 300 | + ) |
|
| 301 | + ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 305 | + // Remove old app with the ID if existent |
|
| 306 | + OC_Helper::rmdirr($baseDir); |
|
| 307 | + // Move to app folder |
|
| 308 | + if(@mkdir($baseDir)) { |
|
| 309 | + $extractDir .= '/' . $folders[0]; |
|
| 310 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 311 | + } |
|
| 312 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 313 | + OC_Helper::rmdirr($extractDir); |
|
| 314 | + return; |
|
| 315 | + } else { |
|
| 316 | + throw new \Exception( |
|
| 317 | + sprintf( |
|
| 318 | + 'Could not extract app with ID %s to %s', |
|
| 319 | + $appId, |
|
| 320 | + $extractDir |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + } else { |
|
| 325 | + // Signature does not match |
|
| 326 | + throw new \Exception( |
|
| 327 | + sprintf( |
|
| 328 | + 'App with id %s has invalid signature', |
|
| 329 | + $appId |
|
| 330 | + ) |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + throw new \Exception( |
|
| 337 | + sprintf( |
|
| 338 | + 'Could not download app %s', |
|
| 339 | + $appId |
|
| 340 | + ) |
|
| 341 | + ); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Check if an update for the app is available |
|
| 346 | + * |
|
| 347 | + * @param string $appId |
|
| 348 | + * @param AppFetcher $appFetcher |
|
| 349 | + * @return string|false false or the version number of the update |
|
| 350 | + */ |
|
| 351 | + public static function isUpdateAvailable($appId, |
|
| 352 | + AppFetcher $appFetcher) { |
|
| 353 | + static $isInstanceReadyForUpdates = null; |
|
| 354 | + |
|
| 355 | + if ($isInstanceReadyForUpdates === null) { |
|
| 356 | + $installPath = OC_App::getInstallPath(); |
|
| 357 | + if ($installPath === false || $installPath === null) { |
|
| 358 | + $isInstanceReadyForUpdates = false; |
|
| 359 | + } else { |
|
| 360 | + $isInstanceReadyForUpdates = true; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if ($isInstanceReadyForUpdates === false) { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + $apps = $appFetcher->get(); |
|
| 369 | + foreach($apps as $app) { |
|
| 370 | + if($app['id'] === $appId) { |
|
| 371 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 372 | + $newestVersion = $app['releases'][0]['version']; |
|
| 373 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
| 374 | + return $newestVersion; |
|
| 375 | + } else { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + return false; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Check if app is already downloaded |
|
| 386 | + * @param string $name name of the application to remove |
|
| 387 | + * @return boolean |
|
| 388 | + * |
|
| 389 | + * The function will check if the app is already downloaded in the apps repository |
|
| 390 | + */ |
|
| 391 | + public function isDownloaded($name) { |
|
| 392 | + foreach(\OC::$APPSROOTS as $dir) { |
|
| 393 | + $dirToTest = $dir['path']; |
|
| 394 | + $dirToTest .= '/'; |
|
| 395 | + $dirToTest .= $name; |
|
| 396 | + $dirToTest .= '/'; |
|
| 397 | + |
|
| 398 | + if (is_dir($dirToTest)) { |
|
| 399 | + return true; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return false; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Removes an app |
|
| 408 | + * @param string $appId ID of the application to remove |
|
| 409 | + * @return boolean |
|
| 410 | + * |
|
| 411 | + * |
|
| 412 | + * This function works as follows |
|
| 413 | + * -# call uninstall repair steps |
|
| 414 | + * -# removing the files |
|
| 415 | + * |
|
| 416 | + * The function will not delete preferences, tables and the configuration, |
|
| 417 | + * this has to be done by the function oc_app_uninstall(). |
|
| 418 | + */ |
|
| 419 | + public function removeApp($appId) { |
|
| 420 | + if($this->isDownloaded( $appId )) { |
|
| 421 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 422 | + OC_Helper::rmdirr($appDir); |
|
| 423 | + return true; |
|
| 424 | + }else{ |
|
| 425 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
| 426 | + |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Installs the app within the bundle and marks the bundle as installed |
|
| 434 | + * |
|
| 435 | + * @param Bundle $bundle |
|
| 436 | + * @throws \Exception If app could not get installed |
|
| 437 | + */ |
|
| 438 | + public function installAppBundle(Bundle $bundle) { |
|
| 439 | + $appIds = $bundle->getAppIdentifiers(); |
|
| 440 | + foreach($appIds as $appId) { |
|
| 441 | + if(!$this->isDownloaded($appId)) { |
|
| 442 | + $this->downloadApp($appId); |
|
| 443 | + } |
|
| 444 | + $this->installApp($appId); |
|
| 445 | + $app = new OC_App(); |
|
| 446 | + $app->enable($appId); |
|
| 447 | + } |
|
| 448 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 449 | + $bundles[] = $bundle->getIdentifier(); |
|
| 450 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Installs shipped apps |
|
| 455 | + * |
|
| 456 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 457 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 458 | + * working ownCloud at the end instead of an aborted update. |
|
| 459 | + * @return array Array of error messages (appid => Exception) |
|
| 460 | + */ |
|
| 461 | + public static function installShippedApps($softErrors = false) { |
|
| 462 | + $errors = []; |
|
| 463 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 464 | + if($dir = opendir( $app_dir['path'] )) { |
|
| 465 | + while( false !== ( $filename = readdir( $dir ))) { |
|
| 466 | + if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 467 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 468 | + if(!Installer::isInstalled($filename)) { |
|
| 469 | + $info=OC_App::getAppInfo($filename); |
|
| 470 | + $enabled = isset($info['default_enable']); |
|
| 471 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
| 472 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
| 473 | + if ($softErrors) { |
|
| 474 | + try { |
|
| 475 | + Installer::installShippedApp($filename); |
|
| 476 | + } catch (HintException $e) { |
|
| 477 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
| 478 | + $errors[$filename] = $e; |
|
| 479 | + continue; |
|
| 480 | + } |
|
| 481 | + throw $e; |
|
| 482 | + } |
|
| 483 | + } else { |
|
| 484 | + Installer::installShippedApp($filename); |
|
| 485 | + } |
|
| 486 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + closedir( $dir ); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $errors; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * install an app already placed in the app folder |
|
| 501 | + * @param string $app id of the app to install |
|
| 502 | + * @return integer |
|
| 503 | + */ |
|
| 504 | + public static function installShippedApp($app) { |
|
| 505 | + //install the database |
|
| 506 | + $appPath = OC_App::getAppPath($app); |
|
| 507 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
| 508 | + try { |
|
| 509 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
| 510 | + } catch (TableExistsException $e) { |
|
| 511 | + throw new HintException( |
|
| 512 | + 'Failed to enable app ' . $app, |
|
| 513 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
|
| 514 | + 0, $e |
|
| 515 | + ); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + //run appinfo/install.php |
|
| 520 | + \OC_App::registerAutoloading($app, $appPath); |
|
| 521 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 522 | + |
|
| 523 | + $info = OC_App::getAppInfo($app); |
|
| 524 | + if (is_null($info)) { |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 527 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 528 | + |
|
| 529 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 530 | + |
|
| 531 | + $config = \OC::$server->getConfig(); |
|
| 532 | + |
|
| 533 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 534 | + if (array_key_exists('ocsid', $info)) { |
|
| 535 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + //set remote/public handlers |
|
| 539 | + foreach($info['remote'] as $name=>$path) { |
|
| 540 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 541 | + } |
|
| 542 | + foreach($info['public'] as $name=>$path) { |
|
| 543 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + OC_App::setAppTypes($info['id']); |
|
| 547 | + |
|
| 548 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 549 | + // requires that autoloading was registered for the app, |
|
| 550 | + // as happens before running the install.php some lines above |
|
| 551 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + return $info['id']; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * check the code of an app with some static code checks |
|
| 559 | + * @param string $folder the folder of the app to check |
|
| 560 | + * @return boolean true for app is o.k. and false for app is not o.k. |
|
| 561 | + */ |
|
| 562 | + public static function checkCode($folder) { |
|
| 563 | + // is the code checker enabled? |
|
| 564 | + if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
| 565 | + return true; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); |
|
| 569 | + $errors = $codeChecker->analyseFolder(basename($folder), $folder); |
|
| 570 | + |
|
| 571 | + return empty($errors); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * @param string $script |
|
| 576 | + */ |
|
| 577 | + private static function includeAppScript($script) { |
|
| 578 | + if ( file_exists($script) ){ |
|
| 579 | + include $script; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | 582 | } |
@@ -27,14 +27,14 @@ |
||
| 27 | 27 | * {@inheritDoc} |
| 28 | 28 | */ |
| 29 | 29 | public function getName() { |
| 30 | - return (string)$this->l10n->t('Enterprise bundle'); |
|
| 30 | + return (string) $this->l10n->t('Enterprise bundle'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * {@inheritDoc} |
| 35 | 35 | */ |
| 36 | 36 | public function getDescription() { |
| 37 | - return (string)$this->l10n->t('Apps for the Enterprise.'); |
|
| 37 | + return (string) $this->l10n->t('Apps for the Enterprise.'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -23,32 +23,32 @@ |
||
| 23 | 23 | |
| 24 | 24 | class EnterpriseBundle extends Bundle { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritDoc} |
|
| 28 | - */ |
|
| 29 | - public function getName() { |
|
| 30 | - return (string)$this->l10n->t('Enterprise bundle'); |
|
| 31 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritDoc} |
|
| 28 | + */ |
|
| 29 | + public function getName() { |
|
| 30 | + return (string)$this->l10n->t('Enterprise bundle'); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * {@inheritDoc} |
|
| 35 | - */ |
|
| 36 | - public function getDescription() { |
|
| 37 | - return (string)$this->l10n->t('Apps for the Enterprise.'); |
|
| 38 | - } |
|
| 33 | + /** |
|
| 34 | + * {@inheritDoc} |
|
| 35 | + */ |
|
| 36 | + public function getDescription() { |
|
| 37 | + return (string)$this->l10n->t('Apps for the Enterprise.'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * {@inheritDoc} |
|
| 42 | - */ |
|
| 43 | - public function getAppIdentifiers() { |
|
| 44 | - return [ |
|
| 45 | - 'admin_audit', |
|
| 46 | - 'user_ldap', |
|
| 47 | - 'files_retention', |
|
| 48 | - 'files_automatedtagging', |
|
| 49 | - 'user_saml', |
|
| 50 | - 'files_accesscontrol', |
|
| 51 | - ]; |
|
| 52 | - } |
|
| 40 | + /** |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + */ |
|
| 43 | + public function getAppIdentifiers() { |
|
| 44 | + return [ |
|
| 45 | + 'admin_audit', |
|
| 46 | + 'user_ldap', |
|
| 47 | + 'files_retention', |
|
| 48 | + 'files_automatedtagging', |
|
| 49 | + 'user_saml', |
|
| 50 | + 'files_accesscontrol', |
|
| 51 | + ]; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
@@ -23,28 +23,28 @@ |
||
| 23 | 23 | |
| 24 | 24 | class GroupwareBundle extends Bundle { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritDoc} |
|
| 28 | - */ |
|
| 29 | - public function getName() { |
|
| 30 | - return (string)$this->l10n->t('Groupware bundle'); |
|
| 31 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritDoc} |
|
| 28 | + */ |
|
| 29 | + public function getName() { |
|
| 30 | + return (string)$this->l10n->t('Groupware bundle'); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * {@inheritDoc} |
|
| 35 | - */ |
|
| 36 | - public function getDescription() { |
|
| 37 | - return (string)$this->l10n->t('Apps for groupware functionalities.'); |
|
| 38 | - } |
|
| 33 | + /** |
|
| 34 | + * {@inheritDoc} |
|
| 35 | + */ |
|
| 36 | + public function getDescription() { |
|
| 37 | + return (string)$this->l10n->t('Apps for groupware functionalities.'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * {@inheritDoc} |
|
| 42 | - */ |
|
| 43 | - public function getAppIdentifiers() { |
|
| 44 | - return [ |
|
| 45 | - 'calendar', |
|
| 46 | - 'contacts', |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + */ |
|
| 43 | + public function getAppIdentifiers() { |
|
| 44 | + return [ |
|
| 45 | + 'calendar', |
|
| 46 | + 'contacts', |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | } |
@@ -27,14 +27,14 @@ |
||
| 27 | 27 | * {@inheritDoc} |
| 28 | 28 | */ |
| 29 | 29 | public function getName() { |
| 30 | - return (string)$this->l10n->t('Groupware bundle'); |
|
| 30 | + return (string) $this->l10n->t('Groupware bundle'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * {@inheritDoc} |
| 35 | 35 | */ |
| 36 | 36 | public function getDescription() { |
| 37 | - return (string)$this->l10n->t('Apps for groupware functionalities.'); |
|
| 37 | + return (string) $this->l10n->t('Apps for groupware functionalities.'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -42,226 +42,226 @@ |
||
| 42 | 42 | |
| 43 | 43 | class TemplateLayout extends \OC_Template { |
| 44 | 44 | |
| 45 | - private static $versionHash = ''; |
|
| 45 | + private static $versionHash = ''; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var \OCP\IConfig |
|
| 49 | - */ |
|
| 50 | - private $config; |
|
| 47 | + /** |
|
| 48 | + * @var \OCP\IConfig |
|
| 49 | + */ |
|
| 50 | + private $config; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $renderAs |
|
| 54 | - * @param string $appId application id |
|
| 55 | - */ |
|
| 56 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 52 | + /** |
|
| 53 | + * @param string $renderAs |
|
| 54 | + * @param string $appId application id |
|
| 55 | + */ |
|
| 56 | + public function __construct( $renderAs, $appId = '' ) { |
|
| 57 | 57 | |
| 58 | - // yes - should be injected .... |
|
| 59 | - $this->config = \OC::$server->getConfig(); |
|
| 58 | + // yes - should be injected .... |
|
| 59 | + $this->config = \OC::$server->getConfig(); |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - // Decide which page we show |
|
| 63 | - if($renderAs == 'user') { |
|
| 64 | - parent::__construct( 'core', 'layout.user' ); |
|
| 65 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 66 | - $this->assign('bodyid', 'body-settings'); |
|
| 67 | - }else{ |
|
| 68 | - $this->assign('bodyid', 'body-user'); |
|
| 69 | - } |
|
| 62 | + // Decide which page we show |
|
| 63 | + if($renderAs == 'user') { |
|
| 64 | + parent::__construct( 'core', 'layout.user' ); |
|
| 65 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 66 | + $this->assign('bodyid', 'body-settings'); |
|
| 67 | + }else{ |
|
| 68 | + $this->assign('bodyid', 'body-user'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // Code integrity notification |
|
| 72 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
| 73 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 74 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
| 75 | - } |
|
| 71 | + // Code integrity notification |
|
| 72 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
| 73 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 74 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - // Add navigation entry |
|
| 78 | - $this->assign( 'application', ''); |
|
| 79 | - $this->assign( 'appid', $appId ); |
|
| 80 | - $navigation = \OC_App::getNavigation(); |
|
| 81 | - $this->assign( 'navigation', $navigation); |
|
| 82 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
| 83 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 84 | - foreach($navigation as $entry) { |
|
| 85 | - if ($entry['active']) { |
|
| 86 | - $this->assign( 'application', $entry['name'] ); |
|
| 87 | - break; |
|
| 88 | - } |
|
| 89 | - } |
|
| 77 | + // Add navigation entry |
|
| 78 | + $this->assign( 'application', ''); |
|
| 79 | + $this->assign( 'appid', $appId ); |
|
| 80 | + $navigation = \OC_App::getNavigation(); |
|
| 81 | + $this->assign( 'navigation', $navigation); |
|
| 82 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
| 83 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 84 | + foreach($navigation as $entry) { |
|
| 85 | + if ($entry['active']) { |
|
| 86 | + $this->assign( 'application', $entry['name'] ); |
|
| 87 | + break; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - foreach($settingsNavigation as $entry) { |
|
| 92 | - if ($entry['active']) { |
|
| 93 | - $this->assign( 'application', $entry['name'] ); |
|
| 94 | - break; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - $userDisplayName = \OC_User::getDisplayName(); |
|
| 98 | - $this->assign('user_displayname', $userDisplayName); |
|
| 99 | - $this->assign('user_uid', \OC_User::getUser()); |
|
| 91 | + foreach($settingsNavigation as $entry) { |
|
| 92 | + if ($entry['active']) { |
|
| 93 | + $this->assign( 'application', $entry['name'] ); |
|
| 94 | + break; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + $userDisplayName = \OC_User::getDisplayName(); |
|
| 98 | + $this->assign('user_displayname', $userDisplayName); |
|
| 99 | + $this->assign('user_uid', \OC_User::getUser()); |
|
| 100 | 100 | |
| 101 | - if (\OC_User::getUser() === false) { |
|
| 102 | - $this->assign('userAvatarSet', false); |
|
| 103 | - } else { |
|
| 104 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 105 | - $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 106 | - } |
|
| 101 | + if (\OC_User::getUser() === false) { |
|
| 102 | + $this->assign('userAvatarSet', false); |
|
| 103 | + } else { |
|
| 104 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 105 | + $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - } else if ($renderAs == 'error') { |
|
| 109 | - parent::__construct('core', 'layout.guest', '', false); |
|
| 110 | - $this->assign('bodyid', 'body-login'); |
|
| 111 | - } else if ($renderAs == 'guest') { |
|
| 112 | - parent::__construct('core', 'layout.guest'); |
|
| 113 | - $this->assign('bodyid', 'body-login'); |
|
| 114 | - } else { |
|
| 115 | - parent::__construct('core', 'layout.base'); |
|
| 108 | + } else if ($renderAs == 'error') { |
|
| 109 | + parent::__construct('core', 'layout.guest', '', false); |
|
| 110 | + $this->assign('bodyid', 'body-login'); |
|
| 111 | + } else if ($renderAs == 'guest') { |
|
| 112 | + parent::__construct('core', 'layout.guest'); |
|
| 113 | + $this->assign('bodyid', 'body-login'); |
|
| 114 | + } else { |
|
| 115 | + parent::__construct('core', 'layout.base'); |
|
| 116 | 116 | |
| 117 | - } |
|
| 118 | - // Send the language to our layouts |
|
| 119 | - $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
| 117 | + } |
|
| 118 | + // Send the language to our layouts |
|
| 119 | + $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
| 120 | 120 | |
| 121 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 122 | - if (empty(self::$versionHash)) { |
|
| 123 | - $v = \OC_App::getAppVersions(); |
|
| 124 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 125 | - self::$versionHash = md5(implode(',', $v)); |
|
| 126 | - } |
|
| 127 | - } else { |
|
| 128 | - self::$versionHash = md5('not installed'); |
|
| 129 | - } |
|
| 121 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 122 | + if (empty(self::$versionHash)) { |
|
| 123 | + $v = \OC_App::getAppVersions(); |
|
| 124 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 125 | + self::$versionHash = md5(implode(',', $v)); |
|
| 126 | + } |
|
| 127 | + } else { |
|
| 128 | + self::$versionHash = md5('not installed'); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - // Add the js files |
|
| 132 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 133 | - $this->assign('jsfiles', array()); |
|
| 134 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 135 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 136 | - $jsConfigHelper = new JSConfigHelper( |
|
| 137 | - \OC::$server->getL10N('core'), |
|
| 138 | - \OC::$server->query(Defaults::class), |
|
| 139 | - \OC::$server->getAppManager(), |
|
| 140 | - \OC::$server->getSession(), |
|
| 141 | - \OC::$server->getUserSession()->getUser(), |
|
| 142 | - \OC::$server->getConfig(), |
|
| 143 | - \OC::$server->getGroupManager(), |
|
| 144 | - \OC::$server->getIniWrapper(), |
|
| 145 | - \OC::$server->getURLGenerator() |
|
| 146 | - ); |
|
| 147 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 148 | - } else { |
|
| 149 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - foreach($jsFiles as $info) { |
|
| 153 | - $web = $info[1]; |
|
| 154 | - $file = $info[2]; |
|
| 155 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 156 | - } |
|
| 131 | + // Add the js files |
|
| 132 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 133 | + $this->assign('jsfiles', array()); |
|
| 134 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 135 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 136 | + $jsConfigHelper = new JSConfigHelper( |
|
| 137 | + \OC::$server->getL10N('core'), |
|
| 138 | + \OC::$server->query(Defaults::class), |
|
| 139 | + \OC::$server->getAppManager(), |
|
| 140 | + \OC::$server->getSession(), |
|
| 141 | + \OC::$server->getUserSession()->getUser(), |
|
| 142 | + \OC::$server->getConfig(), |
|
| 143 | + \OC::$server->getGroupManager(), |
|
| 144 | + \OC::$server->getIniWrapper(), |
|
| 145 | + \OC::$server->getURLGenerator() |
|
| 146 | + ); |
|
| 147 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 148 | + } else { |
|
| 149 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + foreach($jsFiles as $info) { |
|
| 153 | + $web = $info[1]; |
|
| 154 | + $file = $info[2]; |
|
| 155 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - try { |
|
| 159 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 160 | - } catch (\Exception $e) { |
|
| 161 | - $pathInfo = ''; |
|
| 162 | - } |
|
| 158 | + try { |
|
| 159 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 160 | + } catch (\Exception $e) { |
|
| 161 | + $pathInfo = ''; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - // Do not initialise scss appdata until we have a fully installed instance |
|
| 165 | - // Do not load scss for update, errors, installation or login page |
|
| 166 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 167 | - && !\OCP\Util::needUpgrade() |
|
| 168 | - && $pathInfo !== '' |
|
| 169 | - && !preg_match('/^\/login/', $pathInfo)) { |
|
| 170 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 171 | - } else { |
|
| 172 | - // If we ignore the scss compiler, |
|
| 173 | - // we need to load the guest css fallback |
|
| 174 | - \OC_Util::addStyle('guest'); |
|
| 175 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 176 | - } |
|
| 164 | + // Do not initialise scss appdata until we have a fully installed instance |
|
| 165 | + // Do not load scss for update, errors, installation or login page |
|
| 166 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 167 | + && !\OCP\Util::needUpgrade() |
|
| 168 | + && $pathInfo !== '' |
|
| 169 | + && !preg_match('/^\/login/', $pathInfo)) { |
|
| 170 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 171 | + } else { |
|
| 172 | + // If we ignore the scss compiler, |
|
| 173 | + // we need to load the guest css fallback |
|
| 174 | + \OC_Util::addStyle('guest'); |
|
| 175 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - $this->assign('cssfiles', array()); |
|
| 179 | - $this->assign('printcssfiles', []); |
|
| 180 | - $this->assign('versionHash', self::$versionHash); |
|
| 181 | - foreach($cssFiles as $info) { |
|
| 182 | - $web = $info[1]; |
|
| 183 | - $file = $info[2]; |
|
| 178 | + $this->assign('cssfiles', array()); |
|
| 179 | + $this->assign('printcssfiles', []); |
|
| 180 | + $this->assign('versionHash', self::$versionHash); |
|
| 181 | + foreach($cssFiles as $info) { |
|
| 182 | + $web = $info[1]; |
|
| 183 | + $file = $info[2]; |
|
| 184 | 184 | |
| 185 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 186 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 187 | - } else { |
|
| 188 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 185 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 186 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 187 | + } else { |
|
| 188 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - protected function getVersionHashSuffix() { |
|
| 194 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 195 | - // allows chrome workspace mapping in debug mode |
|
| 196 | - return ""; |
|
| 197 | - } |
|
| 198 | - if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 199 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 200 | - } |
|
| 201 | - return '?v=' . self::$versionHash; |
|
| 202 | - } |
|
| 193 | + protected function getVersionHashSuffix() { |
|
| 194 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 195 | + // allows chrome workspace mapping in debug mode |
|
| 196 | + return ""; |
|
| 197 | + } |
|
| 198 | + if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 199 | + return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 200 | + } |
|
| 201 | + return '?v=' . self::$versionHash; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * @param array $styles |
|
| 206 | - * @return array |
|
| 207 | - */ |
|
| 208 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 209 | - // Read the selected theme from the config file |
|
| 210 | - $theme = \OC_Util::getTheme(); |
|
| 204 | + /** |
|
| 205 | + * @param array $styles |
|
| 206 | + * @return array |
|
| 207 | + */ |
|
| 208 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 209 | + // Read the selected theme from the config file |
|
| 210 | + $theme = \OC_Util::getTheme(); |
|
| 211 | 211 | |
| 212 | - if($compileScss) { |
|
| 213 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 214 | - } else { |
|
| 215 | - $SCSSCacher = null; |
|
| 216 | - } |
|
| 212 | + if($compileScss) { |
|
| 213 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 214 | + } else { |
|
| 215 | + $SCSSCacher = null; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - $locator = new \OC\Template\CSSResourceLocator( |
|
| 219 | - \OC::$server->getLogger(), |
|
| 220 | - $theme, |
|
| 221 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 222 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 223 | - $SCSSCacher |
|
| 224 | - ); |
|
| 225 | - $locator->find($styles); |
|
| 226 | - return $locator->getResources(); |
|
| 227 | - } |
|
| 218 | + $locator = new \OC\Template\CSSResourceLocator( |
|
| 219 | + \OC::$server->getLogger(), |
|
| 220 | + $theme, |
|
| 221 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 222 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 223 | + $SCSSCacher |
|
| 224 | + ); |
|
| 225 | + $locator->find($styles); |
|
| 226 | + return $locator->getResources(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * @param array $scripts |
|
| 231 | - * @return array |
|
| 232 | - */ |
|
| 233 | - static public function findJavascriptFiles($scripts) { |
|
| 234 | - // Read the selected theme from the config file |
|
| 235 | - $theme = \OC_Util::getTheme(); |
|
| 229 | + /** |
|
| 230 | + * @param array $scripts |
|
| 231 | + * @return array |
|
| 232 | + */ |
|
| 233 | + static public function findJavascriptFiles($scripts) { |
|
| 234 | + // Read the selected theme from the config file |
|
| 235 | + $theme = \OC_Util::getTheme(); |
|
| 236 | 236 | |
| 237 | - $locator = new \OC\Template\JSResourceLocator( |
|
| 238 | - \OC::$server->getLogger(), |
|
| 239 | - $theme, |
|
| 240 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 241 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 242 | - new JSCombiner( |
|
| 243 | - \OC::$server->getAppDataDir('js'), |
|
| 244 | - \OC::$server->getURLGenerator(), |
|
| 245 | - \OC::$server->getMemCacheFactory()->create('JS'), |
|
| 246 | - \OC::$server->getSystemConfig() |
|
| 247 | - ) |
|
| 248 | - ); |
|
| 249 | - $locator->find($scripts); |
|
| 250 | - return $locator->getResources(); |
|
| 251 | - } |
|
| 237 | + $locator = new \OC\Template\JSResourceLocator( |
|
| 238 | + \OC::$server->getLogger(), |
|
| 239 | + $theme, |
|
| 240 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 241 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 242 | + new JSCombiner( |
|
| 243 | + \OC::$server->getAppDataDir('js'), |
|
| 244 | + \OC::$server->getURLGenerator(), |
|
| 245 | + \OC::$server->getMemCacheFactory()->create('JS'), |
|
| 246 | + \OC::$server->getSystemConfig() |
|
| 247 | + ) |
|
| 248 | + ); |
|
| 249 | + $locator->find($scripts); |
|
| 250 | + return $locator->getResources(); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 255 | - * @param string $filePath Absolute path |
|
| 256 | - * @return string Relative path |
|
| 257 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 258 | - */ |
|
| 259 | - public static function convertToRelativePath($filePath) { |
|
| 260 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 261 | - if(count($relativePath) !== 2) { |
|
| 262 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 263 | - } |
|
| 253 | + /** |
|
| 254 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 255 | + * @param string $filePath Absolute path |
|
| 256 | + * @return string Relative path |
|
| 257 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 258 | + */ |
|
| 259 | + public static function convertToRelativePath($filePath) { |
|
| 260 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 261 | + if(count($relativePath) !== 2) { |
|
| 262 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - return $relativePath[1]; |
|
| 266 | - } |
|
| 265 | + return $relativePath[1]; |
|
| 266 | + } |
|
| 267 | 267 | } |
@@ -53,44 +53,44 @@ discard block |
||
| 53 | 53 | * @param string $renderAs |
| 54 | 54 | * @param string $appId application id |
| 55 | 55 | */ |
| 56 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 56 | + public function __construct($renderAs, $appId = '') { |
|
| 57 | 57 | |
| 58 | 58 | // yes - should be injected .... |
| 59 | 59 | $this->config = \OC::$server->getConfig(); |
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | // Decide which page we show |
| 63 | - if($renderAs == 'user') { |
|
| 64 | - parent::__construct( 'core', 'layout.user' ); |
|
| 65 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 63 | + if ($renderAs == 'user') { |
|
| 64 | + parent::__construct('core', 'layout.user'); |
|
| 65 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
| 66 | 66 | $this->assign('bodyid', 'body-settings'); |
| 67 | - }else{ |
|
| 67 | + } else { |
|
| 68 | 68 | $this->assign('bodyid', 'body-user'); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Code integrity notification |
| 72 | 72 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
| 73 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 73 | + if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 74 | 74 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Add navigation entry |
| 78 | - $this->assign( 'application', ''); |
|
| 79 | - $this->assign( 'appid', $appId ); |
|
| 78 | + $this->assign('application', ''); |
|
| 79 | + $this->assign('appid', $appId); |
|
| 80 | 80 | $navigation = \OC_App::getNavigation(); |
| 81 | - $this->assign( 'navigation', $navigation); |
|
| 81 | + $this->assign('navigation', $navigation); |
|
| 82 | 82 | $settingsNavigation = \OC_App::getSettingsNavigation(); |
| 83 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 84 | - foreach($navigation as $entry) { |
|
| 83 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
| 84 | + foreach ($navigation as $entry) { |
|
| 85 | 85 | if ($entry['active']) { |
| 86 | - $this->assign( 'application', $entry['name'] ); |
|
| 86 | + $this->assign('application', $entry['name']); |
|
| 87 | 87 | break; |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - foreach($settingsNavigation as $entry) { |
|
| 91 | + foreach ($settingsNavigation as $entry) { |
|
| 92 | 92 | if ($entry['active']) { |
| 93 | - $this->assign( 'application', $entry['name'] ); |
|
| 93 | + $this->assign('application', $entry['name']); |
|
| 94 | 94 | break; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | // Send the language to our layouts |
| 119 | 119 | $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
| 120 | 120 | |
| 121 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 121 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 122 | 122 | if (empty(self::$versionHash)) { |
| 123 | 123 | $v = \OC_App::getAppVersions(); |
| 124 | 124 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -149,10 +149,10 @@ discard block |
||
| 149 | 149 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | - foreach($jsFiles as $info) { |
|
| 152 | + foreach ($jsFiles as $info) { |
|
| 153 | 153 | $web = $info[1]; |
| 154 | 154 | $file = $info[2]; |
| 155 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 155 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | try { |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | // Do not initialise scss appdata until we have a fully installed instance |
| 165 | 165 | // Do not load scss for update, errors, installation or login page |
| 166 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 166 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 167 | 167 | && !\OCP\Util::needUpgrade() |
| 168 | 168 | && $pathInfo !== '' |
| 169 | 169 | && !preg_match('/^\/login/', $pathInfo)) { |
@@ -178,27 +178,27 @@ discard block |
||
| 178 | 178 | $this->assign('cssfiles', array()); |
| 179 | 179 | $this->assign('printcssfiles', []); |
| 180 | 180 | $this->assign('versionHash', self::$versionHash); |
| 181 | - foreach($cssFiles as $info) { |
|
| 181 | + foreach ($cssFiles as $info) { |
|
| 182 | 182 | $web = $info[1]; |
| 183 | 183 | $file = $info[2]; |
| 184 | 184 | |
| 185 | 185 | if (substr($file, -strlen('print.css')) === 'print.css') { |
| 186 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 186 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 187 | 187 | } else { |
| 188 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 188 | + $this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | protected function getVersionHashSuffix() { |
| 194 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 194 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 195 | 195 | // allows chrome workspace mapping in debug mode |
| 196 | 196 | return ""; |
| 197 | 197 | } |
| 198 | 198 | if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
| 199 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 199 | + return '?v='.self::$versionHash.'-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 200 | 200 | } |
| 201 | - return '?v=' . self::$versionHash; |
|
| 201 | + return '?v='.self::$versionHash; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | // Read the selected theme from the config file |
| 210 | 210 | $theme = \OC_Util::getTheme(); |
| 211 | 211 | |
| 212 | - if($compileScss) { |
|
| 212 | + if ($compileScss) { |
|
| 213 | 213 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
| 214 | 214 | } else { |
| 215 | 215 | $SCSSCacher = null; |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | $locator = new \OC\Template\CSSResourceLocator( |
| 219 | 219 | \OC::$server->getLogger(), |
| 220 | 220 | $theme, |
| 221 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 222 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 221 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 222 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 223 | 223 | $SCSSCacher |
| 224 | 224 | ); |
| 225 | 225 | $locator->find($styles); |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | $locator = new \OC\Template\JSResourceLocator( |
| 238 | 238 | \OC::$server->getLogger(), |
| 239 | 239 | $theme, |
| 240 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 241 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 240 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 241 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 242 | 242 | new JSCombiner( |
| 243 | 243 | \OC::$server->getAppDataDir('js'), |
| 244 | 244 | \OC::$server->getURLGenerator(), |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public static function convertToRelativePath($filePath) { |
| 260 | 260 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
| 261 | - if(count($relativePath) !== 2) { |
|
| 261 | + if (count($relativePath) !== 2) { |
|
| 262 | 262 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
| 263 | 263 | } |
| 264 | 264 | |
@@ -28,51 +28,51 @@ |
||
| 28 | 28 | use OCP\Migration\IRepairStep; |
| 29 | 29 | |
| 30 | 30 | class InstallCoreBundle implements IRepairStep { |
| 31 | - /** @var BundleFetcher */ |
|
| 32 | - private $bundleFetcher; |
|
| 33 | - /** @var IConfig */ |
|
| 34 | - private $config; |
|
| 35 | - /** @var Installer */ |
|
| 36 | - private $installer; |
|
| 31 | + /** @var BundleFetcher */ |
|
| 32 | + private $bundleFetcher; |
|
| 33 | + /** @var IConfig */ |
|
| 34 | + private $config; |
|
| 35 | + /** @var Installer */ |
|
| 36 | + private $installer; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param BundleFetcher $bundleFetcher |
|
| 40 | - * @param IConfig $config |
|
| 41 | - * @param Installer $installer |
|
| 42 | - */ |
|
| 43 | - public function __construct(BundleFetcher $bundleFetcher, |
|
| 44 | - IConfig $config, |
|
| 45 | - Installer $installer) { |
|
| 46 | - $this->bundleFetcher = $bundleFetcher; |
|
| 47 | - $this->config = $config; |
|
| 48 | - $this->installer = $installer; |
|
| 49 | - } |
|
| 38 | + /** |
|
| 39 | + * @param BundleFetcher $bundleFetcher |
|
| 40 | + * @param IConfig $config |
|
| 41 | + * @param Installer $installer |
|
| 42 | + */ |
|
| 43 | + public function __construct(BundleFetcher $bundleFetcher, |
|
| 44 | + IConfig $config, |
|
| 45 | + Installer $installer) { |
|
| 46 | + $this->bundleFetcher = $bundleFetcher; |
|
| 47 | + $this->config = $config; |
|
| 48 | + $this->installer = $installer; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * {@inheritdoc} |
|
| 53 | - */ |
|
| 54 | - public function getName() { |
|
| 55 | - return 'Install new core bundle components'; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * {@inheritdoc} |
|
| 53 | + */ |
|
| 54 | + public function getName() { |
|
| 55 | + return 'Install new core bundle components'; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritdoc} |
|
| 60 | - */ |
|
| 61 | - public function run(IOutput $output) { |
|
| 62 | - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 58 | + /** |
|
| 59 | + * {@inheritdoc} |
|
| 60 | + */ |
|
| 61 | + public function run(IOutput $output) { |
|
| 62 | + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 63 | 63 | |
| 64 | - if (version_compare($versionFromBeforeUpdate, '12.0.0.14', '>')) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 64 | + if (version_compare($versionFromBeforeUpdate, '12.0.0.14', '>')) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $defaultBundle = $this->bundleFetcher->getDefaultInstallationBundle(); |
|
| 69 | - foreach($defaultBundle as $bundle) { |
|
| 70 | - try { |
|
| 71 | - $this->installer->installAppBundle($bundle); |
|
| 72 | - $output->info('Successfully installed core app bundle.'); |
|
| 73 | - } catch (\Exception $e) { |
|
| 74 | - $output->warning('Could not install core app bundle:' . $e->getMessage()); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 68 | + $defaultBundle = $this->bundleFetcher->getDefaultInstallationBundle(); |
|
| 69 | + foreach($defaultBundle as $bundle) { |
|
| 70 | + try { |
|
| 71 | + $this->installer->installAppBundle($bundle); |
|
| 72 | + $output->info('Successfully installed core app bundle.'); |
|
| 73 | + } catch (\Exception $e) { |
|
| 74 | + $output->warning('Could not install core app bundle:' . $e->getMessage()); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -66,12 +66,12 @@ |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $defaultBundle = $this->bundleFetcher->getDefaultInstallationBundle(); |
| 69 | - foreach($defaultBundle as $bundle) { |
|
| 69 | + foreach ($defaultBundle as $bundle) { |
|
| 70 | 70 | try { |
| 71 | 71 | $this->installer->installAppBundle($bundle); |
| 72 | 72 | $output->info('Successfully installed core app bundle.'); |
| 73 | 73 | } catch (\Exception $e) { |
| 74 | - $output->warning('Could not install core app bundle:' . $e->getMessage()); |
|
| 74 | + $output->warning('Could not install core app bundle:'.$e->getMessage()); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -123,1647 +123,1647 @@ |
||
| 123 | 123 | * TODO: hookup all manager classes |
| 124 | 124 | */ |
| 125 | 125 | class Server extends ServerContainer implements IServerContainer { |
| 126 | - /** @var string */ |
|
| 127 | - private $webRoot; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param string $webRoot |
|
| 131 | - * @param \OC\Config $config |
|
| 132 | - */ |
|
| 133 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 134 | - parent::__construct(); |
|
| 135 | - $this->webRoot = $webRoot; |
|
| 136 | - |
|
| 137 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 138 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 139 | - |
|
| 140 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 141 | - return new PreviewManager( |
|
| 142 | - $c->getConfig(), |
|
| 143 | - $c->getRootFolder(), |
|
| 144 | - $c->getAppDataDir('preview'), |
|
| 145 | - $c->getEventDispatcher(), |
|
| 146 | - $c->getSession()->get('user_id') |
|
| 147 | - ); |
|
| 148 | - }); |
|
| 149 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 150 | - |
|
| 151 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 152 | - return new \OC\Preview\Watcher( |
|
| 153 | - $c->getAppDataDir('preview') |
|
| 154 | - ); |
|
| 155 | - }); |
|
| 156 | - |
|
| 157 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 158 | - $view = new View(); |
|
| 159 | - $util = new Encryption\Util( |
|
| 160 | - $view, |
|
| 161 | - $c->getUserManager(), |
|
| 162 | - $c->getGroupManager(), |
|
| 163 | - $c->getConfig() |
|
| 164 | - ); |
|
| 165 | - return new Encryption\Manager( |
|
| 166 | - $c->getConfig(), |
|
| 167 | - $c->getLogger(), |
|
| 168 | - $c->getL10N('core'), |
|
| 169 | - new View(), |
|
| 170 | - $util, |
|
| 171 | - new ArrayCache() |
|
| 172 | - ); |
|
| 173 | - }); |
|
| 174 | - |
|
| 175 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 176 | - $util = new Encryption\Util( |
|
| 177 | - new View(), |
|
| 178 | - $c->getUserManager(), |
|
| 179 | - $c->getGroupManager(), |
|
| 180 | - $c->getConfig() |
|
| 181 | - ); |
|
| 182 | - return new Encryption\File( |
|
| 183 | - $util, |
|
| 184 | - $c->getRootFolder(), |
|
| 185 | - $c->getShareManager() |
|
| 186 | - ); |
|
| 187 | - }); |
|
| 188 | - |
|
| 189 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 190 | - $view = new View(); |
|
| 191 | - $util = new Encryption\Util( |
|
| 192 | - $view, |
|
| 193 | - $c->getUserManager(), |
|
| 194 | - $c->getGroupManager(), |
|
| 195 | - $c->getConfig() |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - return new Encryption\Keys\Storage($view, $util); |
|
| 199 | - }); |
|
| 200 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 201 | - return new TagMapper($c->getDatabaseConnection()); |
|
| 202 | - }); |
|
| 203 | - |
|
| 204 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 205 | - $tagMapper = $c->query('TagMapper'); |
|
| 206 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
| 207 | - }); |
|
| 208 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 209 | - |
|
| 210 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 211 | - $config = $c->getConfig(); |
|
| 212 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
| 213 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
| 214 | - $factory = new $factoryClass($this); |
|
| 215 | - return $factory; |
|
| 216 | - }); |
|
| 217 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 218 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 219 | - }); |
|
| 220 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 221 | - |
|
| 222 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 223 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 224 | - }); |
|
| 225 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 226 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 227 | - $view = new View(); |
|
| 228 | - $root = new Root( |
|
| 229 | - $manager, |
|
| 230 | - $view, |
|
| 231 | - null, |
|
| 232 | - $c->getUserMountCache(), |
|
| 233 | - $this->getLogger(), |
|
| 234 | - $this->getUserManager() |
|
| 235 | - ); |
|
| 236 | - $connector = new HookConnector($root, $view); |
|
| 237 | - $connector->viewToNode(); |
|
| 238 | - |
|
| 239 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 240 | - $previewConnector->connectWatcher(); |
|
| 241 | - |
|
| 242 | - return $root; |
|
| 243 | - }); |
|
| 244 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 245 | - |
|
| 246 | - $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
| 247 | - return new LazyRoot(function() use ($c) { |
|
| 248 | - return $c->query('RootFolder'); |
|
| 249 | - }); |
|
| 250 | - }); |
|
| 251 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 252 | - |
|
| 253 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 254 | - $config = $c->getConfig(); |
|
| 255 | - return new \OC\User\Manager($config); |
|
| 256 | - }); |
|
| 257 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
| 258 | - |
|
| 259 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 260 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
| 261 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 262 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 263 | - }); |
|
| 264 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 265 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 266 | - }); |
|
| 267 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 268 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 269 | - }); |
|
| 270 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 271 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 272 | - }); |
|
| 273 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 274 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 275 | - }); |
|
| 276 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 277 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 278 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 279 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 280 | - }); |
|
| 281 | - return $groupManager; |
|
| 282 | - }); |
|
| 283 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 284 | - |
|
| 285 | - $this->registerService(Store::class, function(Server $c) { |
|
| 286 | - $session = $c->getSession(); |
|
| 287 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 288 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 289 | - } else { |
|
| 290 | - $tokenProvider = null; |
|
| 291 | - } |
|
| 292 | - $logger = $c->getLogger(); |
|
| 293 | - return new Store($session, $logger, $tokenProvider); |
|
| 294 | - }); |
|
| 295 | - $this->registerAlias(IStore::class, Store::class); |
|
| 296 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 297 | - $dbConnection = $c->getDatabaseConnection(); |
|
| 298 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 299 | - }); |
|
| 300 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 301 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
| 302 | - $crypto = $c->getCrypto(); |
|
| 303 | - $config = $c->getConfig(); |
|
| 304 | - $logger = $c->getLogger(); |
|
| 305 | - $timeFactory = new TimeFactory(); |
|
| 306 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
| 307 | - }); |
|
| 308 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
| 309 | - |
|
| 310 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 311 | - $manager = $c->getUserManager(); |
|
| 312 | - $session = new \OC\Session\Memory(''); |
|
| 313 | - $timeFactory = new TimeFactory(); |
|
| 314 | - // Token providers might require a working database. This code |
|
| 315 | - // might however be called when ownCloud is not yet setup. |
|
| 316 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 317 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 318 | - } else { |
|
| 319 | - $defaultTokenProvider = null; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
| 323 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 324 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 325 | - }); |
|
| 326 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 327 | - /** @var $user \OC\User\User */ |
|
| 328 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 329 | - }); |
|
| 330 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 331 | - /** @var $user \OC\User\User */ |
|
| 332 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 333 | - }); |
|
| 334 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 335 | - /** @var $user \OC\User\User */ |
|
| 336 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 337 | - }); |
|
| 338 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 339 | - /** @var $user \OC\User\User */ |
|
| 340 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 341 | - }); |
|
| 342 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 343 | - /** @var $user \OC\User\User */ |
|
| 344 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 345 | - }); |
|
| 346 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 347 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 348 | - }); |
|
| 349 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 350 | - /** @var $user \OC\User\User */ |
|
| 351 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 352 | - }); |
|
| 353 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 354 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 355 | - }); |
|
| 356 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 357 | - /** @var $user \OC\User\User */ |
|
| 358 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 359 | - }); |
|
| 360 | - return $userSession; |
|
| 361 | - }); |
|
| 362 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 363 | - |
|
| 364 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 365 | - return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
| 366 | - }); |
|
| 367 | - |
|
| 368 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 369 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 370 | - |
|
| 371 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 372 | - return new \OC\AllConfig( |
|
| 373 | - $c->getSystemConfig() |
|
| 374 | - ); |
|
| 375 | - }); |
|
| 376 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 377 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 378 | - |
|
| 379 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 380 | - return new \OC\SystemConfig($config); |
|
| 381 | - }); |
|
| 382 | - |
|
| 383 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 384 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 385 | - }); |
|
| 386 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 387 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 388 | - |
|
| 389 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 390 | - return new \OC\L10N\Factory( |
|
| 391 | - $c->getConfig(), |
|
| 392 | - $c->getRequest(), |
|
| 393 | - $c->getUserSession(), |
|
| 394 | - \OC::$SERVERROOT |
|
| 395 | - ); |
|
| 396 | - }); |
|
| 397 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 398 | - |
|
| 399 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 400 | - $config = $c->getConfig(); |
|
| 401 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 402 | - return new \OC\URLGenerator( |
|
| 403 | - $config, |
|
| 404 | - $cacheFactory |
|
| 405 | - ); |
|
| 406 | - }); |
|
| 407 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 408 | - |
|
| 409 | - $this->registerService('AppHelper', function ($c) { |
|
| 410 | - return new \OC\AppHelper(); |
|
| 411 | - }); |
|
| 412 | - $this->registerService('AppFetcher', function ($c) { |
|
| 413 | - return new AppFetcher( |
|
| 414 | - $this->getAppDataDir('appstore'), |
|
| 415 | - $this->getHTTPClientService(), |
|
| 416 | - $this->query(TimeFactory::class), |
|
| 417 | - $this->getConfig() |
|
| 418 | - ); |
|
| 419 | - }); |
|
| 420 | - $this->registerService('CategoryFetcher', function ($c) { |
|
| 421 | - return new CategoryFetcher( |
|
| 422 | - $this->getAppDataDir('appstore'), |
|
| 423 | - $this->getHTTPClientService(), |
|
| 424 | - $this->query(TimeFactory::class), |
|
| 425 | - $this->getConfig() |
|
| 426 | - ); |
|
| 427 | - }); |
|
| 428 | - |
|
| 429 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 430 | - return new Cache\File(); |
|
| 431 | - }); |
|
| 432 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 433 | - |
|
| 434 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 435 | - $config = $c->getConfig(); |
|
| 436 | - |
|
| 437 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 438 | - $v = \OC_App::getAppVersions(); |
|
| 439 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
| 440 | - $version = implode(',', $v); |
|
| 441 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 442 | - $path = \OC::$SERVERROOT; |
|
| 443 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
| 444 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 445 | - $config->getSystemValue('memcache.local', null), |
|
| 446 | - $config->getSystemValue('memcache.distributed', null), |
|
| 447 | - $config->getSystemValue('memcache.locking', null) |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 452 | - '\\OC\\Memcache\\ArrayCache', |
|
| 453 | - '\\OC\\Memcache\\ArrayCache', |
|
| 454 | - '\\OC\\Memcache\\ArrayCache' |
|
| 455 | - ); |
|
| 456 | - }); |
|
| 457 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 458 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 459 | - |
|
| 460 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 461 | - $systemConfig = $c->getSystemConfig(); |
|
| 462 | - return new RedisFactory($systemConfig); |
|
| 463 | - }); |
|
| 464 | - |
|
| 465 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 466 | - return new \OC\Activity\Manager( |
|
| 467 | - $c->getRequest(), |
|
| 468 | - $c->getUserSession(), |
|
| 469 | - $c->getConfig(), |
|
| 470 | - $c->query(IValidator::class) |
|
| 471 | - ); |
|
| 472 | - }); |
|
| 473 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 474 | - |
|
| 475 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 476 | - return new \OC\Activity\EventMerger( |
|
| 477 | - $c->getL10N('lib') |
|
| 478 | - ); |
|
| 479 | - }); |
|
| 480 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 481 | - |
|
| 482 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 483 | - return new AvatarManager( |
|
| 484 | - $c->getUserManager(), |
|
| 485 | - $c->getAppDataDir('avatar'), |
|
| 486 | - $c->getL10N('lib'), |
|
| 487 | - $c->getLogger(), |
|
| 488 | - $c->getConfig() |
|
| 489 | - ); |
|
| 490 | - }); |
|
| 491 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 492 | - |
|
| 493 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 494 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 495 | - $logger = Log::getLogClass($logType); |
|
| 496 | - call_user_func(array($logger, 'init')); |
|
| 497 | - |
|
| 498 | - return new Log($logger); |
|
| 499 | - }); |
|
| 500 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 501 | - |
|
| 502 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 503 | - $config = $c->getConfig(); |
|
| 504 | - return new \OC\BackgroundJob\JobList( |
|
| 505 | - $c->getDatabaseConnection(), |
|
| 506 | - $config, |
|
| 507 | - new TimeFactory() |
|
| 508 | - ); |
|
| 509 | - }); |
|
| 510 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 511 | - |
|
| 512 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 513 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 514 | - $logger = $c->getLogger(); |
|
| 515 | - if ($cacheFactory->isAvailable()) { |
|
| 516 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
| 517 | - } else { |
|
| 518 | - $router = new \OC\Route\Router($logger); |
|
| 519 | - } |
|
| 520 | - return $router; |
|
| 521 | - }); |
|
| 522 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 523 | - |
|
| 524 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 525 | - return new Search(); |
|
| 526 | - }); |
|
| 527 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 528 | - |
|
| 529 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
| 530 | - return new \OC\Security\RateLimiting\Limiter( |
|
| 531 | - $this->getUserSession(), |
|
| 532 | - $this->getRequest(), |
|
| 533 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
| 534 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 535 | - ); |
|
| 536 | - }); |
|
| 537 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 538 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 539 | - $this->getMemCacheFactory(), |
|
| 540 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 541 | - ); |
|
| 542 | - }); |
|
| 543 | - |
|
| 544 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 545 | - return new SecureRandom(); |
|
| 546 | - }); |
|
| 547 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 548 | - |
|
| 549 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 550 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 551 | - }); |
|
| 552 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 553 | - |
|
| 554 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 555 | - return new Hasher($c->getConfig()); |
|
| 556 | - }); |
|
| 557 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 558 | - |
|
| 559 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 560 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 561 | - }); |
|
| 562 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 563 | - |
|
| 564 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 565 | - $systemConfig = $c->getSystemConfig(); |
|
| 566 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 567 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 568 | - if (!$factory->isValidType($type)) { |
|
| 569 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 570 | - } |
|
| 571 | - $connectionParams = $factory->createConnectionParams(); |
|
| 572 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 573 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 574 | - return $connection; |
|
| 575 | - }); |
|
| 576 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 577 | - |
|
| 578 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
| 579 | - $config = $c->getConfig(); |
|
| 580 | - return new HTTPHelper( |
|
| 581 | - $config, |
|
| 582 | - $c->getHTTPClientService() |
|
| 583 | - ); |
|
| 584 | - }); |
|
| 585 | - |
|
| 586 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 587 | - $user = \OC_User::getUser(); |
|
| 588 | - $uid = $user ? $user : null; |
|
| 589 | - return new ClientService( |
|
| 590 | - $c->getConfig(), |
|
| 591 | - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
| 592 | - ); |
|
| 593 | - }); |
|
| 594 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 595 | - |
|
| 596 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 597 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 598 | - return new EventLogger(); |
|
| 599 | - } else { |
|
| 600 | - return new NullEventLogger(); |
|
| 601 | - } |
|
| 602 | - }); |
|
| 603 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 604 | - |
|
| 605 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 606 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 607 | - return new QueryLogger(); |
|
| 608 | - } else { |
|
| 609 | - return new NullQueryLogger(); |
|
| 610 | - } |
|
| 611 | - }); |
|
| 612 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 613 | - |
|
| 614 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 615 | - return new TempManager( |
|
| 616 | - $c->getLogger(), |
|
| 617 | - $c->getConfig() |
|
| 618 | - ); |
|
| 619 | - }); |
|
| 620 | - $this->registerAlias('TempManager', TempManager::class); |
|
| 621 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 622 | - |
|
| 623 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 624 | - return new \OC\App\AppManager( |
|
| 625 | - $c->getUserSession(), |
|
| 626 | - $c->getAppConfig(), |
|
| 627 | - $c->getGroupManager(), |
|
| 628 | - $c->getMemCacheFactory(), |
|
| 629 | - $c->getEventDispatcher() |
|
| 630 | - ); |
|
| 631 | - }); |
|
| 632 | - $this->registerAlias('AppManager', AppManager::class); |
|
| 633 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 634 | - |
|
| 635 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 636 | - return new DateTimeZone( |
|
| 637 | - $c->getConfig(), |
|
| 638 | - $c->getSession() |
|
| 639 | - ); |
|
| 640 | - }); |
|
| 641 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 642 | - |
|
| 643 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 644 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 645 | - |
|
| 646 | - return new DateTimeFormatter( |
|
| 647 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 648 | - $c->getL10N('lib', $language) |
|
| 649 | - ); |
|
| 650 | - }); |
|
| 651 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 652 | - |
|
| 653 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 654 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 655 | - $listener = new UserMountCacheListener($mountCache); |
|
| 656 | - $listener->listen($c->getUserManager()); |
|
| 657 | - return $mountCache; |
|
| 658 | - }); |
|
| 659 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 660 | - |
|
| 661 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 662 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 663 | - $mountCache = $c->query('UserMountCache'); |
|
| 664 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 665 | - |
|
| 666 | - // builtin providers |
|
| 667 | - |
|
| 668 | - $config = $c->getConfig(); |
|
| 669 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 670 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 671 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 672 | - |
|
| 673 | - return $manager; |
|
| 674 | - }); |
|
| 675 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 676 | - |
|
| 677 | - $this->registerService('IniWrapper', function ($c) { |
|
| 678 | - return new IniGetWrapper(); |
|
| 679 | - }); |
|
| 680 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 681 | - $jobList = $c->getJobList(); |
|
| 682 | - return new AsyncBus($jobList); |
|
| 683 | - }); |
|
| 684 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 685 | - return new TrustedDomainHelper($this->getConfig()); |
|
| 686 | - }); |
|
| 687 | - $this->registerService('Throttler', function(Server $c) { |
|
| 688 | - return new Throttler( |
|
| 689 | - $c->getDatabaseConnection(), |
|
| 690 | - new TimeFactory(), |
|
| 691 | - $c->getLogger(), |
|
| 692 | - $c->getConfig() |
|
| 693 | - ); |
|
| 694 | - }); |
|
| 695 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 696 | - // IConfig and IAppManager requires a working database. This code |
|
| 697 | - // might however be called when ownCloud is not yet setup. |
|
| 698 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 699 | - $config = $c->getConfig(); |
|
| 700 | - $appManager = $c->getAppManager(); |
|
| 701 | - } else { |
|
| 702 | - $config = null; |
|
| 703 | - $appManager = null; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - return new Checker( |
|
| 707 | - new EnvironmentHelper(), |
|
| 708 | - new FileAccessHelper(), |
|
| 709 | - new AppLocator(), |
|
| 710 | - $config, |
|
| 711 | - $c->getMemCacheFactory(), |
|
| 712 | - $appManager, |
|
| 713 | - $c->getTempManager() |
|
| 714 | - ); |
|
| 715 | - }); |
|
| 716 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 717 | - if (isset($this['urlParams'])) { |
|
| 718 | - $urlParams = $this['urlParams']; |
|
| 719 | - } else { |
|
| 720 | - $urlParams = []; |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 724 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 725 | - ) { |
|
| 726 | - $stream = 'fakeinput://data'; |
|
| 727 | - } else { |
|
| 728 | - $stream = 'php://input'; |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - return new Request( |
|
| 732 | - [ |
|
| 733 | - 'get' => $_GET, |
|
| 734 | - 'post' => $_POST, |
|
| 735 | - 'files' => $_FILES, |
|
| 736 | - 'server' => $_SERVER, |
|
| 737 | - 'env' => $_ENV, |
|
| 738 | - 'cookies' => $_COOKIE, |
|
| 739 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 740 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 741 | - : null, |
|
| 742 | - 'urlParams' => $urlParams, |
|
| 743 | - ], |
|
| 744 | - $this->getSecureRandom(), |
|
| 745 | - $this->getConfig(), |
|
| 746 | - $this->getCsrfTokenManager(), |
|
| 747 | - $stream |
|
| 748 | - ); |
|
| 749 | - }); |
|
| 750 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 751 | - |
|
| 752 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 753 | - return new Mailer( |
|
| 754 | - $c->getConfig(), |
|
| 755 | - $c->getLogger(), |
|
| 756 | - $c->query(Defaults::class), |
|
| 757 | - $c->getURLGenerator(), |
|
| 758 | - $c->getL10N('lib') |
|
| 759 | - ); |
|
| 760 | - }); |
|
| 761 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 762 | - |
|
| 763 | - $this->registerService('LDAPProvider', function(Server $c) { |
|
| 764 | - $config = $c->getConfig(); |
|
| 765 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 766 | - if(is_null($factoryClass)) { |
|
| 767 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 768 | - } |
|
| 769 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 770 | - $factory = new $factoryClass($this); |
|
| 771 | - return $factory->getLDAPProvider(); |
|
| 772 | - }); |
|
| 773 | - $this->registerService('LockingProvider', function (Server $c) { |
|
| 774 | - $ini = $c->getIniWrapper(); |
|
| 775 | - $config = $c->getConfig(); |
|
| 776 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 777 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 778 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 779 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 780 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 781 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 782 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 783 | - } |
|
| 784 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
| 785 | - } |
|
| 786 | - return new NoopLockingProvider(); |
|
| 787 | - }); |
|
| 788 | - |
|
| 789 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 790 | - return new \OC\Files\Mount\Manager(); |
|
| 791 | - }); |
|
| 792 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 793 | - |
|
| 794 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 795 | - return new \OC\Files\Type\Detection( |
|
| 796 | - $c->getURLGenerator(), |
|
| 797 | - \OC::$configDir, |
|
| 798 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 799 | - ); |
|
| 800 | - }); |
|
| 801 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 802 | - |
|
| 803 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 804 | - return new \OC\Files\Type\Loader( |
|
| 805 | - $c->getDatabaseConnection() |
|
| 806 | - ); |
|
| 807 | - }); |
|
| 808 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 809 | - $this->registerService(BundleFetcher::class, function () { |
|
| 810 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 811 | - }); |
|
| 812 | - $this->registerService(AppFetcher::class, function() { |
|
| 813 | - return $this->getAppFetcher(); |
|
| 814 | - }); |
|
| 815 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 816 | - return new Manager( |
|
| 817 | - $c->query(IValidator::class) |
|
| 818 | - ); |
|
| 819 | - }); |
|
| 820 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 821 | - |
|
| 822 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 823 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 824 | - $manager->registerCapability(function () use ($c) { |
|
| 825 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 826 | - }); |
|
| 827 | - return $manager; |
|
| 828 | - }); |
|
| 829 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 830 | - |
|
| 831 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 832 | - $config = $c->getConfig(); |
|
| 833 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
| 834 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 835 | - $factory = new $factoryClass($this); |
|
| 836 | - return $factory->getManager(); |
|
| 837 | - }); |
|
| 838 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 839 | - |
|
| 840 | - $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 841 | - /* |
|
| 126 | + /** @var string */ |
|
| 127 | + private $webRoot; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param string $webRoot |
|
| 131 | + * @param \OC\Config $config |
|
| 132 | + */ |
|
| 133 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 134 | + parent::__construct(); |
|
| 135 | + $this->webRoot = $webRoot; |
|
| 136 | + |
|
| 137 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 138 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 139 | + |
|
| 140 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 141 | + return new PreviewManager( |
|
| 142 | + $c->getConfig(), |
|
| 143 | + $c->getRootFolder(), |
|
| 144 | + $c->getAppDataDir('preview'), |
|
| 145 | + $c->getEventDispatcher(), |
|
| 146 | + $c->getSession()->get('user_id') |
|
| 147 | + ); |
|
| 148 | + }); |
|
| 149 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 150 | + |
|
| 151 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 152 | + return new \OC\Preview\Watcher( |
|
| 153 | + $c->getAppDataDir('preview') |
|
| 154 | + ); |
|
| 155 | + }); |
|
| 156 | + |
|
| 157 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
| 158 | + $view = new View(); |
|
| 159 | + $util = new Encryption\Util( |
|
| 160 | + $view, |
|
| 161 | + $c->getUserManager(), |
|
| 162 | + $c->getGroupManager(), |
|
| 163 | + $c->getConfig() |
|
| 164 | + ); |
|
| 165 | + return new Encryption\Manager( |
|
| 166 | + $c->getConfig(), |
|
| 167 | + $c->getLogger(), |
|
| 168 | + $c->getL10N('core'), |
|
| 169 | + new View(), |
|
| 170 | + $util, |
|
| 171 | + new ArrayCache() |
|
| 172 | + ); |
|
| 173 | + }); |
|
| 174 | + |
|
| 175 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 176 | + $util = new Encryption\Util( |
|
| 177 | + new View(), |
|
| 178 | + $c->getUserManager(), |
|
| 179 | + $c->getGroupManager(), |
|
| 180 | + $c->getConfig() |
|
| 181 | + ); |
|
| 182 | + return new Encryption\File( |
|
| 183 | + $util, |
|
| 184 | + $c->getRootFolder(), |
|
| 185 | + $c->getShareManager() |
|
| 186 | + ); |
|
| 187 | + }); |
|
| 188 | + |
|
| 189 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 190 | + $view = new View(); |
|
| 191 | + $util = new Encryption\Util( |
|
| 192 | + $view, |
|
| 193 | + $c->getUserManager(), |
|
| 194 | + $c->getGroupManager(), |
|
| 195 | + $c->getConfig() |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + return new Encryption\Keys\Storage($view, $util); |
|
| 199 | + }); |
|
| 200 | + $this->registerService('TagMapper', function (Server $c) { |
|
| 201 | + return new TagMapper($c->getDatabaseConnection()); |
|
| 202 | + }); |
|
| 203 | + |
|
| 204 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 205 | + $tagMapper = $c->query('TagMapper'); |
|
| 206 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
| 207 | + }); |
|
| 208 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 209 | + |
|
| 210 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 211 | + $config = $c->getConfig(); |
|
| 212 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
| 213 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
| 214 | + $factory = new $factoryClass($this); |
|
| 215 | + return $factory; |
|
| 216 | + }); |
|
| 217 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 218 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 219 | + }); |
|
| 220 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 221 | + |
|
| 222 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 223 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 224 | + }); |
|
| 225 | + $this->registerService('RootFolder', function (Server $c) { |
|
| 226 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 227 | + $view = new View(); |
|
| 228 | + $root = new Root( |
|
| 229 | + $manager, |
|
| 230 | + $view, |
|
| 231 | + null, |
|
| 232 | + $c->getUserMountCache(), |
|
| 233 | + $this->getLogger(), |
|
| 234 | + $this->getUserManager() |
|
| 235 | + ); |
|
| 236 | + $connector = new HookConnector($root, $view); |
|
| 237 | + $connector->viewToNode(); |
|
| 238 | + |
|
| 239 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 240 | + $previewConnector->connectWatcher(); |
|
| 241 | + |
|
| 242 | + return $root; |
|
| 243 | + }); |
|
| 244 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 245 | + |
|
| 246 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
| 247 | + return new LazyRoot(function() use ($c) { |
|
| 248 | + return $c->query('RootFolder'); |
|
| 249 | + }); |
|
| 250 | + }); |
|
| 251 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 252 | + |
|
| 253 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 254 | + $config = $c->getConfig(); |
|
| 255 | + return new \OC\User\Manager($config); |
|
| 256 | + }); |
|
| 257 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
| 258 | + |
|
| 259 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 260 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
| 261 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 262 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 263 | + }); |
|
| 264 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 265 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 266 | + }); |
|
| 267 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 268 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 269 | + }); |
|
| 270 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 271 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 272 | + }); |
|
| 273 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 274 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 275 | + }); |
|
| 276 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 277 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 278 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 279 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 280 | + }); |
|
| 281 | + return $groupManager; |
|
| 282 | + }); |
|
| 283 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 284 | + |
|
| 285 | + $this->registerService(Store::class, function(Server $c) { |
|
| 286 | + $session = $c->getSession(); |
|
| 287 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 288 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 289 | + } else { |
|
| 290 | + $tokenProvider = null; |
|
| 291 | + } |
|
| 292 | + $logger = $c->getLogger(); |
|
| 293 | + return new Store($session, $logger, $tokenProvider); |
|
| 294 | + }); |
|
| 295 | + $this->registerAlias(IStore::class, Store::class); |
|
| 296 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 297 | + $dbConnection = $c->getDatabaseConnection(); |
|
| 298 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 299 | + }); |
|
| 300 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 301 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
| 302 | + $crypto = $c->getCrypto(); |
|
| 303 | + $config = $c->getConfig(); |
|
| 304 | + $logger = $c->getLogger(); |
|
| 305 | + $timeFactory = new TimeFactory(); |
|
| 306 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
| 307 | + }); |
|
| 308 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
| 309 | + |
|
| 310 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 311 | + $manager = $c->getUserManager(); |
|
| 312 | + $session = new \OC\Session\Memory(''); |
|
| 313 | + $timeFactory = new TimeFactory(); |
|
| 314 | + // Token providers might require a working database. This code |
|
| 315 | + // might however be called when ownCloud is not yet setup. |
|
| 316 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 317 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 318 | + } else { |
|
| 319 | + $defaultTokenProvider = null; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
| 323 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 324 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 325 | + }); |
|
| 326 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 327 | + /** @var $user \OC\User\User */ |
|
| 328 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 329 | + }); |
|
| 330 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 331 | + /** @var $user \OC\User\User */ |
|
| 332 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 333 | + }); |
|
| 334 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 335 | + /** @var $user \OC\User\User */ |
|
| 336 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 337 | + }); |
|
| 338 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 339 | + /** @var $user \OC\User\User */ |
|
| 340 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 341 | + }); |
|
| 342 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 343 | + /** @var $user \OC\User\User */ |
|
| 344 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 345 | + }); |
|
| 346 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 347 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 348 | + }); |
|
| 349 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 350 | + /** @var $user \OC\User\User */ |
|
| 351 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 352 | + }); |
|
| 353 | + $userSession->listen('\OC\User', 'logout', function () { |
|
| 354 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 355 | + }); |
|
| 356 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 357 | + /** @var $user \OC\User\User */ |
|
| 358 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 359 | + }); |
|
| 360 | + return $userSession; |
|
| 361 | + }); |
|
| 362 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 363 | + |
|
| 364 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 365 | + return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
| 366 | + }); |
|
| 367 | + |
|
| 368 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 369 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 370 | + |
|
| 371 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 372 | + return new \OC\AllConfig( |
|
| 373 | + $c->getSystemConfig() |
|
| 374 | + ); |
|
| 375 | + }); |
|
| 376 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 377 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 378 | + |
|
| 379 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 380 | + return new \OC\SystemConfig($config); |
|
| 381 | + }); |
|
| 382 | + |
|
| 383 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 384 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 385 | + }); |
|
| 386 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 387 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 388 | + |
|
| 389 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 390 | + return new \OC\L10N\Factory( |
|
| 391 | + $c->getConfig(), |
|
| 392 | + $c->getRequest(), |
|
| 393 | + $c->getUserSession(), |
|
| 394 | + \OC::$SERVERROOT |
|
| 395 | + ); |
|
| 396 | + }); |
|
| 397 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 398 | + |
|
| 399 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 400 | + $config = $c->getConfig(); |
|
| 401 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 402 | + return new \OC\URLGenerator( |
|
| 403 | + $config, |
|
| 404 | + $cacheFactory |
|
| 405 | + ); |
|
| 406 | + }); |
|
| 407 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 408 | + |
|
| 409 | + $this->registerService('AppHelper', function ($c) { |
|
| 410 | + return new \OC\AppHelper(); |
|
| 411 | + }); |
|
| 412 | + $this->registerService('AppFetcher', function ($c) { |
|
| 413 | + return new AppFetcher( |
|
| 414 | + $this->getAppDataDir('appstore'), |
|
| 415 | + $this->getHTTPClientService(), |
|
| 416 | + $this->query(TimeFactory::class), |
|
| 417 | + $this->getConfig() |
|
| 418 | + ); |
|
| 419 | + }); |
|
| 420 | + $this->registerService('CategoryFetcher', function ($c) { |
|
| 421 | + return new CategoryFetcher( |
|
| 422 | + $this->getAppDataDir('appstore'), |
|
| 423 | + $this->getHTTPClientService(), |
|
| 424 | + $this->query(TimeFactory::class), |
|
| 425 | + $this->getConfig() |
|
| 426 | + ); |
|
| 427 | + }); |
|
| 428 | + |
|
| 429 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 430 | + return new Cache\File(); |
|
| 431 | + }); |
|
| 432 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 433 | + |
|
| 434 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 435 | + $config = $c->getConfig(); |
|
| 436 | + |
|
| 437 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 438 | + $v = \OC_App::getAppVersions(); |
|
| 439 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
| 440 | + $version = implode(',', $v); |
|
| 441 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 442 | + $path = \OC::$SERVERROOT; |
|
| 443 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
| 444 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 445 | + $config->getSystemValue('memcache.local', null), |
|
| 446 | + $config->getSystemValue('memcache.distributed', null), |
|
| 447 | + $config->getSystemValue('memcache.locking', null) |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 452 | + '\\OC\\Memcache\\ArrayCache', |
|
| 453 | + '\\OC\\Memcache\\ArrayCache', |
|
| 454 | + '\\OC\\Memcache\\ArrayCache' |
|
| 455 | + ); |
|
| 456 | + }); |
|
| 457 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 458 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 459 | + |
|
| 460 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 461 | + $systemConfig = $c->getSystemConfig(); |
|
| 462 | + return new RedisFactory($systemConfig); |
|
| 463 | + }); |
|
| 464 | + |
|
| 465 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 466 | + return new \OC\Activity\Manager( |
|
| 467 | + $c->getRequest(), |
|
| 468 | + $c->getUserSession(), |
|
| 469 | + $c->getConfig(), |
|
| 470 | + $c->query(IValidator::class) |
|
| 471 | + ); |
|
| 472 | + }); |
|
| 473 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 474 | + |
|
| 475 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 476 | + return new \OC\Activity\EventMerger( |
|
| 477 | + $c->getL10N('lib') |
|
| 478 | + ); |
|
| 479 | + }); |
|
| 480 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 481 | + |
|
| 482 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 483 | + return new AvatarManager( |
|
| 484 | + $c->getUserManager(), |
|
| 485 | + $c->getAppDataDir('avatar'), |
|
| 486 | + $c->getL10N('lib'), |
|
| 487 | + $c->getLogger(), |
|
| 488 | + $c->getConfig() |
|
| 489 | + ); |
|
| 490 | + }); |
|
| 491 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 492 | + |
|
| 493 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 494 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 495 | + $logger = Log::getLogClass($logType); |
|
| 496 | + call_user_func(array($logger, 'init')); |
|
| 497 | + |
|
| 498 | + return new Log($logger); |
|
| 499 | + }); |
|
| 500 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 501 | + |
|
| 502 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 503 | + $config = $c->getConfig(); |
|
| 504 | + return new \OC\BackgroundJob\JobList( |
|
| 505 | + $c->getDatabaseConnection(), |
|
| 506 | + $config, |
|
| 507 | + new TimeFactory() |
|
| 508 | + ); |
|
| 509 | + }); |
|
| 510 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 511 | + |
|
| 512 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 513 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 514 | + $logger = $c->getLogger(); |
|
| 515 | + if ($cacheFactory->isAvailable()) { |
|
| 516 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
| 517 | + } else { |
|
| 518 | + $router = new \OC\Route\Router($logger); |
|
| 519 | + } |
|
| 520 | + return $router; |
|
| 521 | + }); |
|
| 522 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 523 | + |
|
| 524 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 525 | + return new Search(); |
|
| 526 | + }); |
|
| 527 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 528 | + |
|
| 529 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
| 530 | + return new \OC\Security\RateLimiting\Limiter( |
|
| 531 | + $this->getUserSession(), |
|
| 532 | + $this->getRequest(), |
|
| 533 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
| 534 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 535 | + ); |
|
| 536 | + }); |
|
| 537 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 538 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 539 | + $this->getMemCacheFactory(), |
|
| 540 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 541 | + ); |
|
| 542 | + }); |
|
| 543 | + |
|
| 544 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 545 | + return new SecureRandom(); |
|
| 546 | + }); |
|
| 547 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 548 | + |
|
| 549 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 550 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 551 | + }); |
|
| 552 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 553 | + |
|
| 554 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 555 | + return new Hasher($c->getConfig()); |
|
| 556 | + }); |
|
| 557 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 558 | + |
|
| 559 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 560 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 561 | + }); |
|
| 562 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 563 | + |
|
| 564 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 565 | + $systemConfig = $c->getSystemConfig(); |
|
| 566 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 567 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 568 | + if (!$factory->isValidType($type)) { |
|
| 569 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 570 | + } |
|
| 571 | + $connectionParams = $factory->createConnectionParams(); |
|
| 572 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 573 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 574 | + return $connection; |
|
| 575 | + }); |
|
| 576 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 577 | + |
|
| 578 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
| 579 | + $config = $c->getConfig(); |
|
| 580 | + return new HTTPHelper( |
|
| 581 | + $config, |
|
| 582 | + $c->getHTTPClientService() |
|
| 583 | + ); |
|
| 584 | + }); |
|
| 585 | + |
|
| 586 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 587 | + $user = \OC_User::getUser(); |
|
| 588 | + $uid = $user ? $user : null; |
|
| 589 | + return new ClientService( |
|
| 590 | + $c->getConfig(), |
|
| 591 | + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
| 592 | + ); |
|
| 593 | + }); |
|
| 594 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 595 | + |
|
| 596 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 597 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 598 | + return new EventLogger(); |
|
| 599 | + } else { |
|
| 600 | + return new NullEventLogger(); |
|
| 601 | + } |
|
| 602 | + }); |
|
| 603 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 604 | + |
|
| 605 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 606 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 607 | + return new QueryLogger(); |
|
| 608 | + } else { |
|
| 609 | + return new NullQueryLogger(); |
|
| 610 | + } |
|
| 611 | + }); |
|
| 612 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 613 | + |
|
| 614 | + $this->registerService(TempManager::class, function (Server $c) { |
|
| 615 | + return new TempManager( |
|
| 616 | + $c->getLogger(), |
|
| 617 | + $c->getConfig() |
|
| 618 | + ); |
|
| 619 | + }); |
|
| 620 | + $this->registerAlias('TempManager', TempManager::class); |
|
| 621 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 622 | + |
|
| 623 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 624 | + return new \OC\App\AppManager( |
|
| 625 | + $c->getUserSession(), |
|
| 626 | + $c->getAppConfig(), |
|
| 627 | + $c->getGroupManager(), |
|
| 628 | + $c->getMemCacheFactory(), |
|
| 629 | + $c->getEventDispatcher() |
|
| 630 | + ); |
|
| 631 | + }); |
|
| 632 | + $this->registerAlias('AppManager', AppManager::class); |
|
| 633 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 634 | + |
|
| 635 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 636 | + return new DateTimeZone( |
|
| 637 | + $c->getConfig(), |
|
| 638 | + $c->getSession() |
|
| 639 | + ); |
|
| 640 | + }); |
|
| 641 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 642 | + |
|
| 643 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 644 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 645 | + |
|
| 646 | + return new DateTimeFormatter( |
|
| 647 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 648 | + $c->getL10N('lib', $language) |
|
| 649 | + ); |
|
| 650 | + }); |
|
| 651 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 652 | + |
|
| 653 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 654 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 655 | + $listener = new UserMountCacheListener($mountCache); |
|
| 656 | + $listener->listen($c->getUserManager()); |
|
| 657 | + return $mountCache; |
|
| 658 | + }); |
|
| 659 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 660 | + |
|
| 661 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 662 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 663 | + $mountCache = $c->query('UserMountCache'); |
|
| 664 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 665 | + |
|
| 666 | + // builtin providers |
|
| 667 | + |
|
| 668 | + $config = $c->getConfig(); |
|
| 669 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 670 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 671 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 672 | + |
|
| 673 | + return $manager; |
|
| 674 | + }); |
|
| 675 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 676 | + |
|
| 677 | + $this->registerService('IniWrapper', function ($c) { |
|
| 678 | + return new IniGetWrapper(); |
|
| 679 | + }); |
|
| 680 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 681 | + $jobList = $c->getJobList(); |
|
| 682 | + return new AsyncBus($jobList); |
|
| 683 | + }); |
|
| 684 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 685 | + return new TrustedDomainHelper($this->getConfig()); |
|
| 686 | + }); |
|
| 687 | + $this->registerService('Throttler', function(Server $c) { |
|
| 688 | + return new Throttler( |
|
| 689 | + $c->getDatabaseConnection(), |
|
| 690 | + new TimeFactory(), |
|
| 691 | + $c->getLogger(), |
|
| 692 | + $c->getConfig() |
|
| 693 | + ); |
|
| 694 | + }); |
|
| 695 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 696 | + // IConfig and IAppManager requires a working database. This code |
|
| 697 | + // might however be called when ownCloud is not yet setup. |
|
| 698 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 699 | + $config = $c->getConfig(); |
|
| 700 | + $appManager = $c->getAppManager(); |
|
| 701 | + } else { |
|
| 702 | + $config = null; |
|
| 703 | + $appManager = null; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + return new Checker( |
|
| 707 | + new EnvironmentHelper(), |
|
| 708 | + new FileAccessHelper(), |
|
| 709 | + new AppLocator(), |
|
| 710 | + $config, |
|
| 711 | + $c->getMemCacheFactory(), |
|
| 712 | + $appManager, |
|
| 713 | + $c->getTempManager() |
|
| 714 | + ); |
|
| 715 | + }); |
|
| 716 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 717 | + if (isset($this['urlParams'])) { |
|
| 718 | + $urlParams = $this['urlParams']; |
|
| 719 | + } else { |
|
| 720 | + $urlParams = []; |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 724 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 725 | + ) { |
|
| 726 | + $stream = 'fakeinput://data'; |
|
| 727 | + } else { |
|
| 728 | + $stream = 'php://input'; |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + return new Request( |
|
| 732 | + [ |
|
| 733 | + 'get' => $_GET, |
|
| 734 | + 'post' => $_POST, |
|
| 735 | + 'files' => $_FILES, |
|
| 736 | + 'server' => $_SERVER, |
|
| 737 | + 'env' => $_ENV, |
|
| 738 | + 'cookies' => $_COOKIE, |
|
| 739 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 740 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 741 | + : null, |
|
| 742 | + 'urlParams' => $urlParams, |
|
| 743 | + ], |
|
| 744 | + $this->getSecureRandom(), |
|
| 745 | + $this->getConfig(), |
|
| 746 | + $this->getCsrfTokenManager(), |
|
| 747 | + $stream |
|
| 748 | + ); |
|
| 749 | + }); |
|
| 750 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 751 | + |
|
| 752 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 753 | + return new Mailer( |
|
| 754 | + $c->getConfig(), |
|
| 755 | + $c->getLogger(), |
|
| 756 | + $c->query(Defaults::class), |
|
| 757 | + $c->getURLGenerator(), |
|
| 758 | + $c->getL10N('lib') |
|
| 759 | + ); |
|
| 760 | + }); |
|
| 761 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 762 | + |
|
| 763 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
| 764 | + $config = $c->getConfig(); |
|
| 765 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 766 | + if(is_null($factoryClass)) { |
|
| 767 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 768 | + } |
|
| 769 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 770 | + $factory = new $factoryClass($this); |
|
| 771 | + return $factory->getLDAPProvider(); |
|
| 772 | + }); |
|
| 773 | + $this->registerService('LockingProvider', function (Server $c) { |
|
| 774 | + $ini = $c->getIniWrapper(); |
|
| 775 | + $config = $c->getConfig(); |
|
| 776 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 777 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 778 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 779 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 780 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 781 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 782 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 783 | + } |
|
| 784 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
| 785 | + } |
|
| 786 | + return new NoopLockingProvider(); |
|
| 787 | + }); |
|
| 788 | + |
|
| 789 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 790 | + return new \OC\Files\Mount\Manager(); |
|
| 791 | + }); |
|
| 792 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 793 | + |
|
| 794 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 795 | + return new \OC\Files\Type\Detection( |
|
| 796 | + $c->getURLGenerator(), |
|
| 797 | + \OC::$configDir, |
|
| 798 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 799 | + ); |
|
| 800 | + }); |
|
| 801 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 802 | + |
|
| 803 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 804 | + return new \OC\Files\Type\Loader( |
|
| 805 | + $c->getDatabaseConnection() |
|
| 806 | + ); |
|
| 807 | + }); |
|
| 808 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 809 | + $this->registerService(BundleFetcher::class, function () { |
|
| 810 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 811 | + }); |
|
| 812 | + $this->registerService(AppFetcher::class, function() { |
|
| 813 | + return $this->getAppFetcher(); |
|
| 814 | + }); |
|
| 815 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 816 | + return new Manager( |
|
| 817 | + $c->query(IValidator::class) |
|
| 818 | + ); |
|
| 819 | + }); |
|
| 820 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 821 | + |
|
| 822 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 823 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 824 | + $manager->registerCapability(function () use ($c) { |
|
| 825 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 826 | + }); |
|
| 827 | + return $manager; |
|
| 828 | + }); |
|
| 829 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 830 | + |
|
| 831 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 832 | + $config = $c->getConfig(); |
|
| 833 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
| 834 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 835 | + $factory = new $factoryClass($this); |
|
| 836 | + return $factory->getManager(); |
|
| 837 | + }); |
|
| 838 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 839 | + |
|
| 840 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 841 | + /* |
|
| 842 | 842 | * Dark magic for autoloader. |
| 843 | 843 | * If we do a class_exists it will try to load the class which will |
| 844 | 844 | * make composer cache the result. Resulting in errors when enabling |
| 845 | 845 | * the theming app. |
| 846 | 846 | */ |
| 847 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 848 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 849 | - $classExists = true; |
|
| 850 | - } else { |
|
| 851 | - $classExists = false; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
| 855 | - return new ThemingDefaults( |
|
| 856 | - $c->getConfig(), |
|
| 857 | - $c->getL10N('theming'), |
|
| 858 | - $c->getURLGenerator(), |
|
| 859 | - new \OC_Defaults(), |
|
| 860 | - $c->getAppDataDir('theming'), |
|
| 861 | - $c->getMemCacheFactory(), |
|
| 862 | - new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager()) |
|
| 863 | - ); |
|
| 864 | - } |
|
| 865 | - return new \OC_Defaults(); |
|
| 866 | - }); |
|
| 867 | - $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 868 | - /** @var Factory $cacheFactory */ |
|
| 869 | - $cacheFactory = $c->query(Factory::class); |
|
| 870 | - return new SCSSCacher( |
|
| 871 | - $c->getLogger(), |
|
| 872 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 873 | - $c->getURLGenerator(), |
|
| 874 | - $c->getConfig(), |
|
| 875 | - $c->getThemingDefaults(), |
|
| 876 | - \OC::$SERVERROOT, |
|
| 877 | - $cacheFactory->createLocal('SCSS') |
|
| 878 | - ); |
|
| 879 | - }); |
|
| 880 | - $this->registerService(EventDispatcher::class, function () { |
|
| 881 | - return new EventDispatcher(); |
|
| 882 | - }); |
|
| 883 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 884 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 885 | - |
|
| 886 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 887 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 888 | - $request = new Request( |
|
| 889 | - [ |
|
| 890 | - 'get' => $_GET, |
|
| 891 | - 'post' => $_POST, |
|
| 892 | - 'files' => $_FILES, |
|
| 893 | - 'server' => $_SERVER, |
|
| 894 | - 'env' => $_ENV, |
|
| 895 | - 'cookies' => $_COOKIE, |
|
| 896 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 897 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 898 | - : null, |
|
| 899 | - ], |
|
| 900 | - $c->getSecureRandom(), |
|
| 901 | - $c->getConfig() |
|
| 902 | - ); |
|
| 903 | - |
|
| 904 | - return new CryptoWrapper( |
|
| 905 | - $c->getConfig(), |
|
| 906 | - $c->getCrypto(), |
|
| 907 | - $c->getSecureRandom(), |
|
| 908 | - $request |
|
| 909 | - ); |
|
| 910 | - }); |
|
| 911 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 912 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 913 | - |
|
| 914 | - return new CsrfTokenManager( |
|
| 915 | - $tokenGenerator, |
|
| 916 | - $c->query(SessionStorage::class) |
|
| 917 | - ); |
|
| 918 | - }); |
|
| 919 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 920 | - return new SessionStorage($c->getSession()); |
|
| 921 | - }); |
|
| 922 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 923 | - return new ContentSecurityPolicyManager(); |
|
| 924 | - }); |
|
| 925 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 926 | - |
|
| 927 | - $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 928 | - return new ContentSecurityPolicyNonceManager( |
|
| 929 | - $c->getCsrfTokenManager(), |
|
| 930 | - $c->getRequest() |
|
| 931 | - ); |
|
| 932 | - }); |
|
| 933 | - |
|
| 934 | - $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 935 | - $config = $c->getConfig(); |
|
| 936 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
| 937 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 938 | - $factory = new $factoryClass($this); |
|
| 939 | - |
|
| 940 | - $manager = new \OC\Share20\Manager( |
|
| 941 | - $c->getLogger(), |
|
| 942 | - $c->getConfig(), |
|
| 943 | - $c->getSecureRandom(), |
|
| 944 | - $c->getHasher(), |
|
| 945 | - $c->getMountManager(), |
|
| 946 | - $c->getGroupManager(), |
|
| 947 | - $c->getL10N('core'), |
|
| 948 | - $factory, |
|
| 949 | - $c->getUserManager(), |
|
| 950 | - $c->getLazyRootFolder(), |
|
| 951 | - $c->getEventDispatcher() |
|
| 952 | - ); |
|
| 953 | - |
|
| 954 | - return $manager; |
|
| 955 | - }); |
|
| 956 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 957 | - |
|
| 958 | - $this->registerService('SettingsManager', function(Server $c) { |
|
| 959 | - $manager = new \OC\Settings\Manager( |
|
| 960 | - $c->getLogger(), |
|
| 961 | - $c->getDatabaseConnection(), |
|
| 962 | - $c->getL10N('lib'), |
|
| 963 | - $c->getConfig(), |
|
| 964 | - $c->getEncryptionManager(), |
|
| 965 | - $c->getUserManager(), |
|
| 966 | - $c->getLockingProvider(), |
|
| 967 | - $c->getRequest(), |
|
| 968 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
| 969 | - $c->getURLGenerator() |
|
| 970 | - ); |
|
| 971 | - return $manager; |
|
| 972 | - }); |
|
| 973 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 974 | - return new \OC\Files\AppData\Factory( |
|
| 975 | - $c->getRootFolder(), |
|
| 976 | - $c->getSystemConfig() |
|
| 977 | - ); |
|
| 978 | - }); |
|
| 979 | - |
|
| 980 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 981 | - return new LockdownManager(function() use ($c) { |
|
| 982 | - return $c->getSession(); |
|
| 983 | - }); |
|
| 984 | - }); |
|
| 985 | - |
|
| 986 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 987 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 988 | - }); |
|
| 989 | - |
|
| 990 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 991 | - return new CloudIdManager(); |
|
| 992 | - }); |
|
| 993 | - |
|
| 994 | - /* To trick DI since we don't extend the DIContainer here */ |
|
| 995 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 996 | - return new CleanPreviewsBackgroundJob( |
|
| 997 | - $c->getRootFolder(), |
|
| 998 | - $c->getLogger(), |
|
| 999 | - $c->getJobList(), |
|
| 1000 | - new TimeFactory() |
|
| 1001 | - ); |
|
| 1002 | - }); |
|
| 1003 | - |
|
| 1004 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1005 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1006 | - |
|
| 1007 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1008 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1009 | - |
|
| 1010 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1011 | - return new Defaults( |
|
| 1012 | - $c->getThemingDefaults() |
|
| 1013 | - ); |
|
| 1014 | - }); |
|
| 1015 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1016 | - |
|
| 1017 | - $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1018 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1019 | - }); |
|
| 1020 | - |
|
| 1021 | - $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1022 | - return new ShareHelper( |
|
| 1023 | - $c->query(\OCP\Share\IManager::class) |
|
| 1024 | - ); |
|
| 1025 | - }); |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * @return \OCP\Contacts\IManager |
|
| 1030 | - */ |
|
| 1031 | - public function getContactsManager() { |
|
| 1032 | - return $this->query('ContactsManager'); |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - /** |
|
| 1036 | - * @return \OC\Encryption\Manager |
|
| 1037 | - */ |
|
| 1038 | - public function getEncryptionManager() { |
|
| 1039 | - return $this->query('EncryptionManager'); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - /** |
|
| 1043 | - * @return \OC\Encryption\File |
|
| 1044 | - */ |
|
| 1045 | - public function getEncryptionFilesHelper() { |
|
| 1046 | - return $this->query('EncryptionFileHelper'); |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1051 | - */ |
|
| 1052 | - public function getEncryptionKeyStorage() { |
|
| 1053 | - return $this->query('EncryptionKeyStorage'); |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * The current request object holding all information about the request |
|
| 1058 | - * currently being processed is returned from this method. |
|
| 1059 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1060 | - * |
|
| 1061 | - * @return \OCP\IRequest |
|
| 1062 | - */ |
|
| 1063 | - public function getRequest() { |
|
| 1064 | - return $this->query('Request'); |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * Returns the preview manager which can create preview images for a given file |
|
| 1069 | - * |
|
| 1070 | - * @return \OCP\IPreview |
|
| 1071 | - */ |
|
| 1072 | - public function getPreviewManager() { |
|
| 1073 | - return $this->query('PreviewManager'); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1078 | - * |
|
| 1079 | - * @see \OCP\ITagManager::load() |
|
| 1080 | - * @return \OCP\ITagManager |
|
| 1081 | - */ |
|
| 1082 | - public function getTagManager() { |
|
| 1083 | - return $this->query('TagManager'); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * Returns the system-tag manager |
|
| 1088 | - * |
|
| 1089 | - * @return \OCP\SystemTag\ISystemTagManager |
|
| 1090 | - * |
|
| 1091 | - * @since 9.0.0 |
|
| 1092 | - */ |
|
| 1093 | - public function getSystemTagManager() { |
|
| 1094 | - return $this->query('SystemTagManager'); |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * Returns the system-tag object mapper |
|
| 1099 | - * |
|
| 1100 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1101 | - * |
|
| 1102 | - * @since 9.0.0 |
|
| 1103 | - */ |
|
| 1104 | - public function getSystemTagObjectMapper() { |
|
| 1105 | - return $this->query('SystemTagObjectMapper'); |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Returns the avatar manager, used for avatar functionality |
|
| 1110 | - * |
|
| 1111 | - * @return \OCP\IAvatarManager |
|
| 1112 | - */ |
|
| 1113 | - public function getAvatarManager() { |
|
| 1114 | - return $this->query('AvatarManager'); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * Returns the root folder of ownCloud's data directory |
|
| 1119 | - * |
|
| 1120 | - * @return \OCP\Files\IRootFolder |
|
| 1121 | - */ |
|
| 1122 | - public function getRootFolder() { |
|
| 1123 | - return $this->query('LazyRootFolder'); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - /** |
|
| 1127 | - * Returns the root folder of ownCloud's data directory |
|
| 1128 | - * This is the lazy variant so this gets only initialized once it |
|
| 1129 | - * is actually used. |
|
| 1130 | - * |
|
| 1131 | - * @return \OCP\Files\IRootFolder |
|
| 1132 | - */ |
|
| 1133 | - public function getLazyRootFolder() { |
|
| 1134 | - return $this->query('LazyRootFolder'); |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * Returns a view to ownCloud's files folder |
|
| 1139 | - * |
|
| 1140 | - * @param string $userId user ID |
|
| 1141 | - * @return \OCP\Files\Folder|null |
|
| 1142 | - */ |
|
| 1143 | - public function getUserFolder($userId = null) { |
|
| 1144 | - if ($userId === null) { |
|
| 1145 | - $user = $this->getUserSession()->getUser(); |
|
| 1146 | - if (!$user) { |
|
| 1147 | - return null; |
|
| 1148 | - } |
|
| 1149 | - $userId = $user->getUID(); |
|
| 1150 | - } |
|
| 1151 | - $root = $this->getRootFolder(); |
|
| 1152 | - return $root->getUserFolder($userId); |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * Returns an app-specific view in ownClouds data directory |
|
| 1157 | - * |
|
| 1158 | - * @return \OCP\Files\Folder |
|
| 1159 | - * @deprecated since 9.2.0 use IAppData |
|
| 1160 | - */ |
|
| 1161 | - public function getAppFolder() { |
|
| 1162 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1163 | - $root = $this->getRootFolder(); |
|
| 1164 | - if (!$root->nodeExists($dir)) { |
|
| 1165 | - $folder = $root->newFolder($dir); |
|
| 1166 | - } else { |
|
| 1167 | - $folder = $root->get($dir); |
|
| 1168 | - } |
|
| 1169 | - return $folder; |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * @return \OC\User\Manager |
|
| 1174 | - */ |
|
| 1175 | - public function getUserManager() { |
|
| 1176 | - return $this->query('UserManager'); |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - /** |
|
| 1180 | - * @return \OC\Group\Manager |
|
| 1181 | - */ |
|
| 1182 | - public function getGroupManager() { |
|
| 1183 | - return $this->query('GroupManager'); |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - /** |
|
| 1187 | - * @return \OC\User\Session |
|
| 1188 | - */ |
|
| 1189 | - public function getUserSession() { |
|
| 1190 | - return $this->query('UserSession'); |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * @return \OCP\ISession |
|
| 1195 | - */ |
|
| 1196 | - public function getSession() { |
|
| 1197 | - return $this->query('UserSession')->getSession(); |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * @param \OCP\ISession $session |
|
| 1202 | - */ |
|
| 1203 | - public function setSession(\OCP\ISession $session) { |
|
| 1204 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1205 | - $this->query('UserSession')->setSession($session); |
|
| 1206 | - $this->query(Store::class)->setSession($session); |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - /** |
|
| 1210 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1211 | - */ |
|
| 1212 | - public function getTwoFactorAuthManager() { |
|
| 1213 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * @return \OC\NavigationManager |
|
| 1218 | - */ |
|
| 1219 | - public function getNavigationManager() { |
|
| 1220 | - return $this->query('NavigationManager'); |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * @return \OCP\IConfig |
|
| 1225 | - */ |
|
| 1226 | - public function getConfig() { |
|
| 1227 | - return $this->query('AllConfig'); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * @internal For internal use only |
|
| 1232 | - * @return \OC\SystemConfig |
|
| 1233 | - */ |
|
| 1234 | - public function getSystemConfig() { |
|
| 1235 | - return $this->query('SystemConfig'); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - /** |
|
| 1239 | - * Returns the app config manager |
|
| 1240 | - * |
|
| 1241 | - * @return \OCP\IAppConfig |
|
| 1242 | - */ |
|
| 1243 | - public function getAppConfig() { |
|
| 1244 | - return $this->query('AppConfig'); |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * @return \OCP\L10N\IFactory |
|
| 1249 | - */ |
|
| 1250 | - public function getL10NFactory() { |
|
| 1251 | - return $this->query('L10NFactory'); |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * get an L10N instance |
|
| 1256 | - * |
|
| 1257 | - * @param string $app appid |
|
| 1258 | - * @param string $lang |
|
| 1259 | - * @return IL10N |
|
| 1260 | - */ |
|
| 1261 | - public function getL10N($app, $lang = null) { |
|
| 1262 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - /** |
|
| 1266 | - * @return \OCP\IURLGenerator |
|
| 1267 | - */ |
|
| 1268 | - public function getURLGenerator() { |
|
| 1269 | - return $this->query('URLGenerator'); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - /** |
|
| 1273 | - * @return \OCP\IHelper |
|
| 1274 | - */ |
|
| 1275 | - public function getHelper() { |
|
| 1276 | - return $this->query('AppHelper'); |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * @return AppFetcher |
|
| 1281 | - */ |
|
| 1282 | - public function getAppFetcher() { |
|
| 1283 | - return $this->query('AppFetcher'); |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - /** |
|
| 1287 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1288 | - * getMemCacheFactory() instead. |
|
| 1289 | - * |
|
| 1290 | - * @return \OCP\ICache |
|
| 1291 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1292 | - */ |
|
| 1293 | - public function getCache() { |
|
| 1294 | - return $this->query('UserCache'); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - /** |
|
| 1298 | - * Returns an \OCP\CacheFactory instance |
|
| 1299 | - * |
|
| 1300 | - * @return \OCP\ICacheFactory |
|
| 1301 | - */ |
|
| 1302 | - public function getMemCacheFactory() { |
|
| 1303 | - return $this->query('MemCacheFactory'); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * Returns an \OC\RedisFactory instance |
|
| 1308 | - * |
|
| 1309 | - * @return \OC\RedisFactory |
|
| 1310 | - */ |
|
| 1311 | - public function getGetRedisFactory() { |
|
| 1312 | - return $this->query('RedisFactory'); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * Returns the current session |
|
| 1318 | - * |
|
| 1319 | - * @return \OCP\IDBConnection |
|
| 1320 | - */ |
|
| 1321 | - public function getDatabaseConnection() { |
|
| 1322 | - return $this->query('DatabaseConnection'); |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * Returns the activity manager |
|
| 1327 | - * |
|
| 1328 | - * @return \OCP\Activity\IManager |
|
| 1329 | - */ |
|
| 1330 | - public function getActivityManager() { |
|
| 1331 | - return $this->query('ActivityManager'); |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * Returns an job list for controlling background jobs |
|
| 1336 | - * |
|
| 1337 | - * @return \OCP\BackgroundJob\IJobList |
|
| 1338 | - */ |
|
| 1339 | - public function getJobList() { |
|
| 1340 | - return $this->query('JobList'); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - /** |
|
| 1344 | - * Returns a logger instance |
|
| 1345 | - * |
|
| 1346 | - * @return \OCP\ILogger |
|
| 1347 | - */ |
|
| 1348 | - public function getLogger() { |
|
| 1349 | - return $this->query('Logger'); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * Returns a router for generating and matching urls |
|
| 1354 | - * |
|
| 1355 | - * @return \OCP\Route\IRouter |
|
| 1356 | - */ |
|
| 1357 | - public function getRouter() { |
|
| 1358 | - return $this->query('Router'); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * Returns a search instance |
|
| 1363 | - * |
|
| 1364 | - * @return \OCP\ISearch |
|
| 1365 | - */ |
|
| 1366 | - public function getSearch() { |
|
| 1367 | - return $this->query('Search'); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * Returns a SecureRandom instance |
|
| 1372 | - * |
|
| 1373 | - * @return \OCP\Security\ISecureRandom |
|
| 1374 | - */ |
|
| 1375 | - public function getSecureRandom() { |
|
| 1376 | - return $this->query('SecureRandom'); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * Returns a Crypto instance |
|
| 1381 | - * |
|
| 1382 | - * @return \OCP\Security\ICrypto |
|
| 1383 | - */ |
|
| 1384 | - public function getCrypto() { |
|
| 1385 | - return $this->query('Crypto'); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * Returns a Hasher instance |
|
| 1390 | - * |
|
| 1391 | - * @return \OCP\Security\IHasher |
|
| 1392 | - */ |
|
| 1393 | - public function getHasher() { |
|
| 1394 | - return $this->query('Hasher'); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Returns a CredentialsManager instance |
|
| 1399 | - * |
|
| 1400 | - * @return \OCP\Security\ICredentialsManager |
|
| 1401 | - */ |
|
| 1402 | - public function getCredentialsManager() { |
|
| 1403 | - return $this->query('CredentialsManager'); |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * Returns an instance of the HTTP helper class |
|
| 1408 | - * |
|
| 1409 | - * @deprecated Use getHTTPClientService() |
|
| 1410 | - * @return \OC\HTTPHelper |
|
| 1411 | - */ |
|
| 1412 | - public function getHTTPHelper() { |
|
| 1413 | - return $this->query('HTTPHelper'); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * Get the certificate manager for the user |
|
| 1418 | - * |
|
| 1419 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1420 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1421 | - */ |
|
| 1422 | - public function getCertificateManager($userId = '') { |
|
| 1423 | - if ($userId === '') { |
|
| 1424 | - $userSession = $this->getUserSession(); |
|
| 1425 | - $user = $userSession->getUser(); |
|
| 1426 | - if (is_null($user)) { |
|
| 1427 | - return null; |
|
| 1428 | - } |
|
| 1429 | - $userId = $user->getUID(); |
|
| 1430 | - } |
|
| 1431 | - return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * Returns an instance of the HTTP client service |
|
| 1436 | - * |
|
| 1437 | - * @return \OCP\Http\Client\IClientService |
|
| 1438 | - */ |
|
| 1439 | - public function getHTTPClientService() { |
|
| 1440 | - return $this->query('HttpClientService'); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - /** |
|
| 1444 | - * Create a new event source |
|
| 1445 | - * |
|
| 1446 | - * @return \OCP\IEventSource |
|
| 1447 | - */ |
|
| 1448 | - public function createEventSource() { |
|
| 1449 | - return new \OC_EventSource(); |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - /** |
|
| 1453 | - * Get the active event logger |
|
| 1454 | - * |
|
| 1455 | - * The returned logger only logs data when debug mode is enabled |
|
| 1456 | - * |
|
| 1457 | - * @return \OCP\Diagnostics\IEventLogger |
|
| 1458 | - */ |
|
| 1459 | - public function getEventLogger() { |
|
| 1460 | - return $this->query('EventLogger'); |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - /** |
|
| 1464 | - * Get the active query logger |
|
| 1465 | - * |
|
| 1466 | - * The returned logger only logs data when debug mode is enabled |
|
| 1467 | - * |
|
| 1468 | - * @return \OCP\Diagnostics\IQueryLogger |
|
| 1469 | - */ |
|
| 1470 | - public function getQueryLogger() { |
|
| 1471 | - return $this->query('QueryLogger'); |
|
| 1472 | - } |
|
| 1473 | - |
|
| 1474 | - /** |
|
| 1475 | - * Get the manager for temporary files and folders |
|
| 1476 | - * |
|
| 1477 | - * @return \OCP\ITempManager |
|
| 1478 | - */ |
|
| 1479 | - public function getTempManager() { |
|
| 1480 | - return $this->query('TempManager'); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * Get the app manager |
|
| 1485 | - * |
|
| 1486 | - * @return \OCP\App\IAppManager |
|
| 1487 | - */ |
|
| 1488 | - public function getAppManager() { |
|
| 1489 | - return $this->query('AppManager'); |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - /** |
|
| 1493 | - * Creates a new mailer |
|
| 1494 | - * |
|
| 1495 | - * @return \OCP\Mail\IMailer |
|
| 1496 | - */ |
|
| 1497 | - public function getMailer() { |
|
| 1498 | - return $this->query('Mailer'); |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - /** |
|
| 1502 | - * Get the webroot |
|
| 1503 | - * |
|
| 1504 | - * @return string |
|
| 1505 | - */ |
|
| 1506 | - public function getWebRoot() { |
|
| 1507 | - return $this->webRoot; |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * @return \OC\OCSClient |
|
| 1512 | - */ |
|
| 1513 | - public function getOcsClient() { |
|
| 1514 | - return $this->query('OcsClient'); |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * @return \OCP\IDateTimeZone |
|
| 1519 | - */ |
|
| 1520 | - public function getDateTimeZone() { |
|
| 1521 | - return $this->query('DateTimeZone'); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - /** |
|
| 1525 | - * @return \OCP\IDateTimeFormatter |
|
| 1526 | - */ |
|
| 1527 | - public function getDateTimeFormatter() { |
|
| 1528 | - return $this->query('DateTimeFormatter'); |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1533 | - */ |
|
| 1534 | - public function getMountProviderCollection() { |
|
| 1535 | - return $this->query('MountConfigManager'); |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * Get the IniWrapper |
|
| 1540 | - * |
|
| 1541 | - * @return IniGetWrapper |
|
| 1542 | - */ |
|
| 1543 | - public function getIniWrapper() { |
|
| 1544 | - return $this->query('IniWrapper'); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - /** |
|
| 1548 | - * @return \OCP\Command\IBus |
|
| 1549 | - */ |
|
| 1550 | - public function getCommandBus() { |
|
| 1551 | - return $this->query('AsyncCommandBus'); |
|
| 1552 | - } |
|
| 1553 | - |
|
| 1554 | - /** |
|
| 1555 | - * Get the trusted domain helper |
|
| 1556 | - * |
|
| 1557 | - * @return TrustedDomainHelper |
|
| 1558 | - */ |
|
| 1559 | - public function getTrustedDomainHelper() { |
|
| 1560 | - return $this->query('TrustedDomainHelper'); |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - /** |
|
| 1564 | - * Get the locking provider |
|
| 1565 | - * |
|
| 1566 | - * @return \OCP\Lock\ILockingProvider |
|
| 1567 | - * @since 8.1.0 |
|
| 1568 | - */ |
|
| 1569 | - public function getLockingProvider() { |
|
| 1570 | - return $this->query('LockingProvider'); |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * @return \OCP\Files\Mount\IMountManager |
|
| 1575 | - **/ |
|
| 1576 | - function getMountManager() { |
|
| 1577 | - return $this->query('MountManager'); |
|
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1581 | - function getUserMountCache() { |
|
| 1582 | - return $this->query('UserMountCache'); |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - /** |
|
| 1586 | - * Get the MimeTypeDetector |
|
| 1587 | - * |
|
| 1588 | - * @return \OCP\Files\IMimeTypeDetector |
|
| 1589 | - */ |
|
| 1590 | - public function getMimeTypeDetector() { |
|
| 1591 | - return $this->query('MimeTypeDetector'); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - /** |
|
| 1595 | - * Get the MimeTypeLoader |
|
| 1596 | - * |
|
| 1597 | - * @return \OCP\Files\IMimeTypeLoader |
|
| 1598 | - */ |
|
| 1599 | - public function getMimeTypeLoader() { |
|
| 1600 | - return $this->query('MimeTypeLoader'); |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * Get the manager of all the capabilities |
|
| 1605 | - * |
|
| 1606 | - * @return \OC\CapabilitiesManager |
|
| 1607 | - */ |
|
| 1608 | - public function getCapabilitiesManager() { |
|
| 1609 | - return $this->query('CapabilitiesManager'); |
|
| 1610 | - } |
|
| 1611 | - |
|
| 1612 | - /** |
|
| 1613 | - * Get the EventDispatcher |
|
| 1614 | - * |
|
| 1615 | - * @return EventDispatcherInterface |
|
| 1616 | - * @since 8.2.0 |
|
| 1617 | - */ |
|
| 1618 | - public function getEventDispatcher() { |
|
| 1619 | - return $this->query('EventDispatcher'); |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * Get the Notification Manager |
|
| 1624 | - * |
|
| 1625 | - * @return \OCP\Notification\IManager |
|
| 1626 | - * @since 8.2.0 |
|
| 1627 | - */ |
|
| 1628 | - public function getNotificationManager() { |
|
| 1629 | - return $this->query('NotificationManager'); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - /** |
|
| 1633 | - * @return \OCP\Comments\ICommentsManager |
|
| 1634 | - */ |
|
| 1635 | - public function getCommentsManager() { |
|
| 1636 | - return $this->query('CommentsManager'); |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1641 | - */ |
|
| 1642 | - public function getThemingDefaults() { |
|
| 1643 | - return $this->query('ThemingDefaults'); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - /** |
|
| 1647 | - * @return \OC\IntegrityCheck\Checker |
|
| 1648 | - */ |
|
| 1649 | - public function getIntegrityCodeChecker() { |
|
| 1650 | - return $this->query('IntegrityCodeChecker'); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * @return \OC\Session\CryptoWrapper |
|
| 1655 | - */ |
|
| 1656 | - public function getSessionCryptoWrapper() { |
|
| 1657 | - return $this->query('CryptoWrapper'); |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * @return CsrfTokenManager |
|
| 1662 | - */ |
|
| 1663 | - public function getCsrfTokenManager() { |
|
| 1664 | - return $this->query('CsrfTokenManager'); |
|
| 1665 | - } |
|
| 1666 | - |
|
| 1667 | - /** |
|
| 1668 | - * @return Throttler |
|
| 1669 | - */ |
|
| 1670 | - public function getBruteForceThrottler() { |
|
| 1671 | - return $this->query('Throttler'); |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * @return IContentSecurityPolicyManager |
|
| 1676 | - */ |
|
| 1677 | - public function getContentSecurityPolicyManager() { |
|
| 1678 | - return $this->query('ContentSecurityPolicyManager'); |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - /** |
|
| 1682 | - * @return ContentSecurityPolicyNonceManager |
|
| 1683 | - */ |
|
| 1684 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1685 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1686 | - } |
|
| 1687 | - |
|
| 1688 | - /** |
|
| 1689 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1690 | - * |
|
| 1691 | - * @return \OCA\Files_External\Service\BackendService |
|
| 1692 | - */ |
|
| 1693 | - public function getStoragesBackendService() { |
|
| 1694 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1699 | - * |
|
| 1700 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1701 | - */ |
|
| 1702 | - public function getGlobalStoragesService() { |
|
| 1703 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1704 | - } |
|
| 1705 | - |
|
| 1706 | - /** |
|
| 1707 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1708 | - * |
|
| 1709 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1710 | - */ |
|
| 1711 | - public function getUserGlobalStoragesService() { |
|
| 1712 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - /** |
|
| 1716 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1717 | - * |
|
| 1718 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1719 | - */ |
|
| 1720 | - public function getUserStoragesService() { |
|
| 1721 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - /** |
|
| 1725 | - * @return \OCP\Share\IManager |
|
| 1726 | - */ |
|
| 1727 | - public function getShareManager() { |
|
| 1728 | - return $this->query('ShareManager'); |
|
| 1729 | - } |
|
| 1730 | - |
|
| 1731 | - /** |
|
| 1732 | - * Returns the LDAP Provider |
|
| 1733 | - * |
|
| 1734 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 1735 | - */ |
|
| 1736 | - public function getLDAPProvider() { |
|
| 1737 | - return $this->query('LDAPProvider'); |
|
| 1738 | - } |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * @return \OCP\Settings\IManager |
|
| 1742 | - */ |
|
| 1743 | - public function getSettingsManager() { |
|
| 1744 | - return $this->query('SettingsManager'); |
|
| 1745 | - } |
|
| 1746 | - |
|
| 1747 | - /** |
|
| 1748 | - * @return \OCP\Files\IAppData |
|
| 1749 | - */ |
|
| 1750 | - public function getAppDataDir($app) { |
|
| 1751 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1752 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1753 | - return $factory->get($app); |
|
| 1754 | - } |
|
| 1755 | - |
|
| 1756 | - /** |
|
| 1757 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 1758 | - */ |
|
| 1759 | - public function getLockdownManager() { |
|
| 1760 | - return $this->query('LockdownManager'); |
|
| 1761 | - } |
|
| 1762 | - |
|
| 1763 | - /** |
|
| 1764 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1765 | - */ |
|
| 1766 | - public function getCloudIdManager() { |
|
| 1767 | - return $this->query(ICloudIdManager::class); |
|
| 1768 | - } |
|
| 847 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 848 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 849 | + $classExists = true; |
|
| 850 | + } else { |
|
| 851 | + $classExists = false; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
| 855 | + return new ThemingDefaults( |
|
| 856 | + $c->getConfig(), |
|
| 857 | + $c->getL10N('theming'), |
|
| 858 | + $c->getURLGenerator(), |
|
| 859 | + new \OC_Defaults(), |
|
| 860 | + $c->getAppDataDir('theming'), |
|
| 861 | + $c->getMemCacheFactory(), |
|
| 862 | + new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager()) |
|
| 863 | + ); |
|
| 864 | + } |
|
| 865 | + return new \OC_Defaults(); |
|
| 866 | + }); |
|
| 867 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 868 | + /** @var Factory $cacheFactory */ |
|
| 869 | + $cacheFactory = $c->query(Factory::class); |
|
| 870 | + return new SCSSCacher( |
|
| 871 | + $c->getLogger(), |
|
| 872 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 873 | + $c->getURLGenerator(), |
|
| 874 | + $c->getConfig(), |
|
| 875 | + $c->getThemingDefaults(), |
|
| 876 | + \OC::$SERVERROOT, |
|
| 877 | + $cacheFactory->createLocal('SCSS') |
|
| 878 | + ); |
|
| 879 | + }); |
|
| 880 | + $this->registerService(EventDispatcher::class, function () { |
|
| 881 | + return new EventDispatcher(); |
|
| 882 | + }); |
|
| 883 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 884 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 885 | + |
|
| 886 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 887 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 888 | + $request = new Request( |
|
| 889 | + [ |
|
| 890 | + 'get' => $_GET, |
|
| 891 | + 'post' => $_POST, |
|
| 892 | + 'files' => $_FILES, |
|
| 893 | + 'server' => $_SERVER, |
|
| 894 | + 'env' => $_ENV, |
|
| 895 | + 'cookies' => $_COOKIE, |
|
| 896 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 897 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 898 | + : null, |
|
| 899 | + ], |
|
| 900 | + $c->getSecureRandom(), |
|
| 901 | + $c->getConfig() |
|
| 902 | + ); |
|
| 903 | + |
|
| 904 | + return new CryptoWrapper( |
|
| 905 | + $c->getConfig(), |
|
| 906 | + $c->getCrypto(), |
|
| 907 | + $c->getSecureRandom(), |
|
| 908 | + $request |
|
| 909 | + ); |
|
| 910 | + }); |
|
| 911 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 912 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 913 | + |
|
| 914 | + return new CsrfTokenManager( |
|
| 915 | + $tokenGenerator, |
|
| 916 | + $c->query(SessionStorage::class) |
|
| 917 | + ); |
|
| 918 | + }); |
|
| 919 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 920 | + return new SessionStorage($c->getSession()); |
|
| 921 | + }); |
|
| 922 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 923 | + return new ContentSecurityPolicyManager(); |
|
| 924 | + }); |
|
| 925 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 926 | + |
|
| 927 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 928 | + return new ContentSecurityPolicyNonceManager( |
|
| 929 | + $c->getCsrfTokenManager(), |
|
| 930 | + $c->getRequest() |
|
| 931 | + ); |
|
| 932 | + }); |
|
| 933 | + |
|
| 934 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 935 | + $config = $c->getConfig(); |
|
| 936 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
| 937 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 938 | + $factory = new $factoryClass($this); |
|
| 939 | + |
|
| 940 | + $manager = new \OC\Share20\Manager( |
|
| 941 | + $c->getLogger(), |
|
| 942 | + $c->getConfig(), |
|
| 943 | + $c->getSecureRandom(), |
|
| 944 | + $c->getHasher(), |
|
| 945 | + $c->getMountManager(), |
|
| 946 | + $c->getGroupManager(), |
|
| 947 | + $c->getL10N('core'), |
|
| 948 | + $factory, |
|
| 949 | + $c->getUserManager(), |
|
| 950 | + $c->getLazyRootFolder(), |
|
| 951 | + $c->getEventDispatcher() |
|
| 952 | + ); |
|
| 953 | + |
|
| 954 | + return $manager; |
|
| 955 | + }); |
|
| 956 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 957 | + |
|
| 958 | + $this->registerService('SettingsManager', function(Server $c) { |
|
| 959 | + $manager = new \OC\Settings\Manager( |
|
| 960 | + $c->getLogger(), |
|
| 961 | + $c->getDatabaseConnection(), |
|
| 962 | + $c->getL10N('lib'), |
|
| 963 | + $c->getConfig(), |
|
| 964 | + $c->getEncryptionManager(), |
|
| 965 | + $c->getUserManager(), |
|
| 966 | + $c->getLockingProvider(), |
|
| 967 | + $c->getRequest(), |
|
| 968 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
| 969 | + $c->getURLGenerator() |
|
| 970 | + ); |
|
| 971 | + return $manager; |
|
| 972 | + }); |
|
| 973 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 974 | + return new \OC\Files\AppData\Factory( |
|
| 975 | + $c->getRootFolder(), |
|
| 976 | + $c->getSystemConfig() |
|
| 977 | + ); |
|
| 978 | + }); |
|
| 979 | + |
|
| 980 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 981 | + return new LockdownManager(function() use ($c) { |
|
| 982 | + return $c->getSession(); |
|
| 983 | + }); |
|
| 984 | + }); |
|
| 985 | + |
|
| 986 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 987 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 988 | + }); |
|
| 989 | + |
|
| 990 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 991 | + return new CloudIdManager(); |
|
| 992 | + }); |
|
| 993 | + |
|
| 994 | + /* To trick DI since we don't extend the DIContainer here */ |
|
| 995 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 996 | + return new CleanPreviewsBackgroundJob( |
|
| 997 | + $c->getRootFolder(), |
|
| 998 | + $c->getLogger(), |
|
| 999 | + $c->getJobList(), |
|
| 1000 | + new TimeFactory() |
|
| 1001 | + ); |
|
| 1002 | + }); |
|
| 1003 | + |
|
| 1004 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1005 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1006 | + |
|
| 1007 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1008 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1009 | + |
|
| 1010 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1011 | + return new Defaults( |
|
| 1012 | + $c->getThemingDefaults() |
|
| 1013 | + ); |
|
| 1014 | + }); |
|
| 1015 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1016 | + |
|
| 1017 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1018 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1019 | + }); |
|
| 1020 | + |
|
| 1021 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1022 | + return new ShareHelper( |
|
| 1023 | + $c->query(\OCP\Share\IManager::class) |
|
| 1024 | + ); |
|
| 1025 | + }); |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * @return \OCP\Contacts\IManager |
|
| 1030 | + */ |
|
| 1031 | + public function getContactsManager() { |
|
| 1032 | + return $this->query('ContactsManager'); |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + /** |
|
| 1036 | + * @return \OC\Encryption\Manager |
|
| 1037 | + */ |
|
| 1038 | + public function getEncryptionManager() { |
|
| 1039 | + return $this->query('EncryptionManager'); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + /** |
|
| 1043 | + * @return \OC\Encryption\File |
|
| 1044 | + */ |
|
| 1045 | + public function getEncryptionFilesHelper() { |
|
| 1046 | + return $this->query('EncryptionFileHelper'); |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1051 | + */ |
|
| 1052 | + public function getEncryptionKeyStorage() { |
|
| 1053 | + return $this->query('EncryptionKeyStorage'); |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * The current request object holding all information about the request |
|
| 1058 | + * currently being processed is returned from this method. |
|
| 1059 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1060 | + * |
|
| 1061 | + * @return \OCP\IRequest |
|
| 1062 | + */ |
|
| 1063 | + public function getRequest() { |
|
| 1064 | + return $this->query('Request'); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * Returns the preview manager which can create preview images for a given file |
|
| 1069 | + * |
|
| 1070 | + * @return \OCP\IPreview |
|
| 1071 | + */ |
|
| 1072 | + public function getPreviewManager() { |
|
| 1073 | + return $this->query('PreviewManager'); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1078 | + * |
|
| 1079 | + * @see \OCP\ITagManager::load() |
|
| 1080 | + * @return \OCP\ITagManager |
|
| 1081 | + */ |
|
| 1082 | + public function getTagManager() { |
|
| 1083 | + return $this->query('TagManager'); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * Returns the system-tag manager |
|
| 1088 | + * |
|
| 1089 | + * @return \OCP\SystemTag\ISystemTagManager |
|
| 1090 | + * |
|
| 1091 | + * @since 9.0.0 |
|
| 1092 | + */ |
|
| 1093 | + public function getSystemTagManager() { |
|
| 1094 | + return $this->query('SystemTagManager'); |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * Returns the system-tag object mapper |
|
| 1099 | + * |
|
| 1100 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1101 | + * |
|
| 1102 | + * @since 9.0.0 |
|
| 1103 | + */ |
|
| 1104 | + public function getSystemTagObjectMapper() { |
|
| 1105 | + return $this->query('SystemTagObjectMapper'); |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Returns the avatar manager, used for avatar functionality |
|
| 1110 | + * |
|
| 1111 | + * @return \OCP\IAvatarManager |
|
| 1112 | + */ |
|
| 1113 | + public function getAvatarManager() { |
|
| 1114 | + return $this->query('AvatarManager'); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * Returns the root folder of ownCloud's data directory |
|
| 1119 | + * |
|
| 1120 | + * @return \OCP\Files\IRootFolder |
|
| 1121 | + */ |
|
| 1122 | + public function getRootFolder() { |
|
| 1123 | + return $this->query('LazyRootFolder'); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + /** |
|
| 1127 | + * Returns the root folder of ownCloud's data directory |
|
| 1128 | + * This is the lazy variant so this gets only initialized once it |
|
| 1129 | + * is actually used. |
|
| 1130 | + * |
|
| 1131 | + * @return \OCP\Files\IRootFolder |
|
| 1132 | + */ |
|
| 1133 | + public function getLazyRootFolder() { |
|
| 1134 | + return $this->query('LazyRootFolder'); |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * Returns a view to ownCloud's files folder |
|
| 1139 | + * |
|
| 1140 | + * @param string $userId user ID |
|
| 1141 | + * @return \OCP\Files\Folder|null |
|
| 1142 | + */ |
|
| 1143 | + public function getUserFolder($userId = null) { |
|
| 1144 | + if ($userId === null) { |
|
| 1145 | + $user = $this->getUserSession()->getUser(); |
|
| 1146 | + if (!$user) { |
|
| 1147 | + return null; |
|
| 1148 | + } |
|
| 1149 | + $userId = $user->getUID(); |
|
| 1150 | + } |
|
| 1151 | + $root = $this->getRootFolder(); |
|
| 1152 | + return $root->getUserFolder($userId); |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * Returns an app-specific view in ownClouds data directory |
|
| 1157 | + * |
|
| 1158 | + * @return \OCP\Files\Folder |
|
| 1159 | + * @deprecated since 9.2.0 use IAppData |
|
| 1160 | + */ |
|
| 1161 | + public function getAppFolder() { |
|
| 1162 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1163 | + $root = $this->getRootFolder(); |
|
| 1164 | + if (!$root->nodeExists($dir)) { |
|
| 1165 | + $folder = $root->newFolder($dir); |
|
| 1166 | + } else { |
|
| 1167 | + $folder = $root->get($dir); |
|
| 1168 | + } |
|
| 1169 | + return $folder; |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * @return \OC\User\Manager |
|
| 1174 | + */ |
|
| 1175 | + public function getUserManager() { |
|
| 1176 | + return $this->query('UserManager'); |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + /** |
|
| 1180 | + * @return \OC\Group\Manager |
|
| 1181 | + */ |
|
| 1182 | + public function getGroupManager() { |
|
| 1183 | + return $this->query('GroupManager'); |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + /** |
|
| 1187 | + * @return \OC\User\Session |
|
| 1188 | + */ |
|
| 1189 | + public function getUserSession() { |
|
| 1190 | + return $this->query('UserSession'); |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * @return \OCP\ISession |
|
| 1195 | + */ |
|
| 1196 | + public function getSession() { |
|
| 1197 | + return $this->query('UserSession')->getSession(); |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * @param \OCP\ISession $session |
|
| 1202 | + */ |
|
| 1203 | + public function setSession(\OCP\ISession $session) { |
|
| 1204 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1205 | + $this->query('UserSession')->setSession($session); |
|
| 1206 | + $this->query(Store::class)->setSession($session); |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + /** |
|
| 1210 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1211 | + */ |
|
| 1212 | + public function getTwoFactorAuthManager() { |
|
| 1213 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * @return \OC\NavigationManager |
|
| 1218 | + */ |
|
| 1219 | + public function getNavigationManager() { |
|
| 1220 | + return $this->query('NavigationManager'); |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * @return \OCP\IConfig |
|
| 1225 | + */ |
|
| 1226 | + public function getConfig() { |
|
| 1227 | + return $this->query('AllConfig'); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * @internal For internal use only |
|
| 1232 | + * @return \OC\SystemConfig |
|
| 1233 | + */ |
|
| 1234 | + public function getSystemConfig() { |
|
| 1235 | + return $this->query('SystemConfig'); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + /** |
|
| 1239 | + * Returns the app config manager |
|
| 1240 | + * |
|
| 1241 | + * @return \OCP\IAppConfig |
|
| 1242 | + */ |
|
| 1243 | + public function getAppConfig() { |
|
| 1244 | + return $this->query('AppConfig'); |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * @return \OCP\L10N\IFactory |
|
| 1249 | + */ |
|
| 1250 | + public function getL10NFactory() { |
|
| 1251 | + return $this->query('L10NFactory'); |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * get an L10N instance |
|
| 1256 | + * |
|
| 1257 | + * @param string $app appid |
|
| 1258 | + * @param string $lang |
|
| 1259 | + * @return IL10N |
|
| 1260 | + */ |
|
| 1261 | + public function getL10N($app, $lang = null) { |
|
| 1262 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + /** |
|
| 1266 | + * @return \OCP\IURLGenerator |
|
| 1267 | + */ |
|
| 1268 | + public function getURLGenerator() { |
|
| 1269 | + return $this->query('URLGenerator'); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + /** |
|
| 1273 | + * @return \OCP\IHelper |
|
| 1274 | + */ |
|
| 1275 | + public function getHelper() { |
|
| 1276 | + return $this->query('AppHelper'); |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * @return AppFetcher |
|
| 1281 | + */ |
|
| 1282 | + public function getAppFetcher() { |
|
| 1283 | + return $this->query('AppFetcher'); |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + /** |
|
| 1287 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1288 | + * getMemCacheFactory() instead. |
|
| 1289 | + * |
|
| 1290 | + * @return \OCP\ICache |
|
| 1291 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1292 | + */ |
|
| 1293 | + public function getCache() { |
|
| 1294 | + return $this->query('UserCache'); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + /** |
|
| 1298 | + * Returns an \OCP\CacheFactory instance |
|
| 1299 | + * |
|
| 1300 | + * @return \OCP\ICacheFactory |
|
| 1301 | + */ |
|
| 1302 | + public function getMemCacheFactory() { |
|
| 1303 | + return $this->query('MemCacheFactory'); |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * Returns an \OC\RedisFactory instance |
|
| 1308 | + * |
|
| 1309 | + * @return \OC\RedisFactory |
|
| 1310 | + */ |
|
| 1311 | + public function getGetRedisFactory() { |
|
| 1312 | + return $this->query('RedisFactory'); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * Returns the current session |
|
| 1318 | + * |
|
| 1319 | + * @return \OCP\IDBConnection |
|
| 1320 | + */ |
|
| 1321 | + public function getDatabaseConnection() { |
|
| 1322 | + return $this->query('DatabaseConnection'); |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * Returns the activity manager |
|
| 1327 | + * |
|
| 1328 | + * @return \OCP\Activity\IManager |
|
| 1329 | + */ |
|
| 1330 | + public function getActivityManager() { |
|
| 1331 | + return $this->query('ActivityManager'); |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * Returns an job list for controlling background jobs |
|
| 1336 | + * |
|
| 1337 | + * @return \OCP\BackgroundJob\IJobList |
|
| 1338 | + */ |
|
| 1339 | + public function getJobList() { |
|
| 1340 | + return $this->query('JobList'); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + /** |
|
| 1344 | + * Returns a logger instance |
|
| 1345 | + * |
|
| 1346 | + * @return \OCP\ILogger |
|
| 1347 | + */ |
|
| 1348 | + public function getLogger() { |
|
| 1349 | + return $this->query('Logger'); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * Returns a router for generating and matching urls |
|
| 1354 | + * |
|
| 1355 | + * @return \OCP\Route\IRouter |
|
| 1356 | + */ |
|
| 1357 | + public function getRouter() { |
|
| 1358 | + return $this->query('Router'); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * Returns a search instance |
|
| 1363 | + * |
|
| 1364 | + * @return \OCP\ISearch |
|
| 1365 | + */ |
|
| 1366 | + public function getSearch() { |
|
| 1367 | + return $this->query('Search'); |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + /** |
|
| 1371 | + * Returns a SecureRandom instance |
|
| 1372 | + * |
|
| 1373 | + * @return \OCP\Security\ISecureRandom |
|
| 1374 | + */ |
|
| 1375 | + public function getSecureRandom() { |
|
| 1376 | + return $this->query('SecureRandom'); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * Returns a Crypto instance |
|
| 1381 | + * |
|
| 1382 | + * @return \OCP\Security\ICrypto |
|
| 1383 | + */ |
|
| 1384 | + public function getCrypto() { |
|
| 1385 | + return $this->query('Crypto'); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * Returns a Hasher instance |
|
| 1390 | + * |
|
| 1391 | + * @return \OCP\Security\IHasher |
|
| 1392 | + */ |
|
| 1393 | + public function getHasher() { |
|
| 1394 | + return $this->query('Hasher'); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Returns a CredentialsManager instance |
|
| 1399 | + * |
|
| 1400 | + * @return \OCP\Security\ICredentialsManager |
|
| 1401 | + */ |
|
| 1402 | + public function getCredentialsManager() { |
|
| 1403 | + return $this->query('CredentialsManager'); |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * Returns an instance of the HTTP helper class |
|
| 1408 | + * |
|
| 1409 | + * @deprecated Use getHTTPClientService() |
|
| 1410 | + * @return \OC\HTTPHelper |
|
| 1411 | + */ |
|
| 1412 | + public function getHTTPHelper() { |
|
| 1413 | + return $this->query('HTTPHelper'); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * Get the certificate manager for the user |
|
| 1418 | + * |
|
| 1419 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1420 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1421 | + */ |
|
| 1422 | + public function getCertificateManager($userId = '') { |
|
| 1423 | + if ($userId === '') { |
|
| 1424 | + $userSession = $this->getUserSession(); |
|
| 1425 | + $user = $userSession->getUser(); |
|
| 1426 | + if (is_null($user)) { |
|
| 1427 | + return null; |
|
| 1428 | + } |
|
| 1429 | + $userId = $user->getUID(); |
|
| 1430 | + } |
|
| 1431 | + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * Returns an instance of the HTTP client service |
|
| 1436 | + * |
|
| 1437 | + * @return \OCP\Http\Client\IClientService |
|
| 1438 | + */ |
|
| 1439 | + public function getHTTPClientService() { |
|
| 1440 | + return $this->query('HttpClientService'); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + /** |
|
| 1444 | + * Create a new event source |
|
| 1445 | + * |
|
| 1446 | + * @return \OCP\IEventSource |
|
| 1447 | + */ |
|
| 1448 | + public function createEventSource() { |
|
| 1449 | + return new \OC_EventSource(); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + /** |
|
| 1453 | + * Get the active event logger |
|
| 1454 | + * |
|
| 1455 | + * The returned logger only logs data when debug mode is enabled |
|
| 1456 | + * |
|
| 1457 | + * @return \OCP\Diagnostics\IEventLogger |
|
| 1458 | + */ |
|
| 1459 | + public function getEventLogger() { |
|
| 1460 | + return $this->query('EventLogger'); |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + /** |
|
| 1464 | + * Get the active query logger |
|
| 1465 | + * |
|
| 1466 | + * The returned logger only logs data when debug mode is enabled |
|
| 1467 | + * |
|
| 1468 | + * @return \OCP\Diagnostics\IQueryLogger |
|
| 1469 | + */ |
|
| 1470 | + public function getQueryLogger() { |
|
| 1471 | + return $this->query('QueryLogger'); |
|
| 1472 | + } |
|
| 1473 | + |
|
| 1474 | + /** |
|
| 1475 | + * Get the manager for temporary files and folders |
|
| 1476 | + * |
|
| 1477 | + * @return \OCP\ITempManager |
|
| 1478 | + */ |
|
| 1479 | + public function getTempManager() { |
|
| 1480 | + return $this->query('TempManager'); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * Get the app manager |
|
| 1485 | + * |
|
| 1486 | + * @return \OCP\App\IAppManager |
|
| 1487 | + */ |
|
| 1488 | + public function getAppManager() { |
|
| 1489 | + return $this->query('AppManager'); |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + /** |
|
| 1493 | + * Creates a new mailer |
|
| 1494 | + * |
|
| 1495 | + * @return \OCP\Mail\IMailer |
|
| 1496 | + */ |
|
| 1497 | + public function getMailer() { |
|
| 1498 | + return $this->query('Mailer'); |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + /** |
|
| 1502 | + * Get the webroot |
|
| 1503 | + * |
|
| 1504 | + * @return string |
|
| 1505 | + */ |
|
| 1506 | + public function getWebRoot() { |
|
| 1507 | + return $this->webRoot; |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + /** |
|
| 1511 | + * @return \OC\OCSClient |
|
| 1512 | + */ |
|
| 1513 | + public function getOcsClient() { |
|
| 1514 | + return $this->query('OcsClient'); |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * @return \OCP\IDateTimeZone |
|
| 1519 | + */ |
|
| 1520 | + public function getDateTimeZone() { |
|
| 1521 | + return $this->query('DateTimeZone'); |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + /** |
|
| 1525 | + * @return \OCP\IDateTimeFormatter |
|
| 1526 | + */ |
|
| 1527 | + public function getDateTimeFormatter() { |
|
| 1528 | + return $this->query('DateTimeFormatter'); |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1533 | + */ |
|
| 1534 | + public function getMountProviderCollection() { |
|
| 1535 | + return $this->query('MountConfigManager'); |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * Get the IniWrapper |
|
| 1540 | + * |
|
| 1541 | + * @return IniGetWrapper |
|
| 1542 | + */ |
|
| 1543 | + public function getIniWrapper() { |
|
| 1544 | + return $this->query('IniWrapper'); |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + /** |
|
| 1548 | + * @return \OCP\Command\IBus |
|
| 1549 | + */ |
|
| 1550 | + public function getCommandBus() { |
|
| 1551 | + return $this->query('AsyncCommandBus'); |
|
| 1552 | + } |
|
| 1553 | + |
|
| 1554 | + /** |
|
| 1555 | + * Get the trusted domain helper |
|
| 1556 | + * |
|
| 1557 | + * @return TrustedDomainHelper |
|
| 1558 | + */ |
|
| 1559 | + public function getTrustedDomainHelper() { |
|
| 1560 | + return $this->query('TrustedDomainHelper'); |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + /** |
|
| 1564 | + * Get the locking provider |
|
| 1565 | + * |
|
| 1566 | + * @return \OCP\Lock\ILockingProvider |
|
| 1567 | + * @since 8.1.0 |
|
| 1568 | + */ |
|
| 1569 | + public function getLockingProvider() { |
|
| 1570 | + return $this->query('LockingProvider'); |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * @return \OCP\Files\Mount\IMountManager |
|
| 1575 | + **/ |
|
| 1576 | + function getMountManager() { |
|
| 1577 | + return $this->query('MountManager'); |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1581 | + function getUserMountCache() { |
|
| 1582 | + return $this->query('UserMountCache'); |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + /** |
|
| 1586 | + * Get the MimeTypeDetector |
|
| 1587 | + * |
|
| 1588 | + * @return \OCP\Files\IMimeTypeDetector |
|
| 1589 | + */ |
|
| 1590 | + public function getMimeTypeDetector() { |
|
| 1591 | + return $this->query('MimeTypeDetector'); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + /** |
|
| 1595 | + * Get the MimeTypeLoader |
|
| 1596 | + * |
|
| 1597 | + * @return \OCP\Files\IMimeTypeLoader |
|
| 1598 | + */ |
|
| 1599 | + public function getMimeTypeLoader() { |
|
| 1600 | + return $this->query('MimeTypeLoader'); |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * Get the manager of all the capabilities |
|
| 1605 | + * |
|
| 1606 | + * @return \OC\CapabilitiesManager |
|
| 1607 | + */ |
|
| 1608 | + public function getCapabilitiesManager() { |
|
| 1609 | + return $this->query('CapabilitiesManager'); |
|
| 1610 | + } |
|
| 1611 | + |
|
| 1612 | + /** |
|
| 1613 | + * Get the EventDispatcher |
|
| 1614 | + * |
|
| 1615 | + * @return EventDispatcherInterface |
|
| 1616 | + * @since 8.2.0 |
|
| 1617 | + */ |
|
| 1618 | + public function getEventDispatcher() { |
|
| 1619 | + return $this->query('EventDispatcher'); |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * Get the Notification Manager |
|
| 1624 | + * |
|
| 1625 | + * @return \OCP\Notification\IManager |
|
| 1626 | + * @since 8.2.0 |
|
| 1627 | + */ |
|
| 1628 | + public function getNotificationManager() { |
|
| 1629 | + return $this->query('NotificationManager'); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + /** |
|
| 1633 | + * @return \OCP\Comments\ICommentsManager |
|
| 1634 | + */ |
|
| 1635 | + public function getCommentsManager() { |
|
| 1636 | + return $this->query('CommentsManager'); |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1641 | + */ |
|
| 1642 | + public function getThemingDefaults() { |
|
| 1643 | + return $this->query('ThemingDefaults'); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + /** |
|
| 1647 | + * @return \OC\IntegrityCheck\Checker |
|
| 1648 | + */ |
|
| 1649 | + public function getIntegrityCodeChecker() { |
|
| 1650 | + return $this->query('IntegrityCodeChecker'); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * @return \OC\Session\CryptoWrapper |
|
| 1655 | + */ |
|
| 1656 | + public function getSessionCryptoWrapper() { |
|
| 1657 | + return $this->query('CryptoWrapper'); |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * @return CsrfTokenManager |
|
| 1662 | + */ |
|
| 1663 | + public function getCsrfTokenManager() { |
|
| 1664 | + return $this->query('CsrfTokenManager'); |
|
| 1665 | + } |
|
| 1666 | + |
|
| 1667 | + /** |
|
| 1668 | + * @return Throttler |
|
| 1669 | + */ |
|
| 1670 | + public function getBruteForceThrottler() { |
|
| 1671 | + return $this->query('Throttler'); |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + /** |
|
| 1675 | + * @return IContentSecurityPolicyManager |
|
| 1676 | + */ |
|
| 1677 | + public function getContentSecurityPolicyManager() { |
|
| 1678 | + return $this->query('ContentSecurityPolicyManager'); |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + /** |
|
| 1682 | + * @return ContentSecurityPolicyNonceManager |
|
| 1683 | + */ |
|
| 1684 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1685 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1686 | + } |
|
| 1687 | + |
|
| 1688 | + /** |
|
| 1689 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1690 | + * |
|
| 1691 | + * @return \OCA\Files_External\Service\BackendService |
|
| 1692 | + */ |
|
| 1693 | + public function getStoragesBackendService() { |
|
| 1694 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1699 | + * |
|
| 1700 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1701 | + */ |
|
| 1702 | + public function getGlobalStoragesService() { |
|
| 1703 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1704 | + } |
|
| 1705 | + |
|
| 1706 | + /** |
|
| 1707 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1708 | + * |
|
| 1709 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1710 | + */ |
|
| 1711 | + public function getUserGlobalStoragesService() { |
|
| 1712 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + /** |
|
| 1716 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1717 | + * |
|
| 1718 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1719 | + */ |
|
| 1720 | + public function getUserStoragesService() { |
|
| 1721 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + /** |
|
| 1725 | + * @return \OCP\Share\IManager |
|
| 1726 | + */ |
|
| 1727 | + public function getShareManager() { |
|
| 1728 | + return $this->query('ShareManager'); |
|
| 1729 | + } |
|
| 1730 | + |
|
| 1731 | + /** |
|
| 1732 | + * Returns the LDAP Provider |
|
| 1733 | + * |
|
| 1734 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 1735 | + */ |
|
| 1736 | + public function getLDAPProvider() { |
|
| 1737 | + return $this->query('LDAPProvider'); |
|
| 1738 | + } |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * @return \OCP\Settings\IManager |
|
| 1742 | + */ |
|
| 1743 | + public function getSettingsManager() { |
|
| 1744 | + return $this->query('SettingsManager'); |
|
| 1745 | + } |
|
| 1746 | + |
|
| 1747 | + /** |
|
| 1748 | + * @return \OCP\Files\IAppData |
|
| 1749 | + */ |
|
| 1750 | + public function getAppDataDir($app) { |
|
| 1751 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1752 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1753 | + return $factory->get($app); |
|
| 1754 | + } |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 1758 | + */ |
|
| 1759 | + public function getLockdownManager() { |
|
| 1760 | + return $this->query('LockdownManager'); |
|
| 1761 | + } |
|
| 1762 | + |
|
| 1763 | + /** |
|
| 1764 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1765 | + */ |
|
| 1766 | + public function getCloudIdManager() { |
|
| 1767 | + return $this->query(ICloudIdManager::class); |
|
| 1768 | + } |
|
| 1769 | 1769 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
| 138 | 138 | $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
| 139 | 139 | |
| 140 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 140 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
| 141 | 141 | return new PreviewManager( |
| 142 | 142 | $c->getConfig(), |
| 143 | 143 | $c->getRootFolder(), |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | }); |
| 149 | 149 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
| 150 | 150 | |
| 151 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 151 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
| 152 | 152 | return new \OC\Preview\Watcher( |
| 153 | 153 | $c->getAppDataDir('preview') |
| 154 | 154 | ); |
| 155 | 155 | }); |
| 156 | 156 | |
| 157 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 157 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
| 158 | 158 | $view = new View(); |
| 159 | 159 | $util = new Encryption\Util( |
| 160 | 160 | $view, |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | ); |
| 173 | 173 | }); |
| 174 | 174 | |
| 175 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 175 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
| 176 | 176 | $util = new Encryption\Util( |
| 177 | 177 | new View(), |
| 178 | 178 | $c->getUserManager(), |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | ); |
| 187 | 187 | }); |
| 188 | 188 | |
| 189 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 189 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
| 190 | 190 | $view = new View(); |
| 191 | 191 | $util = new Encryption\Util( |
| 192 | 192 | $view, |
@@ -197,32 +197,32 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | return new Encryption\Keys\Storage($view, $util); |
| 199 | 199 | }); |
| 200 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 200 | + $this->registerService('TagMapper', function(Server $c) { |
|
| 201 | 201 | return new TagMapper($c->getDatabaseConnection()); |
| 202 | 202 | }); |
| 203 | 203 | |
| 204 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 204 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
| 205 | 205 | $tagMapper = $c->query('TagMapper'); |
| 206 | 206 | return new TagManager($tagMapper, $c->getUserSession()); |
| 207 | 207 | }); |
| 208 | 208 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
| 209 | 209 | |
| 210 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 210 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
| 211 | 211 | $config = $c->getConfig(); |
| 212 | 212 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
| 213 | 213 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
| 214 | 214 | $factory = new $factoryClass($this); |
| 215 | 215 | return $factory; |
| 216 | 216 | }); |
| 217 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 217 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
| 218 | 218 | return $c->query('SystemTagManagerFactory')->getManager(); |
| 219 | 219 | }); |
| 220 | 220 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
| 221 | 221 | |
| 222 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 222 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
| 223 | 223 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
| 224 | 224 | }); |
| 225 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 225 | + $this->registerService('RootFolder', function(Server $c) { |
|
| 226 | 226 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 227 | 227 | $view = new View(); |
| 228 | 228 | $root = new Root( |
@@ -250,30 +250,30 @@ discard block |
||
| 250 | 250 | }); |
| 251 | 251 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
| 252 | 252 | |
| 253 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 253 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
| 254 | 254 | $config = $c->getConfig(); |
| 255 | 255 | return new \OC\User\Manager($config); |
| 256 | 256 | }); |
| 257 | 257 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
| 258 | 258 | |
| 259 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 259 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
| 260 | 260 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
| 261 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 261 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 262 | 262 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
| 263 | 263 | }); |
| 264 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 264 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
| 265 | 265 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
| 266 | 266 | }); |
| 267 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 267 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 268 | 268 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
| 269 | 269 | }); |
| 270 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 270 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 271 | 271 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
| 272 | 272 | }); |
| 273 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 273 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 274 | 274 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 275 | 275 | }); |
| 276 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 276 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 277 | 277 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 278 | 278 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
| 279 | 279 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -293,11 +293,11 @@ discard block |
||
| 293 | 293 | return new Store($session, $logger, $tokenProvider); |
| 294 | 294 | }); |
| 295 | 295 | $this->registerAlias(IStore::class, Store::class); |
| 296 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 296 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
| 297 | 297 | $dbConnection = $c->getDatabaseConnection(); |
| 298 | 298 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
| 299 | 299 | }); |
| 300 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 300 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
| 301 | 301 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
| 302 | 302 | $crypto = $c->getCrypto(); |
| 303 | 303 | $config = $c->getConfig(); |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | }); |
| 308 | 308 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
| 309 | 309 | |
| 310 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 310 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
| 311 | 311 | $manager = $c->getUserManager(); |
| 312 | 312 | $session = new \OC\Session\Memory(''); |
| 313 | 313 | $timeFactory = new TimeFactory(); |
@@ -320,40 +320,40 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
| 323 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 323 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 324 | 324 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 325 | 325 | }); |
| 326 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 326 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 327 | 327 | /** @var $user \OC\User\User */ |
| 328 | 328 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
| 329 | 329 | }); |
| 330 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 330 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
| 331 | 331 | /** @var $user \OC\User\User */ |
| 332 | 332 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
| 333 | 333 | }); |
| 334 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 334 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 335 | 335 | /** @var $user \OC\User\User */ |
| 336 | 336 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
| 337 | 337 | }); |
| 338 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 338 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 339 | 339 | /** @var $user \OC\User\User */ |
| 340 | 340 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 341 | 341 | }); |
| 342 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 342 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 343 | 343 | /** @var $user \OC\User\User */ |
| 344 | 344 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 345 | 345 | }); |
| 346 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 346 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 347 | 347 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 348 | 348 | }); |
| 349 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 349 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
| 350 | 350 | /** @var $user \OC\User\User */ |
| 351 | 351 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 352 | 352 | }); |
| 353 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 353 | + $userSession->listen('\OC\User', 'logout', function() { |
|
| 354 | 354 | \OC_Hook::emit('OC_User', 'logout', array()); |
| 355 | 355 | }); |
| 356 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 356 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 357 | 357 | /** @var $user \OC\User\User */ |
| 358 | 358 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
| 359 | 359 | }); |
@@ -361,14 +361,14 @@ discard block |
||
| 361 | 361 | }); |
| 362 | 362 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
| 363 | 363 | |
| 364 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 364 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
| 365 | 365 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
| 366 | 366 | }); |
| 367 | 367 | |
| 368 | 368 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
| 369 | 369 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
| 370 | 370 | |
| 371 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 371 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
| 372 | 372 | return new \OC\AllConfig( |
| 373 | 373 | $c->getSystemConfig() |
| 374 | 374 | ); |
@@ -376,17 +376,17 @@ discard block |
||
| 376 | 376 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
| 377 | 377 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 378 | 378 | |
| 379 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 379 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
| 380 | 380 | return new \OC\SystemConfig($config); |
| 381 | 381 | }); |
| 382 | 382 | |
| 383 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 383 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
| 384 | 384 | return new \OC\AppConfig($c->getDatabaseConnection()); |
| 385 | 385 | }); |
| 386 | 386 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
| 387 | 387 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
| 388 | 388 | |
| 389 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 389 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
| 390 | 390 | return new \OC\L10N\Factory( |
| 391 | 391 | $c->getConfig(), |
| 392 | 392 | $c->getRequest(), |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | }); |
| 397 | 397 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
| 398 | 398 | |
| 399 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 399 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
| 400 | 400 | $config = $c->getConfig(); |
| 401 | 401 | $cacheFactory = $c->getMemCacheFactory(); |
| 402 | 402 | return new \OC\URLGenerator( |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | }); |
| 407 | 407 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
| 408 | 408 | |
| 409 | - $this->registerService('AppHelper', function ($c) { |
|
| 409 | + $this->registerService('AppHelper', function($c) { |
|
| 410 | 410 | return new \OC\AppHelper(); |
| 411 | 411 | }); |
| 412 | - $this->registerService('AppFetcher', function ($c) { |
|
| 412 | + $this->registerService('AppFetcher', function($c) { |
|
| 413 | 413 | return new AppFetcher( |
| 414 | 414 | $this->getAppDataDir('appstore'), |
| 415 | 415 | $this->getHTTPClientService(), |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $this->getConfig() |
| 418 | 418 | ); |
| 419 | 419 | }); |
| 420 | - $this->registerService('CategoryFetcher', function ($c) { |
|
| 420 | + $this->registerService('CategoryFetcher', function($c) { |
|
| 421 | 421 | return new CategoryFetcher( |
| 422 | 422 | $this->getAppDataDir('appstore'), |
| 423 | 423 | $this->getHTTPClientService(), |
@@ -426,21 +426,21 @@ discard block |
||
| 426 | 426 | ); |
| 427 | 427 | }); |
| 428 | 428 | |
| 429 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 429 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
| 430 | 430 | return new Cache\File(); |
| 431 | 431 | }); |
| 432 | 432 | $this->registerAlias('UserCache', \OCP\ICache::class); |
| 433 | 433 | |
| 434 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 434 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 435 | 435 | $config = $c->getConfig(); |
| 436 | 436 | |
| 437 | 437 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
| 438 | 438 | $v = \OC_App::getAppVersions(); |
| 439 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
| 439 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php')); |
|
| 440 | 440 | $version = implode(',', $v); |
| 441 | 441 | $instanceId = \OC_Util::getInstanceId(); |
| 442 | 442 | $path = \OC::$SERVERROOT; |
| 443 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
| 443 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT); |
|
| 444 | 444 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
| 445 | 445 | $config->getSystemValue('memcache.local', null), |
| 446 | 446 | $config->getSystemValue('memcache.distributed', null), |
@@ -457,12 +457,12 @@ discard block |
||
| 457 | 457 | $this->registerAlias('MemCacheFactory', Factory::class); |
| 458 | 458 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 459 | 459 | |
| 460 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 460 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 461 | 461 | $systemConfig = $c->getSystemConfig(); |
| 462 | 462 | return new RedisFactory($systemConfig); |
| 463 | 463 | }); |
| 464 | 464 | |
| 465 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 465 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 466 | 466 | return new \OC\Activity\Manager( |
| 467 | 467 | $c->getRequest(), |
| 468 | 468 | $c->getUserSession(), |
@@ -472,14 +472,14 @@ discard block |
||
| 472 | 472 | }); |
| 473 | 473 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 474 | 474 | |
| 475 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 475 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 476 | 476 | return new \OC\Activity\EventMerger( |
| 477 | 477 | $c->getL10N('lib') |
| 478 | 478 | ); |
| 479 | 479 | }); |
| 480 | 480 | $this->registerAlias(IValidator::class, Validator::class); |
| 481 | 481 | |
| 482 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 482 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
| 483 | 483 | return new AvatarManager( |
| 484 | 484 | $c->getUserManager(), |
| 485 | 485 | $c->getAppDataDir('avatar'), |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | }); |
| 491 | 491 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
| 492 | 492 | |
| 493 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 493 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
| 494 | 494 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
| 495 | 495 | $logger = Log::getLogClass($logType); |
| 496 | 496 | call_user_func(array($logger, 'init')); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | }); |
| 500 | 500 | $this->registerAlias('Logger', \OCP\ILogger::class); |
| 501 | 501 | |
| 502 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 502 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
| 503 | 503 | $config = $c->getConfig(); |
| 504 | 504 | return new \OC\BackgroundJob\JobList( |
| 505 | 505 | $c->getDatabaseConnection(), |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | }); |
| 510 | 510 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
| 511 | 511 | |
| 512 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 512 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
| 513 | 513 | $cacheFactory = $c->getMemCacheFactory(); |
| 514 | 514 | $logger = $c->getLogger(); |
| 515 | 515 | if ($cacheFactory->isAvailable()) { |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | }); |
| 522 | 522 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
| 523 | 523 | |
| 524 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 524 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
| 525 | 525 | return new Search(); |
| 526 | 526 | }); |
| 527 | 527 | $this->registerAlias('Search', \OCP\ISearch::class); |
@@ -541,27 +541,27 @@ discard block |
||
| 541 | 541 | ); |
| 542 | 542 | }); |
| 543 | 543 | |
| 544 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 544 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
| 545 | 545 | return new SecureRandom(); |
| 546 | 546 | }); |
| 547 | 547 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
| 548 | 548 | |
| 549 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 549 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
| 550 | 550 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
| 551 | 551 | }); |
| 552 | 552 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
| 553 | 553 | |
| 554 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 554 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
| 555 | 555 | return new Hasher($c->getConfig()); |
| 556 | 556 | }); |
| 557 | 557 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
| 558 | 558 | |
| 559 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 559 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
| 560 | 560 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
| 561 | 561 | }); |
| 562 | 562 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
| 563 | 563 | |
| 564 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 564 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
| 565 | 565 | $systemConfig = $c->getSystemConfig(); |
| 566 | 566 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 567 | 567 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | }); |
| 576 | 576 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
| 577 | 577 | |
| 578 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
| 578 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
| 579 | 579 | $config = $c->getConfig(); |
| 580 | 580 | return new HTTPHelper( |
| 581 | 581 | $config, |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | ); |
| 584 | 584 | }); |
| 585 | 585 | |
| 586 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 586 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
| 587 | 587 | $user = \OC_User::getUser(); |
| 588 | 588 | $uid = $user ? $user : null; |
| 589 | 589 | return new ClientService( |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | }); |
| 594 | 594 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
| 595 | 595 | |
| 596 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 596 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
| 597 | 597 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 598 | 598 | return new EventLogger(); |
| 599 | 599 | } else { |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | }); |
| 603 | 603 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
| 604 | 604 | |
| 605 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 605 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
| 606 | 606 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 607 | 607 | return new QueryLogger(); |
| 608 | 608 | } else { |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | }); |
| 612 | 612 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
| 613 | 613 | |
| 614 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 614 | + $this->registerService(TempManager::class, function(Server $c) { |
|
| 615 | 615 | return new TempManager( |
| 616 | 616 | $c->getLogger(), |
| 617 | 617 | $c->getConfig() |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | $this->registerAlias('TempManager', TempManager::class); |
| 621 | 621 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 622 | 622 | |
| 623 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 623 | + $this->registerService(AppManager::class, function(Server $c) { |
|
| 624 | 624 | return new \OC\App\AppManager( |
| 625 | 625 | $c->getUserSession(), |
| 626 | 626 | $c->getAppConfig(), |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | $this->registerAlias('AppManager', AppManager::class); |
| 633 | 633 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 634 | 634 | |
| 635 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 635 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
| 636 | 636 | return new DateTimeZone( |
| 637 | 637 | $c->getConfig(), |
| 638 | 638 | $c->getSession() |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | }); |
| 641 | 641 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
| 642 | 642 | |
| 643 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 643 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
| 644 | 644 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
| 645 | 645 | |
| 646 | 646 | return new DateTimeFormatter( |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | }); |
| 651 | 651 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
| 652 | 652 | |
| 653 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 653 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
| 654 | 654 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
| 655 | 655 | $listener = new UserMountCacheListener($mountCache); |
| 656 | 656 | $listener->listen($c->getUserManager()); |
@@ -658,10 +658,10 @@ discard block |
||
| 658 | 658 | }); |
| 659 | 659 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
| 660 | 660 | |
| 661 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 661 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
| 662 | 662 | $loader = \OC\Files\Filesystem::getLoader(); |
| 663 | 663 | $mountCache = $c->query('UserMountCache'); |
| 664 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 664 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 665 | 665 | |
| 666 | 666 | // builtin providers |
| 667 | 667 | |
@@ -674,14 +674,14 @@ discard block |
||
| 674 | 674 | }); |
| 675 | 675 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
| 676 | 676 | |
| 677 | - $this->registerService('IniWrapper', function ($c) { |
|
| 677 | + $this->registerService('IniWrapper', function($c) { |
|
| 678 | 678 | return new IniGetWrapper(); |
| 679 | 679 | }); |
| 680 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 680 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
| 681 | 681 | $jobList = $c->getJobList(); |
| 682 | 682 | return new AsyncBus($jobList); |
| 683 | 683 | }); |
| 684 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 684 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
| 685 | 685 | return new TrustedDomainHelper($this->getConfig()); |
| 686 | 686 | }); |
| 687 | 687 | $this->registerService('Throttler', function(Server $c) { |
@@ -692,10 +692,10 @@ discard block |
||
| 692 | 692 | $c->getConfig() |
| 693 | 693 | ); |
| 694 | 694 | }); |
| 695 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 695 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
| 696 | 696 | // IConfig and IAppManager requires a working database. This code |
| 697 | 697 | // might however be called when ownCloud is not yet setup. |
| 698 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 698 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 699 | 699 | $config = $c->getConfig(); |
| 700 | 700 | $appManager = $c->getAppManager(); |
| 701 | 701 | } else { |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | $c->getTempManager() |
| 714 | 714 | ); |
| 715 | 715 | }); |
| 716 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 716 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
| 717 | 717 | if (isset($this['urlParams'])) { |
| 718 | 718 | $urlParams = $this['urlParams']; |
| 719 | 719 | } else { |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | }); |
| 750 | 750 | $this->registerAlias('Request', \OCP\IRequest::class); |
| 751 | 751 | |
| 752 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 752 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
| 753 | 753 | return new Mailer( |
| 754 | 754 | $c->getConfig(), |
| 755 | 755 | $c->getLogger(), |
@@ -763,14 +763,14 @@ discard block |
||
| 763 | 763 | $this->registerService('LDAPProvider', function(Server $c) { |
| 764 | 764 | $config = $c->getConfig(); |
| 765 | 765 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 766 | - if(is_null($factoryClass)) { |
|
| 766 | + if (is_null($factoryClass)) { |
|
| 767 | 767 | throw new \Exception('ldapProviderFactory not set'); |
| 768 | 768 | } |
| 769 | 769 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
| 770 | 770 | $factory = new $factoryClass($this); |
| 771 | 771 | return $factory->getLDAPProvider(); |
| 772 | 772 | }); |
| 773 | - $this->registerService('LockingProvider', function (Server $c) { |
|
| 773 | + $this->registerService('LockingProvider', function(Server $c) { |
|
| 774 | 774 | $ini = $c->getIniWrapper(); |
| 775 | 775 | $config = $c->getConfig(); |
| 776 | 776 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -786,42 +786,42 @@ discard block |
||
| 786 | 786 | return new NoopLockingProvider(); |
| 787 | 787 | }); |
| 788 | 788 | |
| 789 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 789 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
| 790 | 790 | return new \OC\Files\Mount\Manager(); |
| 791 | 791 | }); |
| 792 | 792 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
| 793 | 793 | |
| 794 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 794 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
| 795 | 795 | return new \OC\Files\Type\Detection( |
| 796 | 796 | $c->getURLGenerator(), |
| 797 | 797 | \OC::$configDir, |
| 798 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 798 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 799 | 799 | ); |
| 800 | 800 | }); |
| 801 | 801 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
| 802 | 802 | |
| 803 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 803 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
| 804 | 804 | return new \OC\Files\Type\Loader( |
| 805 | 805 | $c->getDatabaseConnection() |
| 806 | 806 | ); |
| 807 | 807 | }); |
| 808 | 808 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
| 809 | - $this->registerService(BundleFetcher::class, function () { |
|
| 809 | + $this->registerService(BundleFetcher::class, function() { |
|
| 810 | 810 | return new BundleFetcher($this->getL10N('lib')); |
| 811 | 811 | }); |
| 812 | 812 | $this->registerService(AppFetcher::class, function() { |
| 813 | 813 | return $this->getAppFetcher(); |
| 814 | 814 | }); |
| 815 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 815 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
| 816 | 816 | return new Manager( |
| 817 | 817 | $c->query(IValidator::class) |
| 818 | 818 | ); |
| 819 | 819 | }); |
| 820 | 820 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 821 | 821 | |
| 822 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 822 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
| 823 | 823 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
| 824 | - $manager->registerCapability(function () use ($c) { |
|
| 824 | + $manager->registerCapability(function() use ($c) { |
|
| 825 | 825 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
| 826 | 826 | }); |
| 827 | 827 | return $manager; |
@@ -877,13 +877,13 @@ discard block |
||
| 877 | 877 | $cacheFactory->createLocal('SCSS') |
| 878 | 878 | ); |
| 879 | 879 | }); |
| 880 | - $this->registerService(EventDispatcher::class, function () { |
|
| 880 | + $this->registerService(EventDispatcher::class, function() { |
|
| 881 | 881 | return new EventDispatcher(); |
| 882 | 882 | }); |
| 883 | 883 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
| 884 | 884 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
| 885 | 885 | |
| 886 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 886 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
| 887 | 887 | // FIXME: Instantiiated here due to cyclic dependency |
| 888 | 888 | $request = new Request( |
| 889 | 889 | [ |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | $request |
| 909 | 909 | ); |
| 910 | 910 | }); |
| 911 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 911 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
| 912 | 912 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
| 913 | 913 | |
| 914 | 914 | return new CsrfTokenManager( |
@@ -916,10 +916,10 @@ discard block |
||
| 916 | 916 | $c->query(SessionStorage::class) |
| 917 | 917 | ); |
| 918 | 918 | }); |
| 919 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 919 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
| 920 | 920 | return new SessionStorage($c->getSession()); |
| 921 | 921 | }); |
| 922 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 922 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
| 923 | 923 | return new ContentSecurityPolicyManager(); |
| 924 | 924 | }); |
| 925 | 925 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
@@ -970,29 +970,29 @@ discard block |
||
| 970 | 970 | ); |
| 971 | 971 | return $manager; |
| 972 | 972 | }); |
| 973 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 973 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
| 974 | 974 | return new \OC\Files\AppData\Factory( |
| 975 | 975 | $c->getRootFolder(), |
| 976 | 976 | $c->getSystemConfig() |
| 977 | 977 | ); |
| 978 | 978 | }); |
| 979 | 979 | |
| 980 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 980 | + $this->registerService('LockdownManager', function(Server $c) { |
|
| 981 | 981 | return new LockdownManager(function() use ($c) { |
| 982 | 982 | return $c->getSession(); |
| 983 | 983 | }); |
| 984 | 984 | }); |
| 985 | 985 | |
| 986 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 986 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
| 987 | 987 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
| 988 | 988 | }); |
| 989 | 989 | |
| 990 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 990 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
| 991 | 991 | return new CloudIdManager(); |
| 992 | 992 | }); |
| 993 | 993 | |
| 994 | 994 | /* To trick DI since we don't extend the DIContainer here */ |
| 995 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 995 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
| 996 | 996 | return new CleanPreviewsBackgroundJob( |
| 997 | 997 | $c->getRootFolder(), |
| 998 | 998 | $c->getLogger(), |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1008 | 1008 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1009 | 1009 | |
| 1010 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1010 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1011 | 1011 | return new Defaults( |
| 1012 | 1012 | $c->getThemingDefaults() |
| 1013 | 1013 | ); |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | * @deprecated since 9.2.0 use IAppData |
| 1160 | 1160 | */ |
| 1161 | 1161 | public function getAppFolder() { |
| 1162 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1162 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
| 1163 | 1163 | $root = $this->getRootFolder(); |
| 1164 | 1164 | if (!$root->nodeExists($dir)) { |
| 1165 | 1165 | $folder = $root->newFolder($dir); |
@@ -51,176 +51,176 @@ |
||
| 51 | 51 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 52 | 52 | |
| 53 | 53 | class Repair implements IOutput{ |
| 54 | - /* @var IRepairStep[] */ |
|
| 55 | - private $repairSteps; |
|
| 56 | - /** @var EventDispatcher */ |
|
| 57 | - private $dispatcher; |
|
| 58 | - /** @var string */ |
|
| 59 | - private $currentStep; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Creates a new repair step runner |
|
| 63 | - * |
|
| 64 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 65 | - * @param EventDispatcher $dispatcher |
|
| 66 | - */ |
|
| 67 | - public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { |
|
| 68 | - $this->repairSteps = $repairSteps; |
|
| 69 | - $this->dispatcher = $dispatcher; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Run a series of repair steps for common problems |
|
| 74 | - */ |
|
| 75 | - public function run() { |
|
| 76 | - if (count($this->repairSteps) === 0) { |
|
| 77 | - $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 78 | - return; |
|
| 79 | - } |
|
| 80 | - // run each repair step |
|
| 81 | - foreach ($this->repairSteps as $step) { |
|
| 82 | - $this->currentStep = $step->getName(); |
|
| 83 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 84 | - $step->run($this); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Add repair step |
|
| 90 | - * |
|
| 91 | - * @param IRepairStep|string $repairStep repair step |
|
| 92 | - * @throws \Exception |
|
| 93 | - */ |
|
| 94 | - public function addStep($repairStep) { |
|
| 95 | - if (is_string($repairStep)) { |
|
| 96 | - try { |
|
| 97 | - $s = \OC::$server->query($repairStep); |
|
| 98 | - } catch (QueryException $e) { |
|
| 99 | - if (class_exists($repairStep)) { |
|
| 100 | - $s = new $repairStep(); |
|
| 101 | - } else { |
|
| 102 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($s instanceof IRepairStep) { |
|
| 107 | - $this->repairSteps[] = $s; |
|
| 108 | - } else { |
|
| 109 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 110 | - } |
|
| 111 | - } else { |
|
| 112 | - $this->repairSteps[] = $repairStep; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Returns the default repair steps to be run on the |
|
| 118 | - * command line or after an upgrade. |
|
| 119 | - * |
|
| 120 | - * @return IRepairStep[] |
|
| 121 | - */ |
|
| 122 | - public static function getRepairSteps() { |
|
| 123 | - return [ |
|
| 124 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 125 | - new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 126 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 127 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 128 | - new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 129 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 130 | - new MoveAvatars( |
|
| 131 | - \OC::$server->getJobList(), |
|
| 132 | - \OC::$server->getConfig() |
|
| 133 | - ), |
|
| 134 | - new CleanPreviews( |
|
| 135 | - \OC::$server->getJobList(), |
|
| 136 | - \OC::$server->getUserManager(), |
|
| 137 | - \OC::$server->getConfig() |
|
| 138 | - ), |
|
| 139 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 140 | - new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 141 | - new InstallCoreBundle( |
|
| 142 | - \OC::$server->query(BundleFetcher::class), |
|
| 143 | - \OC::$server->getConfig(), |
|
| 144 | - \OC::$server->query(Installer::class) |
|
| 145 | - ) |
|
| 146 | - ]; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Returns expensive repair steps to be run on the |
|
| 151 | - * command line with a special option. |
|
| 152 | - * |
|
| 153 | - * @return IRepairStep[] |
|
| 154 | - */ |
|
| 155 | - public static function getExpensiveRepairSteps() { |
|
| 156 | - return [ |
|
| 157 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 158 | - ]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Returns the repair steps to be run before an |
|
| 163 | - * upgrade. |
|
| 164 | - * |
|
| 165 | - * @return IRepairStep[] |
|
| 166 | - */ |
|
| 167 | - public static function getBeforeUpgradeRepairSteps() { |
|
| 168 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 169 | - $steps = [ |
|
| 170 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 171 | - new SqliteAutoincrement($connection), |
|
| 172 | - ]; |
|
| 173 | - |
|
| 174 | - return $steps; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param string $scope |
|
| 179 | - * @param string $method |
|
| 180 | - * @param array $arguments |
|
| 181 | - */ |
|
| 182 | - public function emit($scope, $method, array $arguments = []) { |
|
| 183 | - if (!is_null($this->dispatcher)) { |
|
| 184 | - $this->dispatcher->dispatch("$scope::$method", |
|
| 185 | - new GenericEvent("$scope::$method", $arguments)); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - public function info($string) { |
|
| 190 | - // for now just emit as we did in the past |
|
| 191 | - $this->emit('\OC\Repair', 'info', array($string)); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param string $message |
|
| 196 | - */ |
|
| 197 | - public function warning($message) { |
|
| 198 | - // for now just emit as we did in the past |
|
| 199 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param int $max |
|
| 204 | - */ |
|
| 205 | - public function startProgress($max = 0) { |
|
| 206 | - // for now just emit as we did in the past |
|
| 207 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param int $step |
|
| 212 | - * @param string $description |
|
| 213 | - */ |
|
| 214 | - public function advance($step = 1, $description = '') { |
|
| 215 | - // for now just emit as we did in the past |
|
| 216 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param int $max |
|
| 221 | - */ |
|
| 222 | - public function finishProgress() { |
|
| 223 | - // for now just emit as we did in the past |
|
| 224 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 225 | - } |
|
| 54 | + /* @var IRepairStep[] */ |
|
| 55 | + private $repairSteps; |
|
| 56 | + /** @var EventDispatcher */ |
|
| 57 | + private $dispatcher; |
|
| 58 | + /** @var string */ |
|
| 59 | + private $currentStep; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Creates a new repair step runner |
|
| 63 | + * |
|
| 64 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 65 | + * @param EventDispatcher $dispatcher |
|
| 66 | + */ |
|
| 67 | + public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { |
|
| 68 | + $this->repairSteps = $repairSteps; |
|
| 69 | + $this->dispatcher = $dispatcher; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Run a series of repair steps for common problems |
|
| 74 | + */ |
|
| 75 | + public function run() { |
|
| 76 | + if (count($this->repairSteps) === 0) { |
|
| 77 | + $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | + // run each repair step |
|
| 81 | + foreach ($this->repairSteps as $step) { |
|
| 82 | + $this->currentStep = $step->getName(); |
|
| 83 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 84 | + $step->run($this); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Add repair step |
|
| 90 | + * |
|
| 91 | + * @param IRepairStep|string $repairStep repair step |
|
| 92 | + * @throws \Exception |
|
| 93 | + */ |
|
| 94 | + public function addStep($repairStep) { |
|
| 95 | + if (is_string($repairStep)) { |
|
| 96 | + try { |
|
| 97 | + $s = \OC::$server->query($repairStep); |
|
| 98 | + } catch (QueryException $e) { |
|
| 99 | + if (class_exists($repairStep)) { |
|
| 100 | + $s = new $repairStep(); |
|
| 101 | + } else { |
|
| 102 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($s instanceof IRepairStep) { |
|
| 107 | + $this->repairSteps[] = $s; |
|
| 108 | + } else { |
|
| 109 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 110 | + } |
|
| 111 | + } else { |
|
| 112 | + $this->repairSteps[] = $repairStep; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Returns the default repair steps to be run on the |
|
| 118 | + * command line or after an upgrade. |
|
| 119 | + * |
|
| 120 | + * @return IRepairStep[] |
|
| 121 | + */ |
|
| 122 | + public static function getRepairSteps() { |
|
| 123 | + return [ |
|
| 124 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 125 | + new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 126 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 127 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 128 | + new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 129 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 130 | + new MoveAvatars( |
|
| 131 | + \OC::$server->getJobList(), |
|
| 132 | + \OC::$server->getConfig() |
|
| 133 | + ), |
|
| 134 | + new CleanPreviews( |
|
| 135 | + \OC::$server->getJobList(), |
|
| 136 | + \OC::$server->getUserManager(), |
|
| 137 | + \OC::$server->getConfig() |
|
| 138 | + ), |
|
| 139 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 140 | + new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 141 | + new InstallCoreBundle( |
|
| 142 | + \OC::$server->query(BundleFetcher::class), |
|
| 143 | + \OC::$server->getConfig(), |
|
| 144 | + \OC::$server->query(Installer::class) |
|
| 145 | + ) |
|
| 146 | + ]; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Returns expensive repair steps to be run on the |
|
| 151 | + * command line with a special option. |
|
| 152 | + * |
|
| 153 | + * @return IRepairStep[] |
|
| 154 | + */ |
|
| 155 | + public static function getExpensiveRepairSteps() { |
|
| 156 | + return [ |
|
| 157 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 158 | + ]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Returns the repair steps to be run before an |
|
| 163 | + * upgrade. |
|
| 164 | + * |
|
| 165 | + * @return IRepairStep[] |
|
| 166 | + */ |
|
| 167 | + public static function getBeforeUpgradeRepairSteps() { |
|
| 168 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 169 | + $steps = [ |
|
| 170 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 171 | + new SqliteAutoincrement($connection), |
|
| 172 | + ]; |
|
| 173 | + |
|
| 174 | + return $steps; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param string $scope |
|
| 179 | + * @param string $method |
|
| 180 | + * @param array $arguments |
|
| 181 | + */ |
|
| 182 | + public function emit($scope, $method, array $arguments = []) { |
|
| 183 | + if (!is_null($this->dispatcher)) { |
|
| 184 | + $this->dispatcher->dispatch("$scope::$method", |
|
| 185 | + new GenericEvent("$scope::$method", $arguments)); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + public function info($string) { |
|
| 190 | + // for now just emit as we did in the past |
|
| 191 | + $this->emit('\OC\Repair', 'info', array($string)); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param string $message |
|
| 196 | + */ |
|
| 197 | + public function warning($message) { |
|
| 198 | + // for now just emit as we did in the past |
|
| 199 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param int $max |
|
| 204 | + */ |
|
| 205 | + public function startProgress($max = 0) { |
|
| 206 | + // for now just emit as we did in the past |
|
| 207 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param int $step |
|
| 212 | + * @param string $description |
|
| 213 | + */ |
|
| 214 | + public function advance($step = 1, $description = '') { |
|
| 215 | + // for now just emit as we did in the past |
|
| 216 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param int $max |
|
| 221 | + */ |
|
| 222 | + public function finishProgress() { |
|
| 223 | + // for now just emit as we did in the past |
|
| 224 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 225 | + } |
|
| 226 | 226 | } |