예제 #1
0
 /**
  * Write an entry to the event log.
  *
  * @param string $message The message
  * @param string $severity The severity
  * @param string $type The type
  * @param string $module The module
  * @param mixed $data The data
  * @return object LogEntry The inserted LogEntry object
  */
 public static function log($message, $severity = 'info', $type = 'default', $module = null, $data = null)
 {
     $module = self::get_module($module);
     $log = new LogEntry(array('message' => $message, 'severity' => $severity, 'module' => $module, 'type' => $type, 'data' => $data, 'ip' => Utils::get_ip()));
     $user = User::identify();
     if ($user->loggedin) {
         $log->user_id = $user->id;
     }
     $log->insert();
     return $log;
 }
예제 #2
0
파일: Box.php 프로젝트: kitsune/ConAsset
 public function deleteBox($barcode)
 {
     $this->connection->query("begin;");
     $query = "\n\t\tSELECT COUNT(a_barcode)\n\t\tFROM assets\n\t\tWHERE a_box = {$barcode};";
     $this->connection->query($query);
     $row = $this->connection->fetch_row();
     if ($row[0] != 0) {
         echo "Cannot delete an Assest Type that is currently being used by assets<br><br>";
     } else {
         $query = "DELETE FROM boxes WHERE b_barcode = {$barcode};";
         $this->connection->query($query);
         //log away
         $user = new User();
         $logEntry = new LogEntry($this->connection);
         $logEntry->setBarcode($barcode);
         $logEntry->setPerson($user->get_Username());
         $logEntry->setType("Box Deleted");
         $logEntry->insert();
     }
     $this->connection->query("commit;");
 }
예제 #3
0
 /**
  * Limit the number of log entries returned
  * - limit => the maximum number of posts to return, implicitly set for many queries
  * - nolimit => do not implicitly set limit
  */
 public function test_get_logs_with_limit()
 {
     for ($i = 1; $i <= 5; $i++) {
         $entry = new LogEntry(array('user_id' => $this->user->id, 'type' => 'default', 'severity' => 'err', 'module' => 'habari', 'message' => 'Event message from test_logs_with_limit' . $i));
         $entry->insert();
     }
     $count_entries = EventLog::get(array('count' => 1, 'limit' => 2, 'user_id' => $this->user->id));
     $this->assert_equal($count_entries, 5, "LIMIT with a COUNT is pointless - COUNTing anything should return a single value.");
     $entries = EventLog::get(array('limit' => 2, 'user_id' => $this->user->id));
     $this->assert_equal(count($entries), 2);
     $count_entries = EventLog::get(array('count' => 1, 'nolimit' => 1, 'user_id' => $this->user->id));
     $this->assert_true($count_entries > 2);
     $entries = EventLog::get(array('nolimit' => 1, 'user_id' => $this->user->id));
     $this->assert_true(count($entries) > 2);
     // OFFSET based on page number (and limit)
     $entries = EventLog::get(array('limit' => 2, 'index' => 2, 'user_id' => $this->user->id));
     $this->assert_equal(count($entries), 2);
     $entries = EventLog::get(array('limit' => 2, 'index' => 3, 'user_id' => $this->user->id));
     $this->assert_equal(count($entries), 1);
 }
예제 #4
0
파일: Asset.php 프로젝트: kitsune/ConAsset
 public function deleteAsset($barcode)
 {
     $this->connection->query("begin;");
     //log this sad event
     $user = new User();
     $logEntry = new LogEntry($this->connection);
     $logEntry->setBarcode($barcode);
     $logEntry->setPerson($user->get_Username());
     $logEntry->setType("Asset Deleted");
     $logEntry->insert();
     $query = "DELETE FROM assets WHERE a_barcode = '{$barcode}'";
     $this->connection->query($query);
     $this->connection->query("commit;");
 }