summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_sharing/appinfo/app.php4
-rw-r--r--apps/files_sharing/appinfo/install.php22
-rw-r--r--apps/files_sharing/appinfo/update.php1
-rw-r--r--apps/files_sharing/appinfo/version2
-rw-r--r--apps/files_sharing/lib/mountprovider.php6
-rw-r--r--apps/files_sharing/lib/sharedstorage.php7
-rw-r--r--apps/user_ldap/appinfo/app.php3
-rw-r--r--apps/user_ldap/appinfo/install.php3
-rw-r--r--apps/user_ldap/appinfo/update.php3
-rw-r--r--apps/user_ldap/appinfo/version2
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/appconfig.php219
-rw-r--r--lib/private/share/share.php2
-rw-r--r--settings/templates/admin.php8
-rw-r--r--tests/lib/appconfig.php451
15 files changed, 400 insertions, 335 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 9000fafd8dd..295d013beff 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -58,10 +58,6 @@ $application->setupPropagation();
\OCP\Util::addScript('files_sharing', 'external');
\OCP\Util::addStyle('files_sharing', 'sharetabview');
-// FIXME: registering a job here will cause additional useless SQL queries
-// when the route is not cron.php, needs a better way
-\OC::$server->getJobList()->add('OCA\Files_sharing\Lib\DeleteOrphanedSharesJob');
-
\OC::$server->getActivityManager()->registerExtension(function() {
return new \OCA\Files_Sharing\Activity(
\OC::$server->query('L10NFactory'),
diff --git a/apps/files_sharing/appinfo/install.php b/apps/files_sharing/appinfo/install.php
new file mode 100644
index 00000000000..f076a17e444
--- /dev/null
+++ b/apps/files_sharing/appinfo/install.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+\OC::$server->getJobList()->add('OCA\Files_sharing\Lib\DeleteOrphanedSharesJob');
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php
index e98b60ea36d..66b8b78cacf 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -28,3 +28,4 @@ if (version_compare($installedVersion, '0.6.0', '<')) {
$m->addAcceptRow();
}
+\OC::$server->getJobList()->add('OCA\Files_sharing\Lib\DeleteOrphanedSharesJob');
diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version
index b6160487433..844f6a91acb 100644
--- a/apps/files_sharing/appinfo/version
+++ b/apps/files_sharing/appinfo/version
@@ -1 +1 @@
-0.6.2
+0.6.3
diff --git a/apps/files_sharing/lib/mountprovider.php b/apps/files_sharing/lib/mountprovider.php
index 3f59fd131d0..14a79625993 100644
--- a/apps/files_sharing/lib/mountprovider.php
+++ b/apps/files_sharing/lib/mountprovider.php
@@ -66,12 +66,6 @@ class MountProvider implements IMountProvider {
return $share['permissions'] > 0;
});
$shares = array_map(function ($share) use ($user, $storageFactory) {
- try {
- Filesystem::initMountPoints($share['uid_owner']);
- } catch(NoUserException $e) {
- \OC::$server->getLogger()->warning('The user \'' . $share['uid_owner'] . '\' of share with ID \'' . $share['id'] . '\' can\'t be retrieved.', array('app' => 'files_sharing'));
- return null;
- }
// for updating etags for the share owner when we make changes to this share.
$ownerPropagator = $this->propagationManager->getChangePropagator($share['uid_owner']);
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index c7529df0617..1ac401f3cf8 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -55,6 +55,10 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
$this->ownerView = $arguments['ownerView'];
}
+ private function init() {
+ Filesystem::initMountPoints($this->share['uid_owner']);
+ }
+
/**
* get id of the mount point
*
@@ -80,6 +84,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return array Returns array with the keys path, permissions, and owner or false if not found
*/
public function getFile($target) {
+ $this->init();
if (!isset($this->files[$target])) {
// Check for partial files
if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
@@ -319,7 +324,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
}
public function rename($path1, $path2) {
-
+ $this->init();
// we need the paths relative to data/user/files
$relPath1 = $this->getMountPoint() . '/' . $path1;
$relPath2 = $this->getMountPoint() . '/' . $path2;
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php
index 68fd1b698e0..60c2accdccb 100644
--- a/apps/user_ldap/appinfo/app.php
+++ b/apps/user_ldap/appinfo/app.php
@@ -59,9 +59,6 @@ if(count($configPrefixes) > 0) {
OC_Group::useBackend($groupBackend);
}
-OCP\Backgroundjob::registerJob('OCA\user_ldap\lib\Jobs');
-OCP\Backgroundjob::registerJob('\OCA\User_LDAP\Jobs\CleanUp');
-
\OCP\Util::connectHook(
'\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName',
diff --git a/apps/user_ldap/appinfo/install.php b/apps/user_ldap/appinfo/install.php
index 0b3f84b8baf..f70eb746480 100644
--- a/apps/user_ldap/appinfo/install.php
+++ b/apps/user_ldap/appinfo/install.php
@@ -23,3 +23,6 @@ $state = OCP\Config::getSystemValue('ldapIgnoreNamingRules', 'doSet');
if($state === 'doSet') {
OCP\Config::setSystemValue('ldapIgnoreNamingRules', false);
}
+
+OCP\Backgroundjob::registerJob('OCA\user_ldap\lib\Jobs');
+OCP\Backgroundjob::registerJob('\OCA\User_LDAP\Jobs\CleanUp');
diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php
index 4907db0cdae..33a7219644b 100644
--- a/apps/user_ldap/appinfo/update.php
+++ b/apps/user_ldap/appinfo/update.php
@@ -34,3 +34,6 @@ if(version_compare($installedVersion, '0.6.2', '<')) {
\OC::$server->getConfig()->deleteAppValue('user_ldap', $prefix . "ldap_nocase");
}
}
+
+OCP\Backgroundjob::registerJob('OCA\user_ldap\lib\Jobs');
+OCP\Backgroundjob::registerJob('\OCA\User_LDAP\Jobs\CleanUp');
diff --git a/apps/user_ldap/appinfo/version b/apps/user_ldap/appinfo/version
index b6160487433..844f6a91acb 100644
--- a/apps/user_ldap/appinfo/version
+++ b/apps/user_ldap/appinfo/version
@@ -1 +1 @@
-0.6.2
+0.6.3
diff --git a/lib/base.php b/lib/base.php
index 9cf0228bbd9..077ecfa4666 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -540,7 +540,7 @@ class OC {
// setup 3rdparty autoloader
$vendorAutoLoad = OC::$THIRDPARTYROOT . '/3rdparty/autoload.php';
if (!file_exists($vendorAutoLoad)) {
- throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty".');
+ throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".');
}
require_once $vendorAutoLoad;
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index b88df10dddd..7ee64980fd0 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -28,23 +28,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-/*
- *
- * The following SQL statement is just a help for developers and will not be
- * executed!
- *
- * CREATE TABLE `appconfig` (
- * `appid` VARCHAR( 255 ) NOT NULL ,
- * `configkey` VARCHAR( 255 ) NOT NULL ,
- * `configvalue` VARCHAR( 255 ) NOT NULL
- * )
- *
- */
namespace OC;
-use OC\DB\Connection;
use OCP\IAppConfig;
+use OCP\IDBConnection;
/**
* This class provides an easy way for apps to store config values in the
@@ -52,54 +40,32 @@ use OCP\IAppConfig;
*/
class AppConfig implements IAppConfig {
/**
- * @var \OC\DB\Connection $conn
+ * @var \OCP\IDBConnection $conn
*/
protected $conn;
private $cache = array();
- private $appsLoaded = array();
-
- /**
- * @var string[]
- */
- private $apps = null;
-
/**
- * @param Connection $conn
+ * @param IDBConnection $conn
*/
- public function __construct(Connection $conn) {
+ public function __construct(IDBConnection $conn) {
$this->conn = $conn;
+ $this->configLoaded = false;
}
/**
* @param string $app
- * @return string[]
- */
- private function getAppCache($app) {
- if (!isset($this->cache[$app])) {
- $this->cache[$app] = array();
- }
- return $this->cache[$app];
- }
-
- /**
- * @param string $app
- * @return \string[]
+ * @return array
*/
private function getAppValues($app) {
- $appCache = $this->getAppCache($app);
- if (array_search($app, $this->appsLoaded) === false) {
- $query = 'SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
- . ' WHERE `appid` = ?';
- $result = $this->conn->executeQuery($query, array($app));
- while ($row = $result->fetch()) {
- $appCache[$row['configkey']] = $row['configvalue'];
- }
- $this->appsLoaded[] = $app;
+ $this->loadConfigValues();
+
+ if (isset($this->cache[$app])) {
+ return $this->cache[$app];
}
- $this->cache[$app] = $appCache;
- return $appCache;
+
+ return [];
}
/**
@@ -111,18 +77,9 @@ class AppConfig implements IAppConfig {
* entry in the appconfig table.
*/
public function getApps() {
- if (is_array($this->apps)) {
- return $this->apps;
- }
- $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`';
- $result = $this->conn->executeQuery($query);
+ $this->loadConfigValues();
- $apps = array();
- while ($appid = $result->fetchColumn()) {
- $apps[] = $appid;
- }
- $this->apps = $apps;
- return $apps;
+ return $this->getSortedKeys($this->cache);
}
/**
@@ -135,8 +92,17 @@ class AppConfig implements IAppConfig {
* not returned.
*/
public function getKeys($app) {
- $values = $this->getAppValues($app);
- $keys = array_keys($values);
+ $this->loadConfigValues();
+
+ if (isset($this->cache[$app])) {
+ return $this->getSortedKeys($this->cache[$app]);
+ }
+
+ return [];
+ }
+
+ public function getSortedKeys($data) {
+ $keys = array_keys($data);
sort($keys);
return $keys;
}
@@ -153,12 +119,13 @@ class AppConfig implements IAppConfig {
* not exist the default value will be returned
*/
public function getValue($app, $key, $default = null) {
- $values = $this->getAppValues($app);
- if (isset($values[$key])) {
- return $values[$key];
- } else {
- return $default;
+ $this->loadConfigValues();
+
+ if ($this->hasKey($app, $key)) {
+ return $this->cache[$app][$key];
}
+
+ return $default;
}
/**
@@ -169,8 +136,9 @@ class AppConfig implements IAppConfig {
* @return bool
*/
public function hasKey($app, $key) {
- $values = $this->getAppValues($app);
- return array_key_exists($key, $values);
+ $this->loadConfigValues();
+
+ return isset($this->cache[$app][$key]);
}
/**
@@ -179,11 +147,9 @@ class AppConfig implements IAppConfig {
* @param string $app app
* @param string $key key
* @param string $value value
- * @return void
+ * @return bool True if the value was inserted or updated, false if the value was the same
*/
public function setValue($app, $key, $value) {
- $inserted = false;
- // Does the key exist? no: insert, yes: update.
if (!$this->hasKey($app, $key)) {
$inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [
'appid' => $app,
@@ -193,29 +159,32 @@ class AppConfig implements IAppConfig {
'appid',
'configkey',
]);
- }
- if (!$inserted) {
- $oldValue = $this->getValue($app, $key);
- if($oldValue === strval($value)) {
- return;
+ if ($inserted) {
+ if (!isset($this->cache[$app])) {
+ $this->cache[$app] = [];
+ }
+
+ $this->cache[$app][$key] = $value;
+ return true;
}
- $data = array(
- 'configvalue' => $value,
- );
- $where = array(
- 'appid' => $app,
- 'configkey' => $key,
- );
- $this->conn->update('*PREFIX*appconfig', $data, $where);
- }
- if (!isset($this->cache[$app])) {
- $this->cache[$app] = array();
- }
- if (is_array($this->apps) and array_search($app, $this->apps) === false) {
- $this->apps[$app] = $app;
}
+
+ $sql = $this->conn->getQueryBuilder();
+ $sql->update('appconfig')
+ ->set('configvalue', $sql->createParameter('configvalue'))
+ ->where($sql->expr()->eq('appid', $sql->createParameter('app')))
+ ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
+ ->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue')))
+ ->setParameter('configvalue', $value)
+ ->setParameter('app', $app)
+ ->setParameter('configkey', $key)
+ ->setParameter('configvalue', $value);
+ $changedRow = (bool) $sql->execute();
+
$this->cache[$app][$key] = $value;
+
+ return $changedRow;
}
/**
@@ -226,14 +195,17 @@ class AppConfig implements IAppConfig {
* @return boolean|null
*/
public function deleteKey($app, $key) {
- $where = array(
- 'appid' => $app,
- 'configkey' => $key,
- );
- $this->conn->delete('*PREFIX*appconfig', $where);
- if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) {
- unset($this->cache[$app][$key]);
- }
+ $this->loadConfigValues();
+
+ $sql = $this->conn->getQueryBuilder();
+ $sql->delete('appconfig')
+ ->where($sql->expr()->eq('appid', $sql->createParameter('app')))
+ ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
+ ->setParameter('app', $app)
+ ->setParameter('configkey', $key);
+ $sql->execute();
+
+ unset($this->cache[$app][$key]);
}
/**
@@ -245,38 +217,65 @@ class AppConfig implements IAppConfig {
* Removes all keys in appconfig belonging to the app.
*/
public function deleteApp($app) {
- $where = array(
- 'appid' => $app,
- );
- $this->conn->delete('*PREFIX*appconfig', $where);
+ $this->loadConfigValues();
+
+ $sql = $this->conn->getQueryBuilder();
+ $sql->delete('appconfig')
+ ->where($sql->expr()->eq('appid', $sql->createParameter('app')))
+ ->setParameter('app', $app);
+ $sql->execute();
+
unset($this->cache[$app]);
- unset($this->apps[$app]);
}
/**
- * get multiply values, either the app or key can be used as wildcard by setting it to false
+ * get multiple values, either the app or key can be used as wildcard by setting it to false
*
* @param string|false $app
* @param string|false $key
* @return array|false
*/
public function getValues($app, $key) {
- if (($app !== false) == ($key !== false)) {
+ if (($app !== false) === ($key !== false)) {
return false;
}
- if ($app !== false) {
+ if ($key === false) {
return $this->getAppValues($app);
} else {
- $query = 'SELECT `configvalue`, `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = ?';
- $result = $this->conn->executeQuery($query, array($key));
+ $configs = [];
+ foreach ($this->getApps() as $appId) {
+ if ($this->hasKey($appId, $key)) {
+ $configs[$appId] = $this->getValue($appId, $key);
+ }
+ }
+
+ return $configs;
+ }
+ }
- $values = array();
- while ($row = $result->fetch((\PDO::FETCH_ASSOC))) {
- $values[$row['appid']] = $row['configvalue'];
+ /**
+ * Load all the app config values
+ */
+ protected function loadConfigValues() {
+ if ($this->configLoaded) return;
+
+ $this->cache = [];
+
+ $sql = $this->conn->getQueryBuilder();
+ $sql->select('*')
+ ->from('appconfig');
+ $result = $sql->execute();
+
+ while ($row = $result->fetch()) {
+ if (!isset($this->cache[$row['appid']])) {
+ $this->cache[$row['appid']] = [];
}
- return $values;
+ $this->cache[$row['appid']][$row['configkey']] = $row['configvalue'];
}
+ $result->closeCursor();
+
+ $this->configLoaded = true;
}
}
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index d0c69badb46..e1735dbf92e 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -37,6 +37,7 @@
namespace OC\Share;
+use OC\Files\Filesystem;
use OCP\IUserSession;
use OCP\IDBConnection;
use OCP\IConfig;
@@ -120,6 +121,7 @@ class Share extends Constants {
*/
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false) {
+ Filesystem::initMountPoints($ownerUser);
$shares = $sharePaths = $fileTargets = array();
$publicShare = false;
$remoteShare = false;
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index 9c161281846..da80ca15b0c 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -554,16 +554,16 @@ if ($_['cronErrors']) {
</ul>
</div>
+<?php if (!empty($_['updaterAppPanel'])): ?>
+ <div id="updater"><?php print_unescaped($_['updaterAppPanel']); ?></div>
+<?php endif; ?>
+
<div class="section">
<h2><?php p($l->t('Version'));?></h2>
<strong><?php p($theme->getTitle()); ?></strong> <?php p(OC_Util::getHumanVersion()) ?>
<?php include('settings.development.notice.php'); ?>
</div>
-<?php if (!empty($_['updaterAppPanel'])): ?>
- <div id="updater"><?php print_unescaped($_['updaterAppPanel']); ?></div>
-<?php endif; ?>
-
<div class="section credits-footer">
<p><?php print_unescaped($theme->getShortFooter()); ?></p>
</div>
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index 5a2cb3f88fc..5ea446aee51 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -7,49 +7,123 @@
* See the COPYING-README file.
*/
-class Test_Appconfig extends \Test\TestCase {
+namespace Test\Lib;
+
+use Test\TestCase;
+
+class AppConfig extends TestCase {
/** @var \OCP\IAppConfig */
protected $appConfig;
/** @var \OCP\IDBConnection */
protected $connection;
+ protected $originalConfig;
+
public function setUp() {
parent::setUp();
$this->connection = \OC::$server->getDatabaseConnection();
- $this->registerAppConfig(new \OC\AppConfig(\OC::$server->getDatabaseConnection()));
-
- $query = $this->connection->prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $query->execute(array('testapp'));
- $query->execute(array('someapp'));
- $query->execute(array('123456'));
- $query->execute(array('anotherapp'));
-
- $query = $this->connection->prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
-
- $query->execute(array('testapp', 'enabled', 'true'));
- $query->execute(array('testapp', 'installed_version', '1.2.3'));
- $query->execute(array('testapp', 'depends_on', 'someapp'));
- $query->execute(array('testapp', 'deletethis', 'deletethis'));
- $query->execute(array('testapp', 'key', 'value'));
-
- $query->execute(array('someapp', 'key', 'value'));
- $query->execute(array('someapp', 'otherkey', 'othervalue'));
-
- $query->execute(array('123456', 'key', 'value'));
- $query->execute(array('123456', 'enabled', 'false'));
-
- $query->execute(array('anotherapp', 'key', 'value'));
- $query->execute(array('anotherapp', 'enabled', 'false'));
+ $sql = $this->connection->getQueryBuilder();
+ $sql->select('*')
+ ->from('appconfig');
+ $result = $sql->execute();
+ $this->originalConfig = $result->fetchAll();
+ $result->closeCursor();
+
+ $sql = $this->connection->getQueryBuilder();
+ $sql->delete('appconfig');
+ $sql->execute();
+
+ $this->registerAppConfig(new \OC\AppConfig($this->connection));
+
+ $sql = $this->connection->getQueryBuilder();
+ $sql->insert('appconfig')
+ ->values([
+ 'appid' => $sql->createParameter('appid'),
+ 'configkey' => $sql->createParameter('configkey'),
+ 'configvalue' => $sql->createParameter('configvalue'),
+ ]);
+
+ $sql->setParameters([
+ 'appid' => 'testapp',
+ 'configkey' => 'enabled',
+ 'configvalue' => 'true',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => 'testapp',
+ 'configkey' => 'installed_version',
+ 'configvalue' => '1.2.3',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => 'testapp',
+ 'configkey' => 'depends_on',
+ 'configvalue' => 'someapp',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => 'testapp',
+ 'configkey' => 'deletethis',
+ 'configvalue' => 'deletethis',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => 'testapp',
+ 'configkey' => 'key',
+ 'configvalue' => 'value',
+ ])->execute();
+
+ $sql->setParameters([
+ 'appid' => 'someapp',
+ 'configkey' => 'key',
+ 'configvalue' => 'value',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => 'someapp',
+ 'configkey' => 'otherkey',
+ 'configvalue' => 'othervalue',
+ ])->execute();
+
+ $sql->setParameters([
+ 'appid' => '123456',
+ 'configkey' => 'key',
+ 'configvalue' => 'value',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => '123456',
+ 'configkey' => 'enabled',
+ 'configvalue' => 'false',
+ ])->execute();
+
+ $sql->setParameters([
+ 'appid' => 'anotherapp',
+ 'configkey' => 'key',
+ 'configvalue' => 'value',
+ ])->execute();
+ $sql->setParameters([
+ 'appid' => 'anotherapp',
+ 'configkey' => 'enabled',
+ 'configvalue' => 'false',
+ ])->execute();
}
public function tearDown() {
- $query = $this->connection->prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $query->execute(array('testapp'));
- $query->execute(array('someapp'));
- $query->execute(array('123456'));
- $query->execute(array('anotherapp'));
+ $sql = $this->connection->getQueryBuilder();
+ $sql->delete('appconfig');
+ $sql->execute();
+
+ $sql = $this->connection->getQueryBuilder();
+ $sql->insert('appconfig')
+ ->values([
+ 'appid' => $sql->createParameter('appid'),
+ 'configkey' => $sql->createParameter('configkey'),
+ 'configvalue' => $sql->createParameter('configvalue'),
+ ]);
+
+ foreach ($this->originalConfig as $configs) {
+ $sql->setParameter('appid', $configs['appid'])
+ ->setParameter('configkey', $configs['configkey'])
+ ->setParameter('configvalue', $configs['configvalue']);
+ $sql->execute();
+ }
$this->registerAppConfig(new \OC\AppConfig(\OC::$server->getDatabaseConnection()));
parent::tearDown();
@@ -61,217 +135,179 @@ class Test_Appconfig extends \Test\TestCase {
* @param \OCP\IAppConfig $appConfig
*/
protected function registerAppConfig($appConfig) {
- \OC::$server->registerService('AppConfig', function ($c) use ($appConfig) {
+ \OC::$server->registerService('AppConfig', function () use ($appConfig) {
return $appConfig;
});
}
- public function getAppConfigs() {
- return [
- [new \OC\AppConfig(\OC::$server->getDatabaseConnection())],
- ];
- }
+ public function testGetApps() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testGetApps($callable) {
- $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
- $result = $query->execute();
- $expected = array();
- while ($row = $result->fetchRow()) {
- $expected[] = $row['appid'];
- }
- sort($expected);
- $apps = call_user_func([$callable, 'getApps']);
- $this->assertEquals($expected, $apps);
+ $this->assertEquals([
+ 'anotherapp',
+ 'someapp',
+ 'testapp',
+ '123456',
+ ], $config->getApps());
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testGetKeys($callable) {
- $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $result = $query->execute(array('testapp'));
- $expected = array();
- while($row = $result->fetchRow()) {
- $expected[] = $row["configkey"];
- }
- sort($expected);
- $keys = call_user_func([$callable, 'getKeys'], 'testapp');
- $this->assertEquals($expected, $keys);
+ public function testGetKeys() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $keys = $config->getKeys('testapp');
+ $this->assertEquals([
+ 'deletethis',
+ 'depends_on',
+ 'enabled',
+ 'installed_version',
+ 'key',
+ ], $keys);
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testGetValue($callable) {
- $value = call_user_func([$callable, 'getValue'], 'testapp', 'installed_version');
+ public function testGetValue() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $value = $config->getValue('testapp', 'installed_version');
$this->assertConfigKey('testapp', 'installed_version', $value);
- $value = call_user_func([$callable, 'getValue'], 'testapp', 'nonexistant');
+ $value = $config->getValue('testapp', 'nonexistant');
$this->assertNull($value);
- $value = call_user_func([$callable, 'getValue'], 'testapp', 'nonexistant', 'default');
+ $value = $config->getValue('testapp', 'nonexistant', 'default');
$this->assertEquals('default', $value);
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testHasKey($callable) {
- $value = call_user_func([$callable, 'hasKey'], 'testapp', 'installed_version');
- $this->assertTrue($value);
+ public function testHasKey() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
- $value = call_user_func([$callable, 'hasKey'], 'nonexistant', 'nonexistant');
- $this->assertFalse($value);
+ $this->assertTrue($config->hasKey('testapp', 'installed_version'));
+ $this->assertFalse($config->hasKey('testapp', 'nonexistant'));
+ $this->assertFalse($config->hasKey('nonexistant', 'nonexistant'));
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testSetValue($callable) {
- call_user_func([$callable, 'setValue'], 'testapp', 'installed_version', '1.33.7');
+ public function testSetValueUpdate() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $this->assertEquals('1.2.3', $config->getValue('testapp', 'installed_version'));
+ $this->assertConfigKey('testapp', 'installed_version', '1.2.3');
+
+ $this->assertFalse($config->setValue('testapp', 'installed_version', '1.2.3'));
+
+ $this->assertEquals('1.2.3', $config->getValue('testapp', 'installed_version'));
+ $this->assertConfigKey('testapp', 'installed_version', '1.2.3');
+
+ $this->assertTrue($config->setValue('testapp', 'installed_version', '1.33.7'));
+
+
+ $this->assertEquals('1.33.7', $config->getValue('testapp', 'installed_version'));
$this->assertConfigKey('testapp', 'installed_version', '1.33.7');
- call_user_func([$callable, 'setValue'], 'someapp', 'somekey', 'somevalue');
+ $config->setValue('someapp', 'somekey', 'somevalue');
$this->assertConfigKey('someapp', 'somekey', 'somevalue');
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testDeleteKey($callable) {
- call_user_func([$callable, 'deleteKey'], 'testapp', 'deletethis');
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
- $query->execute(array('testapp', 'deletethis'));
- $result = (bool)$query->fetchRow();
+ public function testSetValueInsert() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $this->assertFalse($config->hasKey('someapp', 'somekey'));
+ $this->assertNull($config->getValue('someapp', 'somekey'));
+
+ $this->assertTrue($config->setValue('someapp', 'somekey', 'somevalue'));
+
+ $this->assertTrue($config->hasKey('someapp', 'somekey'));
+ $this->assertEquals('somevalue', $config->getValue('someapp', 'somekey'));
+ $this->assertConfigKey('someapp', 'somekey', 'somevalue');
+
+ $this->assertFalse($config->setValue('someapp', 'somekey', 'somevalue'));
+ }
+
+ public function testDeleteKey() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $this->assertTrue($config->hasKey('testapp', 'deletethis'));
+
+ $config->deleteKey('testapp', 'deletethis');
+
+ $this->assertFalse($config->hasKey('testapp', 'deletethis'));
+
+ $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $sql->select('configvalue')
+ ->from('appconfig')
+ ->where($sql->expr()->eq('appid', $sql->createParameter('appid')))
+ ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
+ ->setParameter('appid', 'testapp')
+ ->setParameter('configkey', 'deletethis');
+ $query = $sql->execute();
+ $result = $query->fetch();
+ $query->closeCursor();
$this->assertFalse($result);
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testDeleteApp($callable) {
- call_user_func([$callable, 'deleteApp'], 'someapp');
- $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $query->execute(array('someapp'));
- $result = (bool)$query->fetchRow();
+ public function testDeleteApp() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $this->assertTrue($config->hasKey('someapp', 'otherkey'));
+
+ $config->deleteApp('someapp');
+
+ $this->assertFalse($config->hasKey('someapp', 'otherkey'));
+
+ $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $sql->select('configvalue')
+ ->from('appconfig')
+ ->where($sql->expr()->eq('appid', $sql->createParameter('appid')))
+ ->setParameter('appid', 'someapp');
+ $query = $sql->execute();
+ $result = $query->fetch();
+ $query->closeCursor();
$this->assertFalse($result);
}
- /**
- * @dataProvider getAppConfigs
- *
- * @param mixed $callable
- */
- public function testGetValues($callable) {
- $this->assertFalse(call_user_func([$callable, 'getValues'], 'testapp', 'enabled'));
+ public function testGetValuesNotAllowed() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
- $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $query->execute(array('testapp'));
- $expected = array();
- while ($row = $query->fetchRow()) {
+ $this->assertFalse($config->getValues('testapp', 'enabled'));
+
+ $this->assertFalse($config->getValues(false, false));
+ }
+
+ public function testGetValues() {
+ $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+
+ $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $sql->select(['configkey', 'configvalue'])
+ ->from('appconfig')
+ ->where($sql->expr()->eq('appid', $sql->createParameter('appid')))
+ ->setParameter('appid', 'testapp');
+ $query = $sql->execute();
+ $expected = [];
+ while ($row = $query->fetch()) {
$expected[$row['configkey']] = $row['configvalue'];
}
- $values = call_user_func([$callable, 'getValues'], 'testapp', false);
+ $query->closeCursor();
+
+ $values = $config->getValues('testapp', false);
$this->assertEquals($expected, $values);
- $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?');
- $query->execute(array('enabled'));
- $expected = array();
- while ($row = $query->fetchRow()) {
+ $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $sql->select(['appid', 'configvalue'])
+ ->from('appconfig')
+ ->where($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
+ ->setParameter('configkey', 'enabled');
+ $query = $sql->execute();
+ $expected = [];
+ while ($row = $query->fetch()) {
$expected[$row['appid']] = $row['configvalue'];
}
- $values = call_user_func([$callable, 'getValues'], false, 'enabled');
- $this->assertEquals($expected, $values);
- }
+ $query->closeCursor();
- public function testSetValueUnchanged() {
- $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
- $statementMock->expects($this->once())
- ->method('fetch')
- ->will($this->returnValue(false));
-
- $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
- $connectionMock->expects($this->once())
- ->method('executeQuery')
- ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
- .' WHERE `appid` = ?'), $this->equalTo(array('bar')))
- ->will($this->returnValue($statementMock));
- $connectionMock->expects($this->once())
- ->method('insertIfNotExist')
- ->with($this->equalTo('*PREFIX*appconfig'),
- $this->equalTo(
- array(
- 'appid' => 'bar',
- 'configkey' => 'foo',
- 'configvalue' => 'v1',
- )
- ), $this->equalTo(['appid', 'configkey']))
- ->willReturn(1);
- $connectionMock->expects($this->never())
- ->method('update');
-
- $appconfig = new OC\AppConfig($connectionMock);
- $appconfig->setValue('bar', 'foo', 'v1');
- $appconfig->setValue('bar', 'foo', 'v1');
- $appconfig->setValue('bar', 'foo', 'v1');
- }
-
- public function testSetValueUnchanged2() {
- $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
- $statementMock->expects($this->once())
- ->method('fetch')
- ->will($this->returnValue(false));
-
- $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
- $connectionMock->expects($this->once())
- ->method('executeQuery')
- ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
- .' WHERE `appid` = ?'), $this->equalTo(array('bar')))
- ->will($this->returnValue($statementMock));
- $connectionMock->expects($this->once())
- ->method('insertIfNotExist')
- ->with($this->equalTo('*PREFIX*appconfig'),
- $this->equalTo(
- array(
- 'appid' => 'bar',
- 'configkey' => 'foo',
- 'configvalue' => 'v1',
- )
- ), $this->equalTo(['appid', 'configkey']))
- ->willReturn(1);
- $connectionMock->expects($this->once())
- ->method('update')
- ->with($this->equalTo('*PREFIX*appconfig'),
- $this->equalTo(array('configvalue' => 'v2')),
- $this->equalTo(array('appid' => 'bar', 'configkey' => 'foo'))
- );
-
- $appconfig = new OC\AppConfig($connectionMock);
- $appconfig->setValue('bar', 'foo', 'v1');
- $appconfig->setValue('bar', 'foo', 'v2');
- $appconfig->setValue('bar', 'foo', 'v2');
+ $values = $config->getValues(false, 'enabled');
+ $this->assertEquals($expected, $values);
}
public function testSettingConfigParallel() {
- $appConfig1 = new OC\AppConfig(\OC::$server->getDatabaseConnection());
- $appConfig2 = new OC\AppConfig(\OC::$server->getDatabaseConnection());
+ $appConfig1 = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
+ $appConfig2 = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
$appConfig1->getValue('testapp', 'foo', 'v1');
$appConfig2->getValue('testapp', 'foo', 'v1');
@@ -286,12 +322,19 @@ class Test_Appconfig extends \Test\TestCase {
* @param string $app
* @param string $key
* @param string $expected
- * @throws \OC\DatabaseException
*/
protected function assertConfigKey($app, $key, $expected) {
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
- $result = $query->execute([$app, $key]);
- $actual = $result->fetchRow();
+ $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $sql->select('configvalue')
+ ->from('appconfig')
+ ->where($sql->expr()->eq('appid', $sql->createParameter('appid')))
+ ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
+ ->setParameter('appid', $app)
+ ->setParameter('configkey', $key);
+ $query = $sql->execute();
+ $actual = $query->fetch();
+ $query->closeCursor();
+
$this->assertEquals($expected, $actual['configvalue']);
}
}