Fully implemented option to clear old data in mysql and pdo logstream

This commit is contained in:
Andre Lorbach 2008-11-12 17:03:39 +01:00
parent f22e3019ca
commit 72d000dd2a
9 changed files with 217 additions and 9 deletions

View File

@ -324,12 +324,64 @@ if ( isset($_GET['op']) )
$content['ROWCOUNT'] = $stream->GetLogStreamTotalRowCount();
if ( isset($content['ROWCOUNT']) )
{
// Allow Deleting by Date
$content['DELETE_ALLOWDETAIL'] = true;
// Check for suboperations
if ( isset($_POST['subop']) )
{
if ( $_POST['subop'] == "all" )
{
$timestamp = 0;
}
else if ( $_POST['subop'] == "since" && isset($_POST['olderthan']) )
{
// Take current time and subtract Seconds
$nSecondsSubtract = $_POST['olderthan'];
$timestamp = time() - $nSecondsSubtract;
}
else if ( $_POST['subop'] == "date" && isset($_POST['olderdate_year']) && isset($_POST['olderdate_month']) && isset($_POST['olderdate_day']) )
{
// Generate Timestamp
$timestamp = mktime( 0, 0, 0, intval($_POST['olderdate_month']), intval($_POST['olderdate_day']), intval($_POST['olderdate_year']) );
}
// Continue with delete only inif wherequery is set!
if ( isset($timestamp) )
{
// --- Ask for deletion first!
if ( (!isset($_GET['verify']) || $_GET['verify'] != "yes") )
{
// This will print an additional secure check which the user needs to confirm and exit the script execution.
PrintSecureUserCheck( GetAndReplaceLangStr( $content['LN_SOURCES_WARNDELETEDATA'], $content['DisplayName'] ), $content['LN_DELETEYES'], $content['LN_DELETENO'] );
}
// ---
// Create Lists
CreateOlderThanList( 3600 );
CreateOlderDateFields();
// Now perform the data cleanup!
$content['affectedrows'] = $stream->CleanupLogdataByDate($timestamp);
if ( !isset($content['affectedrows']) )
{
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_DELDATA'], $content['SOURCEID'] );
}
else
{
// Do the final redirect
RedirectResult( GetAndReplaceLangStr( $content['LN_SOURCES_HASBEENDELDATA'], $content['DisplayName'], $content['affectedrows'] ) , "sources.php" );
}
}
else
{
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_INVALIDCLEANUP'], $content['DisplayName'] );
}
}
else
{
// Allow Deleting by Date
$content['DELETE_ALLOWDETAIL'] = true;
// Create Lists
CreateOlderThanList( 3600 );
CreateOlderDateFields();
}
}
else

View File

@ -224,6 +224,13 @@ abstract class LogStream {
*/
public abstract function GetLogStreamTotalRowCount();
/**
* Helper function to cleanup all logdata which is older then the nDateTimeStamp!
*/
public abstract function CleanupLogdataByDate( $nDateTimeStamp );
/*
* Helper functino to trigger initialisation of MsgParsers
*/

View File

@ -635,6 +635,45 @@ class LogStreamDB extends LogStream {
}
/**
* Implementation of the CleanupLogdataByDate function! Returns affected rows!
*/
public function CleanupLogdataByDate( $nDateTimeStamp )
{
global $querycount, $dbmapping;
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Set default rowcount
$rowcount = null;
// Perform if Connection is true!
if ( $this->_dbhandle != null )
{
// Create WHERE attachment
if ( $nDateTimeStamp > 0 )
$szWhere = " WHERE UNIX_TIMESTAMP(" . $dbmapping[$szTableType][SYSLOG_DATE] . ") < " . $nDateTimeStamp;
else
$szWhere = "";
// DELETE DATA NOW!
$szSql = "DELETE FROM " . $this->_logStreamConfigObj->DBTableName . $szWhere;
$myQuery = mysql_query($szSql, $this->_dbhandle);
if ($myQuery)
{
// Get affected rows and return!
$rowcount = mysql_affected_rows();
// Free query now
mysql_free_result ($myQuery);
}
}
//return affected rows
return $rowcount;
}
/**
* Implementation of GetCountSortedByField
*

View File

@ -620,6 +620,30 @@ class LogStreamDisk extends LogStream {
}
/**
* Implementation of GetLogStreamTotalRowCount
*
* not implemented yet!
*/
public function GetLogStreamTotalRowCount()
{
//not implemented
return null;
}
/**
* Implementation of the CleanupLogdataByDate
*
* not implemented yet!
*/
public function CleanupLogdataByDate( $nDateTimeStamp )
{
//not implemented
return null;
}
/**
* Implementation of GetCountSortedByField
*

View File

@ -569,8 +569,6 @@ class LogStreamPDO extends LogStream {
// Free query now
$myQuery->closeCursor();
// Increment for the Footer Stats
$querycount++;
}
@ -583,6 +581,82 @@ class LogStreamPDO extends LogStream {
}
/**
* Implementation of GetLogStreamTotalRowCount
*
* Returns the total amount of rows in the main datatable
*/
public function GetLogStreamTotalRowCount()
{
global $querycount, $dbmapping;
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Set default rowcount
$rowcount = null;
// Perform if Connection is true!
if ( $this->_dbhandle != null )
{
// Get Total Rowcount
$szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName;
$myQuery = $this->_dbhandle->query($szSql);
if ( $myQuery )
{
// Obtain RowCount!
$myRow = $myQuery->fetchColumn();
$rowcount = $myRow;
// Free query now
$myQuery->closeCursor();
// Increment for the Footer Stats
$querycount++;
}
}
//return result
return $rowcount;
}
/**
* Implementation of the CleanupLogdataByDate function! Returns affected rows!
*/
public function CleanupLogdataByDate( $nDateTimeStamp )
{
global $querycount, $dbmapping;
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Set default rowcount
$rowcount = null;
// Perform if Connection is true!
if ( $this->_dbhandle != null )
{
// Create WHERE attachment
if ( $nDateTimeStamp > 0 )
$szWhere = " WHERE " . $dbmapping[$szTableType][SYSLOG_DATE] . " < '" . date('Y-m-d H:i:s', $nDateTimeStamp) . "'";
else
$szWhere = "";
// DELETE DATA NOW!
$szSql = "DELETE FROM " . $this->_logStreamConfigObj->DBTableName . $szWhere;
$myQuery = $this->_dbhandle->query($szSql);
if ( $myQuery )
{
// Get affected rows and return!
$rowcount = $myQuery->rowCount();
// Free query now
$myQuery->closeCursor();
}
}
//return affected rows
return $rowcount;
}
/**
* Implementation of GetCountSortedByField
*

View File

@ -241,6 +241,10 @@ $content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting da
$content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... ";
$content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... ";
$content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range";
$content['LN_SOURCES_ERROR_INVALIDCLEANUP'] = "Invalid Data Cleanup type";
$content['LN_SOURCES_WARNDELETEDATA'] = "Are you sure that you want to clear logdata in the '%1' source? This cannot be undone!";
$content['LN_SOURCES_ERROR_DELDATA'] = "Could not delete data in the '%1' source";
$content['LN_SOURCES_HASBEENDELDATA'] = "Successfully deleted data from the '%1' source, '%2' rows were affected. ";
// Database Upgrade
$content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update";

View File

@ -246,6 +246,10 @@ $content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting da
$content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... ";
$content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... ";
$content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range";
$content['LN_SOURCES_ERROR_INVALIDCLEANUP'] = "Invalid Data Cleanup type";
$content['LN_SOURCES_WARNDELETEDATA'] = "Are you sure that you want to clear logdata in the '%1' source? This cannot be undone!";
$content['LN_SOURCES_ERROR_DELDATA'] = "Could not delete data in the '%1' source";
$content['LN_SOURCES_HASBEENDELDATA'] = "Successfully deleted data from the '%1' source, '%2' rows were affected. ";
// Database Upgrade
$content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update";

View File

@ -241,6 +241,10 @@ $content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting da
$content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... ";
$content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... ";
$content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range";
$content['LN_SOURCES_ERROR_INVALIDCLEANUP'] = "Invalid Data Cleanup type";
$content['LN_SOURCES_WARNDELETEDATA'] = "Are you sure that you want to clear logdata in the '%1' source? This cannot be undone!";
$content['LN_SOURCES_ERROR_DELDATA'] = "Could not delete data in the '%1' source";
$content['LN_SOURCES_HASBEENDELDATA'] = "Successfully deleted data from the '%1' source, '%2' rows were affected. ";
// Database Upgrade
$content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update";

View File

@ -154,13 +154,13 @@
<!-- END olderdate_years -->
</select>
-
<select name="olderdate_from_month" size="1">
<select name="olderdate_month" size="1">
<!-- BEGIN olderdate_months -->
<option {selected} value="{value}">{value}</option>
<!-- END olderdate_months -->
</select>
-
<select name="olderdate_from_day" size="1">
<select name="olderdate_day" size="1">
<!-- BEGIN olderdate_days -->
<option {selected} value="{value}">{value}</option>
<!-- END olderdate_days -->