Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-05-06 21:18:57 +0400
committerThomas Müller <thomas.mueller@tmit.eu>2014-06-05 18:54:03 +0400
commit2d83424a29e4dbaeb16856c87378a753b10cdb90 (patch)
treea196f127f85944cb531e8413e93336d9f5be06b5 /lib/private/preferences.php
parent4b650a20a42b70412cee9dd835e096e16da6d530 (diff)
allow to set pre-condition for setValue
Diffstat (limited to 'lib/private/preferences.php')
-rw-r--r--lib/private/preferences.php40
1 files changed, 26 insertions, 14 deletions
diff --git a/lib/private/preferences.php b/lib/private/preferences.php
index 0dc5b26810a..d1db25bbf09 100644
--- a/lib/private/preferences.php
+++ b/lib/private/preferences.php
@@ -165,44 +165,56 @@ class Preferences {
* @param string $app app
* @param string $key key
* @param string $value value
+ * @param string $preCondition only set value if the key had a specific value before
+ * @return bool true if value was set, otherwise false
*
* Adds a value to the preferences. If the key did not exist before, it
* will be added automagically.
*/
- public function setValue($user, $app, $key, $value) {
+ public function setValue($user, $app, $key, $value, $preCondition = null) {
// Check if the key does exist
$query = 'SELECT COUNT(*) FROM `*PREFIX*preferences`'
. ' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
$count = $this->conn->fetchColumn($query, array($user, $app, $key));
$exists = $count > 0;
- if (!$exists) {
+ $affectedRows = 0;
+
+ if (!$exists && $preCondition === null) {
$data = array(
'userid' => $user,
'appid' => $app,
'configkey' => $key,
'configvalue' => $value,
);
- $this->conn->insert('*PREFIX*preferences', $data);
- } else {
- $data = array(
- 'configvalue' => $value,
- );
- $where = array(
- 'userid' => $user,
- 'appid' => $app,
- 'configkey' => $key,
- );
- $this->conn->update('*PREFIX*preferences', $data, $where);
+ $affectedRows = $this->conn->insert('*PREFIX*preferences', $data);
+ } elseif ($exists) {
+ $data = array($value, $user, $app, $key);
+ $sql = "UPDATE `*PREFIX*preferences` SET `configvalue` = ?"
+ . " WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?";
+
+ if ($preCondition !== null) {
+ if (\OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') {
+ //oracle hack: need to explicitly cast CLOB to CHAR for comparison
+ $sql .= " AND to_char(`configvalue`) = ?";
+ } else {
+ $sql .= " AND `configvalue` = ?";
+ }
+ $data[] = $preCondition;
+ }
+ $affectedRows = $this->conn->executeUpdate($sql, $data);
}
// only add to the cache if we already loaded data for the user
- if (isset($this->cache[$user])) {
+ if ($affectedRows > 0 && isset($this->cache[$user])) {
if (!isset($this->cache[$user][$app])) {
$this->cache[$user][$app] = array();
}
$this->cache[$user][$app][$key] = $value;
}
+
+ return ($affectedRows > 0) ? true : false;
+
}
/**