rfe #1632 Importing and exporting pMA meta-data

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
Madhura Jayaratne 2015-04-10 16:00:57 +05:30
parent 2cc3a536d8
commit ef981aa335
5 changed files with 170 additions and 0 deletions

View File

@ -22,6 +22,7 @@ phpMyAdmin - ChangeLog
+ rfe #1651 Allow copying mutiple rows
+ rfe #1643 No SQL query for loading data
+ rfe #1653 New data validation feature and datetime type
+ rfe #1632 Importing and exporting pMA meta-data
4.4.2.0 (not yet released)
- bug #4835 PMA_hideShowConnection not called after submit_num_fields

View File

@ -128,6 +128,7 @@ if (!defined('TESTSUITE')) {
'sql_utc_time',
'sql_drop_database',
'sql_views_as_tables',
'sql_metadata',
'csv_separator',
'csv_enclosed',
'csv_escaped',

View File

@ -550,6 +550,12 @@ function PMA_exportDatabase(
$export_plugin->exportRoutines($db, $aliases);
}
if (isset($GLOBALS['sql_metadata'])) {
// Types of metatada to export.
// In the future these can be allowed to be selected by the user
$metadataTypes = PMA_getMetadataTypesToExport();
}
$views = array();
foreach ($tables as $table) {
@ -634,6 +640,15 @@ function PMA_exportDatabase(
break 1;
}
}
// now export metadata related to this table
if (isset($GLOBALS['sql_metadata'])) {
if (! $export_plugin->exportMetadata(
$db, $table, $metadataTypes
)) {
return;
}
}
}
if (isset($GLOBALS['sql_create_view'])) {
@ -658,6 +673,15 @@ function PMA_exportDatabase(
if (! $export_plugin->exportDBFooter($db, $db_alias)) {
return;
}
// export metadata related to this db
if (isset($GLOBALS['sql_metadata'])) {
if (! $export_plugin->exportMetadata(
$db, null, $metadataTypes
)) {
return;
}
}
}
/**
@ -775,6 +799,18 @@ function PMA_exportTable(
if (! $export_plugin->exportDBFooter($db, $db_alias)) {
return;
}
if (isset($GLOBALS['sql_metadata'])) {
// Types of metatada to export.
// In the future these can be allowed to be selected by the user
$metadataTypes = PMA_getMetadataTypesToExport();
if (! $export_plugin->exportMetadata(
$db, $table, $metadataTypes
)) {
return;
}
}
}
/**
@ -886,4 +922,24 @@ function PMA_unlockTables()
{
return $GLOBALS['dbi']->tryQuery("UNLOCK TABLES");
}
/**
* Returns the all the metadata types the can be exported with a database or a table
*
* @return array metadata types.
*/
function PMA_getMetadataTypesToExport()
{
return array(
'column_info',
'table_uiprefs',
'tracking',
'bookmark',
'relation',
'table_coords',
'pdf_pages',
'savedsearches',
'central_columns',
);
}
?>

View File

@ -147,6 +147,23 @@ abstract class ExportPlugin
;
}
/**
* Exports metadata from Configuration Storage
*
* @param string $db database being exported
* @param string $table table being exported
* @param array $metadataTypes types of metadata to export
* @param array $targetNames associative array of db and table names of
* target configuraton storage
*
* @return bool Whether it succeeded
*/
public function exportMetadata(
$db, $table, $metadataTypes, $targetNames = array()
) {
;
}
/**
* Returns a stand-in CREATE definition to resolve view dependencies
*

View File

@ -155,6 +155,12 @@ class ExportSql extends ExportPlugin
$leaf->setText(__('Export views as tables'));
$generalOptions->addProperty($leaf);
// export metadata
$leaf = new BoolPropertyItem();
$leaf->setName("metadata");
$leaf->setText(__('Export metadata'));
$generalOptions->addProperty($leaf);
// compatibility maximization
$compats = $GLOBALS['dbi']->getCompatibilities();
if (count($compats) > 0) {
@ -928,6 +934,95 @@ class ExportSql extends ExportPlugin
return $result;
}
/**
* Exports metadata from Configuration Storage
*
* @param string $db database being exported
* @param string $table table being exported
* @param array $metadataTypes types of metadata to export
* @param array $targetNames associative array of db and table names of
* target configuraton storage
*
* @return bool Whether it succeeded
*/
public function exportMetadata(
$db, $table, $metadataTypes, $targetNames = array()
) {
$cfgRelation = PMA_getRelationsParam();
if (! isset($cfgRelation['db'])) {
return true;
}
if (isset($table)) {
$types = array(
'column_info' => 'db_name',
'table_uiprefs' => 'db_name',
'tracking' => 'db_name',
);
} else {
$types = array(
'bookmark' => 'dbase',
'relation' => 'master_db',
'table_coords' => 'db_name',
'pdf_pages' => 'db_name',
'savedsearches' => 'db_name',
'central_columns' => 'db_name',
);
}
$aliases = array();
foreach ($targetNames as $type => $targetName) {
if ($type == 'phpmyadmin') {
$aliases[$cfgRelation['db']] = $targetName;
} else {
if (isset($cfgRelation[$type])) {
$aliases[$cfgRelation['db']]['tables'][$cfgRelation[$type]]['alias']
= $targetName;
}
}
}
$comment = $this->_possibleCRLF()
. $this->_exportComment()
. $this->_exportComment(
sprintf(
__('Metadata for %s'),
isset($table) ? $table : $db
)
)
. $this->_exportComment();
if (! PMA_exportOutputHandler($comment)) {
return false;
}
foreach ($types as $type => $dbNameColumn) {
if (in_array($type, $metadataTypes) && isset($cfgRelation[$type])) {
$sql_query = "SELECT * FROM "
. PMA_Util::backquote($cfgRelation['db'])
. '.' . PMA_Util::backquote($cfgRelation[$type])
. " WHERE " . PMA_Util::backquote($dbNameColumn)
. " = '" . PMA_Util::sqlAddSlashes($db) . "'";
if (isset($table)) {
$sql_query .= " AND `table_name` = '"
. PMA_Util::sqlAddSlashes($table) . "'";
}
if (! $this->exportData(
$cfgRelation['db'],
$cfgRelation[$type],
$GLOBALS['crlf'],
'',
$sql_query,
$aliases
)) {
return false;
}
}
}
return true;
}
/**
* Returns a stand-in CREATE definition to resolve view dependencies
*