Added basic Log class (#143)

This commit is contained in:
Tobias Reich 2014-05-06 21:22:56 +02:00
parent 61a868980e
commit f479511454
3 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,13 @@
# Dump of table lychee_log
# Version 2.5
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `lychee_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` int(11) NOT NULL,
`type` varchar(11) NOT NULL,
`function` varchar(100) NOT NULL,
`line` int(11) NOT NULL,
`text` TEXT DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

View File

@ -29,7 +29,7 @@ class Database extends Module {
if (!Database::createDatabase($database, $name)) exit('Error: Could not create database!');
# Check tables
if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings LIMIT 0;'))
if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings, lychee_log LIMIT 0;'))
if (!Database::createTables($database)) exit('Error: Could not create tables!');
return $database;
@ -119,6 +119,19 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
# Check dependencies
Module::dependencies(isset($database));
# Create log
if (!$database->query('SELECT * FROM lychee_log LIMIT 0;')) {
# Read file
$file = __DIR__ . '/../database/log_table.sql';
$query = @file_get_contents($file);
# Create table
if (!isset($query)||$query===false) return false;
if (!$database->query($query)) return false;
}
# Create settings
if (!$database->query('SELECT * FROM lychee_settings LIMIT 0;')) {

37
php/modules/Log.php Normal file
View File

@ -0,0 +1,37 @@
<?php
###
# @name Log Module
# @author Tobias Reich
# @copyright 2014 by Tobias Reich
###
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
class Log extends Module {
public static function error($database, $function, $line, $text = '') {
# Check dependencies
Module::dependencies(isset($database, $function, $line, $text));
# Get time
$sysstamp = time();
# Escape
$function = mysqli_real_escape_string($database, $function);
$line = mysqli_real_escape_string($database, $line);
$text = mysqli_real_escape_string($database, $text);
# Save in database
$query = "INSERT INTO lychee_log (time, type, function, line, text) VALUES ('$sysstamp', 'error', '$function', '$line', '$text');";
$result = $database->query($query);
if (!$result) return false;
return $database->insert_id;
}
}
?>