From: Robin Appelman Date: Thu, 21 Apr 2011 21:03:45 +0000 (+0200) Subject: loging system X-Git-Tag: v3.0~267^2~558^2~34^2~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=741519fa79bcc261479a1745c347413c75128ed4;p=nextcloud-server.git loging system --- diff --git a/lib/log.php b/lib/log.php index 231ff7997b1..f5651514108 100644 --- a/lib/log.php +++ b/lib/log.php @@ -50,8 +50,9 @@ class OC_LOG { * * This function adds another entry to the log database */ - public static function add( $appid, $subject, $predicate, $object = null ){ - // TODO: write function + public static function add( $appid, $subject, $predicate, $object = ' ' ){ + $query=OC_DB::prepare("INSERT INTO *PREFIX*log(`timestamp`,appid,user,action,info) VALUES(NOW(),?,?,?,?)"); + $query->execute(array($appid,$subject,$predicate,$object)); return true; } @@ -71,8 +72,27 @@ class OC_LOG { * - app: only entries for this app */ public static function get( $filter = array()){ - // TODO: write function - return array(); + $queryString='SELECT * FROM *PREFIX*log WHERE 1=1 '; + $params=array(); + if(isset($filter['from'])){ + $queryString.='AND `timestamp`>? '; + array_push($params,$filter('from')); + } + if(isset($filter['until'])){ + $queryString.='AND `timestamp`execute($params)->fetchAll(); + } /** @@ -83,9 +103,26 @@ class OC_LOG { * This function deletes all entries that are older than $date. */ public static function deleteBefore( $date ){ - // TODO: write function + $query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE `timestamp`execute(array($date)); 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; + } }