Allow using templates created for other databases/tables

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
Madhura Jayaratne 2015-07-02 08:07:18 +05:30
parent cc7d4c446e
commit 4ab83556c6
8 changed files with 24 additions and 58 deletions

View File

@ -69,6 +69,7 @@ function createTemplate(name)
server : PMA_commonParams.get('server'),
db : PMA_commonParams.get('db'),
table : PMA_commonParams.get('table'),
exportType : $('input[name="export_type"]').val(),
templateAction : 'create',
templateName : name,
templateData : JSON.stringify(templateData)
@ -99,6 +100,7 @@ function loadTemplate(id)
server : PMA_commonParams.get('server'),
db : PMA_commonParams.get('db'),
table : PMA_commonParams.get('table'),
exportType : $('input[name="export_type"]').val(),
templateAction : 'load',
templateId : id,
};
@ -144,6 +146,7 @@ function updateTemplate(id)
server : PMA_commonParams.get('server'),
db : PMA_commonParams.get('db'),
table : PMA_commonParams.get('table'),
exportType : $('input[name="export_type"]').val(),
templateAction : 'update',
templateId : id,
templateData : JSON.stringify(templateData)
@ -172,6 +175,7 @@ function deleteTemplate(id)
server : PMA_commonParams.get('server'),
db : PMA_commonParams.get('db'),
table : PMA_commonParams.get('table'),
exportType : $('input[name="export_type"]').val(),
templateAction : 'delete',
templateId : id,
};

View File

@ -43,7 +43,7 @@ $html = PMA_getHtmlForExportOptionHeader($export_type, $db, $table);
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['exporttemplateswork']) {
$html .= PMA_getHtmlForExportTemplateLoading($db, $table);
$html .= PMA_getHtmlForExportTemplateLoading($export_type);
}
$html .= '<form method="post" action="export.php" '

View File

@ -187,10 +187,9 @@ function PMA_getHtmlForExportOptionHeader($export_type, $db, $table)
/**
* Returns Html for saving and loading export templates
*
* @param string $db database
* @param string $table table
* @param string $export_type export type - server, database, or table
*/
function PMA_getHtmlForExportTemplateLoading($db, $table)
function PMA_getHtmlForExportTemplateLoading($export_type)
{
$html = '<div class="exportoptions" id="exporttemplates">';
$html .= '<h3>' . __('Export templates:') . '</h3>';
@ -212,7 +211,7 @@ function PMA_getHtmlForExportTemplateLoading($db, $table)
$html .= '<h4>' . __('Existing templates:') . '</h4>';
$html .= '<label for="template">' . __('Template:') . '</label>';
$html .= '<select name="template" id="template">';
$html .= PMA_getOptionsForExportTemplates($db, $table);
$html .= PMA_getOptionsForExportTemplates($export_type);
$html .= '</select>';
$html .= '<input type="submit" name="loadTemplate" '
. 'id="loadTemplate" value="' . __('Load') . '" />';
@ -233,12 +232,11 @@ function PMA_getHtmlForExportTemplateLoading($db, $table)
/**
* Returns HTML for the options in teplate dropdown
*
* @param string $db database
* @param string $table table
* @param string $export_type export type - server, database, or table
*
* @return string HTML for the options in teplate dropdown
*/
function PMA_getOptionsForExportTemplates($db, $table)
function PMA_getOptionsForExportTemplates($export_type)
{
$ret = '';
@ -250,14 +248,7 @@ function PMA_getOptionsForExportTemplates($db, $table)
. PMA_Util::backquote($cfgRelation['exporttemplates'])
. " WHERE `username` = "
. "'" . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'"
. " AND `db_name` "
. (! empty($db)
? "= '" . PMA_Util::sqlAddSlashes($db) . "'"
: "IS NULL")
. " AND `table_name` "
. (! empty($table)
? "= '" . PMA_Util::sqlAddSlashes($table) . "'"
: "IS NULL")
. " AND `export_type` = '" . $export_type . "'"
. " ORDER BY `template_name`;";
$result = PMA_queryAsControlUser($query);

View File

@ -1024,7 +1024,6 @@ class ExportSql extends ExportPlugin
'column_info' => 'db_name',
'table_uiprefs' => 'db_name',
'tracking' => 'db_name',
'exporttemplates' => 'db_name',
);
} else {
$types = array(
@ -1034,7 +1033,6 @@ class ExportSql extends ExportPlugin
//'table_coords' => 'db_name',
'savedsearches' => 'db_name',
'central_columns' => 'db_name',
'exporttemplates' => 'db_name',
);
}
@ -1077,9 +1075,6 @@ class ExportSql extends ExportPlugin
} elseif ($type == 'savedsearches') {
$sql_query = "SELECT `username`, `db_name`, `search_name`,"
. " `search_data` FROM";
} elseif ($type == 'exporttemplates') {
$sql_query = "SELECT `username`, `db_name`, `table_name`,"
. " `template_name`, `template_data` FROM";
} else {
$sql_query = "SELECT * FROM ";
}

View File

@ -124,14 +124,6 @@ function PMA_relationsCleanupTable($db, $table)
. ' AND item_type = \'table\'))';
PMA_queryAsControlUser($remove_query);
}
if ($cfgRelation['exporttemplateswork']) {
$remove_query = 'DELETE FROM ' . PMA_Util::backquote($cfgRelation['db'])
. '.' . PMA_Util::backquote($cfgRelation['exporttemplates'])
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
. ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
PMA_queryAsControlUser($remove_query);
}
}
/**
@ -219,13 +211,6 @@ function PMA_relationsCleanupDatabase($db)
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'';
PMA_queryAsControlUser($remove_query);
}
if ($cfgRelation['exporttemplateswork']) {
$remove_query = 'DELETE FROM ' . PMA_Util::backquote($cfgRelation['db'])
. '.' . PMA_Util::backquote($cfgRelation['exporttemplates'])
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'';
PMA_queryAsControlUser($remove_query);
}
}
/**

View File

@ -344,13 +344,12 @@ CREATE TABLE IF NOT EXISTS `pma__designer_settings` (
CREATE TABLE IF NOT EXISTS `pma__exporttemplates` (
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(64) COLLATE utf8_bin NOT NULL,
`db_name` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`table_name` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`template_name` varchar(64) COLLATE utf8_bin NOT NULL,
`template_data` text COLLATE utf8_bin NOT NULL,
`username` varchar(64) NOT NULL,
`export_type` varchar(10) NOT NULL,
`template_name` varchar(64) NOT NULL,
`template_data` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `u_user_db_table_template` (`username`,`db_name`,`table_name`,`template_name`)
UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)
)
COMMENT='Saved export templates'
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

View File

@ -296,13 +296,12 @@ CREATE TABLE IF NOT EXISTS `pma__designer_settings` (
CREATE TABLE IF NOT EXISTS `pma__exporttemplates` (
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(64) COLLATE utf8_bin NOT NULL,
`db_name` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`table_name` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`template_name` varchar(64) COLLATE utf8_bin NOT NULL,
`template_data` text COLLATE utf8_bin NOT NULL,
`username` varchar(64) NOT NULL,
`export_type` varchar(10) NOT NULL,
`template_name` varchar(64) NOT NULL,
`template_data` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `u_user_db_table_template` (`username`,`db_name`,`table_name`,`template_name`)
UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)
)
COMMENT='Saved export templates'
COLLATE utf8_bin;

View File

@ -37,18 +37,11 @@ if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
if ('create' == $_REQUEST['templateAction']) {
$query = "INSERT INTO " . $templateTable . "("
. " `username`, `db_name`, `table_name`,"
. " `username`, `export_type`,"
. " `template_name`, `template_data`"
. ") VALUES ("
. "'" . $user . "', "
. (! empty($GLOBALS['db'])
? "'" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'"
: 'NULL'
) . ","
. (! empty($GLOBALS['table'])
? "'" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "'"
: 'NULL'
) . ","
. "'" . PMA_Util::sqlAddSlashes($_REQUEST['exportType']) . "', "
. "'" . PMA_Util::sqlAddSlashes($_REQUEST['templateName']) . "', "
. "'" . PMA_Util::sqlAddSlashes($_REQUEST['templateData']) . "');";
@ -80,7 +73,7 @@ if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
if ('create' == $_REQUEST['templateAction']) {
$response->addJSON(
'data',
PMA_getOptionsForExportTemplates($GLOBALS['db'], $GLOBALS['table'])
PMA_getOptionsForExportTemplates($_REQUEST['exportType'])
);
} elseif ('load' == $_REQUEST['templateAction']) {
$data = null;