diff --git a/src/admin/reports.php b/src/admin/reports.php
index 416c7c7..3cbf8c9 100644
--- a/src/admin/reports.php
+++ b/src/admin/reports.php
@@ -1253,6 +1253,21 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
// Get Objectreference to report
$myReportObj = $myReport["ObjRef"];
+ // Handle GET and POST input!
+ $content['MSG_WARNING_FORMURL'] = $_SERVER['SCRIPT_NAME'] . "?";
+ $content['MSG_CHECK_URL'] = $_SERVER['SCRIPT_NAME'] . "?";
+ foreach ($_GET as $varname => $varvalue)
+ {
+ // All variables!
+ $content['MSG_WARNING_FORMURL'] .= $varname . "=" . $varvalue . "&";
+
+ // Skip the Optimize variable!
+ if (strpos( $varname, "optimize" ) === false )
+ $content['MSG_CHECK_URL'] .= $varname . "=" . $varvalue . "&";
+ }
+ foreach ($_POST as $varname => $varvalue)
+ $content['POST_VARIABLES'][] = array( "varname" => $varname, "varvalue" => $varvalue );
+
// Check if optimize variable is set!
if ( isset($_GET['optimize']) )
{
@@ -1355,13 +1370,6 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
$res = $myReportObj->CheckLogStreamSource( $mySourceID );
if ( $res != SUCCESS )
{
- // Handle GET and POST input!
- $content['MSG_WARNING_FORMURL'] = $_SERVER['SCRIPT_NAME'] . "?";
- foreach ($_GET as $varname => $varvalue)
- $content['MSG_WARNING_FORMURL'] .= $varname . "=" . $varvalue . "&";
- foreach ($_POST as $varname => $varvalue)
- $content['POST_VARIABLES'][] = array( "varname" => $varname, "varvalue" => $varvalue );
-
// Current Logstream Source is not optimized! Show to user!
$content['ISSOURCENOTOPTIMIZED'] = true;
if ( $res == ERROR_DB_DBFIELDNOTFOUND )
diff --git a/src/classes/logstreamconfigpdo.class.php b/src/classes/logstreamconfigpdo.class.php
index 669c8a3..223d59c 100644
--- a/src/classes/logstreamconfigpdo.class.php
+++ b/src/classes/logstreamconfigpdo.class.php
@@ -64,6 +64,35 @@ class LogStreamConfigPDO extends LogStreamConfig {
return new LogStreamPDO($o);
}
+
+ public function GetPDOTriggersSupported()
+ {
+ // TRIGGERS are not supported for all db engines!
+ switch ($this->DBType)
+ {
+ case DB_MYSQL:
+ return true;
+ case DB_MSSQL:
+ return true;
+ case DB_ODBC:
+ return false;
+ case DB_PGSQL:
+ return true;
+ case DB_OCI:
+ return false;
+ case DB_DB2:
+ return false;
+ case DB_FIREBIRD:
+ return false;
+ case DB_INFORMIX:
+ return false;
+ case DB_SQLITE:
+ return false;
+ default:
+ return false;
+ }
+ }
+
public function GetPDODatabaseType()
{
switch ($this->DBType)
diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php
index e515fa1..2e18592 100644
--- a/src/classes/logstreamdb.class.php
+++ b/src/classes/logstreamdb.class.php
@@ -967,9 +967,6 @@ class LogStreamDB extends LogStream {
$myQuery = mysql_query($szSql, $this->_dbhandle);
if ($myQuery)
{
- // Free res!
- // NOT NEEDED HERE! mysql_free_result($myQuery);
-
// Return success
return SUCCESS;
}
diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php
index cb1af2d..f127a75 100644
--- a/src/classes/logstreamdisk.class.php
+++ b/src/classes/logstreamdisk.class.php
@@ -613,7 +613,6 @@ class LogStreamDisk extends LogStream {
public function GetLogStreamStats()
{
// Get some file data!
-
/*
// return results!
return $stats;
@@ -683,7 +682,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to verify fields | not needed in disk logstream!
*/
- public abstract function VerifyFields( $arrProperitesIn )
+ public function VerifyFields( $arrProperitesIn )
{
return SUCCESS;
}
@@ -692,7 +691,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to create missing fields | not needed in disk logstream!
*/
- public abstract function CreateMissingFields( $arrProperitesIn )
+ public function CreateMissingFields( $arrProperitesIn )
{
return SUCCESS;
}
@@ -701,7 +700,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to verify indexes | not needed in disk logstream!
*/
- public abstract function VerifyIndexes( $arrProperitesIn )
+ public function VerifyIndexes( $arrProperitesIn )
{
return SUCCESS;
}
@@ -710,7 +709,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to create missing indexes | not needed in disk logstream!
*/
- public abstract function CreateMissingIndexes( $arrProperitesIn )
+ public function CreateMissingIndexes( $arrProperitesIn )
{
return SUCCESS;
}
@@ -719,7 +718,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to verify triggers | not needed in disk logstream!
*/
- public abstract function VerifyChecksumTrigger( $myTriggerProperty )
+ public function VerifyChecksumTrigger( $myTriggerProperty )
{
return SUCCESS;
}
@@ -728,7 +727,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to verify triggers | not needed in disk logstream!
*/
- public abstract function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty )
+ public function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty )
{
return SUCCESS;
}
@@ -737,7 +736,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to create missing triggers | not needed in disk logstream!
*/
- public abstract function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField )
+ public function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField )
{
return SUCCESS;
}
@@ -746,7 +745,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to verify checksum field | not needed in disk logstream!
*/
- public abstract function VerifyChecksumField( )
+ public function VerifyChecksumField( )
{
return SUCCESS;
}
@@ -755,7 +754,7 @@ class LogStreamDisk extends LogStream {
/*
* Helper function to correct the checksum field | not needed in disk logstream!
*/
- public abstract function ChangeChecksumFieldUnsigned( )
+ public function ChangeChecksumFieldUnsigned( )
{
return SUCCESS;
}
diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php
index 7cd777b..2752eb0 100644
--- a/src/classes/logstreampdo.class.php
+++ b/src/classes/logstreampdo.class.php
@@ -228,6 +228,329 @@ class LogStreamPDO extends LogStream {
return SUCCESS;
}
+
+ /*
+ * Implementation of VerifyFields: Checks if fields exist in table
+ */
+ public function VerifyFields( $arrProperitesIn )
+ {
+ global $dbmapping, $fields;
+
+ // Get List of Indexes as Array
+ $arrFieldKeys = $this->GetFieldsAsArray();
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+
+ // Loop through all fields to see which one is missing!
+ foreach ( $arrProperitesIn as $myproperty )
+ {
+// echo $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "
";
+ if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrFieldKeys) )
+ {
+ OutputDebugMessage("LogStreamPDO|VerifyFields: Found Field for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG);
+ continue;
+ }
+ else
+ {
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|VerifyFields: Missing Field for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_WARN);
+ return ERROR_DB_DBFIELDNOTFOUND;
+ }
+ }
+
+ // Successfull
+ return SUCCESS;
+ }
+
+
+ /*
+ * Implementation of VerifyIndexes: Checks if indexes exist for desired fields
+ */
+ public function VerifyIndexes( $arrProperitesIn )
+ {
+ global $dbmapping, $fields;
+
+ // Get List of Indexes as Array
+ $arrIndexKeys = $this->GetIndexesAsArray();
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+
+ // Loop through all fields to see which one is missing!
+ foreach ( $arrProperitesIn as $myproperty )
+ {
+// echo $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "
";
+ if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrIndexKeys) )
+ {
+ OutputDebugMessage("LogStreamPDO|VerifyIndexes: Found INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG);
+ continue;
+ }
+ else
+ {
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|VerifyIndexes: Missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_WARN);
+ return ERROR_DB_INDEXESMISSING;
+ }
+ }
+
+ // Successfull
+ return SUCCESS;
+ }
+
+
+ /*
+ * Implementation of VerifyChecksumTrigger: Checks if checksum trigger exists
+ */
+ public function VerifyChecksumTrigger( $myTriggerProperty )
+ {
+ global $dbmapping, $fields;
+
+ // Avoid Check if TRIGGERS are not supported!
+ if ( $this->_logStreamConfigObj->GetPDOTriggersSupported() == false )
+ return SUCCESS;
+
+ // Get List of Triggers as Array
+ $arrIndexTriggers = $this->GetTriggersAsArray();
+
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+ $szDBName = $this->_logStreamConfigObj->DBName;
+ $szTableName = $this->_logStreamConfigObj->DBTableName;
+ $szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty];
+
+ // Create Triggername
+ $szTriggerName = $szDBName . "_" . $szTableName . "_" . $szDBTriggerField;
+
+ // Try to find logstream trigger
+ if ( count($arrIndexTriggers) > 0 )
+ {
+ if ( in_array($szTriggerName, $arrIndexTriggers) )
+ return SUCCESS;
+ else
+ {
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|VerifyChecksumTrigger: Missing TRIGGER '" . $szTriggerName . "' for Table '" . $szTableName . "'", DEBUG_WARN);
+ return ERROR_DB_TRIGGERMISSING;
+ }
+ }
+ else
+ {
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|VerifyChecksumTrigger: No TRIGGERS found in your database", DEBUG_WARN);
+ return ERROR_DB_TRIGGERMISSING;
+ }
+ }
+
+
+ /*
+ * Implementation of CreateMissingIndexes: Checks if indexes exist for desired fields
+ */
+ public function CreateMissingIndexes( $arrProperitesIn )
+ {
+ global $dbmapping, $fields, $querycount;
+
+ // Get List of Indexes as Array
+ $arrIndexKeys = $this->GetIndexesAsArray();
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+
+ // Loop through all fields to see which one is missing!
+ foreach ( $arrProperitesIn as $myproperty )
+ {
+ if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrIndexKeys) )
+ continue;
+ else
+ {
+// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+ // Update Table schema now!
+ $szSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD INDEX ( " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " )";
+
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|CreateMissingIndexes: Createing missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' - " . $szSql, DEBUG_INFO);
+
+ // Add missing INDEX now!
+ $myQuery = $this->_dbhandle->query($szSql);
+ if (!$myQuery)
+ {
+ // Return failure!
+ $this->PrintDebugError("Dynamically Adding INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' failed with Statement: '" . $szSql . "'");
+ return ERROR_DB_INDEXFAILED;
+ }
+ else // Free query now
+ $myQuery->closeCursor();
+ }
+ }
+
+ // Successfull
+ return SUCCESS;
+ }
+
+
+ /*
+ * Implementation of CreateMissingFields: Checks if indexes exist for desired fields
+ */
+ public function CreateMissingFields( $arrProperitesIn )
+ {
+ global $dbmapping, $fields, $querycount;
+
+ // Get List of Indexes as Array
+ $arrFieldKeys = $this->GetFieldsAsArray();
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+
+ // Loop through all fields to see which one is missing!
+ foreach ( $arrProperitesIn as $myproperty )
+ {
+ if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrFieldKeys) )
+ continue;
+ else
+ {
+ if ( $this->HandleMissingField( $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrProperitesIn ) == SUCCESS )
+ {
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|CreateMissingFields: Createing missing FIELD for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], DEBUG_INFO);
+ }
+ else
+ {
+ // Return failure!
+ $this->PrintDebugError("Dynamically Adding FIELD for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' failed!");
+ return ERROR_DB_ADDDBFIELDFAILED;
+ }
+ }
+ }
+
+ // Successfull
+ return SUCCESS;
+ }
+
+
+ /*
+ * Implementation of GetCreateMissingTriggerSQL: Creates SQL needed to create a TRIGGER
+ */
+ public function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField )
+ {
+ global $dbmapping, $fields, $querycount;
+
+ // Get List of Triggers as Array
+ $szDBName = $this->_logStreamConfigObj->DBName;
+ $szTableName = $this->_logStreamConfigObj->DBTableName;
+
+ // Create Triggername
+ $szTriggerName = $szDBName . "_" . $szTableName . "_" . $myDBTriggerField;
+
+// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+ // Create TRIGGER SQL!
+ $szSql = "CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT ON `" . $szTableName . "`
+ FOR EACH ROW
+ BEGIN
+ SET NEW." . $myDBTriggerCheckSumField . " = crc32(NEW." . $myDBTriggerField . ");
+ END
+ ;";
+
+ return $szSql;
+ }
+
+
+ /*
+ * Implementation of CreateMissingTrigger: Creates missing triggers !
+ */
+ public function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty )
+ {
+ global $dbmapping, $fields, $querycount;
+
+ // Avoid if TRIGGERS are not supported!
+ if ( $this->_logStreamConfigObj->GetPDOTriggersSupported() == false )
+ return SUCCESS;
+
+ // Get List of Triggers as Array
+ $szTableName = $this->_logStreamConfigObj->DBTableName;
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+ $szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty];
+ $szDBTriggerCheckSumField = $dbmapping[$szTableType]['DBMAPPINGS'][$myCheckSumProperty];
+
+ // Get SQL Code to create the trigger!
+ $szSql = $this->GetCreateMissingTriggerSQL( $szDBTriggerField, $szDBTriggerCheckSumField );
+
+ // Index is missing for this field!
+ OutputDebugMessage("LogStreamPDO|CreateMissingTrigger: Creating missing TRIGGER for '" . $szTableName . "' - $szDBTriggerCheckSumField = crc32(NEW.$szDBTriggerField)" . $szSql, DEBUG_INFO);
+
+ // Add missing INDEX now!
+ $myQuery = $this->_dbhandle->query($szSql);
+ if (!$myQuery)
+ {
+ // Return failure!
+ $this->PrintDebugError("Dynamically Adding TRIGGER for '" . $szTableName . "' failed!
If you want to manually add the TRIGGER, use the following SQL Command:
" . str_replace("\n", "
", $szSql) . "
");
+ return ERROR_DB_TRIGGERFAILED;
+ }
+ else // Free query now
+ $myQuery->closeCursor();
+
+ // Successfull
+ return SUCCESS;
+ }
+
+
+ /*
+ * Implementation of ChangeChecksumFieldUnsigned: Changes the Checkusm field to unsigned!
+ */
+ public function ChangeChecksumFieldUnsigned()
+ {
+ global $dbmapping, $fields, $querycount;
+
+ // Get variables
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+
+// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+ // Change Checksumfield to use UNSIGNED!
+ $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` CHANGE `" .
+ $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "` `" .
+ $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "` INT(11) UNSIGNED NOT NULL DEFAULT '0'";
+
+ // Update Table schema now!
+ $myQuery = $this->_dbhandle->query($szUpdateSql);
+ if (!$myQuery)
+ {
+ // Return failure!
+ $this->PrintDebugError("ER_BAD_FIELD_ERROR - Failed to Change field '" . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "' from signed to unsigned with sql statement: '" . $szUpdateSql . "'");
+ return ERROR_DB_CHECKSUMCHANGEFAILED;
+ }
+ else // Free query now
+ $myQuery->closeCursor();
+
+ // return results
+ return SUCCESS;
+ }
+
+
+ /*
+ * Implementation of VerifyChecksumField: Verifies if the checkusm field is signed or unsigned!
+ */
+ public function VerifyChecksumField()
+ {
+ global $dbmapping, $fields, $querycount;
+
+ // Get variables
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
+
+ // Create SQL and Get INDEXES for table!
+ $szSql = "SHOW COLUMNS FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE Field = '" . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "'";
+ $myQuery = $this->_dbhandle->query($szSql);
+ if ($myQuery)
+ {
+ // Get result!
+ $myRow = $myQuery->fetch(PDO::FETCH_ASSOC);
+ if (strpos( strtolower($myRow['Type']), "unsigned") === false )
+ {
+ // return error code!
+ return ERROR_DB_CHECKSUMERROR;
+ }
+
+ // Free query now
+ $myQuery->closeCursor();
+
+ // Increment for the Footer Stats
+ $querycount++;
+ }
+
+ // return results
+ return SUCCESS;
+ }
+
+
/**
* Read the data from a specific uID which means in this
* case beginning with from the Database ID
@@ -1715,77 +2038,212 @@ class LogStreamPDO extends LogStream {
/*
* Function handles missing database fields automatically!
*/
- private function HandleMissingField()
+ private function HandleMissingField( $szMissingField = null, $arrProperties = null )
{
global $dbmapping, $fields;
// Get Err description
$errdesc = $this->_dbhandle->errorInfo();
- // check matching of error msg!
- if (
- preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc[2], $errOutArr ) || // MySQL
- preg_match("/column \"(.*?)\" does not exist/", $errdesc[2], $errOutArr ) // PostgreSQL
-// ERROR: column "checksum" does not exist LINE 1: ... eventsource, eventcategory, eventuser, systemid, checksum, ... ^
- )
+ // Try to get missing field from SQL Error of not specified as argument
+ if ( $szMissingField == null )
{
- $szTableType = $this->_logStreamConfigObj->DBTableType;
-
- // Loop through all fields to see which one is missing!
- foreach ( $this->_arrProperties as $myproperty )
+ // check matching of error msg!
+ if (
+ preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc[2], $errOutArr ) || // MySQL
+ preg_match("/column \"(.*?)\" does not exist/", $errdesc[2], $errOutArr ) // PostgreSQL
+// ERROR: column "checksum" does not exist LINE 1: ... eventsource, eventcategory, eventuser, systemid, checksum, ... ^
+ )
+ $szMissingField = $errOutArr[1];
+ else
{
- if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && $errOutArr[1] == $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] )
- {
- $szUpdateSql = "";
- if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
- {
- // MYSQL Statements
- if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER )
- $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) NOT NULL DEFAULT '0'";
- if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING )
- $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` varchar(60) NULL";
- if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE )
- $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'";
- }
- else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL )
- {
- // MYSQL Statements
- if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER )
- $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " int NOT NULL DEFAULT '0'";
- if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING )
- $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " varchar(60) NULL";
- if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE )
- $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " timestamp without time zone NULL";
- }
+ $this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc[2]);
+ return ERROR_DB_DBFIELDNOTFOUND;
+ }
+ }
+
+ // Set Properties to default if NULL
+ if ( $arrProperties == null )
+ $arrProperties = $this->_arrProperties;
+
+ // Get Tabletype
+ $szTableType = $this->_logStreamConfigObj->DBTableType;
- if ( strlen($szUpdateSql) > 0 )
- {
- // Update Table schema now!
- $myQuery = $this->_dbhandle->query($szUpdateSql);
- if (!$myQuery)
- {
- // Return failure!
- $this->PrintDebugError("ER_BAD_FIELD_ERROR - Dynamically Adding field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' with Statement failed: '" . $szUpdateSql . "'");
- return ERROR_DB_DBFIELDNOTFOUND;
- }
- else // Free query now
- $myQuery->closeCursor();
- }
- else
+ // Loop through all fields to see which one is missing!
+ foreach ( $arrProperties as $myproperty )
+ {
+ if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && $szMissingField == $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] )
+ {
+ $szUpdateSql = "";
+ if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+ {
+ // MYSQL Statements
+ if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER )
+ $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) NOT NULL DEFAULT '0'";
+ if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING )
+ $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` varchar(60) NULL";
+ if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE )
+ $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'";
+ }
+ else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL )
+ {
+ // MYSQL Statements
+ if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER )
+ $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " int NOT NULL DEFAULT '0'";
+ if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING )
+ $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " varchar(60) NULL";
+ if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE )
+ $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " timestamp without time zone NULL";
+ }
+
+ if ( strlen($szUpdateSql) > 0 )
+ {
+ // Update Table schema now!
+ $myQuery = $this->_dbhandle->query($szUpdateSql);
+ if (!$myQuery)
{
// Return failure!
- $this->PrintDebugError("ER_BAD_FIELD_ERROR - Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' is missing has to be added manually to the database layout!'");
+ $this->PrintDebugError("ER_BAD_FIELD_ERROR - Dynamically Adding field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' with Statement failed: '" . $szUpdateSql . "'");
return ERROR_DB_DBFIELDNOTFOUND;
}
+ else // Free query now
+ $myQuery->closeCursor();
+ }
+ else
+ {
+ // Return failure!
+ $this->PrintDebugError("ER_BAD_FIELD_ERROR - Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' is missing has to be added manually to the database layout!'");
+ return ERROR_DB_DBFIELDNOTFOUND;
}
}
+ }
- // Reached this point means success!
- return SUCCESS;
+ // Reached this point means success!
+ return SUCCESS;
+ }
+
+
+ /*
+ * Helper function to return a list of Indexes for the logstream table
+ */
+ private function GetIndexesAsArray()
+ {
+ global $querycount;
+
+ // Verify database connection (This also opens the database!)
+ $res = $this->Verify();
+ if ( $res != SUCCESS )
+ return $res;
+
+ // Init Array
+ $arrIndexKeys = array();
+
+// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+
+ // Create SQL and Get INDEXES for table!
+ $szSql = "SHOW INDEX FROM " . $this->_logStreamConfigObj->DBTableName;
+ $myQuery = $this->_dbhandle->query($szSql);
+ if ($myQuery)
+ {
+ // Loop through results
+ while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) )
+ {
+ // Add to index keys
+ $arrIndexKeys[] = strtolower($myRow['Key_name']);
+ }
+
+ // Free query now
+ $myQuery->closeCursor();
+
+ // Increment for the Footer Stats
+ $querycount++;
+ }
+
+ // return Array
+ return $arrIndexKeys;
+ }
+
+
+ /*
+ * Helper function to return a list of Fields from the logstream table
+ */
+ private function GetFieldsAsArray()
+ {
+ global $querycount;
+
+ // Verify database connection (This also opens the database!)
+ $res = $this->Verify();
+ if ( $res != SUCCESS )
+ return $res;
+
+ // Init Array
+ $arrFieldKeys = array();
+
+// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+ // Create SQL and Get FIELDS for table!
+ $szSql = "SHOW FIELDS FROM " . $this->_logStreamConfigObj->DBTableName;
+ $myQuery = $this->_dbhandle->query($szSql);
+ if ($myQuery)
+ {
+ // Loop through results
+ while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) )
+ {
+ // Add to index keys
+ $arrFieldKeys[] = strtolower($myRow['Field']);
+ }
+
+ // Free query now
+ $myQuery->closeCursor();
+
+ // Increment for the Footer Stats
+ $querycount++;
}
else
- $this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc[2]);
- return ERROR_DB_DBFIELDNOTFOUND;
+ $this->PrintDebugError("ERROR_DB_QUERYFAILED - GetFieldsAsArray SQL '" . $szSql . "' failed!");
+
+
+ // return Array
+ return $arrFieldKeys;
+ }
+
+
+ /*
+ * Helper function to return a list of Indexes for the logstream table
+ */
+ private function GetTriggersAsArray()
+ {
+ global $querycount;
+
+ // Verify database connection (This also opens the database!)
+ $res = $this->Verify();
+ if ( $res != SUCCESS )
+ return $res;
+
+ // Init Array
+ $arrIndexTriggers = array();
+
+// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL )
+ // Create SQL and Get INDEXES for table!
+ $szSql = "SHOW TRIGGERS";
+ $myQuery = $this->_dbhandle->query($szSql);
+ if ($myQuery)
+ {
+ // Loop through results
+ while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) )
+ {
+ // Add to index keys
+ $arrIndexTriggers[] = strtolower($myRow['Trigger']);
+ }
+
+ // Free query now
+ $myQuery->closeCursor();
+
+ // Increment for the Footer Stats
+ $querycount++;
+ }
+
+ // return Array
+ return $arrIndexTriggers;
}
diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php
index a2eb8fd..c886fe9 100644
--- a/src/lang/en/admin.php
+++ b/src/lang/en/admin.php
@@ -476,6 +476,8 @@ $content['LN_REPORTS_ADD_MISSINGFIELDS'] = "The datasource '%1' does not contain
$content['LN_REPORTS_ERROR_FAILED_ADDING_FIELDS'] = "Failed adding missing datafields in datasource '%1' with error code '%2'";
$content['LN_REPORTS_FIELDS_CREATED'] = "Added missing datafields";
$content['LN_REPORTS_FIELDS_CREATED_SUCCESS'] = "Successfully added missing datafields for datasource '%1'.";
+$content['LN_REPORTS_RECHECKLOGSTREAMSOURCE'] = "Do you want to check the current logstream source again?";
$content['LN_REPORTS_'] = "";
+
?>
\ No newline at end of file
diff --git a/src/templates/admin/admin_reports.html b/src/templates/admin/admin_reports.html
index e8d2a0b..d9302f1 100644
--- a/src/templates/admin/admin_reports.html
+++ b/src/templates/admin/admin_reports.html
@@ -276,6 +276,9 @@
{MSG_WARNING_DETAILS}
+ {LN_REPORTS_RECHECKLOGSTREAMSOURCE} +