diff options
author | Frank Karlitschek <karlitschek@gmx.de> | 2015-03-05 16:06:50 -0500 |
---|---|---|
committer | Frank Karlitschek <karlitschek@gmx.de> | 2015-03-05 16:06:50 -0500 |
commit | a7fc0fc07b42dbd3d88cb73c1b0ab16910a1b828 (patch) | |
tree | 03363e8f9f786aa6823ba9b76cc812621322877e | |
parent | eb2ac86c5d645829477b327402a9881a3d6fdf2b (diff) | |
parent | c032b94b774d9737e5af17064a2c3e61e57c609b (diff) | |
download | nextcloud-server-a7fc0fc07b42dbd3d88cb73c1b0ab16910a1b828.tar.gz nextcloud-server-a7fc0fc07b42dbd3d88cb73c1b0ab16910a1b828.zip |
Merge pull request #14719 from owncloud/fix-totally-broken-appstore
[stable8] Fix totally broken AppStore code…
-rw-r--r-- | lib/private/allconfig.php | 31 | ||||
-rw-r--r-- | lib/private/app.php | 28 | ||||
-rw-r--r-- | lib/public/iconfig.php | 9 | ||||
-rw-r--r-- | settings/ajax/disableapp.php | 3 | ||||
-rw-r--r-- | settings/ajax/enableapp.php | 3 | ||||
-rw-r--r-- | tests/lib/allconfig.php | 27 |
6 files changed, 93 insertions, 8 deletions
diff --git a/lib/private/allconfig.php b/lib/private/allconfig.php index 00defd920d7..ff470b3f85a 100644 --- a/lib/private/allconfig.php +++ b/lib/private/allconfig.php @@ -161,6 +161,37 @@ class AllConfig implements \OCP\IConfig { \OC::$server->getAppConfig()->deleteApp($appName); } + /** + * Determines the apps that have the set the value for the specified + * keys + * + * @param string $value the value to get the app for + * @param string $key the key too lookup + * @return array of app IDs + */ + public function getAppsForKeyValue($key, $value) { + // TODO - FIXME + $this->fixDIInit(); + + $qb = $this->connection->createQueryBuilder(); + $qb + ->select('appid') + ->from('`*PREFIX*appconfig`') + ->where('configvalue = ?') + ->andWhere('configkey = ?') + ->setParameter(0, $value) + ->setParameter(1, $key) + ; + $result = $qb->execute(); + + $appIDs = []; + while ($row = $result->fetch()) { + $appIDs[] = $row['appid']; + } + + sort($appIDs); + return $appIDs; + } /** * Set a user defined value diff --git a/lib/private/app.php b/lib/private/app.php index 9e9a3881068..c12447de752 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -277,6 +277,7 @@ class OC_App { */ public static function enable($app, $groups = null) { self::$enabledAppsCache = array(); // flush + if (!OC_Installer::isInstalled($app)) { $app = self::installApp($app); } @@ -327,6 +328,12 @@ class OC_App { self::$enabledAppsCache = array(); // flush // check if app is a shipped app or not. if not delete \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); + + // Convert OCS ID to regular application identifier + if(is_numeric($app)) { + $app = \OC::$server->getConfig()->getAppsForKeyValue('ocsid', $app)[0]; + } + OC_Appconfig::setValue($app, 'enabled', 'no' ); } @@ -925,7 +932,8 @@ class OC_App { $app1[$i] = OC_App::parseAppInfo($app); $app1[$i]['author'] = $app['personid']; $app1[$i]['ocs_id'] = $app['id']; - $app1[$i]['internal'] = $app1[$i]['active'] = 0; + $app1[$i]['internal'] = 0; + $app1[$i]['active'] = self::isEnabled(\OC::$server->getConfig()->getAppsForKeyValue('ocsid', $app['id'])[0]); $app1[$i]['update'] = false; $app1[$i]['groups'] = false; $app1[$i]['score'] = $app['score']; @@ -1055,7 +1063,6 @@ class OC_App { } } - /** * @param mixed $app * @return bool @@ -1075,8 +1082,21 @@ class OC_App { } else { $app = OC_Installer::installShippedApp($app); } - }else{ - $app = self::downloadApp($app); + } else { + // Maybe the app is already installed - compare the version in this + // case and use the local already installed one. + // FIXME: This is a horrible hack. I feel sad. The god of code cleanness may forgive me. + $internalAppId = $config->getAppsForKeyValue('ocsid', $app); + if(isset($internalAppId[0])) { + if($appData && version_compare(\OC_App::getAppVersion($internalAppId[0]), $appData['version'], '<')) { + $app = self::downloadApp($app); + } else { + self::enable($internalAppId[0]); + $app = $internalAppId[0]; + } + } else { + $app = self::downloadApp($app); + } } if($app!==false) { diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php index 868a4133d2e..06638d0891b 100644 --- a/lib/public/iconfig.php +++ b/lib/public/iconfig.php @@ -109,6 +109,15 @@ interface IConfig { */ public function deleteAppValues($appName); + /** + * Determines the apps that have the set the value for the specified + * keys + * + * @param string $value the value to get the app for + * @param string $key the key too lookup + * @return array of app IDs + */ + public function getAppsForKeyValue($key, $value); /** * Set a user defined value diff --git a/settings/ajax/disableapp.php b/settings/ajax/disableapp.php index 1a133ea9af7..be717e27ca4 100644 --- a/settings/ajax/disableapp.php +++ b/settings/ajax/disableapp.php @@ -11,8 +11,7 @@ $appId = $_POST['appid']; $appId = OC_App::cleanAppId($appId); // FIXME: Clear the cache - move that into some sane helper method -\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-0'); -\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-1'); +\OC::$server->getMemCacheFactory()->create('settings')->clear('listApps-'); OC_App::disable($appId); OC_JSON::success(); diff --git a/settings/ajax/enableapp.php b/settings/ajax/enableapp.php index 88abff487db..fcfa2780332 100644 --- a/settings/ajax/enableapp.php +++ b/settings/ajax/enableapp.php @@ -8,8 +8,7 @@ $groups = isset($_POST['groups']) ? $_POST['groups'] : null; try { OC_App::enable(OC_App::cleanAppId($_POST['appid']), $groups); // FIXME: Clear the cache - move that into some sane helper method - \OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-0'); - \OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-1'); + \OC::$server->getMemCacheFactory()->create('settings')->clear('listApps-'); OC_JSON::success(); } catch (Exception $e) { OC_Log::write('core', $e->getMessage(), OC_Log::ERROR); diff --git a/tests/lib/allconfig.php b/tests/lib/allconfig.php index 7f8ad5ec221..290e40e8d88 100644 --- a/tests/lib/allconfig.php +++ b/tests/lib/allconfig.php @@ -26,6 +26,33 @@ class TestAllConfig extends \Test\TestCase { return new \OC\AllConfig($systemConfig, $connection); } + // FIXME: Actually an integration test... – Shouldn't be in the unit test at all. + public function testGetAppsForKeyValue() { + $config = $this->getConfig(); + + // preparation - add something to the database + $data = [ + ['myFirstApp', 'key1', 'value1'], + ['mySecondApp', 'key1', 'value2'], + ['mySecondApp', 'key3', 'value2'], + ['myThirdApp', 'key3', 'value3'], + ['myThirdApp', 'key3', 'value2'], + ]; + foreach ($data as $entry) { + $config->setAppValue($entry[0], $entry[1], $entry[2]); + } + + $this->assertEquals(['mySecondApp'], $config->getAppsForKeyValue('key1', 'value2')); + $this->assertEquals(['mySecondApp', 'myThirdApp'], $config->getAppsForKeyValue('key3', 'value2')); + $this->assertEquals([], $config->getAppsForKeyValue('NotExisting', 'NotExistingValue')); + + // cleanup + foreach ($data as $entry) { + $config->deleteAppValue($entry[0], $entry[1]); + + } + } + public function testDeleteUserValue() { $config = $this->getConfig(); |