@@ -63,1184 +63,1184 @@ |
||
| 63 | 63 | * upgrading and removing apps. |
| 64 | 64 | */ |
| 65 | 65 | class OC_App { |
| 66 | - static private $appVersion = []; |
|
| 67 | - static private $adminForms = array(); |
|
| 68 | - static private $personalForms = array(); |
|
| 69 | - static private $appInfo = array(); |
|
| 70 | - static private $appTypes = array(); |
|
| 71 | - static private $loadedApps = array(); |
|
| 72 | - static private $altLogin = array(); |
|
| 73 | - static private $alreadyRegistered = []; |
|
| 74 | - const officialApp = 200; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * clean the appId |
|
| 78 | - * |
|
| 79 | - * @param string|boolean $app AppId that needs to be cleaned |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public static function cleanAppId($app) { |
|
| 83 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Check if an app is loaded |
|
| 88 | - * |
|
| 89 | - * @param string $app |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public static function isAppLoaded($app) { |
|
| 93 | - return in_array($app, self::$loadedApps, true); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * loads all apps |
|
| 98 | - * |
|
| 99 | - * @param string[] | string | null $types |
|
| 100 | - * @return bool |
|
| 101 | - * |
|
| 102 | - * This function walks through the ownCloud directory and loads all apps |
|
| 103 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
| 104 | - * exists. |
|
| 105 | - * |
|
| 106 | - * if $types is set, only apps of those types will be loaded |
|
| 107 | - */ |
|
| 108 | - public static function loadApps($types = null) { |
|
| 109 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 110 | - return false; |
|
| 111 | - } |
|
| 112 | - // Load the enabled apps here |
|
| 113 | - $apps = self::getEnabledApps(); |
|
| 114 | - |
|
| 115 | - // Add each apps' folder as allowed class path |
|
| 116 | - foreach($apps as $app) { |
|
| 117 | - $path = self::getAppPath($app); |
|
| 118 | - if($path !== false) { |
|
| 119 | - self::registerAutoloading($app, $path); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // prevent app.php from printing output |
|
| 124 | - ob_start(); |
|
| 125 | - foreach ($apps as $app) { |
|
| 126 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
| 127 | - self::loadApp($app); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - ob_end_clean(); |
|
| 131 | - |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * load a single app |
|
| 137 | - * |
|
| 138 | - * @param string $app |
|
| 139 | - */ |
|
| 140 | - public static function loadApp($app) { |
|
| 141 | - self::$loadedApps[] = $app; |
|
| 142 | - $appPath = self::getAppPath($app); |
|
| 143 | - if($appPath === false) { |
|
| 144 | - return; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // in case someone calls loadApp() directly |
|
| 148 | - self::registerAutoloading($app, $appPath); |
|
| 149 | - |
|
| 150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
| 151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 152 | - self::requireAppFile($app); |
|
| 153 | - if (self::isType($app, array('authentication'))) { |
|
| 154 | - // since authentication apps affect the "is app enabled for group" check, |
|
| 155 | - // the enabled apps cache needs to be cleared to make sure that the |
|
| 156 | - // next time getEnableApps() is called it will also include apps that were |
|
| 157 | - // enabled for groups |
|
| 158 | - self::$enabledAppsCache = array(); |
|
| 159 | - } |
|
| 160 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $info = self::getAppInfo($app); |
|
| 164 | - if (!empty($info['activity']['filters'])) { |
|
| 165 | - foreach ($info['activity']['filters'] as $filter) { |
|
| 166 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - if (!empty($info['activity']['settings'])) { |
|
| 170 | - foreach ($info['activity']['settings'] as $setting) { |
|
| 171 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - if (!empty($info['activity']['providers'])) { |
|
| 175 | - foreach ($info['activity']['providers'] as $provider) { |
|
| 176 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - if (!empty($info['collaboration']['plugins'])) { |
|
| 180 | - // deal with one or many plugin entries |
|
| 181 | - $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
| 182 | - [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
| 183 | - foreach ($plugins as $plugin) { |
|
| 184 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 185 | - $pluginInfo = [ |
|
| 186 | - 'shareType' => $plugin['@attributes']['share-type'], |
|
| 187 | - 'class' => $plugin['@value'], |
|
| 188 | - ]; |
|
| 189 | - \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
| 190 | - } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
| 191 | - \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @internal |
|
| 199 | - * @param string $app |
|
| 200 | - * @param string $path |
|
| 201 | - */ |
|
| 202 | - public static function registerAutoloading($app, $path) { |
|
| 203 | - $key = $app . '-' . $path; |
|
| 204 | - if(isset(self::$alreadyRegistered[$key])) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - self::$alreadyRegistered[$key] = true; |
|
| 209 | - |
|
| 210 | - // Register on PSR-4 composer autoloader |
|
| 211 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
| 212 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
| 213 | - |
|
| 214 | - if (file_exists($path . '/composer/autoload.php')) { |
|
| 215 | - require_once $path . '/composer/autoload.php'; |
|
| 216 | - } else { |
|
| 217 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 218 | - // Register on legacy autoloader |
|
| 219 | - \OC::$loader->addValidRoot($path); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // Register Test namespace only when testing |
|
| 223 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
| 224 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Load app.php from the given app |
|
| 230 | - * |
|
| 231 | - * @param string $app app name |
|
| 232 | - */ |
|
| 233 | - private static function requireAppFile($app) { |
|
| 234 | - try { |
|
| 235 | - // encapsulated here to avoid variable scope conflicts |
|
| 236 | - require_once $app . '/appinfo/app.php'; |
|
| 237 | - } catch (Error $ex) { |
|
| 238 | - \OC::$server->getLogger()->logException($ex); |
|
| 239 | - if (!\OC::$server->getAppManager()->isShipped($app)) { |
|
| 240 | - // Only disable apps which are not shipped |
|
| 241 | - self::disable($app); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * check if an app is of a specific type |
|
| 248 | - * |
|
| 249 | - * @param string $app |
|
| 250 | - * @param string|array $types |
|
| 251 | - * @return bool |
|
| 252 | - */ |
|
| 253 | - public static function isType($app, $types) { |
|
| 254 | - if (is_string($types)) { |
|
| 255 | - $types = array($types); |
|
| 256 | - } |
|
| 257 | - $appTypes = self::getAppTypes($app); |
|
| 258 | - foreach ($types as $type) { |
|
| 259 | - if (array_search($type, $appTypes) !== false) { |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * get the types of an app |
|
| 268 | - * |
|
| 269 | - * @param string $app |
|
| 270 | - * @return array |
|
| 271 | - */ |
|
| 272 | - private static function getAppTypes($app) { |
|
| 273 | - //load the cache |
|
| 274 | - if (count(self::$appTypes) == 0) { |
|
| 275 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - if (isset(self::$appTypes[$app])) { |
|
| 279 | - return explode(',', self::$appTypes[$app]); |
|
| 280 | - } else { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * read app types from info.xml and cache them in the database |
|
| 287 | - */ |
|
| 288 | - public static function setAppTypes($app) { |
|
| 289 | - $appData = self::getAppInfo($app); |
|
| 290 | - if(!is_array($appData)) { |
|
| 291 | - return; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (isset($appData['types'])) { |
|
| 295 | - $appTypes = implode(',', $appData['types']); |
|
| 296 | - } else { |
|
| 297 | - $appTypes = ''; |
|
| 298 | - $appData['types'] = []; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
| 302 | - |
|
| 303 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
| 304 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
| 305 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
| 306 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * get all enabled apps |
|
| 313 | - */ |
|
| 314 | - protected static $enabledAppsCache = array(); |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Returns apps enabled for the current user. |
|
| 318 | - * |
|
| 319 | - * @param bool $forceRefresh whether to refresh the cache |
|
| 320 | - * @param bool $all whether to return apps for all users, not only the |
|
| 321 | - * currently logged in one |
|
| 322 | - * @return string[] |
|
| 323 | - */ |
|
| 324 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
| 325 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 326 | - return array(); |
|
| 327 | - } |
|
| 328 | - // in incognito mode or when logged out, $user will be false, |
|
| 329 | - // which is also the case during an upgrade |
|
| 330 | - $appManager = \OC::$server->getAppManager(); |
|
| 331 | - if ($all) { |
|
| 332 | - $user = null; |
|
| 333 | - } else { |
|
| 334 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if (is_null($user)) { |
|
| 338 | - $apps = $appManager->getInstalledApps(); |
|
| 339 | - } else { |
|
| 340 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
| 341 | - } |
|
| 342 | - $apps = array_filter($apps, function ($app) { |
|
| 343 | - return $app !== 'files';//we add this manually |
|
| 344 | - }); |
|
| 345 | - sort($apps); |
|
| 346 | - array_unshift($apps, 'files'); |
|
| 347 | - return $apps; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * checks whether or not an app is enabled |
|
| 352 | - * |
|
| 353 | - * @param string $app app |
|
| 354 | - * @return bool |
|
| 355 | - * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
| 356 | - * |
|
| 357 | - * This function checks whether or not an app is enabled. |
|
| 358 | - */ |
|
| 359 | - public static function isEnabled($app) { |
|
| 360 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * enables an app |
|
| 365 | - * |
|
| 366 | - * @param string $appId |
|
| 367 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
| 368 | - * @throws \Exception |
|
| 369 | - * @return void |
|
| 370 | - * |
|
| 371 | - * This function set an app as enabled in appconfig. |
|
| 372 | - */ |
|
| 373 | - public function enable($appId, |
|
| 374 | - $groups = null) { |
|
| 375 | - self::$enabledAppsCache = []; // flush |
|
| 376 | - |
|
| 377 | - // Check if app is already downloaded |
|
| 378 | - $installer = \OC::$server->query(Installer::class); |
|
| 379 | - $isDownloaded = $installer->isDownloaded($appId); |
|
| 380 | - |
|
| 381 | - if(!$isDownloaded) { |
|
| 382 | - $installer->downloadApp($appId); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - $installer->installApp($appId); |
|
| 386 | - |
|
| 387 | - $appManager = \OC::$server->getAppManager(); |
|
| 388 | - if (!is_null($groups)) { |
|
| 389 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 390 | - $groupsList = []; |
|
| 391 | - foreach ($groups as $group) { |
|
| 392 | - $groupItem = $groupManager->get($group); |
|
| 393 | - if ($groupItem instanceof \OCP\IGroup) { |
|
| 394 | - $groupsList[] = $groupManager->get($group); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
| 398 | - } else { |
|
| 399 | - $appManager->enableApp($appId); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @param string $app |
|
| 405 | - * @return bool |
|
| 406 | - */ |
|
| 407 | - public static function removeApp($app) { |
|
| 408 | - if (\OC::$server->getAppManager()->isShipped($app)) { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $installer = \OC::$server->query(Installer::class); |
|
| 413 | - return $installer->removeApp($app); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * This function set an app as disabled in appconfig. |
|
| 418 | - * |
|
| 419 | - * @param string $app app |
|
| 420 | - * @throws Exception |
|
| 421 | - */ |
|
| 422 | - public static function disable($app) { |
|
| 423 | - // flush |
|
| 424 | - self::$enabledAppsCache = array(); |
|
| 425 | - |
|
| 426 | - // run uninstall steps |
|
| 427 | - $appData = OC_App::getAppInfo($app); |
|
| 428 | - if (!is_null($appData)) { |
|
| 429 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // emit disable hook - needed anymore ? |
|
| 433 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
| 434 | - |
|
| 435 | - // finally disable it |
|
| 436 | - $appManager = \OC::$server->getAppManager(); |
|
| 437 | - $appManager->disableApp($app); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // This is private as well. It simply works, so don't ask for more details |
|
| 441 | - private static function proceedNavigation($list) { |
|
| 442 | - usort($list, function($a, $b) { |
|
| 443 | - if (isset($a['order']) && isset($b['order'])) { |
|
| 444 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 445 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
| 446 | - return isset($a['order']) ? -1 : 1; |
|
| 447 | - } else { |
|
| 448 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 449 | - } |
|
| 450 | - }); |
|
| 451 | - |
|
| 452 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
| 453 | - foreach ($list as $index => &$navEntry) { |
|
| 454 | - if ($navEntry['id'] == $activeApp) { |
|
| 455 | - $navEntry['active'] = true; |
|
| 456 | - } else { |
|
| 457 | - $navEntry['active'] = false; |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - unset($navEntry); |
|
| 461 | - |
|
| 462 | - return $list; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Get the path where to install apps |
|
| 467 | - * |
|
| 468 | - * @return string|false |
|
| 469 | - */ |
|
| 470 | - public static function getInstallPath() { |
|
| 471 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - foreach (OC::$APPSROOTS as $dir) { |
|
| 476 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
| 477 | - return $dir['path']; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
| 482 | - return null; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * search for an app in all app-directories |
|
| 488 | - * |
|
| 489 | - * @param string $appId |
|
| 490 | - * @return false|string |
|
| 491 | - */ |
|
| 492 | - public static function findAppInDirectories($appId) { |
|
| 493 | - $sanitizedAppId = self::cleanAppId($appId); |
|
| 494 | - if($sanitizedAppId !== $appId) { |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - static $app_dir = array(); |
|
| 498 | - |
|
| 499 | - if (isset($app_dir[$appId])) { |
|
| 500 | - return $app_dir[$appId]; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $possibleApps = array(); |
|
| 504 | - foreach (OC::$APPSROOTS as $dir) { |
|
| 505 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 506 | - $possibleApps[] = $dir; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if (empty($possibleApps)) { |
|
| 511 | - return false; |
|
| 512 | - } elseif (count($possibleApps) === 1) { |
|
| 513 | - $dir = array_shift($possibleApps); |
|
| 514 | - $app_dir[$appId] = $dir; |
|
| 515 | - return $dir; |
|
| 516 | - } else { |
|
| 517 | - $versionToLoad = array(); |
|
| 518 | - foreach ($possibleApps as $possibleApp) { |
|
| 519 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
| 520 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
| 521 | - $versionToLoad = array( |
|
| 522 | - 'dir' => $possibleApp, |
|
| 523 | - 'version' => $version, |
|
| 524 | - ); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
| 528 | - return $versionToLoad['dir']; |
|
| 529 | - //TODO - write test |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Get the directory for the given app. |
|
| 535 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 536 | - * |
|
| 537 | - * @param string $appId |
|
| 538 | - * @return string|false |
|
| 539 | - */ |
|
| 540 | - public static function getAppPath($appId) { |
|
| 541 | - if ($appId === null || trim($appId) === '') { |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 546 | - return $dir['path'] . '/' . $appId; |
|
| 547 | - } |
|
| 548 | - return false; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Get the path for the given app on the access |
|
| 553 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 554 | - * |
|
| 555 | - * @param string $appId |
|
| 556 | - * @return string|false |
|
| 557 | - */ |
|
| 558 | - public static function getAppWebPath($appId) { |
|
| 559 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 560 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 561 | - } |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * get the last version of the app from appinfo/info.xml |
|
| 567 | - * |
|
| 568 | - * @param string $appId |
|
| 569 | - * @param bool $useCache |
|
| 570 | - * @return string |
|
| 571 | - */ |
|
| 572 | - public static function getAppVersion($appId, $useCache = true) { |
|
| 573 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
| 574 | - return self::$appVersion[$appId]; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $file = self::getAppPath($appId); |
|
| 578 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
| 579 | - return self::$appVersion[$appId]; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * get app's version based on it's path |
|
| 584 | - * |
|
| 585 | - * @param string $path |
|
| 586 | - * @return string |
|
| 587 | - */ |
|
| 588 | - public static function getAppVersionByPath($path) { |
|
| 589 | - $infoFile = $path . '/appinfo/info.xml'; |
|
| 590 | - $appData = self::getAppInfo($infoFile, true); |
|
| 591 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Read all app metadata from the info.xml file |
|
| 597 | - * |
|
| 598 | - * @param string $appId id of the app or the path of the info.xml file |
|
| 599 | - * @param bool $path |
|
| 600 | - * @param string $lang |
|
| 601 | - * @return array|null |
|
| 602 | - * @note all data is read from info.xml, not just pre-defined fields |
|
| 603 | - */ |
|
| 604 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
| 605 | - if ($path) { |
|
| 606 | - $file = $appId; |
|
| 607 | - } else { |
|
| 608 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
| 609 | - return self::$appInfo[$appId]; |
|
| 610 | - } |
|
| 611 | - $appPath = self::getAppPath($appId); |
|
| 612 | - if($appPath === false) { |
|
| 613 | - return null; |
|
| 614 | - } |
|
| 615 | - $file = $appPath . '/appinfo/info.xml'; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
|
| 619 | - $data = $parser->parse($file); |
|
| 620 | - |
|
| 621 | - if (is_array($data)) { |
|
| 622 | - $data = OC_App::parseAppInfo($data, $lang); |
|
| 623 | - } |
|
| 624 | - if(isset($data['ocsid'])) { |
|
| 625 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
| 626 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 627 | - $data['ocsid'] = $storedId; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ($lang === null) { |
|
| 632 | - self::$appInfo[$appId] = $data; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - return $data; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Returns the navigation |
|
| 640 | - * |
|
| 641 | - * @return array |
|
| 642 | - * |
|
| 643 | - * This function returns an array containing all entries added. The |
|
| 644 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
| 645 | - * given for each app the following keys exist: |
|
| 646 | - * - active: boolean, signals if the user is on this navigation entry |
|
| 647 | - */ |
|
| 648 | - public static function getNavigation() { |
|
| 649 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
| 650 | - return self::proceedNavigation($entries); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Returns the Settings Navigation |
|
| 655 | - * |
|
| 656 | - * @return string[] |
|
| 657 | - * |
|
| 658 | - * This function returns an array containing all settings pages added. The |
|
| 659 | - * entries are sorted by the key 'order' ascending. |
|
| 660 | - */ |
|
| 661 | - public static function getSettingsNavigation() { |
|
| 662 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
| 663 | - return self::proceedNavigation($entries); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * get the id of loaded app |
|
| 668 | - * |
|
| 669 | - * @return string |
|
| 670 | - */ |
|
| 671 | - public static function getCurrentApp() { |
|
| 672 | - $request = \OC::$server->getRequest(); |
|
| 673 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
| 674 | - $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
| 675 | - if (empty($topFolder)) { |
|
| 676 | - $path_info = $request->getPathInfo(); |
|
| 677 | - if ($path_info) { |
|
| 678 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - if ($topFolder == 'apps') { |
|
| 682 | - $length = strlen($topFolder); |
|
| 683 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
| 684 | - } else { |
|
| 685 | - return $topFolder; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * @param string $type |
|
| 691 | - * @return array |
|
| 692 | - */ |
|
| 693 | - public static function getForms($type) { |
|
| 694 | - $forms = array(); |
|
| 695 | - switch ($type) { |
|
| 696 | - case 'admin': |
|
| 697 | - $source = self::$adminForms; |
|
| 698 | - break; |
|
| 699 | - case 'personal': |
|
| 700 | - $source = self::$personalForms; |
|
| 701 | - break; |
|
| 702 | - default: |
|
| 703 | - return array(); |
|
| 704 | - } |
|
| 705 | - foreach ($source as $form) { |
|
| 706 | - $forms[] = include $form; |
|
| 707 | - } |
|
| 708 | - return $forms; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * register an admin form to be shown |
|
| 713 | - * |
|
| 714 | - * @param string $app |
|
| 715 | - * @param string $page |
|
| 716 | - */ |
|
| 717 | - public static function registerAdmin($app, $page) { |
|
| 718 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * register a personal form to be shown |
|
| 723 | - * @param string $app |
|
| 724 | - * @param string $page |
|
| 725 | - */ |
|
| 726 | - public static function registerPersonal($app, $page) { |
|
| 727 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * @param array $entry |
|
| 732 | - */ |
|
| 733 | - public static function registerLogIn(array $entry) { |
|
| 734 | - self::$altLogin[] = $entry; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * @return array |
|
| 739 | - */ |
|
| 740 | - public static function getAlternativeLogIns() { |
|
| 741 | - return self::$altLogin; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * get a list of all apps in the apps folder |
|
| 746 | - * |
|
| 747 | - * @return array an array of app names (string IDs) |
|
| 748 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
| 749 | - */ |
|
| 750 | - public static function getAllApps() { |
|
| 751 | - |
|
| 752 | - $apps = array(); |
|
| 753 | - |
|
| 754 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
| 755 | - if (!is_readable($apps_dir['path'])) { |
|
| 756 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 757 | - continue; |
|
| 758 | - } |
|
| 759 | - $dh = opendir($apps_dir['path']); |
|
| 760 | - |
|
| 761 | - if (is_resource($dh)) { |
|
| 762 | - while (($file = readdir($dh)) !== false) { |
|
| 763 | - |
|
| 764 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 765 | - |
|
| 766 | - $apps[] = $file; |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - $apps = array_unique($apps); |
|
| 773 | - |
|
| 774 | - return $apps; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * List all apps, this is used in apps.php |
|
| 779 | - * |
|
| 780 | - * @return array |
|
| 781 | - */ |
|
| 782 | - public function listAllApps() { |
|
| 783 | - $installedApps = OC_App::getAllApps(); |
|
| 784 | - |
|
| 785 | - $appManager = \OC::$server->getAppManager(); |
|
| 786 | - //we don't want to show configuration for these |
|
| 787 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
| 788 | - $appList = array(); |
|
| 789 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
| 790 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 791 | - |
|
| 792 | - foreach ($installedApps as $app) { |
|
| 793 | - if (array_search($app, $blacklist) === false) { |
|
| 794 | - |
|
| 795 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
| 796 | - if (!is_array($info)) { |
|
| 797 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 798 | - continue; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - if (!isset($info['name'])) { |
|
| 802 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 803 | - continue; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
| 807 | - $info['groups'] = null; |
|
| 808 | - if ($enabled === 'yes') { |
|
| 809 | - $active = true; |
|
| 810 | - } else if ($enabled === 'no') { |
|
| 811 | - $active = false; |
|
| 812 | - } else { |
|
| 813 | - $active = true; |
|
| 814 | - $info['groups'] = $enabled; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $info['active'] = $active; |
|
| 818 | - |
|
| 819 | - if ($appManager->isShipped($app)) { |
|
| 820 | - $info['internal'] = true; |
|
| 821 | - $info['level'] = self::officialApp; |
|
| 822 | - $info['removable'] = false; |
|
| 823 | - } else { |
|
| 824 | - $info['internal'] = false; |
|
| 825 | - $info['removable'] = true; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - $appPath = self::getAppPath($app); |
|
| 829 | - if($appPath !== false) { |
|
| 830 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 831 | - if (file_exists($appIcon)) { |
|
| 832 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
| 833 | - $info['previewAsIcon'] = true; |
|
| 834 | - } else { |
|
| 835 | - $appIcon = $appPath . '/img/app.svg'; |
|
| 836 | - if (file_exists($appIcon)) { |
|
| 837 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
| 838 | - $info['previewAsIcon'] = true; |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - // fix documentation |
|
| 843 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
| 844 | - foreach ($info['documentation'] as $key => $url) { |
|
| 845 | - // If it is not an absolute URL we assume it is a key |
|
| 846 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
| 847 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
| 848 | - $url = $urlGenerator->linkToDocs($url); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - $info['documentation'][$key] = $url; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - $info['version'] = OC_App::getAppVersion($app); |
|
| 856 | - $appList[] = $info; |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - return $appList; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - public static function shouldUpgrade($app) { |
|
| 864 | - $versions = self::getAppVersions(); |
|
| 865 | - $currentVersion = OC_App::getAppVersion($app); |
|
| 866 | - if ($currentVersion && isset($versions[$app])) { |
|
| 867 | - $installedVersion = $versions[$app]; |
|
| 868 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
| 869 | - return true; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - return false; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Adjust the number of version parts of $version1 to match |
|
| 877 | - * the number of version parts of $version2. |
|
| 878 | - * |
|
| 879 | - * @param string $version1 version to adjust |
|
| 880 | - * @param string $version2 version to take the number of parts from |
|
| 881 | - * @return string shortened $version1 |
|
| 882 | - */ |
|
| 883 | - private static function adjustVersionParts($version1, $version2) { |
|
| 884 | - $version1 = explode('.', $version1); |
|
| 885 | - $version2 = explode('.', $version2); |
|
| 886 | - // reduce $version1 to match the number of parts in $version2 |
|
| 887 | - while (count($version1) > count($version2)) { |
|
| 888 | - array_pop($version1); |
|
| 889 | - } |
|
| 890 | - // if $version1 does not have enough parts, add some |
|
| 891 | - while (count($version1) < count($version2)) { |
|
| 892 | - $version1[] = '0'; |
|
| 893 | - } |
|
| 894 | - return implode('.', $version1); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Check whether the current ownCloud version matches the given |
|
| 899 | - * application's version requirements. |
|
| 900 | - * |
|
| 901 | - * The comparison is made based on the number of parts that the |
|
| 902 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
| 903 | - * app info version is expecting version 6.0, the comparison is |
|
| 904 | - * made on the first two parts of the ownCloud version. |
|
| 905 | - * This means that it's possible to specify "requiremin" => 6 |
|
| 906 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
| 907 | - * |
|
| 908 | - * @param string $ocVersion ownCloud version to check against |
|
| 909 | - * @param array $appInfo app info (from xml) |
|
| 910 | - * |
|
| 911 | - * @return boolean true if compatible, otherwise false |
|
| 912 | - */ |
|
| 913 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
| 914 | - $requireMin = ''; |
|
| 915 | - $requireMax = ''; |
|
| 916 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 917 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
| 918 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 919 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
| 920 | - } else if (isset($appInfo['requiremin'])) { |
|
| 921 | - $requireMin = $appInfo['requiremin']; |
|
| 922 | - } else if (isset($appInfo['require'])) { |
|
| 923 | - $requireMin = $appInfo['require']; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 927 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
| 928 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 929 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
| 930 | - } else if (isset($appInfo['requiremax'])) { |
|
| 931 | - $requireMax = $appInfo['requiremax']; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - if (is_array($ocVersion)) { |
|
| 935 | - $ocVersion = implode('.', $ocVersion); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - if (!empty($requireMin) |
|
| 939 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
| 940 | - ) { |
|
| 941 | - |
|
| 942 | - return false; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - if (!empty($requireMax) |
|
| 946 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
| 947 | - ) { |
|
| 948 | - return false; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return true; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * get the installed version of all apps |
|
| 956 | - */ |
|
| 957 | - public static function getAppVersions() { |
|
| 958 | - static $versions; |
|
| 959 | - |
|
| 960 | - if(!$versions) { |
|
| 961 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 962 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
| 963 | - } |
|
| 964 | - return $versions; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * @param string $app |
|
| 969 | - * @param \OCP\IConfig $config |
|
| 970 | - * @param \OCP\IL10N $l |
|
| 971 | - * @return bool |
|
| 972 | - * |
|
| 973 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
| 974 | - * @throws Exception if no app-name was specified |
|
| 975 | - */ |
|
| 976 | - public function installApp($app, |
|
| 977 | - \OCP\IConfig $config, |
|
| 978 | - \OCP\IL10N $l) { |
|
| 979 | - if ($app !== false) { |
|
| 980 | - // check if the app is compatible with this version of ownCloud |
|
| 981 | - $info = self::getAppInfo($app); |
|
| 982 | - if(!is_array($info)) { |
|
| 983 | - throw new \Exception( |
|
| 984 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 985 | - [$info['name']] |
|
| 986 | - ) |
|
| 987 | - ); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - $version = \OCP\Util::getVersion(); |
|
| 991 | - if (!self::isAppCompatible($version, $info)) { |
|
| 992 | - throw new \Exception( |
|
| 993 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 994 | - array($info['name']) |
|
| 995 | - ) |
|
| 996 | - ); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - // check for required dependencies |
|
| 1000 | - self::checkAppDependencies($config, $l, $info); |
|
| 1001 | - |
|
| 1002 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
| 1003 | - if (isset($appData['id'])) { |
|
| 1004 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1008 | - $appPath = self::getAppPath($app); |
|
| 1009 | - self::registerAutoloading($app, $appPath); |
|
| 1010 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
| 1014 | - } else { |
|
| 1015 | - if(empty($appName) ) { |
|
| 1016 | - throw new \Exception($l->t("No app name specified")); |
|
| 1017 | - } else { |
|
| 1018 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - return $app; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * update the database for the app and call the update script |
|
| 1027 | - * |
|
| 1028 | - * @param string $appId |
|
| 1029 | - * @return bool |
|
| 1030 | - */ |
|
| 1031 | - public static function updateApp($appId) { |
|
| 1032 | - $appPath = self::getAppPath($appId); |
|
| 1033 | - if($appPath === false) { |
|
| 1034 | - return false; |
|
| 1035 | - } |
|
| 1036 | - self::registerAutoloading($appId, $appPath); |
|
| 1037 | - |
|
| 1038 | - $appData = self::getAppInfo($appId); |
|
| 1039 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
| 1040 | - |
|
| 1041 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1042 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1043 | - } else { |
|
| 1044 | - $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
| 1045 | - $ms->migrate(); |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
| 1049 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
| 1050 | - unset(self::$appVersion[$appId]); |
|
| 1051 | - |
|
| 1052 | - // run upgrade code |
|
| 1053 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1054 | - self::loadApp($appId); |
|
| 1055 | - include $appPath . '/appinfo/update.php'; |
|
| 1056 | - } |
|
| 1057 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
| 1058 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1059 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - //set remote/public handlers |
|
| 1063 | - if (array_key_exists('ocsid', $appData)) { |
|
| 1064 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
| 1065 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1066 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
| 1067 | - } |
|
| 1068 | - foreach ($appData['remote'] as $name => $path) { |
|
| 1069 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1070 | - } |
|
| 1071 | - foreach ($appData['public'] as $name => $path) { |
|
| 1072 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - self::setAppTypes($appId); |
|
| 1076 | - |
|
| 1077 | - $version = \OC_App::getAppVersion($appId); |
|
| 1078 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
| 1079 | - |
|
| 1080 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
| 1081 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
| 1082 | - )); |
|
| 1083 | - |
|
| 1084 | - return true; |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * @param string $appId |
|
| 1089 | - * @param string[] $steps |
|
| 1090 | - * @throws \OC\NeedsUpdateException |
|
| 1091 | - */ |
|
| 1092 | - public static function executeRepairSteps($appId, array $steps) { |
|
| 1093 | - if (empty($steps)) { |
|
| 1094 | - return; |
|
| 1095 | - } |
|
| 1096 | - // load the app |
|
| 1097 | - self::loadApp($appId); |
|
| 1098 | - |
|
| 1099 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
| 1100 | - |
|
| 1101 | - // load the steps |
|
| 1102 | - $r = new Repair([], $dispatcher); |
|
| 1103 | - foreach ($steps as $step) { |
|
| 1104 | - try { |
|
| 1105 | - $r->addStep($step); |
|
| 1106 | - } catch (Exception $ex) { |
|
| 1107 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
| 1108 | - \OC::$server->getLogger()->logException($ex); |
|
| 1109 | - } |
|
| 1110 | - } |
|
| 1111 | - // run the steps |
|
| 1112 | - $r->run(); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - public static function setupBackgroundJobs(array $jobs) { |
|
| 1116 | - $queue = \OC::$server->getJobList(); |
|
| 1117 | - foreach ($jobs as $job) { |
|
| 1118 | - $queue->add($job); |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - /** |
|
| 1123 | - * @param string $appId |
|
| 1124 | - * @param string[] $steps |
|
| 1125 | - */ |
|
| 1126 | - private static function setupLiveMigrations($appId, array $steps) { |
|
| 1127 | - $queue = \OC::$server->getJobList(); |
|
| 1128 | - foreach ($steps as $step) { |
|
| 1129 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
| 1130 | - 'app' => $appId, |
|
| 1131 | - 'step' => $step]); |
|
| 1132 | - } |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * @param string $appId |
|
| 1137 | - * @return \OC\Files\View|false |
|
| 1138 | - */ |
|
| 1139 | - public static function getStorage($appId) { |
|
| 1140 | - if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
| 1141 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1142 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1143 | - if (!$view->file_exists($appId)) { |
|
| 1144 | - $view->mkdir($appId); |
|
| 1145 | - } |
|
| 1146 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1147 | - } else { |
|
| 1148 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1149 | - return false; |
|
| 1150 | - } |
|
| 1151 | - } else { |
|
| 1152 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1153 | - return false; |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - protected static function findBestL10NOption($options, $lang) { |
|
| 1158 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
| 1159 | - |
|
| 1160 | - $lang = strtolower($lang); |
|
| 1161 | - $similarLang = $lang; |
|
| 1162 | - if (strpos($similarLang, '_')) { |
|
| 1163 | - // For "de_DE" we want to find "de" and the other way around |
|
| 1164 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - foreach ($options as $option) { |
|
| 1168 | - if (is_array($option)) { |
|
| 1169 | - if ($fallback === false) { |
|
| 1170 | - $fallback = $option['@value']; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - if (!isset($option['@attributes']['lang'])) { |
|
| 1174 | - continue; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 1178 | - if ($attributeLang === $lang) { |
|
| 1179 | - return $option['@value']; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - if ($attributeLang === $similarLang) { |
|
| 1183 | - $similarLangFallback = $option['@value']; |
|
| 1184 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1185 | - if ($similarLangFallback === false) { |
|
| 1186 | - $similarLangFallback = $option['@value']; |
|
| 1187 | - } |
|
| 1188 | - } |
|
| 1189 | - } else { |
|
| 1190 | - $englishFallback = $option; |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - if ($similarLangFallback !== false) { |
|
| 1195 | - return $similarLangFallback; |
|
| 1196 | - } else if ($englishFallback !== false) { |
|
| 1197 | - return $englishFallback; |
|
| 1198 | - } |
|
| 1199 | - return (string) $fallback; |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * parses the app data array and enhanced the 'description' value |
|
| 1204 | - * |
|
| 1205 | - * @param array $data the app data |
|
| 1206 | - * @param string $lang |
|
| 1207 | - * @return array improved app data |
|
| 1208 | - */ |
|
| 1209 | - public static function parseAppInfo(array $data, $lang = null) { |
|
| 1210 | - |
|
| 1211 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
| 1212 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
| 1213 | - } |
|
| 1214 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
| 1215 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
| 1216 | - } |
|
| 1217 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
| 1218 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
| 1219 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
| 1220 | - $data['description'] = trim($data['description']); |
|
| 1221 | - } else { |
|
| 1222 | - $data['description'] = ''; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return $data; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - /** |
|
| 1229 | - * @param \OCP\IConfig $config |
|
| 1230 | - * @param \OCP\IL10N $l |
|
| 1231 | - * @param array $info |
|
| 1232 | - * @throws \Exception |
|
| 1233 | - */ |
|
| 1234 | - public static function checkAppDependencies($config, $l, $info) { |
|
| 1235 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
| 1236 | - $missing = $dependencyAnalyzer->analyze($info); |
|
| 1237 | - if (!empty($missing)) { |
|
| 1238 | - $missingMsg = implode(PHP_EOL, $missing); |
|
| 1239 | - throw new \Exception( |
|
| 1240 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
| 1241 | - [$info['name'], $missingMsg] |
|
| 1242 | - ) |
|
| 1243 | - ); |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 66 | + static private $appVersion = []; |
|
| 67 | + static private $adminForms = array(); |
|
| 68 | + static private $personalForms = array(); |
|
| 69 | + static private $appInfo = array(); |
|
| 70 | + static private $appTypes = array(); |
|
| 71 | + static private $loadedApps = array(); |
|
| 72 | + static private $altLogin = array(); |
|
| 73 | + static private $alreadyRegistered = []; |
|
| 74 | + const officialApp = 200; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * clean the appId |
|
| 78 | + * |
|
| 79 | + * @param string|boolean $app AppId that needs to be cleaned |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public static function cleanAppId($app) { |
|
| 83 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Check if an app is loaded |
|
| 88 | + * |
|
| 89 | + * @param string $app |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public static function isAppLoaded($app) { |
|
| 93 | + return in_array($app, self::$loadedApps, true); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * loads all apps |
|
| 98 | + * |
|
| 99 | + * @param string[] | string | null $types |
|
| 100 | + * @return bool |
|
| 101 | + * |
|
| 102 | + * This function walks through the ownCloud directory and loads all apps |
|
| 103 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
| 104 | + * exists. |
|
| 105 | + * |
|
| 106 | + * if $types is set, only apps of those types will be loaded |
|
| 107 | + */ |
|
| 108 | + public static function loadApps($types = null) { |
|
| 109 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 110 | + return false; |
|
| 111 | + } |
|
| 112 | + // Load the enabled apps here |
|
| 113 | + $apps = self::getEnabledApps(); |
|
| 114 | + |
|
| 115 | + // Add each apps' folder as allowed class path |
|
| 116 | + foreach($apps as $app) { |
|
| 117 | + $path = self::getAppPath($app); |
|
| 118 | + if($path !== false) { |
|
| 119 | + self::registerAutoloading($app, $path); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // prevent app.php from printing output |
|
| 124 | + ob_start(); |
|
| 125 | + foreach ($apps as $app) { |
|
| 126 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
| 127 | + self::loadApp($app); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + ob_end_clean(); |
|
| 131 | + |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * load a single app |
|
| 137 | + * |
|
| 138 | + * @param string $app |
|
| 139 | + */ |
|
| 140 | + public static function loadApp($app) { |
|
| 141 | + self::$loadedApps[] = $app; |
|
| 142 | + $appPath = self::getAppPath($app); |
|
| 143 | + if($appPath === false) { |
|
| 144 | + return; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // in case someone calls loadApp() directly |
|
| 148 | + self::registerAutoloading($app, $appPath); |
|
| 149 | + |
|
| 150 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
| 151 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 152 | + self::requireAppFile($app); |
|
| 153 | + if (self::isType($app, array('authentication'))) { |
|
| 154 | + // since authentication apps affect the "is app enabled for group" check, |
|
| 155 | + // the enabled apps cache needs to be cleared to make sure that the |
|
| 156 | + // next time getEnableApps() is called it will also include apps that were |
|
| 157 | + // enabled for groups |
|
| 158 | + self::$enabledAppsCache = array(); |
|
| 159 | + } |
|
| 160 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $info = self::getAppInfo($app); |
|
| 164 | + if (!empty($info['activity']['filters'])) { |
|
| 165 | + foreach ($info['activity']['filters'] as $filter) { |
|
| 166 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + if (!empty($info['activity']['settings'])) { |
|
| 170 | + foreach ($info['activity']['settings'] as $setting) { |
|
| 171 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + if (!empty($info['activity']['providers'])) { |
|
| 175 | + foreach ($info['activity']['providers'] as $provider) { |
|
| 176 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + if (!empty($info['collaboration']['plugins'])) { |
|
| 180 | + // deal with one or many plugin entries |
|
| 181 | + $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
| 182 | + [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
| 183 | + foreach ($plugins as $plugin) { |
|
| 184 | + if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 185 | + $pluginInfo = [ |
|
| 186 | + 'shareType' => $plugin['@attributes']['share-type'], |
|
| 187 | + 'class' => $plugin['@value'], |
|
| 188 | + ]; |
|
| 189 | + \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
| 190 | + } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
| 191 | + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @internal |
|
| 199 | + * @param string $app |
|
| 200 | + * @param string $path |
|
| 201 | + */ |
|
| 202 | + public static function registerAutoloading($app, $path) { |
|
| 203 | + $key = $app . '-' . $path; |
|
| 204 | + if(isset(self::$alreadyRegistered[$key])) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + self::$alreadyRegistered[$key] = true; |
|
| 209 | + |
|
| 210 | + // Register on PSR-4 composer autoloader |
|
| 211 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
| 212 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
| 213 | + |
|
| 214 | + if (file_exists($path . '/composer/autoload.php')) { |
|
| 215 | + require_once $path . '/composer/autoload.php'; |
|
| 216 | + } else { |
|
| 217 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 218 | + // Register on legacy autoloader |
|
| 219 | + \OC::$loader->addValidRoot($path); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // Register Test namespace only when testing |
|
| 223 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
| 224 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Load app.php from the given app |
|
| 230 | + * |
|
| 231 | + * @param string $app app name |
|
| 232 | + */ |
|
| 233 | + private static function requireAppFile($app) { |
|
| 234 | + try { |
|
| 235 | + // encapsulated here to avoid variable scope conflicts |
|
| 236 | + require_once $app . '/appinfo/app.php'; |
|
| 237 | + } catch (Error $ex) { |
|
| 238 | + \OC::$server->getLogger()->logException($ex); |
|
| 239 | + if (!\OC::$server->getAppManager()->isShipped($app)) { |
|
| 240 | + // Only disable apps which are not shipped |
|
| 241 | + self::disable($app); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * check if an app is of a specific type |
|
| 248 | + * |
|
| 249 | + * @param string $app |
|
| 250 | + * @param string|array $types |
|
| 251 | + * @return bool |
|
| 252 | + */ |
|
| 253 | + public static function isType($app, $types) { |
|
| 254 | + if (is_string($types)) { |
|
| 255 | + $types = array($types); |
|
| 256 | + } |
|
| 257 | + $appTypes = self::getAppTypes($app); |
|
| 258 | + foreach ($types as $type) { |
|
| 259 | + if (array_search($type, $appTypes) !== false) { |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * get the types of an app |
|
| 268 | + * |
|
| 269 | + * @param string $app |
|
| 270 | + * @return array |
|
| 271 | + */ |
|
| 272 | + private static function getAppTypes($app) { |
|
| 273 | + //load the cache |
|
| 274 | + if (count(self::$appTypes) == 0) { |
|
| 275 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + if (isset(self::$appTypes[$app])) { |
|
| 279 | + return explode(',', self::$appTypes[$app]); |
|
| 280 | + } else { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * read app types from info.xml and cache them in the database |
|
| 287 | + */ |
|
| 288 | + public static function setAppTypes($app) { |
|
| 289 | + $appData = self::getAppInfo($app); |
|
| 290 | + if(!is_array($appData)) { |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (isset($appData['types'])) { |
|
| 295 | + $appTypes = implode(',', $appData['types']); |
|
| 296 | + } else { |
|
| 297 | + $appTypes = ''; |
|
| 298 | + $appData['types'] = []; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
| 302 | + |
|
| 303 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
| 304 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
| 305 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
| 306 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * get all enabled apps |
|
| 313 | + */ |
|
| 314 | + protected static $enabledAppsCache = array(); |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Returns apps enabled for the current user. |
|
| 318 | + * |
|
| 319 | + * @param bool $forceRefresh whether to refresh the cache |
|
| 320 | + * @param bool $all whether to return apps for all users, not only the |
|
| 321 | + * currently logged in one |
|
| 322 | + * @return string[] |
|
| 323 | + */ |
|
| 324 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
| 325 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 326 | + return array(); |
|
| 327 | + } |
|
| 328 | + // in incognito mode or when logged out, $user will be false, |
|
| 329 | + // which is also the case during an upgrade |
|
| 330 | + $appManager = \OC::$server->getAppManager(); |
|
| 331 | + if ($all) { |
|
| 332 | + $user = null; |
|
| 333 | + } else { |
|
| 334 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if (is_null($user)) { |
|
| 338 | + $apps = $appManager->getInstalledApps(); |
|
| 339 | + } else { |
|
| 340 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
| 341 | + } |
|
| 342 | + $apps = array_filter($apps, function ($app) { |
|
| 343 | + return $app !== 'files';//we add this manually |
|
| 344 | + }); |
|
| 345 | + sort($apps); |
|
| 346 | + array_unshift($apps, 'files'); |
|
| 347 | + return $apps; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * checks whether or not an app is enabled |
|
| 352 | + * |
|
| 353 | + * @param string $app app |
|
| 354 | + * @return bool |
|
| 355 | + * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
| 356 | + * |
|
| 357 | + * This function checks whether or not an app is enabled. |
|
| 358 | + */ |
|
| 359 | + public static function isEnabled($app) { |
|
| 360 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * enables an app |
|
| 365 | + * |
|
| 366 | + * @param string $appId |
|
| 367 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
| 368 | + * @throws \Exception |
|
| 369 | + * @return void |
|
| 370 | + * |
|
| 371 | + * This function set an app as enabled in appconfig. |
|
| 372 | + */ |
|
| 373 | + public function enable($appId, |
|
| 374 | + $groups = null) { |
|
| 375 | + self::$enabledAppsCache = []; // flush |
|
| 376 | + |
|
| 377 | + // Check if app is already downloaded |
|
| 378 | + $installer = \OC::$server->query(Installer::class); |
|
| 379 | + $isDownloaded = $installer->isDownloaded($appId); |
|
| 380 | + |
|
| 381 | + if(!$isDownloaded) { |
|
| 382 | + $installer->downloadApp($appId); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + $installer->installApp($appId); |
|
| 386 | + |
|
| 387 | + $appManager = \OC::$server->getAppManager(); |
|
| 388 | + if (!is_null($groups)) { |
|
| 389 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 390 | + $groupsList = []; |
|
| 391 | + foreach ($groups as $group) { |
|
| 392 | + $groupItem = $groupManager->get($group); |
|
| 393 | + if ($groupItem instanceof \OCP\IGroup) { |
|
| 394 | + $groupsList[] = $groupManager->get($group); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
| 398 | + } else { |
|
| 399 | + $appManager->enableApp($appId); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @param string $app |
|
| 405 | + * @return bool |
|
| 406 | + */ |
|
| 407 | + public static function removeApp($app) { |
|
| 408 | + if (\OC::$server->getAppManager()->isShipped($app)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $installer = \OC::$server->query(Installer::class); |
|
| 413 | + return $installer->removeApp($app); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * This function set an app as disabled in appconfig. |
|
| 418 | + * |
|
| 419 | + * @param string $app app |
|
| 420 | + * @throws Exception |
|
| 421 | + */ |
|
| 422 | + public static function disable($app) { |
|
| 423 | + // flush |
|
| 424 | + self::$enabledAppsCache = array(); |
|
| 425 | + |
|
| 426 | + // run uninstall steps |
|
| 427 | + $appData = OC_App::getAppInfo($app); |
|
| 428 | + if (!is_null($appData)) { |
|
| 429 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // emit disable hook - needed anymore ? |
|
| 433 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
| 434 | + |
|
| 435 | + // finally disable it |
|
| 436 | + $appManager = \OC::$server->getAppManager(); |
|
| 437 | + $appManager->disableApp($app); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // This is private as well. It simply works, so don't ask for more details |
|
| 441 | + private static function proceedNavigation($list) { |
|
| 442 | + usort($list, function($a, $b) { |
|
| 443 | + if (isset($a['order']) && isset($b['order'])) { |
|
| 444 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 445 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
| 446 | + return isset($a['order']) ? -1 : 1; |
|
| 447 | + } else { |
|
| 448 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 449 | + } |
|
| 450 | + }); |
|
| 451 | + |
|
| 452 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
| 453 | + foreach ($list as $index => &$navEntry) { |
|
| 454 | + if ($navEntry['id'] == $activeApp) { |
|
| 455 | + $navEntry['active'] = true; |
|
| 456 | + } else { |
|
| 457 | + $navEntry['active'] = false; |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + unset($navEntry); |
|
| 461 | + |
|
| 462 | + return $list; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Get the path where to install apps |
|
| 467 | + * |
|
| 468 | + * @return string|false |
|
| 469 | + */ |
|
| 470 | + public static function getInstallPath() { |
|
| 471 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + foreach (OC::$APPSROOTS as $dir) { |
|
| 476 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
| 477 | + return $dir['path']; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
| 482 | + return null; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * search for an app in all app-directories |
|
| 488 | + * |
|
| 489 | + * @param string $appId |
|
| 490 | + * @return false|string |
|
| 491 | + */ |
|
| 492 | + public static function findAppInDirectories($appId) { |
|
| 493 | + $sanitizedAppId = self::cleanAppId($appId); |
|
| 494 | + if($sanitizedAppId !== $appId) { |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + static $app_dir = array(); |
|
| 498 | + |
|
| 499 | + if (isset($app_dir[$appId])) { |
|
| 500 | + return $app_dir[$appId]; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $possibleApps = array(); |
|
| 504 | + foreach (OC::$APPSROOTS as $dir) { |
|
| 505 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 506 | + $possibleApps[] = $dir; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if (empty($possibleApps)) { |
|
| 511 | + return false; |
|
| 512 | + } elseif (count($possibleApps) === 1) { |
|
| 513 | + $dir = array_shift($possibleApps); |
|
| 514 | + $app_dir[$appId] = $dir; |
|
| 515 | + return $dir; |
|
| 516 | + } else { |
|
| 517 | + $versionToLoad = array(); |
|
| 518 | + foreach ($possibleApps as $possibleApp) { |
|
| 519 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
| 520 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
| 521 | + $versionToLoad = array( |
|
| 522 | + 'dir' => $possibleApp, |
|
| 523 | + 'version' => $version, |
|
| 524 | + ); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
| 528 | + return $versionToLoad['dir']; |
|
| 529 | + //TODO - write test |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Get the directory for the given app. |
|
| 535 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 536 | + * |
|
| 537 | + * @param string $appId |
|
| 538 | + * @return string|false |
|
| 539 | + */ |
|
| 540 | + public static function getAppPath($appId) { |
|
| 541 | + if ($appId === null || trim($appId) === '') { |
|
| 542 | + return false; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 546 | + return $dir['path'] . '/' . $appId; |
|
| 547 | + } |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Get the path for the given app on the access |
|
| 553 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 554 | + * |
|
| 555 | + * @param string $appId |
|
| 556 | + * @return string|false |
|
| 557 | + */ |
|
| 558 | + public static function getAppWebPath($appId) { |
|
| 559 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 560 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 561 | + } |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * get the last version of the app from appinfo/info.xml |
|
| 567 | + * |
|
| 568 | + * @param string $appId |
|
| 569 | + * @param bool $useCache |
|
| 570 | + * @return string |
|
| 571 | + */ |
|
| 572 | + public static function getAppVersion($appId, $useCache = true) { |
|
| 573 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
| 574 | + return self::$appVersion[$appId]; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $file = self::getAppPath($appId); |
|
| 578 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
| 579 | + return self::$appVersion[$appId]; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * get app's version based on it's path |
|
| 584 | + * |
|
| 585 | + * @param string $path |
|
| 586 | + * @return string |
|
| 587 | + */ |
|
| 588 | + public static function getAppVersionByPath($path) { |
|
| 589 | + $infoFile = $path . '/appinfo/info.xml'; |
|
| 590 | + $appData = self::getAppInfo($infoFile, true); |
|
| 591 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Read all app metadata from the info.xml file |
|
| 597 | + * |
|
| 598 | + * @param string $appId id of the app or the path of the info.xml file |
|
| 599 | + * @param bool $path |
|
| 600 | + * @param string $lang |
|
| 601 | + * @return array|null |
|
| 602 | + * @note all data is read from info.xml, not just pre-defined fields |
|
| 603 | + */ |
|
| 604 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
| 605 | + if ($path) { |
|
| 606 | + $file = $appId; |
|
| 607 | + } else { |
|
| 608 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
| 609 | + return self::$appInfo[$appId]; |
|
| 610 | + } |
|
| 611 | + $appPath = self::getAppPath($appId); |
|
| 612 | + if($appPath === false) { |
|
| 613 | + return null; |
|
| 614 | + } |
|
| 615 | + $file = $appPath . '/appinfo/info.xml'; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
|
| 619 | + $data = $parser->parse($file); |
|
| 620 | + |
|
| 621 | + if (is_array($data)) { |
|
| 622 | + $data = OC_App::parseAppInfo($data, $lang); |
|
| 623 | + } |
|
| 624 | + if(isset($data['ocsid'])) { |
|
| 625 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
| 626 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 627 | + $data['ocsid'] = $storedId; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ($lang === null) { |
|
| 632 | + self::$appInfo[$appId] = $data; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + return $data; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Returns the navigation |
|
| 640 | + * |
|
| 641 | + * @return array |
|
| 642 | + * |
|
| 643 | + * This function returns an array containing all entries added. The |
|
| 644 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
| 645 | + * given for each app the following keys exist: |
|
| 646 | + * - active: boolean, signals if the user is on this navigation entry |
|
| 647 | + */ |
|
| 648 | + public static function getNavigation() { |
|
| 649 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
| 650 | + return self::proceedNavigation($entries); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Returns the Settings Navigation |
|
| 655 | + * |
|
| 656 | + * @return string[] |
|
| 657 | + * |
|
| 658 | + * This function returns an array containing all settings pages added. The |
|
| 659 | + * entries are sorted by the key 'order' ascending. |
|
| 660 | + */ |
|
| 661 | + public static function getSettingsNavigation() { |
|
| 662 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
| 663 | + return self::proceedNavigation($entries); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * get the id of loaded app |
|
| 668 | + * |
|
| 669 | + * @return string |
|
| 670 | + */ |
|
| 671 | + public static function getCurrentApp() { |
|
| 672 | + $request = \OC::$server->getRequest(); |
|
| 673 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
| 674 | + $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
| 675 | + if (empty($topFolder)) { |
|
| 676 | + $path_info = $request->getPathInfo(); |
|
| 677 | + if ($path_info) { |
|
| 678 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + if ($topFolder == 'apps') { |
|
| 682 | + $length = strlen($topFolder); |
|
| 683 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
| 684 | + } else { |
|
| 685 | + return $topFolder; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * @param string $type |
|
| 691 | + * @return array |
|
| 692 | + */ |
|
| 693 | + public static function getForms($type) { |
|
| 694 | + $forms = array(); |
|
| 695 | + switch ($type) { |
|
| 696 | + case 'admin': |
|
| 697 | + $source = self::$adminForms; |
|
| 698 | + break; |
|
| 699 | + case 'personal': |
|
| 700 | + $source = self::$personalForms; |
|
| 701 | + break; |
|
| 702 | + default: |
|
| 703 | + return array(); |
|
| 704 | + } |
|
| 705 | + foreach ($source as $form) { |
|
| 706 | + $forms[] = include $form; |
|
| 707 | + } |
|
| 708 | + return $forms; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * register an admin form to be shown |
|
| 713 | + * |
|
| 714 | + * @param string $app |
|
| 715 | + * @param string $page |
|
| 716 | + */ |
|
| 717 | + public static function registerAdmin($app, $page) { |
|
| 718 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * register a personal form to be shown |
|
| 723 | + * @param string $app |
|
| 724 | + * @param string $page |
|
| 725 | + */ |
|
| 726 | + public static function registerPersonal($app, $page) { |
|
| 727 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * @param array $entry |
|
| 732 | + */ |
|
| 733 | + public static function registerLogIn(array $entry) { |
|
| 734 | + self::$altLogin[] = $entry; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * @return array |
|
| 739 | + */ |
|
| 740 | + public static function getAlternativeLogIns() { |
|
| 741 | + return self::$altLogin; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * get a list of all apps in the apps folder |
|
| 746 | + * |
|
| 747 | + * @return array an array of app names (string IDs) |
|
| 748 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
| 749 | + */ |
|
| 750 | + public static function getAllApps() { |
|
| 751 | + |
|
| 752 | + $apps = array(); |
|
| 753 | + |
|
| 754 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
| 755 | + if (!is_readable($apps_dir['path'])) { |
|
| 756 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 757 | + continue; |
|
| 758 | + } |
|
| 759 | + $dh = opendir($apps_dir['path']); |
|
| 760 | + |
|
| 761 | + if (is_resource($dh)) { |
|
| 762 | + while (($file = readdir($dh)) !== false) { |
|
| 763 | + |
|
| 764 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 765 | + |
|
| 766 | + $apps[] = $file; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + $apps = array_unique($apps); |
|
| 773 | + |
|
| 774 | + return $apps; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * List all apps, this is used in apps.php |
|
| 779 | + * |
|
| 780 | + * @return array |
|
| 781 | + */ |
|
| 782 | + public function listAllApps() { |
|
| 783 | + $installedApps = OC_App::getAllApps(); |
|
| 784 | + |
|
| 785 | + $appManager = \OC::$server->getAppManager(); |
|
| 786 | + //we don't want to show configuration for these |
|
| 787 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
| 788 | + $appList = array(); |
|
| 789 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
| 790 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 791 | + |
|
| 792 | + foreach ($installedApps as $app) { |
|
| 793 | + if (array_search($app, $blacklist) === false) { |
|
| 794 | + |
|
| 795 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
| 796 | + if (!is_array($info)) { |
|
| 797 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 798 | + continue; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + if (!isset($info['name'])) { |
|
| 802 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
| 807 | + $info['groups'] = null; |
|
| 808 | + if ($enabled === 'yes') { |
|
| 809 | + $active = true; |
|
| 810 | + } else if ($enabled === 'no') { |
|
| 811 | + $active = false; |
|
| 812 | + } else { |
|
| 813 | + $active = true; |
|
| 814 | + $info['groups'] = $enabled; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $info['active'] = $active; |
|
| 818 | + |
|
| 819 | + if ($appManager->isShipped($app)) { |
|
| 820 | + $info['internal'] = true; |
|
| 821 | + $info['level'] = self::officialApp; |
|
| 822 | + $info['removable'] = false; |
|
| 823 | + } else { |
|
| 824 | + $info['internal'] = false; |
|
| 825 | + $info['removable'] = true; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + $appPath = self::getAppPath($app); |
|
| 829 | + if($appPath !== false) { |
|
| 830 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 831 | + if (file_exists($appIcon)) { |
|
| 832 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
| 833 | + $info['previewAsIcon'] = true; |
|
| 834 | + } else { |
|
| 835 | + $appIcon = $appPath . '/img/app.svg'; |
|
| 836 | + if (file_exists($appIcon)) { |
|
| 837 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
| 838 | + $info['previewAsIcon'] = true; |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + // fix documentation |
|
| 843 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
| 844 | + foreach ($info['documentation'] as $key => $url) { |
|
| 845 | + // If it is not an absolute URL we assume it is a key |
|
| 846 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
| 847 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
| 848 | + $url = $urlGenerator->linkToDocs($url); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + $info['documentation'][$key] = $url; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + $info['version'] = OC_App::getAppVersion($app); |
|
| 856 | + $appList[] = $info; |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + return $appList; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + public static function shouldUpgrade($app) { |
|
| 864 | + $versions = self::getAppVersions(); |
|
| 865 | + $currentVersion = OC_App::getAppVersion($app); |
|
| 866 | + if ($currentVersion && isset($versions[$app])) { |
|
| 867 | + $installedVersion = $versions[$app]; |
|
| 868 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
| 869 | + return true; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + return false; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Adjust the number of version parts of $version1 to match |
|
| 877 | + * the number of version parts of $version2. |
|
| 878 | + * |
|
| 879 | + * @param string $version1 version to adjust |
|
| 880 | + * @param string $version2 version to take the number of parts from |
|
| 881 | + * @return string shortened $version1 |
|
| 882 | + */ |
|
| 883 | + private static function adjustVersionParts($version1, $version2) { |
|
| 884 | + $version1 = explode('.', $version1); |
|
| 885 | + $version2 = explode('.', $version2); |
|
| 886 | + // reduce $version1 to match the number of parts in $version2 |
|
| 887 | + while (count($version1) > count($version2)) { |
|
| 888 | + array_pop($version1); |
|
| 889 | + } |
|
| 890 | + // if $version1 does not have enough parts, add some |
|
| 891 | + while (count($version1) < count($version2)) { |
|
| 892 | + $version1[] = '0'; |
|
| 893 | + } |
|
| 894 | + return implode('.', $version1); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Check whether the current ownCloud version matches the given |
|
| 899 | + * application's version requirements. |
|
| 900 | + * |
|
| 901 | + * The comparison is made based on the number of parts that the |
|
| 902 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
| 903 | + * app info version is expecting version 6.0, the comparison is |
|
| 904 | + * made on the first two parts of the ownCloud version. |
|
| 905 | + * This means that it's possible to specify "requiremin" => 6 |
|
| 906 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
| 907 | + * |
|
| 908 | + * @param string $ocVersion ownCloud version to check against |
|
| 909 | + * @param array $appInfo app info (from xml) |
|
| 910 | + * |
|
| 911 | + * @return boolean true if compatible, otherwise false |
|
| 912 | + */ |
|
| 913 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
| 914 | + $requireMin = ''; |
|
| 915 | + $requireMax = ''; |
|
| 916 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 917 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
| 918 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 919 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
| 920 | + } else if (isset($appInfo['requiremin'])) { |
|
| 921 | + $requireMin = $appInfo['requiremin']; |
|
| 922 | + } else if (isset($appInfo['require'])) { |
|
| 923 | + $requireMin = $appInfo['require']; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 927 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
| 928 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 929 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
| 930 | + } else if (isset($appInfo['requiremax'])) { |
|
| 931 | + $requireMax = $appInfo['requiremax']; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + if (is_array($ocVersion)) { |
|
| 935 | + $ocVersion = implode('.', $ocVersion); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + if (!empty($requireMin) |
|
| 939 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
| 940 | + ) { |
|
| 941 | + |
|
| 942 | + return false; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + if (!empty($requireMax) |
|
| 946 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
| 947 | + ) { |
|
| 948 | + return false; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return true; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * get the installed version of all apps |
|
| 956 | + */ |
|
| 957 | + public static function getAppVersions() { |
|
| 958 | + static $versions; |
|
| 959 | + |
|
| 960 | + if(!$versions) { |
|
| 961 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 962 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
| 963 | + } |
|
| 964 | + return $versions; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * @param string $app |
|
| 969 | + * @param \OCP\IConfig $config |
|
| 970 | + * @param \OCP\IL10N $l |
|
| 971 | + * @return bool |
|
| 972 | + * |
|
| 973 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
| 974 | + * @throws Exception if no app-name was specified |
|
| 975 | + */ |
|
| 976 | + public function installApp($app, |
|
| 977 | + \OCP\IConfig $config, |
|
| 978 | + \OCP\IL10N $l) { |
|
| 979 | + if ($app !== false) { |
|
| 980 | + // check if the app is compatible with this version of ownCloud |
|
| 981 | + $info = self::getAppInfo($app); |
|
| 982 | + if(!is_array($info)) { |
|
| 983 | + throw new \Exception( |
|
| 984 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 985 | + [$info['name']] |
|
| 986 | + ) |
|
| 987 | + ); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + $version = \OCP\Util::getVersion(); |
|
| 991 | + if (!self::isAppCompatible($version, $info)) { |
|
| 992 | + throw new \Exception( |
|
| 993 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 994 | + array($info['name']) |
|
| 995 | + ) |
|
| 996 | + ); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + // check for required dependencies |
|
| 1000 | + self::checkAppDependencies($config, $l, $info); |
|
| 1001 | + |
|
| 1002 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
| 1003 | + if (isset($appData['id'])) { |
|
| 1004 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1008 | + $appPath = self::getAppPath($app); |
|
| 1009 | + self::registerAutoloading($app, $appPath); |
|
| 1010 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
| 1014 | + } else { |
|
| 1015 | + if(empty($appName) ) { |
|
| 1016 | + throw new \Exception($l->t("No app name specified")); |
|
| 1017 | + } else { |
|
| 1018 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + return $app; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * update the database for the app and call the update script |
|
| 1027 | + * |
|
| 1028 | + * @param string $appId |
|
| 1029 | + * @return bool |
|
| 1030 | + */ |
|
| 1031 | + public static function updateApp($appId) { |
|
| 1032 | + $appPath = self::getAppPath($appId); |
|
| 1033 | + if($appPath === false) { |
|
| 1034 | + return false; |
|
| 1035 | + } |
|
| 1036 | + self::registerAutoloading($appId, $appPath); |
|
| 1037 | + |
|
| 1038 | + $appData = self::getAppInfo($appId); |
|
| 1039 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
| 1040 | + |
|
| 1041 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1042 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1043 | + } else { |
|
| 1044 | + $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
| 1045 | + $ms->migrate(); |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
| 1049 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
| 1050 | + unset(self::$appVersion[$appId]); |
|
| 1051 | + |
|
| 1052 | + // run upgrade code |
|
| 1053 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1054 | + self::loadApp($appId); |
|
| 1055 | + include $appPath . '/appinfo/update.php'; |
|
| 1056 | + } |
|
| 1057 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
| 1058 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1059 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + //set remote/public handlers |
|
| 1063 | + if (array_key_exists('ocsid', $appData)) { |
|
| 1064 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
| 1065 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1066 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
| 1067 | + } |
|
| 1068 | + foreach ($appData['remote'] as $name => $path) { |
|
| 1069 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1070 | + } |
|
| 1071 | + foreach ($appData['public'] as $name => $path) { |
|
| 1072 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + self::setAppTypes($appId); |
|
| 1076 | + |
|
| 1077 | + $version = \OC_App::getAppVersion($appId); |
|
| 1078 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
| 1079 | + |
|
| 1080 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
| 1081 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
| 1082 | + )); |
|
| 1083 | + |
|
| 1084 | + return true; |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @param string $appId |
|
| 1089 | + * @param string[] $steps |
|
| 1090 | + * @throws \OC\NeedsUpdateException |
|
| 1091 | + */ |
|
| 1092 | + public static function executeRepairSteps($appId, array $steps) { |
|
| 1093 | + if (empty($steps)) { |
|
| 1094 | + return; |
|
| 1095 | + } |
|
| 1096 | + // load the app |
|
| 1097 | + self::loadApp($appId); |
|
| 1098 | + |
|
| 1099 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
| 1100 | + |
|
| 1101 | + // load the steps |
|
| 1102 | + $r = new Repair([], $dispatcher); |
|
| 1103 | + foreach ($steps as $step) { |
|
| 1104 | + try { |
|
| 1105 | + $r->addStep($step); |
|
| 1106 | + } catch (Exception $ex) { |
|
| 1107 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
| 1108 | + \OC::$server->getLogger()->logException($ex); |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1111 | + // run the steps |
|
| 1112 | + $r->run(); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + public static function setupBackgroundJobs(array $jobs) { |
|
| 1116 | + $queue = \OC::$server->getJobList(); |
|
| 1117 | + foreach ($jobs as $job) { |
|
| 1118 | + $queue->add($job); |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + /** |
|
| 1123 | + * @param string $appId |
|
| 1124 | + * @param string[] $steps |
|
| 1125 | + */ |
|
| 1126 | + private static function setupLiveMigrations($appId, array $steps) { |
|
| 1127 | + $queue = \OC::$server->getJobList(); |
|
| 1128 | + foreach ($steps as $step) { |
|
| 1129 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
| 1130 | + 'app' => $appId, |
|
| 1131 | + 'step' => $step]); |
|
| 1132 | + } |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * @param string $appId |
|
| 1137 | + * @return \OC\Files\View|false |
|
| 1138 | + */ |
|
| 1139 | + public static function getStorage($appId) { |
|
| 1140 | + if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
| 1141 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1142 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1143 | + if (!$view->file_exists($appId)) { |
|
| 1144 | + $view->mkdir($appId); |
|
| 1145 | + } |
|
| 1146 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1147 | + } else { |
|
| 1148 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1149 | + return false; |
|
| 1150 | + } |
|
| 1151 | + } else { |
|
| 1152 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1153 | + return false; |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + protected static function findBestL10NOption($options, $lang) { |
|
| 1158 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
| 1159 | + |
|
| 1160 | + $lang = strtolower($lang); |
|
| 1161 | + $similarLang = $lang; |
|
| 1162 | + if (strpos($similarLang, '_')) { |
|
| 1163 | + // For "de_DE" we want to find "de" and the other way around |
|
| 1164 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + foreach ($options as $option) { |
|
| 1168 | + if (is_array($option)) { |
|
| 1169 | + if ($fallback === false) { |
|
| 1170 | + $fallback = $option['@value']; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + if (!isset($option['@attributes']['lang'])) { |
|
| 1174 | + continue; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 1178 | + if ($attributeLang === $lang) { |
|
| 1179 | + return $option['@value']; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + if ($attributeLang === $similarLang) { |
|
| 1183 | + $similarLangFallback = $option['@value']; |
|
| 1184 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1185 | + if ($similarLangFallback === false) { |
|
| 1186 | + $similarLangFallback = $option['@value']; |
|
| 1187 | + } |
|
| 1188 | + } |
|
| 1189 | + } else { |
|
| 1190 | + $englishFallback = $option; |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + if ($similarLangFallback !== false) { |
|
| 1195 | + return $similarLangFallback; |
|
| 1196 | + } else if ($englishFallback !== false) { |
|
| 1197 | + return $englishFallback; |
|
| 1198 | + } |
|
| 1199 | + return (string) $fallback; |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * parses the app data array and enhanced the 'description' value |
|
| 1204 | + * |
|
| 1205 | + * @param array $data the app data |
|
| 1206 | + * @param string $lang |
|
| 1207 | + * @return array improved app data |
|
| 1208 | + */ |
|
| 1209 | + public static function parseAppInfo(array $data, $lang = null) { |
|
| 1210 | + |
|
| 1211 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
| 1212 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
| 1213 | + } |
|
| 1214 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
| 1215 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
| 1216 | + } |
|
| 1217 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
| 1218 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
| 1219 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
| 1220 | + $data['description'] = trim($data['description']); |
|
| 1221 | + } else { |
|
| 1222 | + $data['description'] = ''; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $data; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + /** |
|
| 1229 | + * @param \OCP\IConfig $config |
|
| 1230 | + * @param \OCP\IL10N $l |
|
| 1231 | + * @param array $info |
|
| 1232 | + * @throws \Exception |
|
| 1233 | + */ |
|
| 1234 | + public static function checkAppDependencies($config, $l, $info) { |
|
| 1235 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
| 1236 | + $missing = $dependencyAnalyzer->analyze($info); |
|
| 1237 | + if (!empty($missing)) { |
|
| 1238 | + $missingMsg = implode(PHP_EOL, $missing); |
|
| 1239 | + throw new \Exception( |
|
| 1240 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
| 1241 | + [$info['name'], $missingMsg] |
|
| 1242 | + ) |
|
| 1243 | + ); |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | 1246 | } |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | $apps = self::getEnabledApps(); |
| 114 | 114 | |
| 115 | 115 | // Add each apps' folder as allowed class path |
| 116 | - foreach($apps as $app) { |
|
| 116 | + foreach ($apps as $app) { |
|
| 117 | 117 | $path = self::getAppPath($app); |
| 118 | - if($path !== false) { |
|
| 118 | + if ($path !== false) { |
|
| 119 | 119 | self::registerAutoloading($app, $path); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | public static function loadApp($app) { |
| 141 | 141 | self::$loadedApps[] = $app; |
| 142 | 142 | $appPath = self::getAppPath($app); |
| 143 | - if($appPath === false) { |
|
| 143 | + if ($appPath === false) { |
|
| 144 | 144 | return; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // in case someone calls loadApp() directly |
| 148 | 148 | self::registerAutoloading($app, $appPath); |
| 149 | 149 | |
| 150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
| 151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 150 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
| 151 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
| 152 | 152 | self::requireAppFile($app); |
| 153 | 153 | if (self::isType($app, array('authentication'))) { |
| 154 | 154 | // since authentication apps affect the "is app enabled for group" check, |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | // enabled for groups |
| 158 | 158 | self::$enabledAppsCache = array(); |
| 159 | 159 | } |
| 160 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 160 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $info = self::getAppInfo($app); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
| 182 | 182 | [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
| 183 | 183 | foreach ($plugins as $plugin) { |
| 184 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 184 | + if ($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 185 | 185 | $pluginInfo = [ |
| 186 | 186 | 'shareType' => $plugin['@attributes']['share-type'], |
| 187 | 187 | 'class' => $plugin['@value'], |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | * @param string $path |
| 201 | 201 | */ |
| 202 | 202 | public static function registerAutoloading($app, $path) { |
| 203 | - $key = $app . '-' . $path; |
|
| 204 | - if(isset(self::$alreadyRegistered[$key])) { |
|
| 203 | + $key = $app.'-'.$path; |
|
| 204 | + if (isset(self::$alreadyRegistered[$key])) { |
|
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -211,17 +211,17 @@ discard block |
||
| 211 | 211 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
| 212 | 212 | \OC::$server->registerNamespace($app, $appNamespace); |
| 213 | 213 | |
| 214 | - if (file_exists($path . '/composer/autoload.php')) { |
|
| 215 | - require_once $path . '/composer/autoload.php'; |
|
| 214 | + if (file_exists($path.'/composer/autoload.php')) { |
|
| 215 | + require_once $path.'/composer/autoload.php'; |
|
| 216 | 216 | } else { |
| 217 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 217 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
| 218 | 218 | // Register on legacy autoloader |
| 219 | 219 | \OC::$loader->addValidRoot($path); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Register Test namespace only when testing |
| 223 | 223 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
| 224 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 224 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | private static function requireAppFile($app) { |
| 234 | 234 | try { |
| 235 | 235 | // encapsulated here to avoid variable scope conflicts |
| 236 | - require_once $app . '/appinfo/app.php'; |
|
| 236 | + require_once $app.'/appinfo/app.php'; |
|
| 237 | 237 | } catch (Error $ex) { |
| 238 | 238 | \OC::$server->getLogger()->logException($ex); |
| 239 | 239 | if (!\OC::$server->getAppManager()->isShipped($app)) { |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public static function setAppTypes($app) { |
| 289 | 289 | $appData = self::getAppInfo($app); |
| 290 | - if(!is_array($appData)) { |
|
| 290 | + if (!is_array($appData)) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | } else { |
| 340 | 340 | $apps = $appManager->getEnabledAppsForUser($user); |
| 341 | 341 | } |
| 342 | - $apps = array_filter($apps, function ($app) { |
|
| 343 | - return $app !== 'files';//we add this manually |
|
| 342 | + $apps = array_filter($apps, function($app) { |
|
| 343 | + return $app !== 'files'; //we add this manually |
|
| 344 | 344 | }); |
| 345 | 345 | sort($apps); |
| 346 | 346 | array_unshift($apps, 'files'); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $installer = \OC::$server->query(Installer::class); |
| 379 | 379 | $isDownloaded = $installer->isDownloaded($appId); |
| 380 | 380 | |
| 381 | - if(!$isDownloaded) { |
|
| 381 | + if (!$isDownloaded) { |
|
| 382 | 382 | $installer->downloadApp($appId); |
| 383 | 383 | } |
| 384 | 384 | |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | public static function findAppInDirectories($appId) { |
| 493 | 493 | $sanitizedAppId = self::cleanAppId($appId); |
| 494 | - if($sanitizedAppId !== $appId) { |
|
| 494 | + if ($sanitizedAppId !== $appId) { |
|
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | 497 | static $app_dir = array(); |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | $possibleApps = array(); |
| 504 | 504 | foreach (OC::$APPSROOTS as $dir) { |
| 505 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 505 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
| 506 | 506 | $possibleApps[] = $dir; |
| 507 | 507 | } |
| 508 | 508 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | if (($dir = self::findAppInDirectories($appId)) != false) { |
| 546 | - return $dir['path'] . '/' . $appId; |
|
| 546 | + return $dir['path'].'/'.$appId; |
|
| 547 | 547 | } |
| 548 | 548 | return false; |
| 549 | 549 | } |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | */ |
| 558 | 558 | public static function getAppWebPath($appId) { |
| 559 | 559 | if (($dir = self::findAppInDirectories($appId)) != false) { |
| 560 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 560 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
| 561 | 561 | } |
| 562 | 562 | return false; |
| 563 | 563 | } |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @return string |
| 571 | 571 | */ |
| 572 | 572 | public static function getAppVersion($appId, $useCache = true) { |
| 573 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
| 573 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
| 574 | 574 | return self::$appVersion[$appId]; |
| 575 | 575 | } |
| 576 | 576 | |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | * @return string |
| 587 | 587 | */ |
| 588 | 588 | public static function getAppVersionByPath($path) { |
| 589 | - $infoFile = $path . '/appinfo/info.xml'; |
|
| 589 | + $infoFile = $path.'/appinfo/info.xml'; |
|
| 590 | 590 | $appData = self::getAppInfo($infoFile, true); |
| 591 | 591 | return isset($appData['version']) ? $appData['version'] : ''; |
| 592 | 592 | } |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | return self::$appInfo[$appId]; |
| 610 | 610 | } |
| 611 | 611 | $appPath = self::getAppPath($appId); |
| 612 | - if($appPath === false) { |
|
| 612 | + if ($appPath === false) { |
|
| 613 | 613 | return null; |
| 614 | 614 | } |
| 615 | - $file = $appPath . '/appinfo/info.xml'; |
|
| 615 | + $file = $appPath.'/appinfo/info.xml'; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
@@ -621,9 +621,9 @@ discard block |
||
| 621 | 621 | if (is_array($data)) { |
| 622 | 622 | $data = OC_App::parseAppInfo($data, $lang); |
| 623 | 623 | } |
| 624 | - if(isset($data['ocsid'])) { |
|
| 624 | + if (isset($data['ocsid'])) { |
|
| 625 | 625 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
| 626 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 626 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 627 | 627 | $data['ocsid'] = $storedId; |
| 628 | 628 | } |
| 629 | 629 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @param string $page |
| 716 | 716 | */ |
| 717 | 717 | public static function registerAdmin($app, $page) { |
| 718 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 718 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * @param string $page |
| 725 | 725 | */ |
| 726 | 726 | public static function registerPersonal($app, $page) { |
| 727 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 727 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | |
| 754 | 754 | foreach (OC::$APPSROOTS as $apps_dir) { |
| 755 | 755 | if (!is_readable($apps_dir['path'])) { |
| 756 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 756 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
| 757 | 757 | continue; |
| 758 | 758 | } |
| 759 | 759 | $dh = opendir($apps_dir['path']); |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | if (is_resource($dh)) { |
| 762 | 762 | while (($file = readdir($dh)) !== false) { |
| 763 | 763 | |
| 764 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 764 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
| 765 | 765 | |
| 766 | 766 | $apps[] = $file; |
| 767 | 767 | } |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | $info = OC_App::getAppInfo($app, false, $langCode); |
| 796 | 796 | if (!is_array($info)) { |
| 797 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 797 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
| 798 | 798 | continue; |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | if (!isset($info['name'])) { |
| 802 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 802 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
| 803 | 803 | continue; |
| 804 | 804 | } |
| 805 | 805 | |
@@ -826,13 +826,13 @@ discard block |
||
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | $appPath = self::getAppPath($app); |
| 829 | - if($appPath !== false) { |
|
| 830 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 829 | + if ($appPath !== false) { |
|
| 830 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
| 831 | 831 | if (file_exists($appIcon)) { |
| 832 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
| 832 | + $info['preview'] = $urlGenerator->imagePath($app, $app.'.svg'); |
|
| 833 | 833 | $info['previewAsIcon'] = true; |
| 834 | 834 | } else { |
| 835 | - $appIcon = $appPath . '/img/app.svg'; |
|
| 835 | + $appIcon = $appPath.'/img/app.svg'; |
|
| 836 | 836 | if (file_exists($appIcon)) { |
| 837 | 837 | $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
| 838 | 838 | $info['previewAsIcon'] = true; |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | public static function getAppVersions() { |
| 958 | 958 | static $versions; |
| 959 | 959 | |
| 960 | - if(!$versions) { |
|
| 960 | + if (!$versions) { |
|
| 961 | 961 | $appConfig = \OC::$server->getAppConfig(); |
| 962 | 962 | $versions = $appConfig->getValues(false, 'installed_version'); |
| 963 | 963 | } |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | if ($app !== false) { |
| 980 | 980 | // check if the app is compatible with this version of ownCloud |
| 981 | 981 | $info = self::getAppInfo($app); |
| 982 | - if(!is_array($info)) { |
|
| 982 | + if (!is_array($info)) { |
|
| 983 | 983 | throw new \Exception( |
| 984 | 984 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
| 985 | 985 | [$info['name']] |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | $config->setAppValue($app, 'ocsid', $appData['id']); |
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1007 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 1008 | 1008 | $appPath = self::getAppPath($app); |
| 1009 | 1009 | self::registerAutoloading($app, $appPath); |
| 1010 | 1010 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | |
| 1013 | 1013 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
| 1014 | 1014 | } else { |
| 1015 | - if(empty($appName) ) { |
|
| 1015 | + if (empty($appName)) { |
|
| 1016 | 1016 | throw new \Exception($l->t("No app name specified")); |
| 1017 | 1017 | } else { |
| 1018 | 1018 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | */ |
| 1031 | 1031 | public static function updateApp($appId) { |
| 1032 | 1032 | $appPath = self::getAppPath($appId); |
| 1033 | - if($appPath === false) { |
|
| 1033 | + if ($appPath === false) { |
|
| 1034 | 1034 | return false; |
| 1035 | 1035 | } |
| 1036 | 1036 | self::registerAutoloading($appId, $appPath); |
@@ -1038,8 +1038,8 @@ discard block |
||
| 1038 | 1038 | $appData = self::getAppInfo($appId); |
| 1039 | 1039 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
| 1040 | 1040 | |
| 1041 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1042 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1041 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
| 1042 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
| 1043 | 1043 | } else { |
| 1044 | 1044 | $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
| 1045 | 1045 | $ms->migrate(); |
@@ -1050,26 +1050,26 @@ discard block |
||
| 1050 | 1050 | unset(self::$appVersion[$appId]); |
| 1051 | 1051 | |
| 1052 | 1052 | // run upgrade code |
| 1053 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1053 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
| 1054 | 1054 | self::loadApp($appId); |
| 1055 | - include $appPath . '/appinfo/update.php'; |
|
| 1055 | + include $appPath.'/appinfo/update.php'; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | self::setupBackgroundJobs($appData['background-jobs']); |
| 1058 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1058 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1059 | 1059 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | //set remote/public handlers |
| 1063 | 1063 | if (array_key_exists('ocsid', $appData)) { |
| 1064 | 1064 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
| 1065 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1065 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1066 | 1066 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
| 1067 | 1067 | } |
| 1068 | 1068 | foreach ($appData['remote'] as $name => $path) { |
| 1069 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1069 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | foreach ($appData['public'] as $name => $path) { |
| 1072 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1072 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | self::setAppTypes($appId); |
@@ -1139,17 +1139,17 @@ discard block |
||
| 1139 | 1139 | public static function getStorage($appId) { |
| 1140 | 1140 | if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
| 1141 | 1141 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
| 1142 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1142 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
| 1143 | 1143 | if (!$view->file_exists($appId)) { |
| 1144 | 1144 | $view->mkdir($appId); |
| 1145 | 1145 | } |
| 1146 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1146 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
| 1147 | 1147 | } else { |
| 1148 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1148 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
| 1149 | 1149 | return false; |
| 1150 | 1150 | } |
| 1151 | 1151 | } else { |
| 1152 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1152 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
| 1153 | 1153 | return false; |
| 1154 | 1154 | } |
| 1155 | 1155 | } |
@@ -1181,9 +1181,9 @@ discard block |
||
| 1181 | 1181 | |
| 1182 | 1182 | if ($attributeLang === $similarLang) { |
| 1183 | 1183 | $similarLangFallback = $option['@value']; |
| 1184 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1184 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
| 1185 | 1185 | if ($similarLangFallback === false) { |
| 1186 | - $similarLangFallback = $option['@value']; |
|
| 1186 | + $similarLangFallback = $option['@value']; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | } |
| 1189 | 1189 | } else { |
@@ -1218,7 +1218,7 @@ discard block |
||
| 1218 | 1218 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
| 1219 | 1219 | } else if (isset($data['description']) && is_string($data['description'])) { |
| 1220 | 1220 | $data['description'] = trim($data['description']); |
| 1221 | - } else { |
|
| 1221 | + } else { |
|
| 1222 | 1222 | $data['description'] = ''; |
| 1223 | 1223 | } |
| 1224 | 1224 | |