coding standards
This commit is contained in:
@@ -118,21 +118,25 @@ class PMA_Tracker
|
|||||||
*/
|
*/
|
||||||
static public function isActive()
|
static public function isActive()
|
||||||
{
|
{
|
||||||
if (!self::$enabled) return false;
|
if (! self::$enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/* We need to avoid attempt to track any queries from PMA_getRelationsParam */
|
/* We need to avoid attempt to track any queries from PMA_getRelationsParam */
|
||||||
self::$enabled = false;
|
self::$enabled = false;
|
||||||
$cfgRelation = PMA_getRelationsParam();
|
$cfgRelation = PMA_getRelationsParam();
|
||||||
/* Restore original state */
|
/* Restore original state */
|
||||||
self::$enabled = true;
|
self::$enabled = true;
|
||||||
if (!$cfgRelation['trackingwork']) return false;
|
if (! $cfgRelation['trackingwork']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
self::init();
|
self::init();
|
||||||
|
|
||||||
if(isset(self::$pma_table))
|
if (isset(self::$pma_table)) {
|
||||||
return true;
|
return true;
|
||||||
else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a simple DROP TABLE statement.
|
* Returns a simple DROP TABLE statement.
|
||||||
@@ -189,7 +193,6 @@ class PMA_Tracker
|
|||||||
$str = explode("\n", $tablename);
|
$str = explode("\n", $tablename);
|
||||||
$tablename = $str[0];
|
$tablename = $str[0];
|
||||||
|
|
||||||
|
|
||||||
$tablename = str_replace(';', '', $tablename);
|
$tablename = str_replace(';', '', $tablename);
|
||||||
$tablename = str_replace('`', '', $tablename);
|
$tablename = str_replace('`', '', $tablename);
|
||||||
$tablename = trim($tablename);
|
$tablename = trim($tablename);
|
||||||
@@ -210,13 +213,17 @@ class PMA_Tracker
|
|||||||
*/
|
*/
|
||||||
static public function isTracked($dbname, $tablename)
|
static public function isTracked($dbname, $tablename)
|
||||||
{
|
{
|
||||||
if (!self::$enabled) return false;
|
if (! self::$enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/* We need to avoid attempt to track any queries from PMA_getRelationsParam */
|
/* We need to avoid attempt to track any queries from PMA_getRelationsParam */
|
||||||
self::$enabled = false;
|
self::$enabled = false;
|
||||||
$cfgRelation = PMA_getRelationsParam();
|
$cfgRelation = PMA_getRelationsParam();
|
||||||
/* Restore original state */
|
/* Restore original state */
|
||||||
self::$enabled = true;
|
self::$enabled = true;
|
||||||
if (!$cfgRelation['trackingwork']) return false;
|
if (! $cfgRelation['trackingwork']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$sql_query =
|
$sql_query =
|
||||||
" SELECT tracking_active FROM " . self::$pma_table .
|
" SELECT tracking_active FROM " . self::$pma_table .
|
||||||
@@ -226,11 +233,12 @@ class PMA_Tracker
|
|||||||
|
|
||||||
$row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query));
|
$row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query));
|
||||||
|
|
||||||
if(isset($row['tracking_active']) and $row['tracking_active'] == 1)
|
if (isset($row['tracking_active']) && $row['tracking_active'] == 1) {
|
||||||
return true;
|
return true;
|
||||||
else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the comment line for the log.
|
* Returns the comment line for the log.
|
||||||
@@ -262,8 +270,9 @@ class PMA_Tracker
|
|||||||
{
|
{
|
||||||
global $sql_backquotes;
|
global $sql_backquotes;
|
||||||
|
|
||||||
if($tracking_set == '')
|
if ($tracking_set == '') {
|
||||||
$tracking_set = self::$default_tracking_set;
|
$tracking_set = self::$default_tracking_set;
|
||||||
|
}
|
||||||
|
|
||||||
require_once './libraries/export/sql.php';
|
require_once './libraries/export/sql.php';
|
||||||
|
|
||||||
@@ -277,9 +286,9 @@ class PMA_Tracker
|
|||||||
|
|
||||||
$sql_result = PMA_DBI_query($sql_query);
|
$sql_result = PMA_DBI_query($sql_query);
|
||||||
|
|
||||||
while($row = PMA_DBI_fetch_array($sql_result))
|
while ($row = PMA_DBI_fetch_array($sql_result)) {
|
||||||
$columns[] = $row;
|
$columns[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
$sql_query = '
|
$sql_query = '
|
||||||
SHOW INDEX FROM ' . PMA_backquote($dbname) . '.' . PMA_backquote($tablename);
|
SHOW INDEX FROM ' . PMA_backquote($dbname) . '.' . PMA_backquote($tablename);
|
||||||
@@ -288,35 +297,29 @@ class PMA_Tracker
|
|||||||
|
|
||||||
$indexes = array();
|
$indexes = array();
|
||||||
|
|
||||||
while( $row = PMA_DBI_fetch_array($sql_result))
|
while( $row = PMA_DBI_fetch_array($sql_result)) {
|
||||||
$indexes[] = $row;
|
$indexes[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
$snapshot = array('COLUMNS' => $columns , 'INDEXES' => $indexes);
|
$snapshot = array('COLUMNS' => $columns , 'INDEXES' => $indexes);
|
||||||
$snapshot = serialize($snapshot);
|
$snapshot = serialize($snapshot);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
|
// Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
|
||||||
$sql_backquotes = true;
|
$sql_backquotes = true;
|
||||||
|
|
||||||
$create_sql = "";
|
$create_sql = "";
|
||||||
|
|
||||||
if(self::$add_drop_table == true and $is_view == false)
|
if (self::$add_drop_table == true && $is_view == false) {
|
||||||
{
|
|
||||||
$create_sql .= self::getLogComment() .
|
$create_sql .= self::getLogComment() .
|
||||||
self::getStatementDropTable(PMA_backquote($tablename)) . ";\n";
|
self::getStatementDropTable(PMA_backquote($tablename)) . ";\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self::$add_drop_view == true and $is_view == true)
|
if (self::$add_drop_view == true && $is_view == true) {
|
||||||
{
|
|
||||||
$create_sql .= self::getLogComment() .
|
$create_sql .= self::getLogComment() .
|
||||||
self::getStatementDropView(PMA_backquote($tablename)) . ";\n";
|
self::getStatementDropView(PMA_backquote($tablename)) . ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$create_sql .= self::getLogComment() .
|
$create_sql .= self::getLogComment() .
|
||||||
PMA_getTableDef($dbname, $tablename, "\n", "");
|
PMA_getTableDef($dbname, $tablename, "\n", "");
|
||||||
|
|
||||||
@@ -348,8 +351,7 @@ class PMA_Tracker
|
|||||||
|
|
||||||
$result = PMA_query_as_controluser($sql_query);
|
$result = PMA_query_as_controluser($sql_query);
|
||||||
|
|
||||||
if($result)
|
if ($result) {
|
||||||
{
|
|
||||||
// Deactivate previous version
|
// Deactivate previous version
|
||||||
self::deactivateTracking($dbname, $tablename, ($version - 1));
|
self::deactivateTracking($dbname, $tablename, ($version - 1));
|
||||||
}
|
}
|
||||||
@@ -377,19 +379,17 @@ class PMA_Tracker
|
|||||||
|
|
||||||
$date = date('Y-m-d H:i:s');
|
$date = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
if ($tracking_set == '') {
|
||||||
if($tracking_set == '')
|
|
||||||
$tracking_set = self::$default_tracking_set;
|
$tracking_set = self::$default_tracking_set;
|
||||||
|
}
|
||||||
|
|
||||||
require_once './libraries/export/sql.php';
|
require_once './libraries/export/sql.php';
|
||||||
|
|
||||||
$create_sql = "";
|
$create_sql = "";
|
||||||
|
|
||||||
if(self::$add_drop_database == true)
|
if (self::$add_drop_database == true) {
|
||||||
{
|
|
||||||
$create_sql .= self::getLogComment() .
|
$create_sql .= self::getLogComment() .
|
||||||
self::getStatementDropDatabase(PMA_backquote($dbname)) . ";\n";
|
self::getStatementDropDatabase(PMA_backquote($dbname)) . ";\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$create_sql .= self::getLogComment() . $query;
|
$create_sql .= self::getLogComment() . $query;
|
||||||
@@ -497,15 +497,16 @@ class PMA_Tracker
|
|||||||
" WHERE " . PMA_backquote('db_name') . " = '" . PMA_sqlAddslashes($dbname) . "' " .
|
" WHERE " . PMA_backquote('db_name') . " = '" . PMA_sqlAddslashes($dbname) . "' " .
|
||||||
" AND " . PMA_backquote('table_name') . " = '" . PMA_sqlAddslashes($tablename) . "' ";
|
" AND " . PMA_backquote('table_name') . " = '" . PMA_sqlAddslashes($tablename) . "' ";
|
||||||
|
|
||||||
if($statement != "")
|
if ($statement != "") {
|
||||||
$sql_query .= " AND FIND_IN_SET('" . $statement . "',tracking) > 0" ;
|
$sql_query .= " AND FIND_IN_SET('" . $statement . "',tracking) > 0" ;
|
||||||
|
}
|
||||||
$row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query));
|
$row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query));
|
||||||
if(isset($row[0]))
|
if (isset($row[0])) {
|
||||||
$version = $row[0];
|
$version = $row[0];
|
||||||
|
}
|
||||||
if(!isset($version)) $version = -1;
|
if (! isset($version)) {
|
||||||
|
$version = -1;
|
||||||
|
}
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,13 +543,13 @@ class PMA_Tracker
|
|||||||
|
|
||||||
// Iterate tracked data definition statements
|
// Iterate tracked data definition statements
|
||||||
// For each log entry we want to get date, username and statement
|
// For each log entry we want to get date, username and statement
|
||||||
foreach ($log_schema_entries as $log_entry)
|
foreach ($log_schema_entries as $log_entry) {
|
||||||
{
|
if (trim($log_entry) != '') {
|
||||||
if(trim($log_entry) != '')
|
|
||||||
{
|
|
||||||
$date = substr($log_entry, 0, 19);
|
$date = substr($log_entry, 0, 19);
|
||||||
$username = substr($log_entry, 20, strpos($log_entry, "\n") - 20);
|
$username = substr($log_entry, 20, strpos($log_entry, "\n") - 20);
|
||||||
if($i == 0) $ddl_date_from = $date;
|
if ($i == 0) {
|
||||||
|
$ddl_date_from = $date;
|
||||||
|
}
|
||||||
$statement = rtrim(strstr($log_entry, "\n"));
|
$statement = rtrim(strstr($log_entry, "\n"));
|
||||||
|
|
||||||
$ddlog[] = array( 'date' => $date,
|
$ddlog[] = array( 'date' => $date,
|
||||||
@@ -568,13 +569,13 @@ class PMA_Tracker
|
|||||||
|
|
||||||
// Iterate tracked data manipulation statements
|
// Iterate tracked data manipulation statements
|
||||||
// For each log entry we want to get date, username and statement
|
// For each log entry we want to get date, username and statement
|
||||||
foreach ($log_data_entries as $log_entry)
|
foreach ($log_data_entries as $log_entry) {
|
||||||
{
|
if (trim($log_entry) != '') {
|
||||||
if(trim($log_entry) != '')
|
|
||||||
{
|
|
||||||
$date = substr($log_entry, 0, 19);
|
$date = substr($log_entry, 0, 19);
|
||||||
$username = substr($log_entry, 20, strpos($log_entry, "\n") - 20);
|
$username = substr($log_entry, 20, strpos($log_entry, "\n") - 20);
|
||||||
if($i == 0) $dml_date_from = $date;
|
if ($i == 0) {
|
||||||
|
$dml_date_from = $date;
|
||||||
|
}
|
||||||
$statement = rtrim(strstr($log_entry, "\n"));
|
$statement = rtrim(strstr($log_entry, "\n"));
|
||||||
|
|
||||||
$dmlog[] = array( 'date' => $date,
|
$dmlog[] = array( 'date' => $date,
|
||||||
@@ -587,16 +588,16 @@ class PMA_Tracker
|
|||||||
$dml_date_to = $date;
|
$dml_date_to = $date;
|
||||||
|
|
||||||
// Define begin and end of date range for both logs
|
// Define begin and end of date range for both logs
|
||||||
if(strtotime($ddl_date_from) <= strtotime($dml_date_from))
|
if (strtotime($ddl_date_from) <= strtotime($dml_date_from)) {
|
||||||
$data['date_from'] = $ddl_date_from;
|
$data['date_from'] = $ddl_date_from;
|
||||||
else
|
} else {
|
||||||
$data['date_from'] = $dml_date_from;
|
$data['date_from'] = $dml_date_from;
|
||||||
|
}
|
||||||
if(strtotime($ddl_date_to) >= strtotime($dml_date_to))
|
if (strtotime($ddl_date_to) >= strtotime($dml_date_to)) {
|
||||||
$data['date_to'] = $ddl_date_to;
|
$data['date_to'] = $ddl_date_to;
|
||||||
else
|
} else {
|
||||||
$data['date_to'] = $dml_date_to;
|
$data['date_to'] = $dml_date_to;
|
||||||
|
}
|
||||||
$data['ddlog'] = $ddlog;
|
$data['ddlog'] = $ddlog;
|
||||||
$data['dmlog'] = $dmlog;
|
$data['dmlog'] = $dmlog;
|
||||||
$data['tracking'] = $mixed['tracking'];
|
$data['tracking'] = $mixed['tracking'];
|
||||||
@@ -640,8 +641,7 @@ class PMA_Tracker
|
|||||||
$tokens = array_map('strtoupper', $tokens);
|
$tokens = array_map('strtoupper', $tokens);
|
||||||
|
|
||||||
// Parse USE statement, need it for SQL dump imports
|
// Parse USE statement, need it for SQL dump imports
|
||||||
if(substr($query, 0, 4) == 'USE ')
|
if (substr($query, 0, 4) == 'USE ') {
|
||||||
{
|
|
||||||
$prefix = explode('USE ', $query);
|
$prefix = explode('USE ', $query);
|
||||||
$GLOBALS['db'] = self::getTableName($prefix[1]);
|
$GLOBALS['db'] = self::getTableName($prefix[1]);
|
||||||
}
|
}
|
||||||
@@ -653,10 +653,9 @@ class PMA_Tracker
|
|||||||
$result['type'] = 'DDL';
|
$result['type'] = 'DDL';
|
||||||
|
|
||||||
// Parse CREATE VIEW statement
|
// Parse CREATE VIEW statement
|
||||||
if(in_array('CREATE', $tokens) == true and
|
if (in_array('CREATE', $tokens) == true &&
|
||||||
in_array('VIEW', $tokens) == true and
|
in_array('VIEW', $tokens) == true &&
|
||||||
in_array('AS', $tokens) == true)
|
in_array('AS', $tokens) == true) {
|
||||||
{
|
|
||||||
$result['identifier'] = 'CREATE VIEW';
|
$result['identifier'] = 'CREATE VIEW';
|
||||||
|
|
||||||
$index = array_search('VIEW', $tokens);
|
$index = array_search('VIEW', $tokens);
|
||||||
@@ -665,11 +664,10 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse ALTER VIEW statement
|
// Parse ALTER VIEW statement
|
||||||
if(in_array('ALTER', $tokens) == true and
|
if (in_array('ALTER', $tokens) == true &&
|
||||||
in_array('VIEW', $tokens) == true and
|
in_array('VIEW', $tokens) == true &&
|
||||||
in_array('AS', $tokens) == true and
|
in_array('AS', $tokens) == true &&
|
||||||
!isset($result['identifier']))
|
! isset($result['identifier'])) {
|
||||||
{
|
|
||||||
$result['identifier'] = 'ALTER VIEW';
|
$result['identifier'] = 'ALTER VIEW';
|
||||||
|
|
||||||
$index = array_search('VIEW', $tokens);
|
$index = array_search('VIEW', $tokens);
|
||||||
@@ -678,22 +676,20 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse DROP VIEW statement
|
// Parse DROP VIEW statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 10) == 'DROP VIEW ')
|
if (! isset($result['identifier']) && substr($query, 0, 10) == 'DROP VIEW ') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'DROP VIEW';
|
$result['identifier'] = 'DROP VIEW';
|
||||||
|
|
||||||
$prefix = explode('DROP VIEW ', $query);
|
$prefix = explode('DROP VIEW ', $query);
|
||||||
$str = strstr($prefix[1], 'IF EXISTS');
|
$str = strstr($prefix[1], 'IF EXISTS');
|
||||||
|
|
||||||
if($str == FALSE )
|
if ($str == FALSE ) {
|
||||||
$str = $prefix[1];
|
$str = $prefix[1];
|
||||||
|
}
|
||||||
$result['tablename'] = self::getTableName($str);
|
$result['tablename'] = self::getTableName($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse CREATE DATABASE statement
|
// Parse CREATE DATABASE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 15) == 'CREATE DATABASE')
|
if (! isset($result['identifier']) && substr($query, 0, 15) == 'CREATE DATABASE') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'CREATE DATABASE';
|
$result['identifier'] = 'CREATE DATABASE';
|
||||||
$str = str_replace('CREATE DATABASE', '', $query);
|
$str = str_replace('CREATE DATABASE', '', $query);
|
||||||
$str = str_replace('IF NOT EXISTS', '', $str);
|
$str = str_replace('IF NOT EXISTS', '', $str);
|
||||||
@@ -705,15 +701,13 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse ALTER DATABASE statement
|
// Parse ALTER DATABASE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 14) == 'ALTER DATABASE')
|
if (! isset($result['identifier']) && substr($query, 0, 14) == 'ALTER DATABASE') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'ALTER DATABASE';
|
$result['identifier'] = 'ALTER DATABASE';
|
||||||
$result['tablename'] = '';
|
$result['tablename'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse DROP DATABASE statement
|
// Parse DROP DATABASE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 13) == 'DROP DATABASE')
|
if (! isset($result['identifier']) && substr($query, 0, 13) == 'DROP DATABASE') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'DROP DATABASE';
|
$result['identifier'] = 'DROP DATABASE';
|
||||||
$str = str_replace('DROP DATABASE', '', $query);
|
$str = str_replace('DROP DATABASE', '', $query);
|
||||||
$str = str_replace('IF EXISTS', '', $str);
|
$str = str_replace('IF EXISTS', '', $str);
|
||||||
@@ -722,8 +716,7 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse CREATE TABLE statement
|
// Parse CREATE TABLE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 12) == 'CREATE TABLE')
|
if (! isset($result['identifier']) && substr($query, 0, 12) == 'CREATE TABLE' ) {
|
||||||
{
|
|
||||||
$result['identifier'] = 'CREATE TABLE';
|
$result['identifier'] = 'CREATE TABLE';
|
||||||
$query = str_replace('IF NOT EXISTS', '', $query);
|
$query = str_replace('IF NOT EXISTS', '', $query);
|
||||||
$prefix = explode('CREATE TABLE ', $query);
|
$prefix = explode('CREATE TABLE ', $query);
|
||||||
@@ -732,8 +725,7 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse ALTER TABLE statement
|
// Parse ALTER TABLE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 12) == 'ALTER TABLE ')
|
if (! isset($result['identifier']) && substr($query, 0, 12) == 'ALTER TABLE ') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'ALTER TABLE';
|
$result['identifier'] = 'ALTER TABLE';
|
||||||
|
|
||||||
$prefix = explode('ALTER TABLE ', $query);
|
$prefix = explode('ALTER TABLE ', $query);
|
||||||
@@ -742,27 +734,25 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse DROP TABLE statement
|
// Parse DROP TABLE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 11) == 'DROP TABLE ')
|
if (! isset($result['identifier']) && substr($query, 0, 11) == 'DROP TABLE ') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'DROP TABLE';
|
$result['identifier'] = 'DROP TABLE';
|
||||||
|
|
||||||
$prefix = explode('DROP TABLE ', $query);
|
$prefix = explode('DROP TABLE ', $query);
|
||||||
$str = strstr($prefix[1], 'IF EXISTS');
|
$str = strstr($prefix[1], 'IF EXISTS');
|
||||||
|
|
||||||
if($str == FALSE )
|
if ($str == FALSE ) {
|
||||||
$str = $prefix[1];
|
$str = $prefix[1];
|
||||||
|
}
|
||||||
$result['tablename'] = self::getTableName($str);
|
$result['tablename'] = self::getTableName($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse CREATE INDEX statement
|
// Parse CREATE INDEX statement
|
||||||
if(!isset($result['identifier']) and
|
if (! isset($result['identifier']) &&
|
||||||
( substr($query, 0, 12) == 'CREATE INDEX' or
|
( substr($query, 0, 12) == 'CREATE INDEX' ||
|
||||||
substr($query, 0, 19) == 'CREATE UNIQUE INDEX' or
|
substr($query, 0, 19) == 'CREATE UNIQUE INDEX' ||
|
||||||
substr($query, 0, 20) == 'CREATE SPATIAL INDEX'
|
substr($query, 0, 20) == 'CREATE SPATIAL INDEX'
|
||||||
)
|
)
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
$result['identifier'] = 'CREATE INDEX';
|
$result['identifier'] = 'CREATE INDEX';
|
||||||
$prefix = explode('ON ', $query);
|
$prefix = explode('ON ', $query);
|
||||||
$suffix = explode('(', $prefix[1]);
|
$suffix = explode('(', $prefix[1]);
|
||||||
@@ -770,16 +760,14 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse DROP INDEX statement
|
// Parse DROP INDEX statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 10) == 'DROP INDEX')
|
if (! isset($result['identifier']) && substr($query, 0, 10) == 'DROP INDEX') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'DROP INDEX';
|
$result['identifier'] = 'DROP INDEX';
|
||||||
$prefix = explode('ON ', $query);
|
$prefix = explode('ON ', $query);
|
||||||
$result['tablename'] = self::getTableName($prefix[1]);
|
$result['tablename'] = self::getTableName($prefix[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse RENAME TABLE statement
|
// Parse RENAME TABLE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 13) == 'RENAME TABLE ')
|
if (! isset($result['identifier']) && substr($query, 0, 13) == 'RENAME TABLE ') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'RENAME TABLE';
|
$result['identifier'] = 'RENAME TABLE';
|
||||||
$prefix = explode('RENAME TABLE ', $query);
|
$prefix = explode('RENAME TABLE ', $query);
|
||||||
$names = explode(' TO ', $prefix[1]);
|
$names = explode(' TO ', $prefix[1]);
|
||||||
@@ -791,12 +779,11 @@ class PMA_Tracker
|
|||||||
* DML statements
|
* DML statements
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!isset($result['identifier']))
|
if (! isset($result['identifier'])) {
|
||||||
$result["type"] = 'DML';
|
$result["type"] = 'DML';
|
||||||
|
}
|
||||||
// Parse UPDATE statement
|
// Parse UPDATE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 6) == 'UPDATE')
|
if (! isset($result['identifier']) && substr($query, 0, 6) == 'UPDATE') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'UPDATE';
|
$result['identifier'] = 'UPDATE';
|
||||||
$prefix = explode('UPDATE ', $query);
|
$prefix = explode('UPDATE ', $query);
|
||||||
$suffix = explode(' ', $prefix[1]);
|
$suffix = explode(' ', $prefix[1]);
|
||||||
@@ -804,8 +791,7 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse INSERT INTO statement
|
// Parse INSERT INTO statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 11 ) == 'INSERT INTO')
|
if (! isset($result['identifier']) && substr($query, 0, 11 ) == 'INSERT INTO') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'INSERT';
|
$result['identifier'] = 'INSERT';
|
||||||
$prefix = explode('INSERT INTO', $query);
|
$prefix = explode('INSERT INTO', $query);
|
||||||
$suffix = explode('(', $prefix[1]);
|
$suffix = explode('(', $prefix[1]);
|
||||||
@@ -813,8 +799,7 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse DELETE statement
|
// Parse DELETE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 6 ) == 'DELETE')
|
if (! isset($result['identifier']) && substr($query, 0, 6 ) == 'DELETE') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'DELETE';
|
$result['identifier'] = 'DELETE';
|
||||||
$prefix = explode('FROM ', $query);
|
$prefix = explode('FROM ', $query);
|
||||||
$suffix = explode(' ', $prefix[1]);
|
$suffix = explode(' ', $prefix[1]);
|
||||||
@@ -822,8 +807,7 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse TRUNCATE statement
|
// Parse TRUNCATE statement
|
||||||
if(!isset($result['identifier']) and substr($query, 0, 8 ) == 'TRUNCATE')
|
if (! isset($result['identifier']) && substr($query, 0, 8 ) == 'TRUNCATE') {
|
||||||
{
|
|
||||||
$result['identifier'] = 'TRUNCATE';
|
$result['identifier'] = 'TRUNCATE';
|
||||||
$prefix = explode('TRUNCATE', $query);
|
$prefix = explode('TRUNCATE', $query);
|
||||||
$result['tablename'] = self::getTableName($prefix[1]);
|
$result['tablename'] = self::getTableName($prefix[1]);
|
||||||
@@ -843,16 +827,13 @@ class PMA_Tracker
|
|||||||
static public function handleQuery($query)
|
static public function handleQuery($query)
|
||||||
{
|
{
|
||||||
// If query is marked as untouchable, leave
|
// If query is marked as untouchable, leave
|
||||||
if(strstr($query, "/*NOTRACK*/"))
|
if (strstr($query, "/*NOTRACK*/")) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//$query = trim($query);
|
if (! (substr($query, -1) == ';')) {
|
||||||
//$query = ltrim($query, '-');
|
|
||||||
|
|
||||||
|
|
||||||
if(!(substr($query, -1) == ';'))
|
|
||||||
$query = $query . ";\n";
|
$query = $query . ";\n";
|
||||||
|
}
|
||||||
// Get some information about query
|
// Get some information about query
|
||||||
$result = self::parseQuery($query);
|
$result = self::parseQuery($query);
|
||||||
|
|
||||||
@@ -865,37 +846,37 @@ class PMA_Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we found a valid statement
|
// If we found a valid statement
|
||||||
if(isset($result['identifier']))
|
if (isset($result['identifier'])) {
|
||||||
{
|
|
||||||
$version = self::getVersion($dbname, $result['tablename'], $result['identifier']);
|
$version = self::getVersion($dbname, $result['tablename'], $result['identifier']);
|
||||||
|
|
||||||
// If version not exists and auto-creation is enabled
|
// If version not exists and auto-creation is enabled
|
||||||
if(self::$version_auto_create == true and
|
if (self::$version_auto_create == true
|
||||||
self::isTracked($dbname, $result['tablename']) == false and
|
&& self::isTracked($dbname, $result['tablename']) == false
|
||||||
$version == -1)
|
&& $version == -1) {
|
||||||
{
|
|
||||||
// Create the version
|
// Create the version
|
||||||
|
|
||||||
if($result['identifier'] == 'CREATE TABLE')
|
switch ($result['identifier']) {
|
||||||
|
case 'CREATE TABLE':
|
||||||
self::createVersion($dbname, $result['tablename'], '1');
|
self::createVersion($dbname, $result['tablename'], '1');
|
||||||
|
break;
|
||||||
if($result['identifier'] == 'CREATE VIEW')
|
case 'CREATE VIEW':
|
||||||
self::createVersion($dbname, $result['tablename'], '1', '', true);
|
self::createVersion($dbname, $result['tablename'], '1', '', true);
|
||||||
|
break;
|
||||||
if($result['identifier'] == 'CREATE DATABASE')
|
case 'CREATE DATABASE':
|
||||||
self::createDatabaseVersion($dbname, '1', $query);
|
self::createDatabaseVersion($dbname, '1', $query);
|
||||||
|
break;
|
||||||
|
} // end switch
|
||||||
}
|
}
|
||||||
|
|
||||||
// If version exists
|
// If version exists
|
||||||
if(self::isTracked($dbname, $result['tablename']) and $version != -1)
|
if (self::isTracked($dbname, $result['tablename']) && $version != -1) {
|
||||||
{
|
if ($result['type'] == 'DDL') {
|
||||||
if($result['type'] == 'DDL')
|
|
||||||
$save_to = 'schema_sql';
|
$save_to = 'schema_sql';
|
||||||
else if($result['type'] == 'DML')
|
} elseif ($result['type'] == 'DML') {
|
||||||
$save_to = 'data_sql';
|
$save_to = 'data_sql';
|
||||||
else
|
} else {
|
||||||
$save_to = '';
|
$save_to = '';
|
||||||
|
}
|
||||||
$date = date('Y-m-d H:i:s');
|
$date = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
// Cut off `dbname`. from query
|
// Cut off `dbname`. from query
|
||||||
@@ -912,8 +893,9 @@ class PMA_Tracker
|
|||||||
" " . PMA_backquote('date_updated') . " = '" . $date . "' ";
|
" " . PMA_backquote('date_updated') . " = '" . $date . "' ";
|
||||||
|
|
||||||
// If table was renamed we have to change the tablename attribute in pma_tracking too
|
// If table was renamed we have to change the tablename attribute in pma_tracking too
|
||||||
if($result['identifier'] == 'RENAME TABLE')
|
if ($result['identifier'] == 'RENAME TABLE') {
|
||||||
$sql_query .= ', ' . PMA_backquote('table_name') . ' = \'' . PMA_sqlAddslashes($result['tablename_after_rename']) . '\' ';
|
$sql_query .= ', ' . PMA_backquote('table_name') . ' = \'' . PMA_sqlAddslashes($result['tablename_after_rename']) . '\' ';
|
||||||
|
}
|
||||||
|
|
||||||
// Save the tracking information only for
|
// Save the tracking information only for
|
||||||
// 1. the database
|
// 1. the database
|
||||||
|
Reference in New Issue
Block a user