Merge branch 'QA_4_9' into QA_5_0
[phpmyadmin.git] / view_operations.php
blob2933652304a20a61bef0519446c6ca37c812e88e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * View manipulations
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\DatabaseInterface;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Operations;
13 use PhpMyAdmin\Relation;
14 use PhpMyAdmin\Response;
15 use PhpMyAdmin\Table;
16 use PhpMyAdmin\Template;
17 use PhpMyAdmin\Util;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
23 global $sql_query, $url_query;
25 require_once ROOT_PATH . 'libraries/common.inc.php';
27 /** @var Response $response */
28 $response = $containerBuilder->get(Response::class);
30 /** @var DatabaseInterface $dbi */
31 $dbi = $containerBuilder->get(DatabaseInterface::class);
33 $pma_table = new Table($GLOBALS['table'], $GLOBALS['db']);
35 $header = $response->getHeader();
36 $scripts = $header->getScripts();
37 $scripts->addFile('table/operations.js');
39 /** @var Template $template */
40 $template = $containerBuilder->get('template');
42 /**
43 * Runs common work
45 require ROOT_PATH . 'libraries/tbl_common.inc.php';
46 $url_query .= '&amp;goto=view_operations.php&amp;back=view_operations.php';
47 $url_params['goto'] = $url_params['back'] = 'view_operations.php';
49 /** @var Relation $relation */
50 $relation = $containerBuilder->get('relation');
51 $operations = new Operations($dbi, $relation);
53 /**
54 * Updates if required
56 $_message = new Message();
57 $_type = 'success';
58 if (isset($_POST['submitoptions'])) {
59 if (isset($_POST['new_name'])) {
60 if ($pma_table->rename($_POST['new_name'])) {
61 $_message->addText($pma_table->getLastMessage());
62 $result = true;
63 $GLOBALS['table'] = $pma_table->getName();
64 /* Force reread after rename */
65 $pma_table->getStatusInfo(null, true);
66 $reload = true;
67 } else {
68 $_message->addText($pma_table->getLastError());
69 $result = false;
73 $warning_messages = $operations->getWarningMessagesArray();
76 if (isset($result)) {
77 // set to success by default, because result set could be empty
78 // (for example, a table rename)
79 if (empty($_message->getString())) {
80 if ($result) {
81 $_message->addText(
82 __('Your SQL query has been executed successfully.')
84 } else {
85 $_message->addText(__('Error'));
87 // $result should exist, regardless of $_message
88 $_type = $result ? 'success' : 'error';
90 if (! empty($warning_messages)) {
91 $_message->addMessagesString($warning_messages);
92 $_message->isError(true);
93 unset($warning_messages);
95 echo Util::getMessage(
96 $_message,
97 $sql_query,
98 $_type
101 unset($_message, $_type);
103 $url_params['goto'] = 'view_operations.php';
104 $url_params['back'] = 'view_operations.php';
106 $drop_view_url_params = array_merge(
107 $url_params,
109 'sql_query' => 'DROP VIEW ' . Util::backquote($GLOBALS['table']),
110 'goto' => 'tbl_structure.php',
111 'reload' => '1',
112 'purge' => '1',
113 'message_to_show' => sprintf(
114 __('View %s has been dropped.'),
115 $GLOBALS['table']
117 'table' => $GLOBALS['table'],
121 echo $template->render('table/operations/view', [
122 'db' => $GLOBALS['db'],
123 'table' => $GLOBALS['table'],
124 'delete_data_or_table_link' => $operations->getDeleteDataOrTablelink(
125 $drop_view_url_params,
126 'DROP VIEW',
127 __('Delete the view (DROP)'),
128 'drop_view_anchor'