use oc_preferences to store ocs privatedata
This commit is contained in:
parent
aa33812104
commit
7d15a45e09
1 changed files with 18 additions and 58 deletions
76
lib/ocs.php
76
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{
|
||||
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();
|
||||
$apps=OC_PREFERENCES::getApps($user);
|
||||
}
|
||||
if($key){
|
||||
$keys=array($key);
|
||||
}else{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue