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:
authorRobin Appelman <icewind1991@gmail.com>2011-07-28 22:23:58 +0400
committerRobin Appelman <icewind1991@gmail.com>2011-07-28 22:23:58 +0400
commit7d15a45e09bfa27597a1169e12ba79b6e5221946 (patch)
tree7d8a56fdcf29f8bbab28bed68ab14e6a0442f057 /lib/ocs.php
parentaa33812104d37bd6d7e7de5b1cebdfb63f5ae9d0 (diff)
use oc_preferences to store ocs privatedata
Diffstat (limited to 'lib/ocs.php')
-rw-r--r--lib/ocs.php76
1 files changed, 18 insertions, 58 deletions
diff --git a/lib/ocs.php b/lib/ocs.php
index 4e9e6522e8b..b1be2cb11cf 100644
--- a/lib/ocs.php
+++ b/lib/ocs.php
@@ -463,7 +463,6 @@ class OC_OCS {
$xml[$i]['key']=$log['key'];
$xml[$i]['app']=$log['app'];
$xml[$i]['value']=$log['value'];
- $xml[$i]['timestamp']=$log['timestamp'];
}
@@ -511,28 +510,26 @@ class OC_OCS {
* @param bool $like use LIKE instead of = when comparing keys
* @return array
*/
- public static function getData($user,$app="",$key="",$like=false) {
- $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy, needs to be replaced with a seperate user field the next time we break db compatibiliy
- $compareFunction=($like)?'LIKE':'=';
-
+ public static function getData($user,$app="",$key="") {
if($app){
- if (!trim($key)) {
- $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? order by `timestamp` desc');
- $result=$query->execute(array($app))->fetchAll();
- } else {
- $query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? and `key` $compareFunction ? order by `timestamp` desc");
- $result=$query->execute(array($app,$key))->fetchAll();
- }
+ $apps=array($app);
+ }else{
+ $apps=OC_PREFERENCES::getApps($user);
+ }
+ if($key){
+ $keys=array($key);
}else{
- if (!trim($key)) {
- $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata order by `timestamp` desc');
- $result=$query->execute()->fetchAll();
- } else {
- $query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where `key` $compareFunction ? order by `timestamp` desc");
- $result=$query->execute(array($key))->fetchAll();
+ foreach($apps as $app){
+ $keys=OC_PREFERENCES::getKeys($user,$app);
+ }
+ }
+ $result=array();
+ foreach($apps as $app){
+ foreach($keys as $key){
+ $value=OC_PREFERENCES::getValue($user,$app,$key);
+ $result[]=array('app'=>$app,'key'=>$key,'value'=>$value);
}
}
- $result=self::trimKeys($result,$user);
return $result;
}
@@ -545,25 +542,7 @@ class OC_OCS {
* @return bool
*/
public static function setData($user, $app, $key, $value) {
- $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy
- //TODO: locking tables, fancy stuff, error checking/handling
- $query=OC_DB::prepare("select count(*) as co from *PREFIX*privatedata where `key` = ? and app = ?");
- $result=$query->execute(array($key,$app))->fetchAll();
- $totalcount=$result[0]['co'];
- if ($totalcount != 0) {
- $query=OC_DB::prepare("update *PREFIX*privatedata set value=?, `timestamp` = now() where `key` = ? and app = ?");
-
- } else {
- $result = OC_DB::prepare("insert into *PREFIX*privatedata(value, `key`, app, `timestamp`) values(?, ?, ?, now())");
- }
- $result = $query->execute(array($value,$key,$app));
- if (PEAR::isError($result)){
- $entry='DB Error: "'.$result->getMessage().'"<br />';
- error_log($entry);
- return false;
- }else{
- return true;
- }
+ return OC_PREFERENCES::setValue($user,$app,$key,$value);
}
/**
@@ -574,26 +553,7 @@ class OC_OCS {
* @return string xml/json
*/
public static function deleteData($user, $app, $key) {
- $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy
- //TODO: prepared statements, locking tables, fancy stuff, error checking/handling
- $query=OC_DB::prepare("delete from *PREFIX*privatedata where `key` = ? and app = ?");
- $result = $query->execute(array($key,$app));
- if (PEAR::isError($result)){
- $entry='DB Error: "'.$result->getMessage().'"<br />';
- error_log($entry);
- return false;
- }else{
- return true;
- }
- }
-
- //trim username prefixes from $array
- private static function trimKeys($array,$user){
- $length=strlen("$user::");
- foreach($array as &$item){
- $item['key']=substr($item['key'],$length);
- }
- return $array;
+ return OC_PREFERENCES::deleteKey($user,$app,$key);
}
}