Skip to content

Commit

Permalink
Extract HTML from Sql::getQueryResponseForNoResultsReturned
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Aug 20, 2020
1 parent 55c5c80 commit f6215b6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 70 deletions.
151 changes: 81 additions & 70 deletions libraries/classes/Sql.php
Expand Up @@ -1255,6 +1255,7 @@ private function getQueryResponseForNoResultsReturned(
?string $complete_query
) {
global $url_query;

if ($this->isDeleteTransformationInfo($analyzed_sql_results)) {
$this->deleteTransformationInfo($db, $table, $analyzed_sql_results);
}
Expand All @@ -1269,89 +1270,99 @@ private function getQueryResponseForNoResultsReturned(
);
}

$html_output = '';
$html_message = Generator::getMessage(
$queryMessage = Generator::getMessage(
$message,
$GLOBALS['sql_query'],
'success'
);
$html_output .= $html_message;
if (! isset($GLOBALS['show_as_php'])) {
if (! empty($GLOBALS['reload'])) {
$extra_data['reload'] = 1;
$extra_data['db'] = $GLOBALS['db'];
}

// For ajax requests add message and sql_query as JSON
if (empty($_REQUEST['ajax_page_request'])) {
$extra_data['message'] = $message;
if ($GLOBALS['cfg']['ShowSQL']) {
$extra_data['sql_query'] = $html_message;
}
if (isset($GLOBALS['show_as_php'])) {
return $queryMessage;
}

if (! empty($GLOBALS['reload'])) {
$extra_data['reload'] = 1;
$extra_data['db'] = $GLOBALS['db'];
}

// For ajax requests add message and sql_query as JSON
if (empty($_REQUEST['ajax_page_request'])) {
$extra_data['message'] = $message;
if ($GLOBALS['cfg']['ShowSQL']) {
$extra_data['sql_query'] = $queryMessage;
}
}

$response = Response::getInstance();
$response->addJSON($extra_data ?? []);

if (! empty($analyzed_sql_results['is_select']) &&
! isset($extra_data['error'])) {
$url_query = $url_query ?? null;

$displayParts = [
'edit_lnk' => null,
'del_lnk' => null,
'sort_lnk' => '1',
'nav_bar' => '0',
'bkm_form' => '1',
'text_btn' => '1',
'pview_lnk' => '1',
];
$response = Response::getInstance();
$response->addJSON($extra_data ?? []);

$html_output .= $this->getHtmlForSqlQueryResultsTable(
$displayResultsObject,
$pmaThemeImage,
$url_query,
$displayParts,
false,
0,
$num_rows,
true,
$result,
$analyzed_sql_results,
true
);
if (empty($analyzed_sql_results['is_select']) || isset($extra_data['error'])) {
return $queryMessage;
}

if ($profiling_results !== null) {
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('sql.js');
$html_output .= $this->getHtmlForProfilingChart(
$url_query,
$db,
$profiling_results
);
}
$url_query = $url_query ?? null;

$html_output .= $displayResultsObject->getCreateViewQueryResultOp(
$analyzed_sql_results
);
$displayParts = [
'edit_lnk' => null,
'del_lnk' => null,
'sort_lnk' => '1',
'nav_bar' => '0',
'bkm_form' => '1',
'text_btn' => '1',
'pview_lnk' => '1',
];

$cfgBookmark = Bookmark::getParams($GLOBALS['cfg']['Server']['user']);
if (is_array($cfgBookmark)) {
$html_output .= $this->getHtmlForBookmark(
$displayParts,
$cfgBookmark,
$sql_query,
$db,
$table,
$complete_query ?? $sql_query,
$cfgBookmark['user']
);
}
}
$sqlQueryResultsTable = $this->getHtmlForSqlQueryResultsTable(
$displayResultsObject,
$pmaThemeImage,
$url_query,
$displayParts,
false,
0,
$num_rows,
true,
$result,
$analyzed_sql_results,
true
);

$profilingChart = '';
if ($profiling_results !== null) {
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('sql.js');
$profilingChart = $this->getHtmlForProfilingChart(
$url_query,
$db,
$profiling_results
);
}

return $html_output;
$queryResultsOperations = $displayResultsObject->getCreateViewQueryResultOp(
$analyzed_sql_results
);

$bookmark = '';
$cfgBookmark = Bookmark::getParams($GLOBALS['cfg']['Server']['user']);
if (is_array($cfgBookmark)) {
$bookmark = $this->getHtmlForBookmark(
$displayParts,
$cfgBookmark,
$sql_query,
$db,
$table,
$complete_query ?? $sql_query,
$cfgBookmark['user']
);
}

return $this->template->render('sql/no_results_returned', [
'message' => $queryMessage,
'sql_query_results_table' => $sqlQueryResultsTable,
'profiling_chart' => $profilingChart,
'query_results_operations' => $queryResultsOperations,
'bookmark' => $bookmark,
]);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions templates/sql/no_results_returned.twig
@@ -0,0 +1,9 @@
{{ message|raw }}

{{ sql_query_results_table|raw }}

{{ profiling_chart|raw }}

{{ query_results_operations|raw }}

{{ bookmark|raw }}

0 comments on commit f6215b6

Please sign in to comment.