From ce5c6e9e524f0d24cc3260a75a7f2265eb990bbc Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Tue, 9 Jul 2013 10:52:21 +0530 Subject: [PATCH 01/30] Use a drop down as only one check option can be selected. --- view_create.php | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/view_create.php b/view_create.php index af53a5550c..90f25a8841 100644 --- a/view_create.php +++ b/view_create.php @@ -56,41 +56,40 @@ if (isset($_REQUEST['createview'])) { $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as']; if (isset($_REQUEST['view']['with'])) { - $options = array_intersect($_REQUEST['view']['with'], $view_with_options); - if (count($options)) { - $sql_query .= $sep . ' WITH ' . implode(' ', $options); + if (in_array($_REQUEST['view']['with'], $view_with_options)) { + $sql_query .= $sep . ' WITH ' . $_REQUEST['view']['with']; } } if ($GLOBALS['dbi']->tryQuery($sql_query)) { - + include_once './libraries/tbl_views.lib.php'; - + // If different column names defined for VIEW $view_columns = array(); if (isset($_REQUEST['view']['column_names'])) { $view_columns = explode(',', $_REQUEST['view']['column_names']); } - + $column_map = PMA_getColumnMap($_REQUEST['view']['as'], $view_columns); $pma_tranformation_data = PMA_getExistingTranformationData($GLOBALS['db']); - + if ($pma_tranformation_data !== false) { - + // SQL for store new transformation details of VIEW $new_transformations_sql = PMA_getNewTransformationDataSql( $pma_tranformation_data, $column_map, $_REQUEST['view']['name'], $GLOBALS['db'] - ); - + ); + // Store new transformations if ($new_transformations_sql != '') { $GLOBALS['dbi']->tryQuery($new_transformations_sql); } - + } unset($pma_tranformation_data); - + if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::success(); include './' . $cfg['DefaultTabDatabase']; @@ -103,9 +102,9 @@ if (isset($_REQUEST['createview'])) { ) ); } - + exit; - + } else { if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); @@ -202,18 +201,16 @@ $htmlString .= '>' . htmlspecialchars($view['as']) . '' . 'WITH' . ''; +$htmlString .= '' - . '
'; + $htmlString .= '>' . htmlspecialchars($option) . ''; } +$htmlString .= ' Date: Wed, 10 Jul 2013 14:53:54 +0530 Subject: [PATCH 03/30] Use ajax dialog for view editing --- js/functions.js | 11 +++---- js/messages.php | 2 +- libraries/structure.lib.php | 43 ++++++++++++++++-------- view_create.php | 66 ++++++++++++++++++++++--------------- 4 files changed, 76 insertions(+), 46 deletions(-) diff --git a/js/functions.js b/js/functions.js index c010a4ad77..65498b4451 100644 --- a/js/functions.js +++ b/js/functions.js @@ -3675,7 +3675,7 @@ function printPage() */ AJAX.registerTeardown('functions.js', function () { $('input#print').unbind('click'); - $('span a.create_view.ajax').die('click'); + $('a.create_view.ajax, a.alter_view.ajax').die('click'); $('#createViewDialog').find('input, select').die('keydown'); }); @@ -3684,7 +3684,7 @@ AJAX.registerOnload('functions.js', function () { /** * Ajaxification for the "Create View" action */ - $('span a.create_view.ajax').live('click', function (e) { + $('a.create_view.ajax, a.alter_view.ajax').live('click', function (e) { e.preventDefault(); PMA_createViewDialog($(this)); }); @@ -3704,7 +3704,7 @@ function PMA_createViewDialog($this) { var $msg = PMA_ajaxShowMessage(); var syntaxHighlighter = null; - $.get($this.attr('href') + '&ajax_request=1', function (data) { + $.get($this.attr('href') + '&ajax_request=1&ajax_dialog=1', function (data) { if (data.success === true) { PMA_ajaxRemoveMessage($msg); var buttonOptions = {}; @@ -3729,11 +3729,10 @@ function PMA_createViewDialog($this) }; var $dialog = $('
').attr('id', 'createViewDialog').append(data.message).dialog({ width: 500, - minWidth: 300, - maxWidth: 620, + minWidth: 400, modal: true, buttons: buttonOptions, - title: PMA_messages.strCreateView, + title: $this.is('.create_view') ? PMA_messages.strCreateView : PMA_messages.strEditView, close: function () { $(this).remove(); } diff --git a/js/messages.php b/js/messages.php index 445901bdd4..3df253a468 100644 --- a/js/messages.php +++ b/js/messages.php @@ -377,7 +377,7 @@ $js_messages['strLatestAvailable'] = __(', latest stable version:'); $js_messages['strUpToDate'] = __('up to date'); $js_messages['strCreateView'] = __('Create view'); - +$js_messages['strEditView'] = __('Edit view'); echo "var PMA_messages = new Array();\n"; foreach ($js_messages as $name => $js_message) { diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 8bec377eee..035be91303 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1449,19 +1449,36 @@ function PMA_getHtmlDivForMoveColumnsDialog() */ function PMA_getHtmlForEditView($url_params) { - $create_view = $GLOBALS['dbi']->getDefinition( - $GLOBALS['db'], 'VIEW', $GLOBALS['table'] + $retval = array(); + $query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`" + . " FROM `INFORMATION_SCHEMA`.`VIEWS`" + . " WHERE TABLE_SCHEMA='" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'" + . " AND TABLE_NAME='" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "';"; + $item = $GLOBALS['dbi']->fetchSingleRow($query); + + $view = array( + 'operation' => 'alter', + 'name' => $GLOBALS['table'], + 'as' => $item['VIEW_DEFINITION'], + 'with' => $item['CHECK_OPTION'], + ); + $url = 'view_create.php' . PMA_generate_common_url($url_params) . '&'; + $url .= implode( + '&', + array_map( + function($key, $val) { + return 'view[' . urlencode($key) . ']=' . urlencode($val); + }, + array_keys($view), + $view + ) ); - $create_view = preg_replace('@^CREATE@', 'ALTER', $create_view); $html_output = PMA_Util::linkOrButton( - 'tbl_sql.php' . PMA_generate_common_url( - $url_params + - array( - 'sql_query' => $create_view, - 'show_query' => '1', - ) - ), - PMA_Util::getIcon('b_edit.png', __('Edit view'), true) + $url, + PMA_Util::getIcon('b_edit.png', __('Edit view'), true), + array( + 'class' => 'alter_view ajax' + ) ); return $html_output; } @@ -1722,10 +1739,10 @@ function getHtmlForRowStatsTable($showtable, $tbl_collation, && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0 ) { - list($avg_row_length_value, $avg_row_length_unit) + list($avg_row_length_value, $avg_row_length_unit) = PMA_Util::formatByteDown( $showtable['Avg_row_length'], - 6, + 6, 1 ); $html_output .= PMA_getHtmlForRowStatsTableRow( diff --git a/view_create.php b/view_create.php index a79a190791..d46c5c328c 100644 --- a/view_create.php +++ b/view_create.php @@ -27,20 +27,23 @@ $view_algorithm_options = array( ); $view_with_options = array( - 'CASCADED CHECK OPTION', - 'LOCAL CHECK OPTION' + 'CASCADED', + 'LOCAL' ); -if (isset($_REQUEST['createview'])) { +if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { /** * Creates the view */ $sep = "\r\n"; - $sql_query = 'CREATE'; - - if (isset($_REQUEST['view']['or_replace'])) { - $sql_query .= ' OR REPLACE'; + if (isset($_REQUEST['createview'])) { + $sql_query = 'CREATE'; + if (isset($_REQUEST['view']['or_replace'])) { + $sql_query .= ' OR REPLACE'; + } + } else { + $sql_query = 'ALTER'; } if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) { @@ -90,7 +93,7 @@ if (isset($_REQUEST['createview'])) { } unset($pma_tranformation_data); - if ($GLOBALS['is_ajax_request'] != true) { + if (! isset($_REQUEST['ajax_dialog'])) { $message = PMA_Message::success(); include './' . $cfg['DefaultTabDatabase']; } else { @@ -106,7 +109,7 @@ if (isset($_REQUEST['createview'])) { exit; } else { - if ($GLOBALS['is_ajax_request'] != true) { + if (! isset($_REQUEST['ajax_dialog'])) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } else { $response = PMA_Response::getInstance(); @@ -125,12 +128,13 @@ if (isset($_REQUEST['createview'])) { // prefill values if not already filled from former submission $view = array( + 'operation' => 'create', 'or_replace' => '', 'algorithm' => '', 'name' => '', 'column_names' => '', 'as' => $sql_query, - 'with' => array(), + 'with' => '', ); if (PMA_isValid($_REQUEST['view'], 'array')) { @@ -148,17 +152,23 @@ $htmlString = '' . '
' . PMA_generate_common_hidden_inputs($url_params) . '
' - . '' . __('Details') . '' - . '' - . '' - . '' - . ''; + $htmlString .= ' value="1" />'; } $htmlString .= '' . '' . '' - . '' - . '' - . '' - . '' - . '' + . ''; + +$htmlString .= '' + . ''; + +$htmlString .= '' . '' - . '' - . '' + . ''; + +$htmlString .= '' + . ''; + +$htmlString .= '' + . ''; + +$htmlString .= '' . '' - . '' - . '' - . ''; -$htmlString .= '' + . ''; -$htmlString .= '' - . '' - . '
' + . (isset($_REQUEST['ajax_dialog']) ? __('Details') : ($view['operation'] == 'create' ? __('Create view') : __('Edit view'))) + . '' + . ''; + +if ($view['operation'] == 'create') { + $htmlString .= '' + . '' + . '' - . '' - . '' + +$htmlString .= '' . '' . '' . '' - . '' + . '' . '' . '
'; } -$htmlString .= ' value="1" />' - . '
WITH
WITH CHECK OPTION'; $htmlString .= '
' . ''; -if ($GLOBALS['is_ajax_request'] != true) { +if (! isset($_REQUEST['ajax_dialog'])) { $htmlString .= '
' - . '' + . '' . '
'; } else { - $htmlString .= '' - . ''; + $htmlString .= '' + . ''; } $htmlString .= '' From 18dfc07367cb22d6ff4486c3044d139e9e1131b5 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 11 Jul 2013 15:20:59 +0530 Subject: [PATCH 04/30] Add definer field --- libraries/structure.lib.php | 3 ++- view_create.php | 43 ++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 035be91303..d11e02e492 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1450,7 +1450,7 @@ function PMA_getHtmlDivForMoveColumnsDialog() function PMA_getHtmlForEditView($url_params) { $retval = array(); - $query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`" + $query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`" . " FROM `INFORMATION_SCHEMA`.`VIEWS`" . " WHERE TABLE_SCHEMA='" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'" . " AND TABLE_NAME='" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "';"; @@ -1458,6 +1458,7 @@ function PMA_getHtmlForEditView($url_params) $view = array( 'operation' => 'alter', + 'definer' => $item['DEFINER'], 'name' => $GLOBALS['table'], 'as' => $item['VIEW_DEFINITION'], 'with' => $item['CHECK_OPTION'], diff --git a/view_create.php b/view_create.php index d46c5c328c..10a537707c 100644 --- a/view_create.php +++ b/view_create.php @@ -50,6 +50,10 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm']; } + if (! empty($_REQUEST['view']['definer'])) { + $sql_query .= $sep . ' DEFINER ' . $_REQUEST['view']['definer']; + } + $sql_query .= $sep . ' VIEW ' . PMA_Util::backquote($_REQUEST['view']['name']); if (! empty($_REQUEST['view']['column_names'])) { @@ -131,6 +135,7 @@ $view = array( 'operation' => 'create', 'or_replace' => '', 'algorithm' => '', + 'definer' => '', 'name' => '', 'column_names' => '', 'as' => $sql_query, @@ -164,14 +169,12 @@ if ($view['operation'] == 'create') { if ($view['or_replace']) { $htmlString .= ' checked="checked"'; } - $htmlString .= ' value="1" />
' - . '
' . __('VIEW name') . '' - . '
' . __('Column names') . '
' . __('Definer') . '' + . '
' . __('Column names') . '' - . '
AS
' . __('VIEW name') . '' + . '
' . __('Column names') . '' + . '
AS' . '' - . '
WITH CHECK OPTION'; + . '
WITH CHECK OPTION'; +$htmlString .= '
' +$htmlString .= '' . '
'; if (! isset($_REQUEST['ajax_dialog'])) { From 7e2efa97b4bb361189c75e385f2eb68701fef12d Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 11 Jul 2013 18:02:59 +0530 Subject: [PATCH 06/30] Do line wrapping for Codemirror editor --- js/functions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/functions.js b/js/functions.js index 39e9e6e944..f2923cd1b7 100644 --- a/js/functions.js +++ b/js/functions.js @@ -3740,7 +3740,7 @@ function PMA_createViewDialog($this) // Attach syntax highlited editor if (typeof CodeMirror !== 'undefined') { var $elm = $dialog.find('textarea'); - var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql"}; + var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql", lineWrapping: true}; syntaxHighlighter = CodeMirror.fromTextArea($elm[0], opts); } $('input:visible[type=text]', $dialog).first().focus(); From 846ead2f909dcbd7399c05d53131483ba3376d09 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 11 Jul 2013 18:35:09 +0530 Subject: [PATCH 07/30] Fix typos --- view_create.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/view_create.php b/view_create.php index 4c60ec2c91..88c453a5ef 100644 --- a/view_create.php +++ b/view_create.php @@ -56,7 +56,7 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { } if (! empty($_REQUEST['view']['definer'])) { - $sql_query .= $sep . ' DEFINER ' . $_REQUEST['view']['definer']; + $sql_query .= $sep . ' DEFINER = ' . $_REQUEST['view']['definer']; } if (isset($_REQUEST['view']['sql_security'])) { @@ -119,6 +119,7 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { PMA_Message::success(), $sql_query ) ); + $response->isSuccess(true); } exit; @@ -203,7 +204,7 @@ $htmlString .= '' . __('Definer') . '' . ''; $htmlString .= 'SQL SECURITY' - . '' . ''; foreach ($view_sql_security_options as $option) { $htmlString .= '