public static function createVersion($dbname, $tablename, $version, $tracking_set = '', $is_view = false)
{
global $sql_backquotes, $export_type;
if ($tracking_set == '') {
$tracking_set = $GLOBALS['cfg']['Server']['tracking_default_statements'];
}
// get Export SQL instance
include_once "libraries/plugin_interface.lib.php";
/* @var $export_sql_plugin \PMA\libraries\plugins\export\ExportSql */
$export_sql_plugin = PMA_getPlugin("export", "sql", 'libraries/plugins/export/', array('export_type' => $export_type, 'single_table' => false));
$sql_backquotes = true;
$date = date('Y-m-d H:i:s');
// Get data definition snapshot of table
$columns = $GLOBALS['dbi']->getColumns($dbname, $tablename, null, true);
// int indices to reduce size
$columns = array_values($columns);
// remove Privileges to reduce size
for ($i = 0, $nb = count($columns); $i < $nb; $i++) {
unset($columns[$i]['Privileges']);
}
$indexes = $GLOBALS['dbi']->getTableIndexes($dbname, $tablename);
$snapshot = array('COLUMNS' => $columns, 'INDEXES' => $indexes);
$snapshot = serialize($snapshot);
// Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
$sql_backquotes = true;
$create_sql = "";
if ($GLOBALS['cfg']['Server']['tracking_add_drop_table'] == true && $is_view == false) {
$create_sql .= self::getLogComment() . 'DROP TABLE IF EXISTS ' . Util::backquote($tablename) . ";\n";
}
if ($GLOBALS['cfg']['Server']['tracking_add_drop_view'] == true && $is_view == true) {
$create_sql .= self::getLogComment() . 'DROP VIEW IF EXISTS ' . Util::backquote($tablename) . ";\n";
}
$create_sql .= self::getLogComment() . $export_sql_plugin->getTableDef($dbname, $tablename, "\n", "");
// Save version
$sql_query = "/*NOTRACK*/\n" . "INSERT INTO " . self::_getTrackingTable() . " (" . "db_name, " . "table_name, " . "version, " . "date_created, " . "date_updated, " . "schema_snapshot, " . "schema_sql, " . "data_sql, " . "tracking " . ") " . "values (\n '" . $GLOBALS['dbi']->escapeString($dbname) . "',\n '" . $GLOBALS['dbi']->escapeString($tablename) . "',\n '" . $GLOBALS['dbi']->escapeString($version) . "',\n '" . $GLOBALS['dbi']->escapeString($date) . "',\n '" . $GLOBALS['dbi']->escapeString($date) . "',\n '" . $GLOBALS['dbi']->escapeString($snapshot) . "',\n '" . $GLOBALS['dbi']->escapeString($create_sql) . "',\n '" . $GLOBALS['dbi']->escapeString("\n") . "',\n '" . $GLOBALS['dbi']->escapeString($tracking_set) . "' )";
$result = PMA_queryAsControlUser($sql_query);
if ($result) {
// Deactivate previous version
self::deactivateTracking($dbname, $tablename, $version - 1);
}
return $result;
}