mirror of
https://github.com/nextcloud/server.git
synced 2026-03-04 18:28:08 +01:00
make logs work with sqlite
This commit is contained in:
@@ -300,7 +300,13 @@ class OC_DB {
|
||||
// We need Database type and table prefix
|
||||
$CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );
|
||||
$CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" );
|
||||
|
||||
|
||||
// differences is getting the current timestamp
|
||||
if( $CONFIG_DBTYPE == 'sqlite' ){
|
||||
$query = str_replace( 'NOW()', "strftime('%s', 'now')", $query );
|
||||
$query = str_replace( 'now()', "strftime('%s', 'now')", $query );
|
||||
}
|
||||
|
||||
// differences in escaping of table names (` for mysql)
|
||||
// Problem: what if there is a ` in the value we want to insert?
|
||||
if( $CONFIG_DBTYPE == 'sqlite' ){
|
||||
@@ -310,7 +316,7 @@ class OC_DB {
|
||||
$query = str_replace( '`', '"', $query );
|
||||
}
|
||||
|
||||
// replace table names
|
||||
// replace table name prefix
|
||||
$query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query );
|
||||
|
||||
return $query;
|
||||
|
||||
17
lib/log.php
17
lib/log.php
@@ -52,7 +52,14 @@ class OC_LOG {
|
||||
*/
|
||||
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));
|
||||
$result=$query->execute(array($appid,$subject,$predicate,$object));
|
||||
// Die if we have an error
|
||||
if( PEAR::isError($result)) {
|
||||
$entry = 'DB Error: "'.$result->getMessage().'"<br />';
|
||||
$entry .= 'Offending command was: '.$query.'<br />';
|
||||
error_log( $entry );
|
||||
die( $entry );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -91,7 +98,13 @@ class OC_LOG {
|
||||
array_push($params,$filter('app'));
|
||||
}
|
||||
$query=OC_DB::prepare($queryString);
|
||||
return $query->execute($params)->fetchAll();
|
||||
$result=$query->execute($params)->fetchAll();
|
||||
if(count($result)>0 and is_numeric($result[0]['timestamp'])){
|
||||
foreach($result as &$row){
|
||||
$row['timestamp']=OC_UTIL::formatDate($row['timestamp']);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user