From b919ae96f093a927e83f9f114a34400a4095ea5e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 7 Jul 2015 12:12:54 +0200 Subject: Display app names in update page for app updates Whenever the update page is displayed for apps, show app names instead of the core update text. --- core/templates/update.admin.php | 15 +++++++++ lib/base.php | 56 +++++++++++++++++++++------------- lib/private/app/appmanager.php | 67 +++++++++++++++++++++++++++++++++++++++++ tests/lib/app/manager.php | 67 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+), 21 deletions(-) diff --git a/core/templates/update.admin.php b/core/templates/update.admin.php index ccd5d236828..4e28aacf023 100644 --- a/core/templates/update.admin.php +++ b/core/templates/update.admin.php @@ -1,7 +1,20 @@
+ +

t('The following apps will be updated:')); ?>

+

t('%s will be updated to version %s.', array($_['productName'], $_['version']))); ?>

+ + +
+
    + +
  • ()
  • + +
+
+
t('The following apps will be disabled:')) ?> @@ -17,9 +30,11 @@ t('The theme %s has been disabled.', array($_['oldTheme']))) ?>
+
t('Please make sure that the database, the config folder and the data folder have been backed up before proceeding.')) ?>
+
t('To avoid timeouts with larger installations, you can instead run the following command from your installation directory:')) ?> diff --git a/lib/base.php b/lib/base.php index 9a682a7e90f..0a0d66aaf25 100644 --- a/lib/base.php +++ b/lib/base.php @@ -346,27 +346,7 @@ class OC { if (\OCP\Util::needUpgrade()) { $systemConfig = \OC::$server->getSystemConfig(); if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { - $version = OC_Util::getVersion(); - $oldTheme = $systemConfig->getValue('theme'); - $systemConfig->setValue('theme', ''); - OC_Util::addScript('config'); // needed for web root - OC_Util::addScript('update'); - $tmpl = new OC_Template('', 'update.admin', 'guest'); - $tmpl->assign('version', OC_Util::getVersionString()); - - // get third party apps - $apps = OC_App::getEnabledApps(); - $incompatibleApps = array(); - foreach ($apps as $appId) { - $info = OC_App::getAppInfo($appId); - if(!OC_App::isAppCompatible($version, $info)) { - $incompatibleApps[] = $info; - } - } - $tmpl->assign('appList', $incompatibleApps); - $tmpl->assign('productName', 'ownCloud'); // for now - $tmpl->assign('oldTheme', $oldTheme); - $tmpl->printPage(); + self::printUpgradePage(); exit(); } else { return true; @@ -375,6 +355,40 @@ class OC { return false; } + /** + * Prints the upgrade page + */ + private static function printUpgradePage() { + $systemConfig = \OC::$server->getSystemConfig(); + $oldTheme = $systemConfig->getValue('theme'); + $systemConfig->setValue('theme', ''); + \OCP\Util::addScript('config'); // needed for web root + \OCP\Util::addScript('update'); + + // check whether this is a core update or apps update + $installedVersion = $systemConfig->getValue('version', '0.0.0'); + $currentVersion = implode('.', OC_Util::getVersion()); + + $appManager = \OC::$server->getAppManager(); + + $tmpl = new OC_Template('', 'update.admin', 'guest'); + $tmpl->assign('version', OC_Util::getVersionString()); + + // if not a core upgrade, then it's apps upgrade + if (version_compare($currentVersion, $installedVersion, '=')) { + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade()); + $tmpl->assign('isAppsOnlyUpgrade', true); + } else { + // get third party apps + $version = OC_Util::getVersion(); + $tmpl->assign('appList', $appManager->getIncompatibleApps($version)); + $tmpl->assign('isAppsOnlyUpgrade', false); + } + $tmpl->assign('productName', 'ownCloud'); // for now + $tmpl->assign('oldTheme', $oldTheme); + $tmpl->printPage(); + } + public static function initTemplateEngine() { // Add the stuff we need always // following logic will import all vendor libraries that are diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 7a61cd53c59..86674aa047c 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -209,4 +209,71 @@ class AppManager implements IAppManager { $settingsMemCache = $this->memCacheFactory->create('settings'); $settingsMemCache->clear('listApps'); } + + /** + * Returns a list of apps that need upgrade + * + * @return array list of app info from apps that need an upgrade + * + * @internal + */ + public function getAppsNeedingUpgrade() { + $appsToUpgrade = []; + $apps = $this->getInstalledApps(); + foreach ($apps as $appId) { + $appInfo = $this->getAppInfo($appId); + $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); + if ($appDbVersion + && isset($appInfo['version']) + && version_compare($appInfo['version'], $appDbVersion, '>') + ) { + $appsToUpgrade[] = $appInfo; + } + } + + return $appsToUpgrade; + } + + /** + * Returns the app information from "appinfo/info.xml". + * + * If no version was present in "appinfo/info.xml", reads it + * from the external "appinfo/version" file instead. + * + * @param string $appId app id + * + * @return array app iinfo + * + * @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); + } + return $appInfo; + } + + /** + * Returns a list of apps incompatible with the given version + * + * @param array $version version as array of version components + * + * @return array list of app info from incompatible apps + * + * @internal + */ + public function getIncompatibleApps($version) { + $apps = $this->getInstalledApps(); + $incompatibleApps = array(); + foreach ($apps as $appId) { + $info = $this->getAppInfo($appId); + if (!\OC_App::isAppCompatible($version, $info)) { + $incompatibleApps[] = $info; + } + } + return $incompatibleApps; + } + } diff --git a/tests/lib/app/manager.php b/tests/lib/app/manager.php index 6cf7eb3bb6c..248112722c4 100644 --- a/tests/lib/app/manager.php +++ b/tests/lib/app/manager.php @@ -204,4 +204,71 @@ class Manager extends \PHPUnit_Framework_TestCase { $this->appConfig->setValue('test4', 'enabled', '["asd"]'); $this->assertEquals(['test1', 'test3'], $this->manager->getEnabledAppsForUser($user)); } + + public function testGetAppsNeedingUpgrade() { + $this->manager = $this->getMockBuilder('\OC\App\AppManager') + ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory]) + ->setMethods(['getAppInfo']) + ->getMock(); + + $appInfos = [ + 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'], + 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'], + 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'], + 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'], + ]; + + $this->manager->expects($this->any()) + ->method('getAppInfo') + ->will($this->returnCallback( + function($appId) use ($appInfos) { + return $appInfos[$appId]; + } + )); + + $this->appConfig->setValue('test1', 'enabled', 'yes'); + $this->appConfig->setValue('test1', 'installed_version', '1.0.0'); + $this->appConfig->setValue('test2', 'enabled', 'yes'); + $this->appConfig->setValue('test2', 'installed_version', '1.0.0'); + $this->appConfig->setValue('test3', 'enabled', 'yes'); + $this->appConfig->setValue('test3', 'installed_version', '1.0.0'); + + $apps = $this->manager->getAppsNeedingUpgrade(); + + $this->assertCount(2, $apps); + $this->assertEquals('test1', $apps[0]['id']); + $this->assertEquals('test3', $apps[1]['id']); + } + + public function testGetIncompatibleApps() { + $this->manager = $this->getMockBuilder('\OC\App\AppManager') + ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory]) + ->setMethods(['getAppInfo']) + ->getMock(); + + $appInfos = [ + 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'], + 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'], + 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'], + 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'], + ]; + + $this->manager->expects($this->any()) + ->method('getAppInfo') + ->will($this->returnCallback( + function($appId) use ($appInfos) { + return $appInfos[$appId]; + } + )); + + $this->appConfig->setValue('test1', 'enabled', 'yes'); + $this->appConfig->setValue('test2', 'enabled', 'yes'); + $this->appConfig->setValue('test3', 'enabled', 'yes'); + + $apps = $this->manager->getIncompatibleApps('8.2.0'); + + $this->assertCount(2, $apps); + $this->assertEquals('test1', $apps[0]['id']); + $this->assertEquals('test3', $apps[1]['id']); + } } -- cgit v1.2.3 From a2674b2b303c6b2a5935638af04f0e4a61afae24 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 20 Aug 2015 11:14:30 +0200 Subject: Additions to update page Apps to update and to disable will always be shown. Main title changes only when apps need updated, not core. Added bullet style. Exclude incompatible apps from updated apps list. --- core/css/styles.css | 7 +++++++ core/templates/update.admin.php | 11 +++++------ lib/base.php | 9 +++++---- lib/private/app/appmanager.php | 6 ++++-- tests/lib/app/manager.php | 9 ++++++--- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/css/styles.css b/core/css/styles.css index e019b874f61..f4ef236a5c6 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -672,6 +672,13 @@ label.infield { color: #ccc; } +#body-login .update .appList { + list-style: disc; + text-align: left; + margin-left: 25px; + margin-right: 25px; +} + #body-login .v-align { width: inherit; } diff --git a/core/templates/update.admin.php b/core/templates/update.admin.php index 4e28aacf023..191f727df71 100644 --- a/core/templates/update.admin.php +++ b/core/templates/update.admin.php @@ -1,13 +1,14 @@
-

t('The following apps will be updated:')); ?>

+

t('Apps update required.')); ?>

t('%s will be updated to version %s.', array($_['productName'], $_['version']))); ?>

+ t('These apps will be updated:')); ?>
  • ()
  • @@ -15,11 +16,11 @@
- +
- t('The following apps will be disabled:')) ?> + t('These incompatible apps will be disabled:')) ?>
    - +
  • ()
@@ -30,11 +31,9 @@ t('The theme %s has been disabled.', array($_['oldTheme']))) ?>
-
t('Please make sure that the database, the config folder and the data folder have been backed up before proceeding.')) ?>
-
t('To avoid timeouts with larger installations, you can instead run the following command from your installation directory:')) ?> diff --git a/lib/base.php b/lib/base.php index 0a0d66aaf25..860260576dc 100644 --- a/lib/base.php +++ b/lib/base.php @@ -376,14 +376,15 @@ class OC { // if not a core upgrade, then it's apps upgrade if (version_compare($currentVersion, $installedVersion, '=')) { - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade()); $tmpl->assign('isAppsOnlyUpgrade', true); } else { - // get third party apps - $version = OC_Util::getVersion(); - $tmpl->assign('appList', $appManager->getIncompatibleApps($version)); $tmpl->assign('isAppsOnlyUpgrade', false); } + + // get third party apps + $ocVersion = OC_Util::getVersion(); + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); + $tmpl->assign('incompatibleAppsList', $appManager->getIncompatibleApps($ocVersion)); $tmpl->assign('productName', 'ownCloud'); // for now $tmpl->assign('oldTheme', $oldTheme); $tmpl->printPage(); diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 86674aa047c..75b1c0a7865 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -213,11 +213,12 @@ class AppManager implements IAppManager { /** * Returns a list of apps that need upgrade * + * @param array $version ownCloud version as array of version components * @return array list of app info from apps that need an upgrade * * @internal */ - public function getAppsNeedingUpgrade() { + public function getAppsNeedingUpgrade($ocVersion) { $appsToUpgrade = []; $apps = $this->getInstalledApps(); foreach ($apps as $appId) { @@ -226,6 +227,7 @@ class AppManager implements IAppManager { if ($appDbVersion && isset($appInfo['version']) && version_compare($appInfo['version'], $appDbVersion, '>') + && \OC_App::isAppCompatible($ocVersion, $appInfo) ) { $appsToUpgrade[] = $appInfo; } @@ -258,7 +260,7 @@ class AppManager implements IAppManager { /** * Returns a list of apps incompatible with the given version * - * @param array $version version as array of version components + * @param array $version ownCloud version as array of version components * * @return array list of app info from incompatible apps * diff --git a/tests/lib/app/manager.php b/tests/lib/app/manager.php index 248112722c4..7333d7601b1 100644 --- a/tests/lib/app/manager.php +++ b/tests/lib/app/manager.php @@ -212,9 +212,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->getMock(); $appInfos = [ - 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'], + 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '9.0.0'], 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'], 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'], + 'test4' => ['id' => 'test4', 'version' => '3.0.0', 'requiremin' => '8.1.0'], 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'], ]; @@ -232,12 +233,14 @@ class Manager extends \PHPUnit_Framework_TestCase { $this->appConfig->setValue('test2', 'installed_version', '1.0.0'); $this->appConfig->setValue('test3', 'enabled', 'yes'); $this->appConfig->setValue('test3', 'installed_version', '1.0.0'); + $this->appConfig->setValue('test4', 'enabled', 'yes'); + $this->appConfig->setValue('test4', 'installed_version', '2.4.0'); - $apps = $this->manager->getAppsNeedingUpgrade(); + $apps = $this->manager->getAppsNeedingUpgrade('8.2.0'); $this->assertCount(2, $apps); $this->assertEquals('test1', $apps[0]['id']); - $this->assertEquals('test3', $apps[1]['id']); + $this->assertEquals('test4', $apps[1]['id']); } public function testGetIncompatibleApps() { -- cgit v1.2.3