Merge pull request #8097 from nextcloud/deprecate-static-app
Deprecate static methods from \OCP\App
This commit is contained in:
commit
367b5a794d
|
@ -72,8 +72,8 @@ class PluginManagerTest extends TestCase {
|
|||
|
||||
$appManager->method('getAppInfo')
|
||||
->will($this->returnValueMap([
|
||||
['adavapp', $appInfo1],
|
||||
['adavapp2', $appInfo2],
|
||||
['adavapp', false, null, $appInfo1],
|
||||
['adavapp2', false, null, $appInfo2],
|
||||
]));
|
||||
|
||||
$pluginManager = new PluginManager($server, $appManager);
|
||||
|
|
|
@ -268,7 +268,7 @@ class Storage extends Wrapper {
|
|||
*/
|
||||
private function doDelete($path, $method, $ownerOnly = false) {
|
||||
if (self::$disableTrash
|
||||
|| !\OC_App::isEnabled('files_trashbin')
|
||||
|| !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')
|
||||
|| (pathinfo($path, PATHINFO_EXTENSION) === 'part')
|
||||
|| $this->shouldMoveToTrash($path) === false
|
||||
) {
|
||||
|
|
|
@ -80,6 +80,12 @@ class AppManager implements IAppManager {
|
|||
/** @var string[] */
|
||||
private $alwaysEnabled;
|
||||
|
||||
/** @var array */
|
||||
private $appInfos = [];
|
||||
|
||||
/** @var array */
|
||||
private $appVersions = [];
|
||||
|
||||
/**
|
||||
* @param IUserSession $userSession
|
||||
* @param AppConfig $appConfig
|
||||
|
@ -341,17 +347,45 @@ class AppManager implements IAppManager {
|
|||
*
|
||||
* @param string $appId app id
|
||||
*
|
||||
* @param bool $path
|
||||
* @param null $lang
|
||||
* @return array app info
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getAppInfo($appId) {
|
||||
$appInfo = \OC_App::getAppInfo($appId);
|
||||
if (!isset($appInfo['version'])) {
|
||||
// read version from separate file
|
||||
$appInfo['version'] = \OC_App::getAppVersion($appId);
|
||||
public function getAppInfo(string $appId, bool $path = false, $lang = null) {
|
||||
if ($path) {
|
||||
$file = $appId;
|
||||
} else {
|
||||
if ($lang === null && isset($this->appInfos[$appId])) {
|
||||
return $this->appInfos[$appId];
|
||||
}
|
||||
try {
|
||||
$appPath = $this->getAppPath($appId);
|
||||
} catch (AppPathNotFoundException $e) {
|
||||
return null;
|
||||
}
|
||||
$file = $appPath . '/appinfo/info.xml';
|
||||
}
|
||||
return $appInfo;
|
||||
|
||||
$parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo'));
|
||||
$data = $parser->parse($file);
|
||||
|
||||
if (is_array($data)) {
|
||||
$data = \OC_App::parseAppInfo($data, $lang);
|
||||
}
|
||||
|
||||
if ($lang === null) {
|
||||
$this->appInfos[$appId] = $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getAppVersion(string $appId, bool $useCache = true) {
|
||||
if(!$useCache || !isset($this->appVersions[$appId])) {
|
||||
$appInfo = \OC::$server->getAppManager()->getAppInfo($appId);
|
||||
$this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0';
|
||||
}
|
||||
return $this->appVersions[$appId];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,6 +46,7 @@ class DeprecationCheck extends AbstractCheck {
|
|||
'OCP\AppFramework\IApi' => '8.0.0',
|
||||
'OCP\User' => '13.0.0',
|
||||
'OCP\BackgroundJob' => '14.0.0',
|
||||
'OCP\App' => '14.0.0',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -102,6 +103,13 @@ class DeprecationCheck extends AbstractCheck {
|
|||
'OCP\App::addNavigationEntry' => '8.1.0',
|
||||
'OCP\App::getActiveNavigationEntry' => '8.2.0',
|
||||
'OCP\App::setActiveNavigationEntry' => '8.1.0',
|
||||
'OCP\App::registerPersonal' => '14.0.0',
|
||||
'OCP\App::registerAdmin' => '14.0.0',
|
||||
'OC_App::getAppInfo' => '14.0.0',
|
||||
'OCP\App::getAppInfo' => '14.0.0',
|
||||
'OC_App::getAppVersion' => '14.0.0',
|
||||
'OCP\App::getAppVersion' => '14.0.0',
|
||||
'OCP\App::registerPersonal' => '14.0.0',
|
||||
|
||||
'OCP\AppFramework\Controller::params' => '7.0.0',
|
||||
'OCP\AppFramework\Controller::getParams' => '7.0.0',
|
||||
|
|
|
@ -471,6 +471,9 @@ class Installer {
|
|||
*/
|
||||
public function removeApp($appId) {
|
||||
if($this->isDownloaded( $appId )) {
|
||||
if (\OC::$server->getAppManager()->isShipped($appId)) {
|
||||
return false;
|
||||
}
|
||||
$appDir = OC_App::getInstallPath() . '/' . $appId;
|
||||
OC_Helper::rmdirr($appDir);
|
||||
return true;
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
*
|
||||
*/
|
||||
use OC\App\DependencyAnalyzer;
|
||||
use OC\App\InfoParser;
|
||||
use OC\App\Platform;
|
||||
use OC\DB\MigrationService;
|
||||
use OC\Installer;
|
||||
|
@ -63,10 +62,8 @@ use OCP\App\ManagerEvent;
|
|||
* upgrading and removing apps.
|
||||
*/
|
||||
class OC_App {
|
||||
static private $appVersion = [];
|
||||
static private $adminForms = array();
|
||||
static private $personalForms = array();
|
||||
static private $appInfo = array();
|
||||
static private $appTypes = array();
|
||||
static private $loadedApps = array();
|
||||
static private $altLogin = array();
|
||||
|
@ -422,19 +419,6 @@ class OC_App {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @return bool
|
||||
*/
|
||||
public static function removeApp($app) {
|
||||
if (\OC::$server->getAppManager()->isShipped($app)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$installer = \OC::$server->query(Installer::class);
|
||||
return $installer->removeApp($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function set an app as disabled in appconfig.
|
||||
*
|
||||
|
@ -590,15 +574,10 @@ class OC_App {
|
|||
* @param string $appId
|
||||
* @param bool $useCache
|
||||
* @return string
|
||||
* @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion()
|
||||
*/
|
||||
public static function getAppVersion($appId, $useCache = true) {
|
||||
if($useCache && isset(self::$appVersion[$appId])) {
|
||||
return self::$appVersion[$appId];
|
||||
}
|
||||
|
||||
$file = self::getAppPath($appId);
|
||||
self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
|
||||
return self::$appVersion[$appId];
|
||||
return \OC::$server->getAppManager()->getAppVersion($appId, $useCache);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -609,7 +588,7 @@ class OC_App {
|
|||
*/
|
||||
public static function getAppVersionByPath($path) {
|
||||
$infoFile = $path . '/appinfo/info.xml';
|
||||
$appData = self::getAppInfo($infoFile, true);
|
||||
$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
|
||||
return isset($appData['version']) ? $appData['version'] : '';
|
||||
}
|
||||
|
||||
|
@ -622,39 +601,10 @@ class OC_App {
|
|||
* @param string $lang
|
||||
* @return array|null
|
||||
* @note all data is read from info.xml, not just pre-defined fields
|
||||
* @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo()
|
||||
*/
|
||||
public static function getAppInfo($appId, $path = false, $lang = null) {
|
||||
if ($path) {
|
||||
$file = $appId;
|
||||
} else {
|
||||
if ($lang === null && isset(self::$appInfo[$appId])) {
|
||||
return self::$appInfo[$appId];
|
||||
}
|
||||
$appPath = self::getAppPath($appId);
|
||||
if($appPath === false) {
|
||||
return null;
|
||||
}
|
||||
$file = $appPath . '/appinfo/info.xml';
|
||||
}
|
||||
|
||||
$parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo'));
|
||||
$data = $parser->parse($file);
|
||||
|
||||
if (is_array($data)) {
|
||||
$data = OC_App::parseAppInfo($data, $lang);
|
||||
}
|
||||
if(isset($data['ocsid'])) {
|
||||
$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
|
||||
if($storedId !== '' && $storedId !== $data['ocsid']) {
|
||||
$data['ocsid'] = $storedId;
|
||||
}
|
||||
}
|
||||
|
||||
if ($lang === null) {
|
||||
self::$appInfo[$appId] = $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -986,63 +936,6 @@ class OC_App {
|
|||
return $versions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @param \OCP\IConfig $config
|
||||
* @param \OCP\IL10N $l
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception if app is not compatible with this version of ownCloud
|
||||
* @throws Exception if no app-name was specified
|
||||
*/
|
||||
public function installApp($app,
|
||||
\OCP\IConfig $config,
|
||||
\OCP\IL10N $l) {
|
||||
if ($app !== false) {
|
||||
// check if the app is compatible with this version of ownCloud
|
||||
$info = self::getAppInfo($app);
|
||||
if(!is_array($info)) {
|
||||
throw new \Exception(
|
||||
$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
|
||||
[$info['name']]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$version = \OCP\Util::getVersion();
|
||||
if (!self::isAppCompatible($version, $info)) {
|
||||
throw new \Exception(
|
||||
$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
|
||||
array($info['name'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// check for required dependencies
|
||||
self::checkAppDependencies($config, $l, $info);
|
||||
|
||||
$config->setAppValue($app, 'enabled', 'yes');
|
||||
if (isset($appData['id'])) {
|
||||
$config->setAppValue($app, 'ocsid', $appData['id']);
|
||||
}
|
||||
|
||||
if(isset($info['settings']) && is_array($info['settings'])) {
|
||||
$appPath = self::getAppPath($app);
|
||||
self::registerAutoloading($app, $appPath);
|
||||
}
|
||||
|
||||
\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
|
||||
} else {
|
||||
if(empty($appName) ) {
|
||||
throw new \Exception($l->t("No app name specified"));
|
||||
} else {
|
||||
throw new \Exception($l->t("App '%s' could not be installed!", $appName));
|
||||
}
|
||||
}
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* update the database for the app and call the update script
|
||||
*
|
||||
|
@ -1068,7 +961,8 @@ class OC_App {
|
|||
|
||||
self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
|
||||
self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
|
||||
unset(self::$appVersion[$appId]);
|
||||
// update appversion in app manager
|
||||
\OC::$server->getAppManager()->getAppVersion($appId, false);
|
||||
|
||||
// run upgrade code
|
||||
if (file_exists($appPath . '/appinfo/update.php')) {
|
||||
|
|
|
@ -40,52 +40,10 @@ namespace OCP;
|
|||
/**
|
||||
* This class provides functions to manage apps in ownCloud
|
||||
* @since 4.0.0
|
||||
* @deprecated 14.0.0
|
||||
*/
|
||||
class App {
|
||||
|
||||
/**
|
||||
* Adds an entry to the navigation
|
||||
*
|
||||
* This function adds a new entry to the navigation visible to users. $data
|
||||
* is an associative array.
|
||||
* The following keys are required:
|
||||
* - id: unique id for this entry ('addressbook_index')
|
||||
* - href: link to the page
|
||||
* - name: Human readable name ('Addressbook')
|
||||
*
|
||||
* The following keys are optional:
|
||||
* - icon: path to the icon of the app
|
||||
* - order: integer, that influences the position of your application in
|
||||
* the navigation. Lower values come first.
|
||||
*
|
||||
* @param array $data containing the data
|
||||
* @return boolean
|
||||
*
|
||||
* @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->add() instead to
|
||||
* register a closure, this helps to speed up all requests against ownCloud
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function addNavigationEntry($data) {
|
||||
\OC::$server->getNavigationManager()->add($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a navigation entry as active
|
||||
* @param string $id id of the entry
|
||||
* @return boolean
|
||||
*
|
||||
* This function sets a navigation entry as active and removes the 'active'
|
||||
* property from all other entries. The templates can use this for
|
||||
* highlighting the current position of the user.
|
||||
*
|
||||
* @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->setActiveEntry() instead
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function setActiveNavigationEntry( $id ) {
|
||||
\OC::$server->getNavigationManager()->setActiveEntry($id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Configuration Screen that should appear in the personal settings section.
|
||||
|
@ -93,6 +51,7 @@ class App {
|
|||
* @param string $page page to be included
|
||||
* @return void
|
||||
* @since 4.0.0
|
||||
* @deprecated 14.0.0 Use settings section in appinfo.xml to register personal admin sections
|
||||
*/
|
||||
public static function registerPersonal( $app, $page ) {
|
||||
\OC_App::registerPersonal( $app, $page );
|
||||
|
@ -104,6 +63,7 @@ class App {
|
|||
* @param string $page string page to be included
|
||||
* @return void
|
||||
* @since 4.0.0
|
||||
* @deprecated 14.0.0 Use settings section in appinfo.xml to register admin sections
|
||||
*/
|
||||
public static function registerAdmin( $app, $page ) {
|
||||
\OC_App::registerAdmin( $app, $page );
|
||||
|
@ -114,6 +74,7 @@ class App {
|
|||
* @param string $app id of the app or the path of the info.xml file
|
||||
* @param boolean $path (optional)
|
||||
* @return array|null
|
||||
* @deprecated 14.0.0 ise \OC::$server->getAppManager()->getAppInfo($appId)
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function getAppInfo( $app, $path=false ) {
|
||||
|
@ -148,8 +109,9 @@ class App {
|
|||
* @param string $app
|
||||
* @return string
|
||||
* @since 4.0.0
|
||||
* @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion($appId)
|
||||
*/
|
||||
public static function getAppVersion( $app ) {
|
||||
return \OC_App::getAppVersion( $app );
|
||||
return \OC::$server->getAppManager()->getAppVersion($app);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,26 @@ use OCP\IUser;
|
|||
* @since 8.0.0
|
||||
*/
|
||||
interface IAppManager {
|
||||
|
||||
/**
|
||||
* Returns the app information from "appinfo/info.xml".
|
||||
*
|
||||
* @param string $appId
|
||||
* @return mixed
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function getAppInfo(string $appId, bool $path = false, $lang = null);
|
||||
|
||||
/**
|
||||
* Returns the app information from "appinfo/info.xml".
|
||||
*
|
||||
* @param string $appId
|
||||
* @param bool $useCache
|
||||
* @return mixed
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function getAppVersion(string $appId, bool $useCache = true);
|
||||
|
||||
/**
|
||||
* Check if an app is enabled for user
|
||||
*
|
||||
|
|
|
@ -40,7 +40,10 @@ if (!array_key_exists('appid', $_POST)) {
|
|||
$appId = (string)$_POST['appid'];
|
||||
$appId = OC_App::cleanAppId($appId);
|
||||
|
||||
$result = OC_App::removeApp($appId);
|
||||
// FIXME: move to controller
|
||||
/** @var \OC\Installer $installer */
|
||||
$installer = \OC::$server->query(\OC\Installer::class);
|
||||
$result = $installer->removeApp($app);
|
||||
if($result !== false) {
|
||||
// FIXME: Clear the cache - move that into some sane helper method
|
||||
\OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-0');
|
||||
|
|
|
@ -172,14 +172,14 @@ class ManagerTest extends TestCase {
|
|||
->method('getAppInfo')
|
||||
->will($this->returnValueMap([
|
||||
[
|
||||
'mycustom2faapp',
|
||||
'mycustom2faapp', false, null,
|
||||
['two-factor-providers' => [
|
||||
'\OCA\MyCustom2faApp\FakeProvider',
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'twofactor_backupcodes',
|
||||
'twofactor_backupcodes', false, null,
|
||||
['two-factor-providers' => [
|
||||
'\OCA\TwoFactorBackupCodes\Provider\FakeBackupCodesProvider',
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue