Remove the Rte\Export class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
44d1600ce2
commit
fdfc246040
@ -27,9 +27,6 @@ use const ENT_QUOTES;
|
||||
*/
|
||||
class Events
|
||||
{
|
||||
/** @var Export */
|
||||
private $export;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
@ -42,7 +39,6 @@ class Events
|
||||
public function __construct(DatabaseInterface $dbi)
|
||||
{
|
||||
$this->dbi = $dbi;
|
||||
$this->export = new Export($this->dbi);
|
||||
$this->template = new Template();
|
||||
}
|
||||
|
||||
@ -104,7 +100,7 @@ class Events
|
||||
* Process all requests
|
||||
*/
|
||||
$this->handleEditor();
|
||||
$this->export->events();
|
||||
$this->export();
|
||||
|
||||
$items = $this->dbi->getEvents($db);
|
||||
$response = Response::getInstance();
|
||||
@ -797,4 +793,58 @@ class Events
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function export(): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (empty($_GET['export_item']) || empty($_GET['item_name'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$itemName = $_GET['item_name'];
|
||||
$exportData = $this->dbi->getDefinition($db, 'EVENT', $itemName);
|
||||
|
||||
if (! $exportData) {
|
||||
$exportData = false;
|
||||
}
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
$itemName = htmlspecialchars(Util::backquote($_GET['item_name']));
|
||||
if ($exportData !== false) {
|
||||
$exportData = htmlspecialchars(trim($exportData));
|
||||
$title = sprintf(__('Export of event %s'), $itemName);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->addJSON('message', $exportData);
|
||||
$response->addJSON('title', $title);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$exportData = '<textarea cols="40" rows="15" style="width: 100%;">'
|
||||
. $exportData . '</textarea>';
|
||||
echo "<fieldset>\n" . '<legend>' . $title . "</legend>\n"
|
||||
. $exportData . "</fieldset>\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
__('Error in processing request: No event with name %1$s found in database %2$s.'),
|
||||
$itemName,
|
||||
htmlspecialchars(Util::backquote($db))
|
||||
);
|
||||
$message = Message::error($message);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('message', $message);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$message->display();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,178 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Common functions for the export functionality for Routines, Triggers and Events.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Rte;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Util;
|
||||
use function htmlspecialchars;
|
||||
use function sprintf;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Rte\Export class
|
||||
*/
|
||||
class Export
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param DatabaseInterface $dbi DatabaseInterface object
|
||||
*/
|
||||
public function __construct(DatabaseInterface $dbi)
|
||||
{
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called from one of the other functions in this file
|
||||
* and it completes the handling of the export functionality.
|
||||
*
|
||||
* @param string|false $export_data The SQL query to create the requested item
|
||||
* @param string $type RTE type (routine|trigger|event).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function handle($export_data, string $type): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
$exportMessage = '';
|
||||
$noViewMessage = '';
|
||||
if ($type === 'routine') {
|
||||
$exportMessage = __('Export of routine %s');
|
||||
$noViewMessage = __(
|
||||
'No routine with name %1$s found in database %2$s. '
|
||||
. 'You might be lacking the necessary privileges to view/export this routine.'
|
||||
);
|
||||
} elseif ($type === 'event') {
|
||||
$exportMessage = __('Export of event %s');
|
||||
} elseif ($type === 'trigger') {
|
||||
$exportMessage = __('Export of trigger %s');
|
||||
}
|
||||
|
||||
$item_name = htmlspecialchars(Util::backquote($_GET['item_name']));
|
||||
if ($export_data !== false) {
|
||||
$export_data = htmlspecialchars(trim($export_data));
|
||||
$title = sprintf($exportMessage, $item_name);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->addJSON('message', $export_data);
|
||||
$response->addJSON('title', $title);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$export_data = '<textarea cols="40" rows="15" style="width: 100%;">'
|
||||
. $export_data . '</textarea>';
|
||||
echo "<fieldset>\n"
|
||||
, '<legend>' . $title . "</legend>\n"
|
||||
, $export_data
|
||||
, "</fieldset>\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$_db = htmlspecialchars(Util::backquote($db));
|
||||
$message = __('Error in processing request:') . ' '
|
||||
. sprintf($noViewMessage, $item_name, $_db);
|
||||
$message = Message::error($message);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('message', $message);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$message->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary, prepares event information and passes
|
||||
* it to handle() for the actual export.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function events(): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (empty($_GET['export_item']) || empty($_GET['item_name'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item_name = $_GET['item_name'];
|
||||
$export_data = $this->dbi->getDefinition($db, 'EVENT', $item_name);
|
||||
|
||||
if (! $export_data) {
|
||||
$export_data = false;
|
||||
}
|
||||
|
||||
$this->handle($export_data, 'event');
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary, prepares routine information and passes
|
||||
* it to handle() for the actual export.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function routines(): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (empty($_GET['export_item']) || empty($_GET['item_name']) || empty($_GET['item_type'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($_GET['item_type'] !== 'FUNCTION' && $_GET['item_type'] !== 'PROCEDURE') {
|
||||
return;
|
||||
}
|
||||
|
||||
$rtn_definition = $this->dbi->getDefinition($db, $_GET['item_type'], $_GET['item_name']);
|
||||
$export_data = false;
|
||||
|
||||
if ($rtn_definition !== null) {
|
||||
$export_data = "DELIMITER $$\n" . $rtn_definition . "$$\nDELIMITER ;\n";
|
||||
}
|
||||
|
||||
$this->handle($export_data, 'routine');
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary, prepares trigger information and passes
|
||||
* it to handle() for the actual export.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function triggers(): void
|
||||
{
|
||||
global $db, $table;
|
||||
|
||||
if (empty($_GET['export_item']) || empty($_GET['item_name'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item_name = $_GET['item_name'];
|
||||
$triggers = $this->dbi->getTriggers($db, $table, '');
|
||||
$export_data = false;
|
||||
|
||||
foreach ($triggers as $trigger) {
|
||||
if ($trigger['name'] === $item_name) {
|
||||
$export_data = $trigger['create'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->handle($export_data, 'trigger');
|
||||
}
|
||||
}
|
||||
@ -44,9 +44,6 @@ use const ENT_QUOTES;
|
||||
*/
|
||||
class Routines
|
||||
{
|
||||
/** @var Export */
|
||||
private $export;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
@ -59,7 +56,6 @@ class Routines
|
||||
public function __construct(DatabaseInterface $dbi)
|
||||
{
|
||||
$this->dbi = $dbi;
|
||||
$this->export = new Export($this->dbi);
|
||||
$this->template = new Template();
|
||||
}
|
||||
|
||||
@ -109,7 +105,7 @@ class Routines
|
||||
*/
|
||||
$this->handleEditor();
|
||||
$this->handleExecute();
|
||||
$this->export->routines();
|
||||
$this->export();
|
||||
/**
|
||||
* Display a list of available routines
|
||||
*/
|
||||
@ -1863,4 +1859,65 @@ class Routines
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
private function export(): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (empty($_GET['export_item']) || empty($_GET['item_name']) || empty($_GET['item_type'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($_GET['item_type'] !== 'FUNCTION' && $_GET['item_type'] !== 'PROCEDURE') {
|
||||
return;
|
||||
}
|
||||
|
||||
$routineDefinition = $this->dbi->getDefinition($db, $_GET['item_type'], $_GET['item_name']);
|
||||
$exportData = false;
|
||||
|
||||
if ($routineDefinition !== null) {
|
||||
$exportData = "DELIMITER $$\n" . $routineDefinition . "$$\nDELIMITER ;\n";
|
||||
}
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
$itemName = htmlspecialchars(Util::backquote($_GET['item_name']));
|
||||
if ($exportData !== false) {
|
||||
$exportData = htmlspecialchars(trim($exportData));
|
||||
$title = sprintf(__('Export of routine %s'), $itemName);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->addJSON('message', $exportData);
|
||||
$response->addJSON('title', $title);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$exportData = '<textarea cols="40" rows="15" style="width: 100%;">'
|
||||
. $exportData . '</textarea>';
|
||||
echo "<fieldset>\n" . '<legend>' . $title . "</legend>\n"
|
||||
. $exportData . "</fieldset>\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
__(
|
||||
'Error in processing request: No routine with name %1$s found in database %2$s.'
|
||||
. ' You might be lacking the necessary privileges to view/export this routine.'
|
||||
),
|
||||
$itemName,
|
||||
htmlspecialchars(Util::backquote($db))
|
||||
);
|
||||
$message = Message::error($message);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('message', $message);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$message->display();
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,9 +26,6 @@ use const ENT_QUOTES;
|
||||
*/
|
||||
class Triggers
|
||||
{
|
||||
/** @var Export */
|
||||
private $export;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
@ -41,7 +38,6 @@ class Triggers
|
||||
public function __construct(DatabaseInterface $dbi)
|
||||
{
|
||||
$this->dbi = $dbi;
|
||||
$this->export = new Export($this->dbi);
|
||||
$this->template = new Template();
|
||||
}
|
||||
|
||||
@ -80,7 +76,7 @@ class Triggers
|
||||
* Process all requests
|
||||
*/
|
||||
$this->handleEditor();
|
||||
$this->export->triggers();
|
||||
$this->export();
|
||||
|
||||
$items = $this->dbi->getTriggers($db, $table);
|
||||
$response = Response::getInstance();
|
||||
@ -597,4 +593,62 @@ class Triggers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function export(): void
|
||||
{
|
||||
global $db, $table;
|
||||
|
||||
if (empty($_GET['export_item']) || empty($_GET['item_name'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$itemName = $_GET['item_name'];
|
||||
$triggers = $this->dbi->getTriggers($db, $table, '');
|
||||
$exportData = false;
|
||||
|
||||
foreach ($triggers as $trigger) {
|
||||
if ($trigger['name'] === $itemName) {
|
||||
$exportData = $trigger['create'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
$itemName = htmlspecialchars(Util::backquote($_GET['item_name']));
|
||||
if ($exportData !== false) {
|
||||
$exportData = htmlspecialchars(trim($exportData));
|
||||
$title = sprintf(__('Export of trigger %s'), $itemName);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->addJSON('message', $exportData);
|
||||
$response->addJSON('title', $title);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$exportData = '<textarea cols="40" rows="15" style="width: 100%;">'
|
||||
. $exportData . '</textarea>';
|
||||
echo "<fieldset>\n" . '<legend>' . $title . "</legend>\n"
|
||||
. $exportData . "</fieldset>\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
__('Error in processing request: No trigger with name %1$s found in database %2$s.'),
|
||||
$itemName,
|
||||
htmlspecialchars(Util::backquote($db))
|
||||
);
|
||||
$message = Message::error($message);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('message', $message);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$message->display();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user