From 6d5e60bd9b801b2fe8dde2c947aa31b1d2b6ae87 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 5 Mar 2015 22:34:46 +0100 Subject: 14719 without public API --- lib/private/allconfig.php | 32 -------------------------------- lib/private/app.php | 32 ++++++++++++++++++++++++-------- lib/public/iconfig.php | 10 ---------- tests/lib/allconfig.php | 27 --------------------------- 4 files changed, 24 insertions(+), 77 deletions(-) diff --git a/lib/private/allconfig.php b/lib/private/allconfig.php index ff470b3f85a..d729936bc32 100644 --- a/lib/private/allconfig.php +++ b/lib/private/allconfig.php @@ -161,38 +161,6 @@ 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 c12447de752..d3dcf1f8c81 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -330,8 +330,8 @@ class OC_App { \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]; + if(self::getInternalAppIdByOcs($app) !== false) { + $app = self::getInternalAppIdByOcs($app); } OC_Appconfig::setValue($app, 'enabled', 'no' ); @@ -903,6 +903,21 @@ class OC_App { return $combinedApps; } + /** + * Returns the internal app ID or false + * @param string $ocsID + * @return string|false + */ + protected static function getInternalAppIdByOcs($ocsID) { + if(is_numeric($ocsID)) { + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); + if(array_search($ocsID, $idArray)) { + return array_search($ocsID, $idArray); + } + } + return false; + } + /** * get a list of all apps on apps.owncloud.com * @return array, multi-dimensional array of apps. @@ -928,12 +943,13 @@ class OC_App { $i = 0; $l = \OC::$server->getL10N('core'); foreach ($remoteApps as $app) { + $potentialCleanId = self::getInternalAppIdByOcs($app['id']); // enhance app info (for example the description) $app1[$i] = OC_App::parseAppInfo($app); $app1[$i]['author'] = $app['personid']; $app1[$i]['ocs_id'] = $app['id']; $app1[$i]['internal'] = 0; - $app1[$i]['active'] = self::isEnabled(\OC::$server->getConfig()->getAppsForKeyValue('ocsid', $app['id'])[0]); + $app1[$i]['active'] = ($potentialCleanId !== false) ? self::isEnabled($potentialCleanId) : false; $app1[$i]['update'] = false; $app1[$i]['groups'] = false; $app1[$i]['score'] = $app['score']; @@ -1086,13 +1102,13 @@ class OC_App { // 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'], '<')) { + $internalAppId = self::getInternalAppIdByOcs($app); + if($internalAppId !== false) { + if($appData && version_compare(\OC_App::getAppVersion($internalAppId), $appData['version'], '<')) { $app = self::downloadApp($app); } else { - self::enable($internalAppId[0]); - $app = $internalAppId[0]; + self::enable($internalAppId); + $app = $internalAppId; } } else { $app = self::downloadApp($app); diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php index 06638d0891b..96384ce476c 100644 --- a/lib/public/iconfig.php +++ b/lib/public/iconfig.php @@ -109,16 +109,6 @@ 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/tests/lib/allconfig.php b/tests/lib/allconfig.php index 290e40e8d88..7f8ad5ec221 100644 --- a/tests/lib/allconfig.php +++ b/tests/lib/allconfig.php @@ -26,33 +26,6 @@ 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(); -- cgit v1.2.3