public static function getTrackedData($dbname, $tablename, $version)
{
$sql_query = " SELECT * FROM " . self::_getTrackingTable() . " WHERE `db_name` = '" . $GLOBALS['dbi']->escapeString($dbname) . "' ";
if (!empty($tablename)) {
$sql_query .= " AND `table_name` = '" . $GLOBALS['dbi']->escapeString($tablename) . "' ";
}
$sql_query .= " AND `version` = '" . $GLOBALS['dbi']->escapeString($version) . "' " . " ORDER BY `version` DESC LIMIT 1";
$mixed = $GLOBALS['dbi']->fetchAssoc(PMA_queryAsControlUser($sql_query));
// Parse log
$log_schema_entries = explode('# log ', $mixed['schema_sql']);
$log_data_entries = explode('# log ', $mixed['data_sql']);
$ddl_date_from = $date = date('Y-m-d H:i:s');
$ddlog = array();
$first_iteration = true;
// Iterate tracked data definition statements
// For each log entry we want to get date, username and statement
foreach ($log_schema_entries as $log_entry) {
if (trim($log_entry) != '') {
$date = mb_substr($log_entry, 0, 19);
$username = mb_substr($log_entry, 20, mb_strpos($log_entry, "\n") - 20);
if ($first_iteration) {
$ddl_date_from = $date;
$first_iteration = false;
}
$statement = rtrim(mb_strstr($log_entry, "\n"));
$ddlog[] = array('date' => $date, 'username' => $username, 'statement' => $statement);
}
}
$date_from = $ddl_date_from;
$ddl_date_to = $date;
$dml_date_from = $date_from;
$dmlog = array();
$first_iteration = true;
// Iterate tracked data manipulation statements
// For each log entry we want to get date, username and statement
foreach ($log_data_entries as $log_entry) {
if (trim($log_entry) != '') {
$date = mb_substr($log_entry, 0, 19);
$username = mb_substr($log_entry, 20, mb_strpos($log_entry, "\n") - 20);
if ($first_iteration) {
$dml_date_from = $date;
$first_iteration = false;
}
$statement = rtrim(mb_strstr($log_entry, "\n"));
$dmlog[] = array('date' => $date, 'username' => $username, 'statement' => $statement);
}
}
$dml_date_to = $date;
// Define begin and end of date range for both logs
$data = array();
if (strtotime($ddl_date_from) <= strtotime($dml_date_from)) {
$data['date_from'] = $ddl_date_from;
} else {
$data['date_from'] = $dml_date_from;
}
if (strtotime($ddl_date_to) >= strtotime($dml_date_to)) {
$data['date_to'] = $ddl_date_to;
} else {
$data['date_to'] = $dml_date_to;
}
$data['ddlog'] = $ddlog;
$data['dmlog'] = $dmlog;
$data['tracking'] = $mixed['tracking'];
$data['schema_snapshot'] = $mixed['schema_snapshot'];
return $data;
}