Use isInstalled of AppManger instead of reimplement it
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
2d5febd0b9
commit
514de5dfa1
|
@ -58,6 +58,7 @@ class Install extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
/** @var Installer $installer */
|
||||||
$installer = \OC::$server->query(Installer::class);
|
$installer = \OC::$server->query(Installer::class);
|
||||||
$installer->downloadApp($appId);
|
$installer->downloadApp($appId);
|
||||||
$result = $installer->installApp($appId);
|
$result = $installer->installApp($appId);
|
||||||
|
|
|
@ -204,7 +204,9 @@ class AppManager implements IAppManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an app is installed in the instance
|
* Check if an app is enabled in the instance
|
||||||
|
*
|
||||||
|
* Notice: This actually checks if the app is enabled and not only if it is installed.
|
||||||
*
|
*
|
||||||
* @param string $appId
|
* @param string $appId
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|
|
@ -165,17 +165,6 @@ class Installer {
|
||||||
return $info['id'];
|
return $info['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks whether or not an app is installed
|
|
||||||
* @param string $app app
|
|
||||||
* @returns bool
|
|
||||||
*
|
|
||||||
* Checks whether or not an app is installed, i.e. registered in apps table.
|
|
||||||
*/
|
|
||||||
public static function isInstalled( $app ) {
|
|
||||||
return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the specified app from the appstore
|
* Updates the specified app from the appstore
|
||||||
*
|
*
|
||||||
|
@ -510,17 +499,19 @@ class Installer {
|
||||||
* @return array Array of error messages (appid => Exception)
|
* @return array Array of error messages (appid => Exception)
|
||||||
*/
|
*/
|
||||||
public static function installShippedApps($softErrors = false) {
|
public static function installShippedApps($softErrors = false) {
|
||||||
|
$appManager = \OC::$server->getAppManager();
|
||||||
|
$config = \OC::$server->getConfig();
|
||||||
$errors = [];
|
$errors = [];
|
||||||
foreach(\OC::$APPSROOTS as $app_dir) {
|
foreach(\OC::$APPSROOTS as $app_dir) {
|
||||||
if($dir = opendir( $app_dir['path'] )) {
|
if($dir = opendir( $app_dir['path'] )) {
|
||||||
while( false !== ( $filename = readdir( $dir ))) {
|
while( false !== ( $filename = readdir( $dir ))) {
|
||||||
if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
|
if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
|
||||||
if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
|
if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
|
||||||
if(!Installer::isInstalled($filename)) {
|
if($config->getAppValue($filename, "installed_version", null) === null) {
|
||||||
$info=OC_App::getAppInfo($filename);
|
$info=OC_App::getAppInfo($filename);
|
||||||
$enabled = isset($info['default_enable']);
|
$enabled = isset($info['default_enable']);
|
||||||
if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
|
if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps()))
|
||||||
&& \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
|
&& $config->getAppValue($filename, 'enabled') !== 'no') {
|
||||||
if ($softErrors) {
|
if ($softErrors) {
|
||||||
try {
|
try {
|
||||||
Installer::installShippedApp($filename);
|
Installer::installShippedApp($filename);
|
||||||
|
@ -534,7 +525,7 @@ class Installer {
|
||||||
} else {
|
} else {
|
||||||
Installer::installShippedApp($filename);
|
Installer::installShippedApp($filename);
|
||||||
}
|
}
|
||||||
\OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
|
$config->setAppValue($filename, 'enabled', 'yes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,6 +383,7 @@ class OC_App {
|
||||||
array $groups = []) {
|
array $groups = []) {
|
||||||
|
|
||||||
// Check if app is already downloaded
|
// Check if app is already downloaded
|
||||||
|
/** @var Installer $installer */
|
||||||
$installer = \OC::$server->query(Installer::class);
|
$installer = \OC::$server->query(Installer::class);
|
||||||
$isDownloaded = $installer->isDownloaded($appId);
|
$isDownloaded = $installer->isDownloaded($appId);
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,9 @@ interface IAppManager {
|
||||||
public function isEnabledForUser($appId, $user = null);
|
public function isEnabledForUser($appId, $user = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an app is installed in the instance
|
* Check if an app is enabled in the instance
|
||||||
|
*
|
||||||
|
* Notice: This actually checks if the app is enabled and not only if it is installed.
|
||||||
*
|
*
|
||||||
* @param string $appId
|
* @param string $appId
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|
|
@ -103,9 +103,9 @@ class InstallerTest extends TestCase {
|
||||||
\OC::$server->getLogger(),
|
\OC::$server->getLogger(),
|
||||||
\OC::$server->getConfig()
|
\OC::$server->getConfig()
|
||||||
);
|
);
|
||||||
$installer->installApp(self::$appid);
|
$this->assertNull(\OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is not listed before installation');
|
||||||
$isInstalled = Installer::isInstalled(self::$appid);
|
$this->assertSame('testapp', $installer->installApp(self::$appid));
|
||||||
$this->assertTrue($isInstalled);
|
$this->assertSame('no', \OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is listed after installation');
|
||||||
$this->assertSame('0.9', \OC::$server->getConfig()->getAppValue('testapp', 'installed_version'));
|
$this->assertSame('0.9', \OC::$server->getConfig()->getAppValue('testapp', 'installed_version'));
|
||||||
$installer->removeApp(self::$appid);
|
$installer->removeApp(self::$appid);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue