]> source.dussan.org Git - nextcloud-server.git/commitdiff
loging system
authorRobin Appelman <icewind1991@gmail.com>
Thu, 21 Apr 2011 21:03:45 +0000 (23:03 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Thu, 21 Apr 2011 21:03:45 +0000 (23:03 +0200)
lib/log.php

index 231ff7997b10b9d74d0a18fa4687a8df97b82d2c..f5651514108205c823953d57828eb052d5649879 100644 (file)
@@ -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`<? ';
+                       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 {
         * 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`<?");
+               $query->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;
+       }
 }