Skip to content
Snippets Groups Projects
Commit 741519fa authored by Robin Appelman's avatar Robin Appelman
Browse files

loging system

parent 4e2ef271
No related branches found
No related tags found
Loading
...@@ -50,8 +50,9 @@ class OC_LOG { ...@@ -50,8 +50,9 @@ class OC_LOG {
* *
* This function adds another entry to the log database * This function adds another entry to the log database
*/ */
public static function add( $appid, $subject, $predicate, $object = null ){ public static function add( $appid, $subject, $predicate, $object = ' ' ){
// TODO: write function $query=OC_DB::prepare("INSERT INTO *PREFIX*log(`timestamp`,appid,user,action,info) VALUES(NOW(),?,?,?,?)");
$query->execute(array($appid,$subject,$predicate,$object));
return true; return true;
} }
...@@ -71,8 +72,27 @@ class OC_LOG { ...@@ -71,8 +72,27 @@ class OC_LOG {
* - app: only entries for this app * - app: only entries for this app
*/ */
public static function get( $filter = array()){ public static function get( $filter = array()){
// TODO: write function $queryString='SELECT * FROM *PREFIX*log WHERE 1=1 ';
return array(); $params=array();
if(isset($filter['from'])){
$queryString.='AND `timestamp`>? ';
array_push($params,$filter('from'));
}
if(isset($filter['until'])){
$queryString.='AND `timestamp`<? ';
array_push($params,$filter('until'));
}
if(isset($filter['user'])){
$queryString.='AND user=? ';
array_push($params,$filter('user'));
}
if(isset($filter['app'])){
$queryString.='AND appid=? ';
array_push($params,$filter('app'));
}
$query=OC_DB::prepare($queryString);
return $query->execute($params)->fetchAll();
} }
/** /**
...@@ -83,9 +103,26 @@ class OC_LOG { ...@@ -83,9 +103,26 @@ class OC_LOG {
* This function deletes all entries that are older than $date. * This function deletes all entries that are older than $date.
*/ */
public static function deleteBefore( $date ){ public static function deleteBefore( $date ){
// TODO: write function $query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE `timestamp`<?");
$query->execute(array($date));
return true; return true;
} }
/**
* @brief filter an array of log entries on action
* @param array $logs the log entries to filter
* @param array $actions an array of actions to filter for
* @returns array
*/
public static function filterAction($logs,$actions){
$filteredLogs=array();
foreach($logs as $log){
if(array_search($log['action'],$actions)!==false){
$filteredLogs[]=$log;
}
}
return $filteredLogs;
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment