summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-03-27 16:07:41 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-03-27 16:07:41 +0100
commit4d12c4a38b13e2319b85db27b03ba0eb6b9cff35 (patch)
treefe7934b972d2423c702c92366c17600fecaf3857
parent722e50a112579d851b958a21cf26c2e85a4ce5c2 (diff)
parent378eef7eb45bd2ec8e6a06e2ba776f55078dcbef (diff)
downloadnextcloud-server-4d12c4a38b13e2319b85db27b03ba0eb6b9cff35.tar.gz
nextcloud-server-4d12c4a38b13e2319b85db27b03ba0eb6b9cff35.zip
Merge pull request #13938 from owncloud/deprecate-iappconfig
Deprecated \OCP\IAppConfig - add missing methods to IConfig
-rw-r--r--apps/files_sharing/tests/api.php20
-rw-r--r--lib/private/allconfig.php89
-rw-r--r--lib/private/legacy/appconfig.php2
-rw-r--r--lib/private/share/helper.php8
-rw-r--r--lib/public/iappconfig.php7
-rw-r--r--lib/public/iconfig.php37
-rw-r--r--tests/lib/share/share.php10
7 files changed, 155 insertions, 18 deletions
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index d3f0171075e..44c6b1dc4b9 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -1312,9 +1312,19 @@ class Test_Files_Sharing_Api extends TestCase {
public function testDefaultExpireDate() {
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_default_expire_date', 'yes');
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_enforce_expire_date', 'yes');
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_expire_after_n_days', '2');
+
+ // TODO drop this once all code paths use the DI version - otherwise
+ // the cache inside this config object is out of date because
+ // OC_Appconfig is used and bypasses this cache which lead to integrity
+ // constraint violations
+ $config = \OC::$server->getConfig();
+ $config->deleteAppValue('core', 'shareapi_default_expire_date');
+ $config->deleteAppValue('core', 'shareapi_enforce_expire_date');
+ $config->deleteAppValue('core', 'shareapi_expire_after_n_days');
+
+ $config->setAppValue('core', 'shareapi_default_expire_date', 'yes');
+ $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes');
+ $config->setAppValue('core', 'shareapi_expire_after_n_days', '2');
// default expire date is set to 2 days
// the time when the share was created is set to 3 days in the past
@@ -1358,8 +1368,8 @@ class Test_Files_Sharing_Api extends TestCase {
//cleanup
$result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
$this->assertTrue($result);
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_default_expire_date', 'no');
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_enforce_expire_date', 'no');
+ $config->setAppValue('core', 'shareapi_default_expire_date', 'no');
+ $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
}
}
diff --git a/lib/private/allconfig.php b/lib/private/allconfig.php
index df75a332a13..5706abc92be 100644
--- a/lib/private/allconfig.php
+++ b/lib/private/allconfig.php
@@ -26,6 +26,8 @@
*/
namespace OC;
+
+use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\PreConditionNotMetException;
@@ -39,6 +41,9 @@ class AllConfig implements \OCP\IConfig {
/** @var IDBConnection */
private $connection;
+ /** @var IAppConfig */
+ private $appConfig;
+
/**
* 3 dimensional array with the following structure:
* [ $userId =>
@@ -80,11 +85,17 @@ class AllConfig implements \OCP\IConfig {
*
* otherwise a SQLite database is created in the wrong directory
* because the database connection was created with an uninitialized config
+ *
+ * The same applies for the app config, because it uses the database
+ * connection itself
*/
private function fixDIInit() {
if($this->connection === null) {
$this->connection = \OC::$server->getDatabaseConnection();
}
+ if ($this->appConfig === null) {
+ $this->appConfig = \OC::$server->getAppConfig();
+ }
}
/**
@@ -134,7 +145,10 @@ class AllConfig implements \OCP\IConfig {
* @return string[] the keys stored for the app
*/
public function getAppKeys($appName) {
- return \OC::$server->getAppConfig()->getKeys($appName);
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ return $this->appConfig->getKeys($appName);
}
/**
@@ -145,7 +159,24 @@ class AllConfig implements \OCP\IConfig {
* @param string $value the value that should be stored
*/
public function setAppValue($appName, $key, $value) {
- \OC::$server->getAppConfig()->setValue($appName, $key, $value);
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ $this->appConfig->setValue($appName, $key, $value);
+ }
+
+ /**
+ * Checks if a key is set in the apps config
+ *
+ * @param string $appName the appName tto look a key up
+ * @param string $key the key to look up
+ * @return bool
+ */
+ public function hasAppKey($appName, $key) {
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ $this->appConfig->hasKey($appName, $key);
}
/**
@@ -157,7 +188,49 @@ class AllConfig implements \OCP\IConfig {
* @return string the saved value
*/
public function getAppValue($appName, $key, $default = '') {
- return \OC::$server->getAppConfig()->getValue($appName, $key, $default);
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ return $this->appConfig->getValue($appName, $key, $default);
+ }
+
+ /**
+ * Get all app values that are stored
+ *
+ * @param string $appName the appName
+ * @return array with key - value pair as they are saved previously
+ */
+ public function getAppValuesByApp($appName) {
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ return $this->appConfig->getValues($appName, false);
+ }
+
+ /**
+ * Get all app values that use the same key
+ *
+ * @param string $key the appName
+ * @return array with key - value pair as they are saved previously with the
+ * app name as key
+ */
+ public function getAppValuesByKey($key) {
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ return $this->appConfig->getValues(false, $key);
+ }
+
+ /**
+ * Get all apps that have at least one value saved
+ *
+ * @return array containing app names
+ */
+ public function getApps() {
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ return $this->appConfig->getApps();
}
/**
@@ -167,7 +240,10 @@ class AllConfig implements \OCP\IConfig {
* @param string $key the key of the value, under which it was saved
*/
public function deleteAppValue($appName, $key) {
- \OC::$server->getAppConfig()->deleteKey($appName, $key);
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ $this->appConfig->deleteKey($appName, $key);
}
/**
@@ -176,7 +252,10 @@ class AllConfig implements \OCP\IConfig {
* @param string $appName the appName the configs are stored under
*/
public function deleteAppValues($appName) {
- \OC::$server->getAppConfig()->deleteApp($appName);
+ // TODO - FIXME
+ $this->fixDIInit();
+
+ $this->appConfig->deleteApp($appName);
}
diff --git a/lib/private/legacy/appconfig.php b/lib/private/legacy/appconfig.php
index 3bf1fbd739e..00302d5577f 100644
--- a/lib/private/legacy/appconfig.php
+++ b/lib/private/legacy/appconfig.php
@@ -27,7 +27,7 @@
* This class provides an easy way for apps to store config values in the
* database.
*
- * @deprecated use \OC::$server->getAppConfig() to get an \OCP\IAppConfig instance
+ * @deprecated use \OC::$server->getConfig() to get an \OCP\IConfig instance
*/
class OC_Appconfig {
/**
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php
index 39dc8d8c7ef..5345c8a018f 100644
--- a/lib/private/share/helper.php
+++ b/lib/private/share/helper.php
@@ -170,14 +170,16 @@ class Helper extends \OC\Share\Constants {
*/
public static function getDefaultExpireSetting() {
+ $config = \OC::$server->getConfig();
+
$defaultExpireSettings = array('defaultExpireDateSet' => false);
// get default expire settings
- $defaultExpireDate = \OC_Appconfig::getValue('core', 'shareapi_default_expire_date', 'no');
+ $defaultExpireDate = $config->getAppValue('core', 'shareapi_default_expire_date', 'no');
if ($defaultExpireDate === 'yes') {
- $enforceExpireDate = \OC_Appconfig::getValue('core', 'shareapi_enforce_expire_date', 'no');
+ $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no');
$defaultExpireSettings['defaultExpireDateSet'] = true;
- $defaultExpireSettings['expireAfterDays'] = (int)\OC_Appconfig::getValue('core', 'shareapi_expire_after_n_days', '7');
+ $defaultExpireSettings['expireAfterDays'] = (int)($config->getAppValue('core', 'shareapi_expire_after_n_days', '7'));
$defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes' ? true : false;
}
diff --git a/lib/public/iappconfig.php b/lib/public/iappconfig.php
index 33fc3e4e362..8846445f94c 100644
--- a/lib/public/iappconfig.php
+++ b/lib/public/iappconfig.php
@@ -27,6 +27,10 @@ namespace OCP;
/**
* This class provides an easy way for apps to store config values in the
* database.
+ *
+ * @deprecated This interface will be dropped with ownCloud 10.1 which will be
+ * released in the first quarter of 2017. Use the methods of
+ * \OCP\IConfig instead
*/
interface IAppConfig {
/**
@@ -34,6 +38,7 @@ interface IAppConfig {
* @param string $app
* @param string $key
* @return bool
+ * @deprecated use method hasAppKey of \OCP\IConfig
*/
public function hasKey($app, $key);
@@ -76,6 +81,7 @@ interface IAppConfig {
* @param string|false $key
* @param string|false $app
* @return array|false
+ * @deprecated use method getAppValuesByApp or getAppValuesByKey of \OCP\IConfig
*/
public function getValues($app, $key);
@@ -94,6 +100,7 @@ interface IAppConfig {
/**
* Get all apps using the config
* @return array an array of app ids
+ * @deprecated use method getApps of \OCP\IConfig
*
* This function returns a list of all apps that have at least one
* entry in the appconfig table.
diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php
index c63ba1a90a6..8321c4043cd 100644
--- a/lib/public/iconfig.php
+++ b/lib/public/iconfig.php
@@ -90,6 +90,16 @@ interface IConfig {
public function setAppValue($appName, $key, $value);
/**
+ * Checks if a key is set in the apps config
+ *
+ * @param string $appName the appName tto look a key up
+ * @param string $key the key to look up
+ * @return bool
+ * @since 8.1.0
+ */
+ public function hasAppKey($appName, $key);
+
+ /**
* Looks up an app wide defined value
*
* @param string $appName the appName that we stored the value under
@@ -100,6 +110,33 @@ interface IConfig {
public function getAppValue($appName, $key, $default = '');
/**
+ * Get all app values that are stored
+ *
+ * @param string $appName the appName
+ * @return array with key - value pair as they are saved previously
+ * @since 8.1.0
+ */
+ public function getAppValuesByApp($appName);
+
+ /**
+ * Get all app values that use the same key
+ *
+ * @param string $key the appName
+ * @return array with key - value pair as they are saved previously with the
+ * app name as key
+ * @since 8.1.0
+ */
+ public function getAppValuesByKey($key);
+
+ /**
+ * Get all apps that have at least one value saved
+ *
+ * @return array containing app names
+ * @since 8.1.0
+ */
+ public function getApps();
+
+ /**
* Delete an app wide defined value
*
* @param string $appName the appName that we stored the value under
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 42bb82968af..a564fe04b11 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -857,8 +857,10 @@ class Test_Share extends \Test\TestCase {
public function testShareItemWithLinkAndDefaultExpireDate() {
OC_User::setUserId($this->user1);
- \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes');
- \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2');
+ $config = \OC::$server->getConfig();
+
+ $config->setAppValue('core', 'shareapi_default_expire_date', 'yes');
+ $config->setAppValue('core', 'shareapi_expire_after_n_days', '2');
$token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ);
$this->assertInternalType(
@@ -875,8 +877,8 @@ class Test_Share extends \Test\TestCase {
'Failed asserting that the returned row has an default expiration date.'
);
- \OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date');
- \OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days');
+ $config->deleteAppValue('core', 'shareapi_default_expire_date');
+ $config->deleteAppValue('core', 'shareapi_expire_after_n_days');
}