Browse Source

Move isType to AppManager

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/36591/head
Côme Chilliet 3 years ago
parent
commit
8dc5f82189
No known key found for this signature in database GPG Key ID: A3E2F658B28C760A
  1. 39
      lib/private/App/AppManager.php
  2. 29
      lib/private/legacy/OC_App.php
  3. 6
      lib/public/App/IAppManager.php

39
lib/private/App/AppManager.php

@ -100,6 +100,7 @@ class AppManager implements IAppManager {
/** @var array */
private array $autoDisabledApps = [];
private array $appTypes = [];
/** @var array<string, true> */
private array $loadedApps = [];
@ -177,6 +178,42 @@ class AppManager implements IAppManager {
return array_keys($appsForGroups);
}
/**
* check if an app is of a specific type
*
* @param string $app
* @param array $types
* @return bool
*/
public function isType(string $app, array $types): bool {
$appTypes = $this->getAppTypes($app);
foreach ($types as $type) {
if (array_search($type, $appTypes) !== false) {
return true;
}
}
return false;
}
/**
* get the types of an app
*
* @param string $app
* @return string[]
*/
private function getAppTypes(string $app): array {
//load the cache
if (count($this->appTypes) === 0) {
$this->appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
}
if (isset($this->appTypes[$app])) {
return explode(',', $this->appTypes[$app]);
}
return [];
}
/**
* @return array
*/
@ -332,7 +369,7 @@ class AppManager implements IAppManager {
if ($ex instanceof ServerNotAvailableException) {
throw $ex;
}
if (!$this->isShipped($app) && !\OC_App::isType($app, ['authentication'])) {
if (!$this->isShipped($app) && !$this->isType($app, ['authentication'])) {
$this->logger->error("App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(), [
'exception' => $ex,
]);

29
lib/private/legacy/OC_App.php

@ -75,7 +75,6 @@ use Psr\Log\LoggerInterface;
class OC_App {
private static $adminForms = [];
private static $personalForms = [];
private static $appTypes = [];
private static $altLogin = [];
private static $alreadyRegistered = [];
public const supportedApp = 300;
@ -199,34 +198,10 @@ class OC_App {
* @param string $app
* @param array $types
* @return bool
* @deprecated 26.0.0 call \OC::$server->get(IAppManager::class)->isType($app, $types)
*/
public static function isType(string $app, array $types): bool {
$appTypes = self::getAppTypes($app);
foreach ($types as $type) {
if (array_search($type, $appTypes) !== false) {
return true;
}
}
return false;
}
/**
* get the types of an app
*
* @param string $app
* @return array
*/
private static function getAppTypes(string $app): array {
//load the cache
if (count(self::$appTypes) == 0) {
self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
}
if (isset(self::$appTypes[$app])) {
return explode(',', self::$appTypes[$app]);
}
return [];
return \OC::$server->get(IAppManager::class)->isType($app, $types);
}
/**

6
lib/public/App/IAppManager.php

@ -196,6 +196,12 @@ interface IAppManager {
*/
public function isShipped($appId);
/**
* Check if an app is of a specific type
* @since 26.0.0
*/
public function isType(string $app, array $types): bool;
/**
* @return string[]
* @since 9.0.0

Loading…
Cancel
Save