Skip to content

Commit

Permalink
Allow using templates created for other databases/tables
Browse files Browse the repository at this point in the history
Signed-off-by: Madhura Jayaratne <[email protected]>
  • Loading branch information
madhuracj committed Jul 2, 2015
1 parent cc7d4c4 commit 4ab8355
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 58 deletions.
4 changes: 4 additions & 0 deletions js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion libraries/display_export.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['exporttemplateswork']) {
$html .= PMA_getHtmlForExportTemplateLoading($db, $table);
$html .= PMA_getHtmlForExportTemplateLoading($export_type);
}

$html .= '<form method="post" action="export.php" '
Expand Down
21 changes: 6 additions & 15 deletions libraries/display_export.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
Expand All @@ -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') . '" />';
Expand All @@ -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 = '';

Expand All @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions libraries/plugins/export/ExportSql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,6 @@ private function _exportMetadata(
'column_info' => 'db_name',
'table_uiprefs' => 'db_name',
'tracking' => 'db_name',
'exporttemplates' => 'db_name',
);
} else {
$types = array(
Expand All @@ -1034,7 +1033,6 @@ private function _exportMetadata(
//'table_coords' => 'db_name',
'savedsearches' => 'db_name',
'central_columns' => 'db_name',
'exporttemplates' => 'db_name',
);
}

Expand Down Expand Up @@ -1077,9 +1075,6 @@ private function _exportMetadata(
} 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 ";
}
Expand Down
15 changes: 0 additions & 15 deletions libraries/relation_cleanup.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
11 changes: 5 additions & 6 deletions sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 5 additions & 6 deletions sql/create_tables_drizzle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 3 additions & 10 deletions tbl_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,11 @@

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']) . "');";

Expand Down Expand Up @@ -80,7 +73,7 @@
if ('create' == $_REQUEST['templateAction']) {
$response->addJSON(
'data',
PMA_getOptionsForExportTemplates($GLOBALS['db'], $GLOBALS['table'])
PMA_getOptionsForExportTemplates($_REQUEST['exportType'])
);
} elseif ('load' == $_REQUEST['templateAction']) {
$data = null;
Expand Down

0 comments on commit 4ab8355

Please sign in to comment.