diff --git a/src/admin/sources.php b/src/admin/sources.php index 4d05616..4e45586 100644 --- a/src/admin/sources.php +++ b/src/admin/sources.php @@ -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 ) { diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index ed5f65d..8b76ece 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -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 ) { diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 10e9ca2..f11e2b7 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -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:
" . $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) ) diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 5929402..2e507f5 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -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:
" . $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) )