Fixed bug id #291, custom filters are now taken care in database logstream sources when cleaning up data.

This commit is contained in:
Andre Lorbach 2011-11-08 10:32:11 +01:00
parent dad3dbc2fe
commit 318b4f7c70
4 changed files with 86 additions and 11 deletions

View File

@ -350,6 +350,8 @@ if ( isset($_GET['op']) )
{
// Create LogStream Object
$stream = $tmpSource['ObjRef']->LogStreamFactory($tmpSource['ObjRef']);
// Verify if datasource is available
$res = $stream->Verify();
if ( $res != SUCCESS )
{

View File

@ -53,6 +53,7 @@ abstract class LogStream {
protected $_current_uId = -1;
protected $_logStreamConfigObj = null;
protected $_arrProperties = null;
protected $_arrFilterProperties = null; // Helper Array to store all detected properties from Filterstring
/**
* Open the stream for read access.
@ -619,7 +620,7 @@ abstract class LogStream {
// Split key and value
$tmpArray = explode(":", $myEntry, 2);
//print_r ( $tmpArray );
// Continue if empty filter!
if ( strlen(trim($tmpArray[FILTER_TMP_VALUE])) == 0 )
continue;
@ -978,6 +979,10 @@ abstract class LogStream {
//done!
}
// Add to detected filter array
if ( $this->_arrFilterProperties == null || !in_array($tmpKeyName, $this->_arrFilterProperties) )
$this->_arrFilterProperties[] = $tmpKeyName;
// Ignore if unknown filter!
if ( $tmpFilterType != FILTER_TYPE_UNKNOWN )
{

View File

@ -554,14 +554,36 @@ class LogStreamDB extends LogStream {
// Perform if Connection is true!
if ( $this->_dbhandle != null )
{
// Create WHERE attachment
// --- Init Filters if necessary!
if ( $this->_filters == null )
$this->SetFilter( "" ); // This will init filters!
// Create SQL Where Clause!
$this->CreateSQLWhereClause();
// ---
// --- Add default WHERE clause
if ( strlen($this->_SQLwhereClause) > 0 )
$szWhere = $this->_SQLwhereClause;
else
$szWhere = "";
// Add Datefilter if necessary!
if ( $nDateTimeStamp > 0 )
$szWhere = " WHERE UNIX_TIMESTAMP(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") < " . $nDateTimeStamp;
else
$szWhere = "";
{
if ( strlen($szWhere) > 0 )
$szWhere .= " AND ";
else
$szWhere = " WHERE ";
// Append Date Filter!
$szWhere .= " UNIX_TIMESTAMP(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") < " . $nDateTimeStamp;
}
// ---
// DELETE DATA NOW!
$szSql = "DELETE FROM " . $this->_logStreamConfigObj->DBTableName . $szWhere;
OutputDebugMessage("LogStreamDB|CleanupLogdataByDate: Created SQL Query:<br>" . $szSql, DEBUG_DEBUG);
$myQuery = mysql_query($szSql, $this->_dbhandle);
if ($myQuery)
{
@ -956,9 +978,21 @@ class LogStreamDB extends LogStream {
// Reset WhereClause
$this->_SQLwhereClause = "";
// --- Build Query Array
$arrayQueryProperties = $this->_arrProperties;
if ( isset($this->_arrFilterProperties) && $this->_arrFilterProperties != null)
{
foreach ( $this->_arrFilterProperties as $filterproperty )
{
if ( $this->_arrProperties == null || !in_array($filterproperty, $this->_arrProperties) )
$arrayQueryProperties[] = $filterproperty;
}
}
// ---
// Loop through all available properties
foreach( $this->_arrProperties as $propertyname )
foreach( $arrayQueryProperties as $propertyname )
{
// If the property exists in the filter array, we have something to filter for ^^!
if ( array_key_exists($propertyname, $this->_filters) )

View File

@ -652,14 +652,36 @@ class LogStreamPDO extends LogStream {
// Perform if Connection is true!
if ( $this->_dbhandle != null )
{
// Create WHERE attachment
// --- Init Filters if necessary!
if ( $this->_filters == null )
$this->SetFilter( "" ); // This will init filters!
// Create SQL Where Clause!
$this->CreateSQLWhereClause();
// ---
// --- Add default WHERE clause
if ( strlen($this->_SQLwhereClause) > 0 )
$szWhere = $this->_SQLwhereClause;
else
$szWhere = "";
// Add Datefilter if necessary!
if ( $nDateTimeStamp > 0 )
$szWhere = " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . " < '" . date('Y-m-d H:i:s', $nDateTimeStamp) . "'";
else
$szWhere = "";
{
if ( strlen($szWhere) > 0 )
$szWhere .= " AND ";
else
$szWhere = " WHERE ";
// Append Date Filter!
$szWhere .= $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . " < '" . date('Y-m-d H:i:s', $nDateTimeStamp) . "'";
}
// ---
// DELETE DATA NOW!
$szSql = "DELETE FROM " . $this->_logStreamConfigObj->DBTableName . $szWhere;
OutputDebugMessage("LogStreamPDO|CleanupLogdataByDate: Created SQL Query:<br>" . $szSql, DEBUG_DEBUG);
$myQuery = $this->_dbhandle->query($szSql);
if ( $myQuery )
{
@ -1126,8 +1148,20 @@ class LogStreamPDO extends LogStream {
// Reset WhereClause
$this->_SQLwhereClause = "";
// --- Build Query Array
$arrayQueryProperties = $this->_arrProperties;
if ( isset($this->_arrFilterProperties) && $this->_arrFilterProperties != null)
{
foreach ( $this->_arrFilterProperties as $filterproperty )
{
if ( $this->_arrProperties == null || !in_array($filterproperty, $this->_arrProperties) )
$arrayQueryProperties[] = $filterproperty;
}
}
// ---
// Loop through all available properties
foreach( $this->_arrProperties as $propertyname )
foreach( $arrayQueryProperties as $propertyname )
{
// If the property exists in the filter array, we have something to filter for ^^!
if ( array_key_exists($propertyname, $this->_filters) )