Update website
This commit is contained in:
parent
a0b0d3dae7
commit
ae7ef6ad45
3151 changed files with 566766 additions and 48 deletions
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Controllers\AbstractController as Controller;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
|
||||
abstract class AbstractController extends Controller
|
||||
{
|
||||
/** @var string */
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
*/
|
||||
public function __construct($response, Template $template, $db)
|
||||
{
|
||||
parent::__construct($response, $template);
|
||||
$this->db = $db;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/**
|
||||
* Central Columns view/edit
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Database\CentralColumns;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use function is_bool;
|
||||
use function parse_str;
|
||||
use function sprintf;
|
||||
|
||||
class CentralColumnsController extends AbstractController
|
||||
{
|
||||
/** @var CentralColumns */
|
||||
private $centralColumns;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
* @param CentralColumns $centralColumns
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $centralColumns)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->centralColumns = $centralColumns;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $cfg, $db, $message, $pos, $num_cols;
|
||||
|
||||
if (isset($_POST['edit_save'])) {
|
||||
echo $this->editSave([
|
||||
'col_name' => $_POST['col_name'] ?? null,
|
||||
'orig_col_name' => $_POST['orig_col_name'] ?? null,
|
||||
'col_default' => $_POST['col_default'] ?? null,
|
||||
'col_default_sel' => $_POST['col_default_sel'] ?? null,
|
||||
'col_extra' => $_POST['col_extra'] ?? null,
|
||||
'col_isNull' => $_POST['col_isNull'] ?? null,
|
||||
'col_length' => $_POST['col_length'] ?? null,
|
||||
'col_attribute' => $_POST['col_attribute'] ?? null,
|
||||
'col_type' => $_POST['col_type'] ?? null,
|
||||
'collation' => $_POST['collation'] ?? null,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($_POST['add_new_column'])) {
|
||||
$tmp_msg = $this->addNewColumn([
|
||||
'col_name' => $_POST['col_name'] ?? null,
|
||||
'col_default' => $_POST['col_default'] ?? null,
|
||||
'col_default_sel' => $_POST['col_default_sel'] ?? null,
|
||||
'col_extra' => $_POST['col_extra'] ?? null,
|
||||
'col_isNull' => $_POST['col_isNull'] ?? null,
|
||||
'col_length' => $_POST['col_length'] ?? null,
|
||||
'col_attribute' => $_POST['col_attribute'] ?? null,
|
||||
'col_type' => $_POST['col_type'] ?? null,
|
||||
'collation' => $_POST['collation'] ?? null,
|
||||
]);
|
||||
}
|
||||
if (isset($_POST['getColumnList'])) {
|
||||
$this->response->addJSON('message', $this->getColumnList([
|
||||
'cur_table' => $_POST['cur_table'] ?? null,
|
||||
]));
|
||||
|
||||
return;
|
||||
}
|
||||
if (isset($_POST['add_column'])) {
|
||||
$tmp_msg = $this->addColumn([
|
||||
'table-select' => $_POST['table-select'] ?? null,
|
||||
'column-select' => $_POST['column-select'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->addScriptFiles([
|
||||
'vendor/jquery/jquery.uitablefilter.js',
|
||||
'vendor/jquery/jquery.tablesorter.js',
|
||||
'database/central_columns.js',
|
||||
]);
|
||||
|
||||
if (isset($_POST['edit_central_columns_page'])) {
|
||||
$this->editPage([
|
||||
'selected_fld' => $_POST['selected_fld'] ?? null,
|
||||
'db' => $_POST['db'] ?? null,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
if (isset($_POST['multi_edit_central_column_save'])) {
|
||||
$message = $this->updateMultipleColumn([
|
||||
'db' => $_POST['db'] ?? null,
|
||||
'orig_col_name' => $_POST['orig_col_name'] ?? null,
|
||||
'field_name' => $_POST['field_name'] ?? null,
|
||||
'field_default_type' => $_POST['field_default_type'] ?? null,
|
||||
'field_default_value' => $_POST['field_default_value'] ?? null,
|
||||
'field_length' => $_POST['field_length'] ?? null,
|
||||
'field_attribute' => $_POST['field_attribute'] ?? null,
|
||||
'field_type' => $_POST['field_type'] ?? null,
|
||||
'field_collation' => $_POST['field_collation'] ?? null,
|
||||
'field_null' => $_POST['field_null'] ?? null,
|
||||
'col_extra' => $_POST['col_extra'] ?? null,
|
||||
]);
|
||||
if (! is_bool($message)) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', $message);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['delete_save'])) {
|
||||
$tmp_msg = $this->deleteSave([
|
||||
'db' => $_POST['db'] ?? null,
|
||||
'col_name' => $_POST['col_name'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->main([
|
||||
'pos' => $_POST['pos'] ?? null,
|
||||
'total_rows' => $_POST['total_rows'] ?? null,
|
||||
]);
|
||||
|
||||
$pos = 0;
|
||||
if (Core::isValid($_POST['pos'], 'integer')) {
|
||||
$pos = (int) $_POST['pos'];
|
||||
}
|
||||
$num_cols = $this->centralColumns->getColumnsCount(
|
||||
$db,
|
||||
$pos,
|
||||
(int) $cfg['MaxRows']
|
||||
);
|
||||
$message = Message::success(
|
||||
sprintf(__('Showing rows %1$s - %2$s.'), $pos + 1, $pos + $num_cols)
|
||||
);
|
||||
if (! isset($tmp_msg) || $tmp_msg === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = $tmp_msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function main(array $params): void
|
||||
{
|
||||
global $text_dir, $PMA_Theme;
|
||||
|
||||
if (! empty($params['total_rows'])
|
||||
&& Core::isValid($params['total_rows'], 'integer')
|
||||
) {
|
||||
$totalRows = (int) $params['total_rows'];
|
||||
} else {
|
||||
$totalRows = $this->centralColumns->getCount($this->db);
|
||||
}
|
||||
|
||||
$pos = 0;
|
||||
if (Core::isValid($params['pos'], 'integer')) {
|
||||
$pos = (int) $params['pos'];
|
||||
}
|
||||
|
||||
$variables = $this->centralColumns->getTemplateVariablesForMain(
|
||||
$this->db,
|
||||
$totalRows,
|
||||
$pos,
|
||||
$PMA_Theme->getImgPath(),
|
||||
$text_dir
|
||||
);
|
||||
|
||||
$this->render('database/central_columns/main', $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @return array JSON
|
||||
*/
|
||||
public function getColumnList(array $params): array
|
||||
{
|
||||
return $this->centralColumns->getListRaw(
|
||||
$this->db,
|
||||
$params['cur_table'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
public function populateColumns(): void
|
||||
{
|
||||
$columns = $this->centralColumns->getColumnsNotInCentralList($this->db, $_POST['selectedTable']);
|
||||
$this->render('database/central_columns/populate_columns', ['columns' => $columns]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function editSave(array $params)
|
||||
{
|
||||
$columnDefault = $params['col_default'];
|
||||
if ($columnDefault === 'NONE' && $params['col_default_sel'] !== 'USER_DEFINED') {
|
||||
$columnDefault = '';
|
||||
}
|
||||
|
||||
return $this->centralColumns->updateOneColumn(
|
||||
$this->db,
|
||||
$params['orig_col_name'],
|
||||
$params['col_name'],
|
||||
$params['col_type'],
|
||||
$params['col_attribute'],
|
||||
$params['col_length'],
|
||||
isset($params['col_isNull']) ? 1 : 0,
|
||||
$params['collation'],
|
||||
$params['col_extra'] ?? '',
|
||||
$columnDefault
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function addNewColumn(array $params)
|
||||
{
|
||||
$columnDefault = $params['col_default'];
|
||||
if ($columnDefault === 'NONE' && $params['col_default_sel'] !== 'USER_DEFINED') {
|
||||
$columnDefault = '';
|
||||
}
|
||||
|
||||
return $this->centralColumns->updateOneColumn(
|
||||
$this->db,
|
||||
'',
|
||||
$params['col_name'],
|
||||
$params['col_type'],
|
||||
$params['col_attribute'],
|
||||
$params['col_length'],
|
||||
isset($params['col_isNull']) ? 1 : 0,
|
||||
$params['collation'],
|
||||
$params['col_extra'] ?? '',
|
||||
$columnDefault
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function addColumn(array $params)
|
||||
{
|
||||
return $this->centralColumns->syncUniqueColumns(
|
||||
[$params['column-select']],
|
||||
false,
|
||||
$params['table-select']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function editPage(array $params): void
|
||||
{
|
||||
$rows = $this->centralColumns->getHtmlForEditingPage(
|
||||
$params['selected_fld'],
|
||||
$params['db']
|
||||
);
|
||||
|
||||
$this->render('database/central_columns/edit', ['rows' => $rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function updateMultipleColumn(array $params)
|
||||
{
|
||||
return $this->centralColumns->updateMultipleColumn($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function deleteSave(array $params)
|
||||
{
|
||||
$name = [];
|
||||
parse_str($params['col_name'], $name);
|
||||
|
||||
return $this->centralColumns->deleteColumnsFromList(
|
||||
$params['db'],
|
||||
$name['selected_fld'],
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Index;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Transformations;
|
||||
use PhpMyAdmin\Util;
|
||||
use function is_array;
|
||||
use function str_replace;
|
||||
|
||||
class DataDictionaryController extends AbstractController
|
||||
{
|
||||
/** @var Relation */
|
||||
private $relation;
|
||||
|
||||
/** @var Transformations */
|
||||
private $transformations;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
* @param Relation $relation
|
||||
* @param Transformations $transformations
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $relation, $transformations, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->relation = $relation;
|
||||
$this->transformations = $transformations;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
Util::checkParameters(['db'], true);
|
||||
|
||||
$header = $this->response->getHeader();
|
||||
$header->enablePrintView();
|
||||
|
||||
$cfgRelation = $this->relation->getRelationsParam();
|
||||
|
||||
$comment = $this->relation->getDbComment($this->db);
|
||||
|
||||
$this->dbi->selectDb($this->db);
|
||||
$tablesNames = $this->dbi->getTables($this->db);
|
||||
|
||||
$tables = [];
|
||||
foreach ($tablesNames as $tableName) {
|
||||
$showComment = (string) $this->dbi->getTable(
|
||||
$this->db,
|
||||
$tableName
|
||||
)->getStatusInfo('TABLE_COMMENT');
|
||||
|
||||
[, $primaryKeys] = Util::processIndexData(
|
||||
$this->dbi->getTableIndexes($this->db, $tableName)
|
||||
);
|
||||
|
||||
[$foreigners, $hasRelation] = $this->relation->getRelationsAndStatus(
|
||||
! empty($cfgRelation['relation']),
|
||||
$this->db,
|
||||
$tableName
|
||||
);
|
||||
|
||||
$columnsComments = $this->relation->getComments($this->db, $tableName);
|
||||
|
||||
$columns = $this->dbi->getColumns($this->db, $tableName);
|
||||
$rows = [];
|
||||
foreach ($columns as $row) {
|
||||
$extractedColumnSpec = Util::extractColumnSpec($row['Type']);
|
||||
|
||||
$relation = '';
|
||||
if ($hasRelation) {
|
||||
$foreigner = $this->relation->searchColumnInForeigners(
|
||||
$foreigners,
|
||||
$row['Field']
|
||||
);
|
||||
if (is_array($foreigner) && isset($foreigner['foreign_table'], $foreigner['foreign_field'])) {
|
||||
$relation = $foreigner['foreign_table'];
|
||||
$relation .= ' -> ';
|
||||
$relation .= $foreigner['foreign_field'];
|
||||
}
|
||||
}
|
||||
|
||||
$mime = '';
|
||||
if ($cfgRelation['mimework']) {
|
||||
$mimeMap = $this->transformations->getMime(
|
||||
$this->db,
|
||||
$tableName,
|
||||
true
|
||||
);
|
||||
if (is_array($mimeMap) && isset($mimeMap[$row['Field']]['mimetype'])) {
|
||||
$mime = str_replace(
|
||||
'_',
|
||||
'/',
|
||||
$mimeMap[$row['Field']]['mimetype']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$row['Field']] = [
|
||||
'name' => $row['Field'],
|
||||
'has_primary_key' => isset($primaryKeys[$row['Field']]),
|
||||
'type' => $extractedColumnSpec['type'],
|
||||
'print_type' => $extractedColumnSpec['print_type'],
|
||||
'is_nullable' => $row['Null'] !== '' && $row['Null'] !== 'NO',
|
||||
'default' => $row['Default'] ?? null,
|
||||
'comment' => $columnsComments[$row['Field']] ?? '',
|
||||
'mime' => $mime,
|
||||
'relation' => $relation,
|
||||
];
|
||||
}
|
||||
|
||||
$tables[$tableName] = [
|
||||
'name' => $tableName,
|
||||
'comment' => $showComment,
|
||||
'has_relation' => $hasRelation,
|
||||
'has_mime' => $cfgRelation['mimework'],
|
||||
'columns' => $rows,
|
||||
'indexes' => Index::getFromTable($tableName, $this->db),
|
||||
];
|
||||
}
|
||||
|
||||
$this->render('database/data_dictionary/index', [
|
||||
'database' => $this->db,
|
||||
'comment' => $comment,
|
||||
'tables' => $tables,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Database\Designer;
|
||||
use PhpMyAdmin\Database\Designer\Common as DesignerCommon;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function htmlspecialchars;
|
||||
use function in_array;
|
||||
use function sprintf;
|
||||
|
||||
class DesignerController extends AbstractController
|
||||
{
|
||||
/** @var Designer */
|
||||
private $databaseDesigner;
|
||||
|
||||
/** @var DesignerCommon */
|
||||
private $designerCommon;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
Template $template,
|
||||
$db,
|
||||
Designer $databaseDesigner,
|
||||
DesignerCommon $designerCommon
|
||||
) {
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->databaseDesigner = $databaseDesigner;
|
||||
$this->designerCommon = $designerCommon;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $script_display_field, $tab_column, $tables_all_keys, $tables_pk_or_unique_keys;
|
||||
global $success, $page, $message, $display_page, $selected_page, $tab_pos, $fullTableNames, $script_tables;
|
||||
global $script_contr, $params, $tables, $num_tables, $total_num_tables, $sub_part;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos, $classes_side_menu, $cfg, $err_url;
|
||||
|
||||
if (isset($_POST['dialog'])) {
|
||||
if ($_POST['dialog'] === 'edit') {
|
||||
$html = $this->databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
|
||||
} elseif ($_POST['dialog'] === 'delete') {
|
||||
$html = $this->databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'deletePage');
|
||||
} elseif ($_POST['dialog'] === 'save_as') {
|
||||
$html = $this->databaseDesigner->getHtmlForPageSaveAs($_POST['db']);
|
||||
} elseif ($_POST['dialog'] === 'export') {
|
||||
$html = $this->databaseDesigner->getHtmlForSchemaExport(
|
||||
$_POST['db'],
|
||||
$_POST['selected_page']
|
||||
);
|
||||
} elseif ($_POST['dialog'] === 'add_table') {
|
||||
// Pass the db and table to the getTablesInfo so we only have the table we asked for
|
||||
$script_display_field = $this->designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
|
||||
$tab_column = $this->designerCommon->getColumnsInfo($script_display_field);
|
||||
$tables_all_keys = $this->designerCommon->getAllKeys($script_display_field);
|
||||
$tables_pk_or_unique_keys = $this->designerCommon->getPkOrUniqueKeys($script_display_field);
|
||||
|
||||
$html = $this->databaseDesigner->getDatabaseTables(
|
||||
$_POST['db'],
|
||||
$script_display_field,
|
||||
[],
|
||||
-1,
|
||||
$tab_column,
|
||||
$tables_all_keys,
|
||||
$tables_pk_or_unique_keys
|
||||
);
|
||||
}
|
||||
|
||||
if (! empty($html)) {
|
||||
$this->response->addHTML($html);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($_POST['operation'])) {
|
||||
if ($_POST['operation'] === 'deletePage') {
|
||||
$success = $this->designerCommon->deletePage($_POST['selected_page']);
|
||||
$this->response->setRequestStatus($success);
|
||||
} elseif ($_POST['operation'] === 'savePage') {
|
||||
if ($_POST['save_page'] === 'same') {
|
||||
$page = $_POST['selected_page'];
|
||||
} elseif ($this->designerCommon->getPageExists($_POST['selected_value'])) {
|
||||
$this->response->addJSON(
|
||||
'message',
|
||||
/* l10n: The user tries to save a page with an existing name in Designer */
|
||||
__(
|
||||
sprintf(
|
||||
'There already exists a page named "%s" please rename it to something else.',
|
||||
htmlspecialchars($_POST['selected_value'])
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->response->setRequestStatus(false);
|
||||
|
||||
return;
|
||||
} else {
|
||||
$page = $this->designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
|
||||
$this->response->addJSON('id', $page);
|
||||
}
|
||||
$success = $this->designerCommon->saveTablePositions($page);
|
||||
$this->response->setRequestStatus($success);
|
||||
} elseif ($_POST['operation'] === 'setDisplayField') {
|
||||
[
|
||||
$success,
|
||||
$message,
|
||||
] = $this->designerCommon->saveDisplayField(
|
||||
$_POST['db'],
|
||||
$_POST['table'],
|
||||
$_POST['field']
|
||||
);
|
||||
$this->response->setRequestStatus($success);
|
||||
$this->response->addJSON('message', $message);
|
||||
} elseif ($_POST['operation'] === 'addNewRelation') {
|
||||
[$success, $message] = $this->designerCommon->addNewRelation(
|
||||
$_POST['db'],
|
||||
$_POST['T1'],
|
||||
$_POST['F1'],
|
||||
$_POST['T2'],
|
||||
$_POST['F2'],
|
||||
$_POST['on_delete'],
|
||||
$_POST['on_update'],
|
||||
$_POST['DB1'],
|
||||
$_POST['DB2']
|
||||
);
|
||||
$this->response->setRequestStatus($success);
|
||||
$this->response->addJSON('message', $message);
|
||||
} elseif ($_POST['operation'] === 'removeRelation') {
|
||||
[$success, $message] = $this->designerCommon->removeRelation(
|
||||
$_POST['T1'],
|
||||
$_POST['F1'],
|
||||
$_POST['T2'],
|
||||
$_POST['F2']
|
||||
);
|
||||
$this->response->setRequestStatus($success);
|
||||
$this->response->addJSON('message', $message);
|
||||
} elseif ($_POST['operation'] === 'save_setting_value') {
|
||||
$success = $this->designerCommon->saveSetting($_POST['index'], $_POST['value']);
|
||||
$this->response->setRequestStatus($success);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$script_display_field = $this->designerCommon->getTablesInfo();
|
||||
|
||||
$display_page = -1;
|
||||
$selected_page = null;
|
||||
|
||||
$visualBuilderMode = isset($_GET['query']);
|
||||
|
||||
if ($visualBuilderMode) {
|
||||
$display_page = $this->designerCommon->getDefaultPage($_GET['db']);
|
||||
} elseif (! empty($_GET['page'])) {
|
||||
$display_page = $_GET['page'];
|
||||
} else {
|
||||
$display_page = $this->designerCommon->getLoadingPage($_GET['db']);
|
||||
}
|
||||
if ($display_page != -1) {
|
||||
$selected_page = $this->designerCommon->getPageName($display_page);
|
||||
}
|
||||
$tab_pos = $this->designerCommon->getTablePositions($display_page);
|
||||
|
||||
$fullTableNames = [];
|
||||
|
||||
foreach ($script_display_field as $designerTable) {
|
||||
$fullTableNames[] = $designerTable->getDbTableString();
|
||||
}
|
||||
|
||||
foreach ($tab_pos as $position) {
|
||||
if (in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$designerTables = $this->designerCommon->getTablesInfo($position['dbName'], $position['tableName']);
|
||||
foreach ($designerTables as $designerTable) {
|
||||
$script_display_field[] = $designerTable;
|
||||
}
|
||||
}
|
||||
|
||||
$tab_column = $this->designerCommon->getColumnsInfo($script_display_field);
|
||||
$script_tables = $this->designerCommon->getScriptTabs($script_display_field);
|
||||
$tables_pk_or_unique_keys = $this->designerCommon->getPkOrUniqueKeys($script_display_field);
|
||||
$tables_all_keys = $this->designerCommon->getAllKeys($script_display_field);
|
||||
$classes_side_menu = $this->databaseDesigner->returnClassNamesFromMenuButtons();
|
||||
|
||||
$script_contr = $this->designerCommon->getScriptContr($script_display_field);
|
||||
|
||||
$params = ['lang' => $GLOBALS['lang']];
|
||||
if (isset($_GET['db'])) {
|
||||
$params['db'] = $_GET['db'];
|
||||
}
|
||||
|
||||
$this->response->getFooter()->setMinimal();
|
||||
$header = $this->response->getHeader();
|
||||
$header->setBodyId('designer_body');
|
||||
|
||||
$this->addScriptFiles([
|
||||
'vendor/jquery/jquery.fullscreen.js',
|
||||
'designer/database.js',
|
||||
'designer/objects.js',
|
||||
'designer/page.js',
|
||||
'designer/history.js',
|
||||
'designer/move.js',
|
||||
'designer/init.js',
|
||||
]);
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
|
||||
// Embed some data into HTML, later it will be read
|
||||
// by designer/init.js and converted to JS variables.
|
||||
$this->response->addHTML(
|
||||
$this->databaseDesigner->getHtmlForMain(
|
||||
$db,
|
||||
$_GET['db'],
|
||||
$script_display_field,
|
||||
$script_tables,
|
||||
$script_contr,
|
||||
$script_display_field,
|
||||
$display_page,
|
||||
$visualBuilderMode,
|
||||
$selected_page,
|
||||
$classes_side_menu,
|
||||
$tab_pos,
|
||||
$tab_column,
|
||||
$tables_all_keys,
|
||||
$tables_pk_or_unique_keys
|
||||
)
|
||||
);
|
||||
|
||||
$this->response->addHTML('<div id="PMA_disable_floating_menubar"></div>');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Database\Events;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function strlen;
|
||||
|
||||
final class EventsController extends AbstractController
|
||||
{
|
||||
/** @var Events */
|
||||
private $events;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, Events $events, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->events = $events;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $tables, $num_tables, $total_num_tables, $sub_part, $errors, $text_dir, $PMA_Theme;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos, $cfg, $err_url;
|
||||
|
||||
if (! $this->response->isAjax()) {
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
} elseif (strlen($db) > 0) {
|
||||
$this->dbi->selectDb($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep a list of errors that occurred while
|
||||
* processing an 'Add' or 'Edit' operation.
|
||||
*/
|
||||
$errors = [];
|
||||
|
||||
$this->events->handleEditor();
|
||||
$this->events->export();
|
||||
|
||||
$items = $this->dbi->getEvents($db);
|
||||
|
||||
$this->render('database/events/index', [
|
||||
'db' => $db,
|
||||
'items' => $items,
|
||||
'select_all_arrow_src' => $PMA_Theme->getImgPath() . 'arrow_' . $text_dir . '.png',
|
||||
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $db),
|
||||
'scheduler_state' => $this->events->getEventSchedulerStatus(),
|
||||
'text_dir' => $text_dir,
|
||||
'theme_image_path' => $PMA_Theme->getImgPath(),
|
||||
'is_ajax' => $this->response->isAjax() && empty($_REQUEST['ajax_page_request']),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Config\PageSettings;
|
||||
use PhpMyAdmin\Export;
|
||||
use PhpMyAdmin\Export\Options;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function array_merge;
|
||||
use function is_array;
|
||||
|
||||
final class ExportController extends AbstractController
|
||||
{
|
||||
/** @var Export */
|
||||
private $export;
|
||||
|
||||
/** @var Options */
|
||||
private $exportOptions;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, Export $export, Options $exportOptions)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->export = $export;
|
||||
$this->exportOptions = $exportOptions;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $table, $sub_part, $url_params, $sql_query;
|
||||
global $tables, $num_tables, $total_num_tables, $tooltip_truename;
|
||||
global $tooltip_aliasname, $pos, $table_select, $unlim_num_rows, $cfg, $err_url;
|
||||
|
||||
$pageSettings = new PageSettings('Export');
|
||||
$pageSettingsErrorHtml = $pageSettings->getErrorHTML();
|
||||
$pageSettingsHtml = $pageSettings->getHTML();
|
||||
|
||||
$this->addScriptFiles(['export.js']);
|
||||
|
||||
// $sub_part is used in Util::getDbInfo() to see if we are coming from
|
||||
// /database/export, in which case we don't obey $cfg['MaxTableList']
|
||||
$sub_part = '_export';
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params['goto'] = Url::getFromRoute('/database/export');
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
|
||||
// exit if no tables in db found
|
||||
if ($num_tables < 1) {
|
||||
$this->response->addHTML(
|
||||
Message::error(__('No tables found in database.'))->getDisplay()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($_POST['selected_tbl']) && empty($table_select)) {
|
||||
$table_select = $_POST['selected_tbl'];
|
||||
}
|
||||
|
||||
$tablesForMultiValues = [];
|
||||
|
||||
foreach ($tables as $each_table) {
|
||||
if (isset($_POST['table_select']) && is_array($_POST['table_select'])) {
|
||||
$is_checked = $this->export->getCheckedClause(
|
||||
$each_table['Name'],
|
||||
$_POST['table_select']
|
||||
);
|
||||
} elseif (isset($table_select)) {
|
||||
$is_checked = $this->export->getCheckedClause(
|
||||
$each_table['Name'],
|
||||
$table_select
|
||||
);
|
||||
} else {
|
||||
$is_checked = true;
|
||||
}
|
||||
if (isset($_POST['table_structure']) && is_array($_POST['table_structure'])) {
|
||||
$structure_checked = $this->export->getCheckedClause(
|
||||
$each_table['Name'],
|
||||
$_POST['table_structure']
|
||||
);
|
||||
} else {
|
||||
$structure_checked = $is_checked;
|
||||
}
|
||||
if (isset($_POST['table_data']) && is_array($_POST['table_data'])) {
|
||||
$data_checked = $this->export->getCheckedClause(
|
||||
$each_table['Name'],
|
||||
$_POST['table_data']
|
||||
);
|
||||
} else {
|
||||
$data_checked = $is_checked;
|
||||
}
|
||||
|
||||
$tablesForMultiValues[] = [
|
||||
'name' => $each_table['Name'],
|
||||
'is_checked_select' => $is_checked,
|
||||
'is_checked_structure' => $structure_checked,
|
||||
'is_checked_data' => $data_checked,
|
||||
];
|
||||
}
|
||||
|
||||
if (! isset($sql_query)) {
|
||||
$sql_query = '';
|
||||
}
|
||||
if (! isset($unlim_num_rows)) {
|
||||
$unlim_num_rows = 0;
|
||||
}
|
||||
|
||||
$isReturnBackFromRawExport = isset($_POST['export_type']) && $_POST['export_type'] === 'raw';
|
||||
if (isset($_POST['raw_query']) || $isReturnBackFromRawExport) {
|
||||
$export_type = 'raw';
|
||||
} else {
|
||||
$export_type = 'database';
|
||||
}
|
||||
|
||||
$GLOBALS['single_table'] = $_POST['single_table'] ?? $_GET['single_table'] ?? $GLOBALS['single_table'] ?? null;
|
||||
|
||||
$exportList = Plugins::getExport($export_type, isset($GLOBALS['single_table']));
|
||||
|
||||
if (empty($exportList)) {
|
||||
$this->response->addHTML(Message::error(
|
||||
__('Could not load export plugins, please check your installation!')
|
||||
)->getDisplay());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$options = $this->exportOptions->getOptions(
|
||||
$export_type,
|
||||
$db,
|
||||
$table,
|
||||
$sql_query,
|
||||
$num_tables,
|
||||
$unlim_num_rows,
|
||||
$exportList
|
||||
);
|
||||
|
||||
$this->render('database/export/index', array_merge($options, [
|
||||
'page_settings_error_html' => $pageSettingsErrorHtml,
|
||||
'page_settings_html' => $pageSettingsHtml,
|
||||
'structure_or_data_forced' => $_POST['structure_or_data_forced'] ?? 0,
|
||||
'tables' => $tablesForMultiValues,
|
||||
]));
|
||||
}
|
||||
|
||||
public function tables(): void
|
||||
{
|
||||
if (empty($_POST['selected_tbl'])) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', __('No table selected.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->index();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Charsets;
|
||||
use PhpMyAdmin\Charsets\Charset;
|
||||
use PhpMyAdmin\Config\PageSettings;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Encoding;
|
||||
use PhpMyAdmin\Import;
|
||||
use PhpMyAdmin\Import\Ajax;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function intval;
|
||||
|
||||
final class ImportController extends AbstractController
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $max_upload_size, $table, $tables, $num_tables, $total_num_tables, $cfg;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos, $sub_part, $SESSION_KEY, $PMA_Theme, $err_url;
|
||||
|
||||
$pageSettings = new PageSettings('Import');
|
||||
$pageSettingsErrorHtml = $pageSettings->getErrorHTML();
|
||||
$pageSettingsHtml = $pageSettings->getHTML();
|
||||
|
||||
$this->addScriptFiles(['import.js']);
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
|
||||
[$SESSION_KEY, $uploadId] = Ajax::uploadProgressSetup();
|
||||
|
||||
$importList = Plugins::getImport('database');
|
||||
|
||||
if (empty($importList)) {
|
||||
$this->response->addHTML(Message::error(__(
|
||||
'Could not load import plugins, please check your installation!'
|
||||
))->getDisplay());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$offset = null;
|
||||
if (Core::isValid($_REQUEST['offset'], 'numeric')) {
|
||||
$offset = intval($_REQUEST['offset']);
|
||||
}
|
||||
|
||||
$timeoutPassed = $_REQUEST['timeout_passed'] ?? null;
|
||||
$localImportFile = $_REQUEST['local_import_file'] ?? null;
|
||||
$compressions = Import::getCompressions();
|
||||
|
||||
$allCharsets = Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
|
||||
$charsets = [];
|
||||
/** @var Charset $charset */
|
||||
foreach ($allCharsets as $charset) {
|
||||
$charsets[] = [
|
||||
'name' => $charset->getName(),
|
||||
'description' => $charset->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
$idKey = $_SESSION[$SESSION_KEY]['handler']::getIdKey();
|
||||
$hiddenInputs = [
|
||||
$idKey => $uploadId,
|
||||
'import_type' => 'database',
|
||||
'db' => $db,
|
||||
];
|
||||
|
||||
$this->render('database/import/index', [
|
||||
'page_settings_error_html' => $pageSettingsErrorHtml,
|
||||
'page_settings_html' => $pageSettingsHtml,
|
||||
'upload_id' => $uploadId,
|
||||
'handler' => $_SESSION[$SESSION_KEY]['handler'],
|
||||
'theme_image_path' => $PMA_Theme->getImgPath(),
|
||||
'hidden_inputs' => $hiddenInputs,
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
'max_upload_size' => $max_upload_size,
|
||||
'import_list' => $importList,
|
||||
'local_import_file' => $localImportFile,
|
||||
'is_upload' => $GLOBALS['is_upload'],
|
||||
'upload_dir' => $cfg['UploadDir'] ?? null,
|
||||
'timeout_passed_global' => $GLOBALS['timeout_passed'] ?? null,
|
||||
'compressions' => $compressions,
|
||||
'is_encoding_supported' => Encoding::isSupported(),
|
||||
'encodings' => Encoding::listEncodings(),
|
||||
'import_charset' => $cfg['Import']['charset'] ?? null,
|
||||
'timeout_passed' => $timeoutPassed,
|
||||
'offset' => $offset,
|
||||
'can_convert_kanji' => Encoding::canConvertKanji(),
|
||||
'charsets' => $charsets,
|
||||
'is_foreign_key_check' => Util::isForeignKeyCheck(),
|
||||
'user_upload_dir' => Util::userDir($cfg['UploadDir'] ?? ''),
|
||||
'local_files' => Import::getLocalFiles($importList),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Database\MultiTableQuery;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
|
||||
/**
|
||||
* Handles database multi-table querying
|
||||
*/
|
||||
class MultiTableQueryController extends AbstractController
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$this->addScriptFiles([
|
||||
'vendor/jquery/jquery.md5.js',
|
||||
'database/multi_table_query.js',
|
||||
'database/query_generator.js',
|
||||
]);
|
||||
|
||||
$queryInstance = new MultiTableQuery($this->dbi, $this->template, $this->db);
|
||||
|
||||
$this->response->addHTML($queryInstance->getFormHtml());
|
||||
}
|
||||
|
||||
public function displayResults(): void
|
||||
{
|
||||
global $PMA_Theme;
|
||||
|
||||
$params = [
|
||||
'sql_query' => $_POST['sql_query'],
|
||||
'db' => $_POST['db'] ?? $_GET['db'] ?? null,
|
||||
];
|
||||
|
||||
$this->response->addHTML(MultiTableQuery::displayResults(
|
||||
$params['sql_query'],
|
||||
$params['db'],
|
||||
$PMA_Theme->getImgPath()
|
||||
));
|
||||
}
|
||||
|
||||
public function table(): void
|
||||
{
|
||||
$params = [
|
||||
'tables' => $_GET['tables'],
|
||||
'db' => $_GET['db'] ?? null,
|
||||
];
|
||||
$constrains = $this->dbi->getForeignKeyConstrains(
|
||||
$params['db'],
|
||||
$params['tables']
|
||||
);
|
||||
$this->response->addJSON(['foreignKeyConstrains' => $constrains]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,419 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Charsets;
|
||||
use PhpMyAdmin\CheckUserPrivileges;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Operations;
|
||||
use PhpMyAdmin\Plugins;
|
||||
use PhpMyAdmin\Plugins\Export\ExportSql;
|
||||
use PhpMyAdmin\Query\Utilities;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\RelationCleanup;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function count;
|
||||
use function mb_strtolower;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Handles miscellaneous database operations.
|
||||
*/
|
||||
class OperationsController extends AbstractController
|
||||
{
|
||||
/** @var Operations */
|
||||
private $operations;
|
||||
|
||||
/** @var CheckUserPrivileges */
|
||||
private $checkUserPrivileges;
|
||||
|
||||
/** @var Relation */
|
||||
private $relation;
|
||||
|
||||
/** @var RelationCleanup */
|
||||
private $relationCleanup;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
Template $template,
|
||||
$db,
|
||||
Operations $operations,
|
||||
CheckUserPrivileges $checkUserPrivileges,
|
||||
Relation $relation,
|
||||
RelationCleanup $relationCleanup,
|
||||
$dbi
|
||||
) {
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->operations = $operations;
|
||||
$this->checkUserPrivileges = $checkUserPrivileges;
|
||||
$this->relation = $relation;
|
||||
$this->relationCleanup = $relationCleanup;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $cfg, $db, $server, $sql_query, $move, $message, $tables_full, $err_url;
|
||||
global $export_sql_plugin, $views, $sqlConstratints, $local_query, $reload, $url_params, $tables;
|
||||
global $total_num_tables, $sub_part, $tooltip_truename;
|
||||
global $db_collation, $tooltip_aliasname, $pos, $is_information_schema, $single_table, $num_tables;
|
||||
|
||||
$this->checkUserPrivileges->getPrivileges();
|
||||
|
||||
$this->addScriptFiles(['database/operations.js']);
|
||||
|
||||
$sql_query = '';
|
||||
|
||||
/**
|
||||
* Rename/move or copy database
|
||||
*/
|
||||
if (strlen($db) > 0
|
||||
&& (! empty($_POST['db_rename']) || ! empty($_POST['db_copy']))
|
||||
) {
|
||||
if (! empty($_POST['db_rename'])) {
|
||||
$move = true;
|
||||
} else {
|
||||
$move = false;
|
||||
}
|
||||
|
||||
if (! isset($_POST['newname']) || strlen($_POST['newname']) === 0) {
|
||||
$message = Message::error(__('The database name is empty!'));
|
||||
} else {
|
||||
// lower_case_table_names=1 `DB` becomes `db`
|
||||
if ($this->dbi->getLowerCaseNames() === '1') {
|
||||
$_POST['newname'] = mb_strtolower(
|
||||
$_POST['newname']
|
||||
);
|
||||
}
|
||||
|
||||
if ($_POST['newname'] === $_REQUEST['db']) {
|
||||
$message = Message::error(
|
||||
__('Cannot copy database to the same name. Change the name and try again.')
|
||||
);
|
||||
} else {
|
||||
$_error = false;
|
||||
if ($move || ! empty($_POST['create_database_before_copying'])) {
|
||||
$this->operations->createDbBeforeCopy();
|
||||
}
|
||||
|
||||
// here I don't use DELIMITER because it's not part of the
|
||||
// language; I have to send each statement one by one
|
||||
|
||||
// to avoid selecting alternatively the current and new db
|
||||
// we would need to modify the CREATE definitions to qualify
|
||||
// the db name
|
||||
$this->operations->runProcedureAndFunctionDefinitions($db);
|
||||
|
||||
// go back to current db, just in case
|
||||
$this->dbi->selectDb($db);
|
||||
|
||||
$tables_full = $this->dbi->getTablesFull($db);
|
||||
|
||||
// remove all foreign key constraints, otherwise we can get errors
|
||||
/** @var ExportSql $export_sql_plugin */
|
||||
$export_sql_plugin = Plugins::getPlugin(
|
||||
'export',
|
||||
'sql',
|
||||
'libraries/classes/Plugins/Export/',
|
||||
[
|
||||
'single_table' => isset($single_table),
|
||||
'export_type' => 'database',
|
||||
]
|
||||
);
|
||||
|
||||
// create stand-in tables for views
|
||||
$views = $this->operations->getViewsAndCreateSqlViewStandIn(
|
||||
$tables_full,
|
||||
$export_sql_plugin,
|
||||
$db
|
||||
);
|
||||
|
||||
// copy tables
|
||||
$sqlConstratints = $this->operations->copyTables(
|
||||
$tables_full,
|
||||
$move,
|
||||
$db
|
||||
);
|
||||
|
||||
// handle the views
|
||||
if (! $_error) {
|
||||
$this->operations->handleTheViews($views, $move, $db);
|
||||
}
|
||||
unset($views);
|
||||
|
||||
// now that all tables exist, create all the accumulated constraints
|
||||
if (! $_error && count($sqlConstratints) > 0) {
|
||||
$this->operations->createAllAccumulatedConstraints($sqlConstratints);
|
||||
}
|
||||
unset($sqlConstratints);
|
||||
|
||||
if ($this->dbi->getVersion() >= 50100) {
|
||||
// here DELIMITER is not used because it's not part of the
|
||||
// language; each statement is sent one by one
|
||||
|
||||
$this->operations->runEventDefinitionsForDb($db);
|
||||
}
|
||||
|
||||
// go back to current db, just in case
|
||||
$this->dbi->selectDb($db);
|
||||
|
||||
// Duplicate the bookmarks for this db (done once for each db)
|
||||
$this->operations->duplicateBookmarks($_error, $db);
|
||||
|
||||
if (! $_error && $move) {
|
||||
if (isset($_POST['adjust_privileges'])
|
||||
&& ! empty($_POST['adjust_privileges'])
|
||||
) {
|
||||
$this->operations->adjustPrivilegesMoveDb($db, $_POST['newname']);
|
||||
}
|
||||
|
||||
/**
|
||||
* cleanup pmadb stuff for this db
|
||||
*/
|
||||
$this->relationCleanup->database($db);
|
||||
|
||||
// if someday the RENAME DATABASE reappears, do not DROP
|
||||
$local_query = 'DROP DATABASE '
|
||||
. Util::backquote($db) . ';';
|
||||
$sql_query .= "\n" . $local_query;
|
||||
$this->dbi->query($local_query);
|
||||
|
||||
$message = Message::success(
|
||||
__('Database %1$s has been renamed to %2$s.')
|
||||
);
|
||||
$message->addParam($db);
|
||||
$message->addParam($_POST['newname']);
|
||||
} elseif (! $_error) {
|
||||
if (isset($_POST['adjust_privileges'])
|
||||
&& ! empty($_POST['adjust_privileges'])
|
||||
) {
|
||||
$this->operations->adjustPrivilegesCopyDb($db, $_POST['newname']);
|
||||
}
|
||||
|
||||
$message = Message::success(
|
||||
__('Database %1$s has been copied to %2$s.')
|
||||
);
|
||||
$message->addParam($db);
|
||||
$message->addParam($_POST['newname']);
|
||||
} else {
|
||||
$message = Message::error();
|
||||
}
|
||||
$reload = true;
|
||||
|
||||
/* Change database to be used */
|
||||
if (! $_error && $move) {
|
||||
$db = $_POST['newname'];
|
||||
} elseif (! $_error) {
|
||||
if (isset($_POST['switch_to_new'])
|
||||
&& $_POST['switch_to_new'] === 'true'
|
||||
) {
|
||||
$_SESSION['pma_switch_to_new'] = true;
|
||||
$db = $_POST['newname'];
|
||||
} else {
|
||||
$_SESSION['pma_switch_to_new'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Database has been successfully renamed/moved. If in an Ajax request,
|
||||
* generate the output with {@link Response} and exit
|
||||
*/
|
||||
if ($this->response->isAjax()) {
|
||||
$this->response->setRequestStatus($message->isSuccess());
|
||||
$this->response->addJSON('message', $message);
|
||||
$this->response->addJSON('newname', $_POST['newname']);
|
||||
$this->response->addJSON(
|
||||
'sql_query',
|
||||
Generator::getMessage('', $sql_query)
|
||||
);
|
||||
$this->response->addJSON('db', $db);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for relations stuff
|
||||
*/
|
||||
$cfgRelation = $this->relation->getRelationsParam();
|
||||
|
||||
/**
|
||||
* Check if comments were updated
|
||||
* (must be done before displaying the menu tabs)
|
||||
*/
|
||||
if (isset($_POST['comment'])) {
|
||||
$this->relation->setDbComment($db, $_POST['comment']);
|
||||
}
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params['goto'] = Url::getFromRoute('/database/operations');
|
||||
|
||||
// Gets the database structure
|
||||
$sub_part = '_structure';
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,
|
||||
$isSystemSchema,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
|
||||
$oldMessage = '';
|
||||
if (isset($message)) {
|
||||
$oldMessage = Generator::getMessage($message, $sql_query);
|
||||
unset($message);
|
||||
}
|
||||
|
||||
$db_collation = $this->dbi->getDbCollation($db);
|
||||
$is_information_schema = Utilities::isSystemSchema($db);
|
||||
|
||||
if ($is_information_schema) {
|
||||
return;
|
||||
}
|
||||
|
||||
$databaseComment = '';
|
||||
if ($cfgRelation['commwork']) {
|
||||
$databaseComment = $this->relation->getDbComment($db);
|
||||
}
|
||||
|
||||
$hasAdjustPrivileges = $GLOBALS['db_priv'] && $GLOBALS['table_priv']
|
||||
&& $GLOBALS['col_priv'] && $GLOBALS['proc_priv'] && $GLOBALS['is_reload_priv'];
|
||||
|
||||
$isDropDatabaseAllowed = ($this->dbi->isSuperUser() || $cfg['AllowUserDropDatabase'])
|
||||
&& ! $isSystemSchema && $db !== 'mysql';
|
||||
|
||||
$switchToNew = isset($_SESSION['pma_switch_to_new']) && $_SESSION['pma_switch_to_new'];
|
||||
|
||||
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
|
||||
$collations = Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
|
||||
|
||||
if (! $cfgRelation['allworks']
|
||||
&& $cfg['PmaNoRelation_DisableWarning'] == false
|
||||
) {
|
||||
$message = Message::notice(
|
||||
__(
|
||||
'The phpMyAdmin configuration storage has been deactivated. ' .
|
||||
'%sFind out why%s.'
|
||||
)
|
||||
);
|
||||
$message->addParamHtml(
|
||||
'<a href="' . Url::getFromRoute('/check-relations')
|
||||
. '" data-post="' . Url::getCommon(['db' => $db]) . '">'
|
||||
);
|
||||
$message->addParamHtml('</a>');
|
||||
/* Show error if user has configured something, notice elsewhere */
|
||||
if (! empty($cfg['Servers'][$server]['pmadb'])) {
|
||||
$message->isError(true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->render('database/operations/index', [
|
||||
'message' => $oldMessage,
|
||||
'db' => $db,
|
||||
'has_comment' => $cfgRelation['commwork'],
|
||||
'db_comment' => $databaseComment,
|
||||
'db_collation' => $db_collation,
|
||||
'has_adjust_privileges' => $hasAdjustPrivileges,
|
||||
'is_drop_database_allowed' => $isDropDatabaseAllowed,
|
||||
'switch_to_new' => $switchToNew,
|
||||
'charsets' => $charsets,
|
||||
'collations' => $collations,
|
||||
]);
|
||||
}
|
||||
|
||||
public function collation(): void
|
||||
{
|
||||
global $db, $cfg, $err_url;
|
||||
|
||||
if (! $this->response->isAjax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($_POST['db_collation'])) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', Message::error(__('No collation provided.')));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql_query = 'ALTER DATABASE ' . Util::backquote($db)
|
||||
. ' DEFAULT' . Util::getCharsetQueryPart($_POST['db_collation'] ?? '');
|
||||
$this->dbi->query($sql_query);
|
||||
$message = Message::success();
|
||||
|
||||
/**
|
||||
* Changes tables charset if requested by the user
|
||||
*/
|
||||
if (isset($_POST['change_all_tables_collations']) &&
|
||||
$_POST['change_all_tables_collations'] === 'on'
|
||||
) {
|
||||
[$tables] = Util::getDbInfo($db, null);
|
||||
foreach ($tables as $tableName => $data) {
|
||||
if ($this->dbi->getTable($db, $tableName)->isView()) {
|
||||
// Skip views, we can not change the collation of a view.
|
||||
// issue #15283
|
||||
continue;
|
||||
}
|
||||
$sql_query = 'ALTER TABLE '
|
||||
. Util::backquote($db)
|
||||
. '.'
|
||||
. Util::backquote($tableName)
|
||||
. ' DEFAULT '
|
||||
. Util::getCharsetQueryPart($_POST['db_collation'] ?? '');
|
||||
$this->dbi->query($sql_query);
|
||||
|
||||
/**
|
||||
* Changes columns charset if requested by the user
|
||||
*/
|
||||
if (! isset($_POST['change_all_tables_columns_collations']) ||
|
||||
$_POST['change_all_tables_columns_collations'] !== 'on'
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->operations->changeAllColumnsCollation($db, $tableName, $_POST['db_collation']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->setRequestStatus($message->isSuccess());
|
||||
$this->response->addJSON('message', $message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Controller for database privileges
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Server\Privileges;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Controller for database privileges
|
||||
*/
|
||||
class PrivilegesController extends AbstractController
|
||||
{
|
||||
/** @var Privileges */
|
||||
private $privileges;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, Privileges $privileges, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->privileges = $privileges;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function index(array $params): string
|
||||
{
|
||||
global $cfg, $text_dir, $PMA_Theme;
|
||||
|
||||
$scriptName = Util::getScriptNameForOption(
|
||||
$cfg['DefaultTabDatabase'],
|
||||
'database'
|
||||
);
|
||||
|
||||
$privileges = [];
|
||||
if ($this->dbi->isSuperUser()) {
|
||||
$privileges = $this->privileges->getAllPrivileges($params['checkprivsdb']);
|
||||
}
|
||||
|
||||
return $this->template->render('database/privileges/index', [
|
||||
'is_superuser' => $this->dbi->isSuperUser(),
|
||||
'db' => $params['checkprivsdb'],
|
||||
'database_url' => $scriptName,
|
||||
'theme_image_path' => $PMA_Theme->getImgPath(),
|
||||
'text_dir' => $text_dir,
|
||||
'is_createuser' => $this->dbi->isCreateUser(),
|
||||
'is_grantuser' => $this->dbi->isGrantUser(),
|
||||
'privileges' => $privileges,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Database\Qbe;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Operations;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\RelationCleanup;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\SavedSearches;
|
||||
use PhpMyAdmin\Sql;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Transformations;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function stripos;
|
||||
|
||||
class QueryByExampleController extends AbstractController
|
||||
{
|
||||
/** @var Relation */
|
||||
private $relation;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, Relation $relation, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->relation = $relation;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $savedSearchList, $savedSearch, $currentSearchId, $PMA_Theme;
|
||||
global $sql_query, $goto, $sub_part, $tables, $num_tables, $total_num_tables;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos, $url_params, $cfg, $err_url;
|
||||
|
||||
// Gets the relation settings
|
||||
$cfgRelation = $this->relation->getRelationsParam();
|
||||
|
||||
$savedSearchList = [];
|
||||
$savedSearch = null;
|
||||
$currentSearchId = null;
|
||||
$this->addScriptFiles(['database/qbe.js']);
|
||||
if ($cfgRelation['savedsearcheswork']) {
|
||||
//Get saved search list.
|
||||
$savedSearch = new SavedSearches($GLOBALS, $this->relation);
|
||||
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
|
||||
->setDbname($db);
|
||||
|
||||
if (! empty($_POST['searchId'])) {
|
||||
$savedSearch->setId($_POST['searchId']);
|
||||
}
|
||||
|
||||
//Action field is sent.
|
||||
if (isset($_POST['action'])) {
|
||||
$savedSearch->setSearchName($_POST['searchName']);
|
||||
if ($_POST['action'] === 'create') {
|
||||
$saveResult = $savedSearch->setId(null)
|
||||
->setCriterias($_POST)
|
||||
->save();
|
||||
} elseif ($_POST['action'] === 'update') {
|
||||
$saveResult = $savedSearch->setCriterias($_POST)
|
||||
->save();
|
||||
} elseif ($_POST['action'] === 'delete') {
|
||||
$deleteResult = $savedSearch->delete();
|
||||
//After deletion, reset search.
|
||||
$savedSearch = new SavedSearches($GLOBALS, $this->relation);
|
||||
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
|
||||
->setDbname($db);
|
||||
$_POST = [];
|
||||
} elseif ($_POST['action'] === 'load') {
|
||||
if (empty($_POST['searchId'])) {
|
||||
//when not loading a search, reset the object.
|
||||
$savedSearch = new SavedSearches($GLOBALS, $this->relation);
|
||||
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
|
||||
->setDbname($db);
|
||||
$_POST = [];
|
||||
} else {
|
||||
$loadResult = $savedSearch->load();
|
||||
}
|
||||
}
|
||||
//Else, it's an "update query"
|
||||
}
|
||||
|
||||
$savedSearchList = $savedSearch->getList();
|
||||
$currentSearchId = $savedSearch->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* A query has been submitted -> (maybe) execute it
|
||||
*/
|
||||
$hasMessageToDisplay = false;
|
||||
if (isset($_POST['submit_sql']) && ! empty($sql_query)) {
|
||||
if (stripos($sql_query, 'SELECT') !== 0) {
|
||||
$hasMessageToDisplay = true;
|
||||
} else {
|
||||
$goto = Url::getFromRoute('/database/sql');
|
||||
|
||||
$sql = new Sql(
|
||||
$this->dbi,
|
||||
$this->relation,
|
||||
new RelationCleanup($this->dbi, $this->relation),
|
||||
new Operations($this->dbi, $this->relation),
|
||||
new Transformations(),
|
||||
$this->template
|
||||
);
|
||||
|
||||
$this->response->addHTML($sql->executeQueryAndSendQueryResponse(
|
||||
null, // analyzed_sql_results
|
||||
false, // is_gotofile
|
||||
$_POST['db'], // db
|
||||
null, // table
|
||||
false, // find_real_end
|
||||
null, // sql_query_for_bookmark
|
||||
null, // extra_data
|
||||
null, // message_to_show
|
||||
null, // sql_data
|
||||
$goto, // goto
|
||||
$PMA_Theme->getImgPath(),
|
||||
null, // disp_query
|
||||
null, // disp_message
|
||||
$sql_query, // sql_query
|
||||
null // complete_query
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$sub_part = '_qbe';
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params['goto'] = Url::getFromRoute('/database/qbe');
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
|
||||
$databaseQbe = new Qbe($this->relation, $this->template, $this->dbi, $db, $savedSearchList, $savedSearch);
|
||||
|
||||
$this->render('database/qbe/index', [
|
||||
'url_params' => $url_params,
|
||||
'has_message_to_display' => $hasMessageToDisplay,
|
||||
'selection_form_html' => $databaseQbe->getSelectionForm(),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\CheckUserPrivileges;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Database\Routines;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\DbTableExists;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function in_array;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Routines management.
|
||||
*/
|
||||
class RoutinesController extends AbstractController
|
||||
{
|
||||
/** @var CheckUserPrivileges */
|
||||
private $checkUserPrivileges;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, CheckUserPrivileges $checkUserPrivileges, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->checkUserPrivileges = $checkUserPrivileges;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos;
|
||||
global $errors, $PMA_Theme, $text_dir, $err_url, $url_params, $cfg;
|
||||
|
||||
$type = $_REQUEST['type'] ?? null;
|
||||
|
||||
$this->checkUserPrivileges->getPrivileges();
|
||||
|
||||
if (! $this->response->isAjax()) {
|
||||
/**
|
||||
* Displays the header and tabs
|
||||
*/
|
||||
if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
|
||||
Util::checkParameters(['db', 'table']);
|
||||
|
||||
$url_params = ['db' => $db, 'table' => $table];
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
|
||||
$err_url .= Url::getCommon($url_params, '&');
|
||||
|
||||
DbTableExists::check();
|
||||
} else {
|
||||
$table = '';
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
}
|
||||
} elseif (strlen($db) > 0) {
|
||||
$this->dbi->selectDb($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep a list of errors that occurred while
|
||||
* processing an 'Add' or 'Edit' operation.
|
||||
*/
|
||||
$errors = [];
|
||||
|
||||
$routines = new Routines($this->dbi, $this->template, $this->response);
|
||||
|
||||
$routines->handleEditor();
|
||||
$routines->handleExecute();
|
||||
$routines->export();
|
||||
|
||||
if (! Core::isValid($type, ['FUNCTION', 'PROCEDURE'])) {
|
||||
$type = null;
|
||||
}
|
||||
|
||||
$items = $this->dbi->getRoutines($db, $type);
|
||||
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
|
||||
|
||||
$rows = '';
|
||||
foreach ($items as $item) {
|
||||
$rows .= $routines->getRow($item, $isAjax ? 'ajaxInsert hide' : '');
|
||||
}
|
||||
|
||||
$this->render('database/routines/index', [
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
'items' => $items,
|
||||
'rows' => $rows,
|
||||
'select_all_arrow_src' => $PMA_Theme->getImgPath() . 'arrow_' . $text_dir . '.png',
|
||||
'has_privilege' => Util::currentUserHasPrivilege('CREATE ROUTINE', $db, $table),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Database\Search;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
class SearchController extends AbstractController
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $cfg, $db, $err_url, $url_params, $tables, $num_tables, $total_num_tables, $sub_part;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos;
|
||||
|
||||
$this->addScriptFiles([
|
||||
'database/search.js',
|
||||
'vendor/stickyfill.min.js',
|
||||
'sql.js',
|
||||
'makegrid.js',
|
||||
]);
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If config variable $cfg['UseDbSearch'] is on false : exit.
|
||||
if (! $cfg['UseDbSearch']) {
|
||||
Generator::mysqlDie(
|
||||
__('Access denied!'),
|
||||
'',
|
||||
false,
|
||||
$err_url
|
||||
);
|
||||
}
|
||||
$url_params['goto'] = Url::getFromRoute('/database/search');
|
||||
|
||||
// Create a database search instance
|
||||
$databaseSearch = new Search($this->dbi, $db, $this->template);
|
||||
|
||||
// Display top links if we are not in an Ajax request
|
||||
if (! $this->response->isAjax()) {
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
}
|
||||
|
||||
// Main search form has been submitted, get results
|
||||
if (isset($_POST['submit_search'])) {
|
||||
$this->response->addHTML($databaseSearch->getSearchResults());
|
||||
}
|
||||
|
||||
// If we are in an Ajax request, we need to exit after displaying all the HTML
|
||||
if ($this->response->isAjax() && empty($_REQUEST['ajax_page_request'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Display the search form
|
||||
$this->response->addHTML($databaseSearch->getMainHtml());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use function json_encode;
|
||||
|
||||
/**
|
||||
* Table/Column autocomplete in SQL editors.
|
||||
*/
|
||||
class SqlAutoCompleteController extends AbstractController
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $cfg, $db, $sql_autocomplete;
|
||||
|
||||
$sql_autocomplete = true;
|
||||
if ($cfg['EnableAutocompleteForTablesAndColumns']) {
|
||||
$db = $_POST['db'] ?? $db;
|
||||
$sql_autocomplete = [];
|
||||
if ($db) {
|
||||
$tableNames = $this->dbi->getTables($db);
|
||||
foreach ($tableNames as $tableName) {
|
||||
$sql_autocomplete[$tableName] = $this->dbi->getColumns(
|
||||
$db,
|
||||
$tableName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->response->addJSON(['tables' => json_encode($sql_autocomplete)]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Config\PageSettings;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\SqlQueryForm;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function htmlspecialchars;
|
||||
|
||||
/**
|
||||
* Database SQL executor
|
||||
*/
|
||||
class SqlController extends AbstractController
|
||||
{
|
||||
/** @var SqlQueryForm */
|
||||
private $sqlQueryForm;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, SqlQueryForm $sqlQueryForm)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->sqlQueryForm = $sqlQueryForm;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $goto, $back, $db, $cfg, $err_url;
|
||||
|
||||
$this->addScriptFiles([
|
||||
'makegrid.js',
|
||||
'vendor/jquery/jquery.uitablefilter.js',
|
||||
'vendor/stickyfill.min.js',
|
||||
'sql.js',
|
||||
]);
|
||||
|
||||
$pageSettings = new PageSettings('Sql');
|
||||
$this->response->addHTML($pageSettings->getErrorHTML());
|
||||
$this->response->addHTML($pageSettings->getHTML());
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* After a syntax error, we return to this script
|
||||
* with the typed query in the textarea.
|
||||
*/
|
||||
$goto = Url::getFromRoute('/database/sql');
|
||||
$back = $goto;
|
||||
|
||||
$this->response->addHTML($this->sqlQueryForm->getHtml(
|
||||
true,
|
||||
false,
|
||||
isset($_POST['delimiter'])
|
||||
? htmlspecialchars($_POST['delimiter'])
|
||||
: ';'
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Utils\Formatter;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Format SQL for SQL editors.
|
||||
*/
|
||||
class SqlFormatController extends AbstractController
|
||||
{
|
||||
public function index(): void
|
||||
{
|
||||
$params = ['sql' => $_POST['sql'] ?? null];
|
||||
$query = strlen((string) $params['sql']) > 0 ? $params['sql'] : '';
|
||||
$this->response->addJSON(['sql' => Formatter::format($query)]);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\CheckUserPrivileges;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Tracker;
|
||||
use PhpMyAdmin\Tracking;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function count;
|
||||
use function htmlspecialchars;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Tracking configuration for database.
|
||||
*/
|
||||
class TrackingController extends AbstractController
|
||||
{
|
||||
/** @var Tracking */
|
||||
private $tracking;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, Tracking $tracking, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->tracking = $tracking;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $text_dir, $url_params, $tables, $num_tables, $PMA_Theme;
|
||||
global $total_num_tables, $sub_part, $pos, $data, $cfg;
|
||||
global $tooltip_truename, $tooltip_aliasname, $err_url;
|
||||
|
||||
$this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'database/tracking.js']);
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params['goto'] = Url::getFromRoute('/table/tracking');
|
||||
$url_params['back'] = Url::getFromRoute('/database/tracking');
|
||||
|
||||
// Get the database structure
|
||||
$sub_part = '_structure';
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,
|
||||
$isSystemSchema,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
|
||||
if (isset($_POST['delete_tracking'], $_POST['table'])) {
|
||||
Tracker::deleteTracking($db, $_POST['table']);
|
||||
echo Message::success(
|
||||
__('Tracking data deleted successfully.')
|
||||
)->getDisplay();
|
||||
} elseif (isset($_POST['submit_create_version'])) {
|
||||
$this->tracking->createTrackingForMultipleTables($_POST['selected']);
|
||||
echo Message::success(
|
||||
sprintf(
|
||||
__(
|
||||
'Version %1$s was created for selected tables,'
|
||||
. ' tracking is active for them.'
|
||||
),
|
||||
htmlspecialchars($_POST['version'])
|
||||
)
|
||||
)->getDisplay();
|
||||
} elseif (isset($_POST['submit_mult'])) {
|
||||
if (! empty($_POST['selected_tbl'])) {
|
||||
if ($_POST['submit_mult'] === 'delete_tracking') {
|
||||
foreach ($_POST['selected_tbl'] as $table) {
|
||||
Tracker::deleteTracking($db, $table);
|
||||
}
|
||||
echo Message::success(
|
||||
__('Tracking data deleted successfully.')
|
||||
)->getDisplay();
|
||||
} elseif ($_POST['submit_mult'] === 'track') {
|
||||
echo $this->template->render('create_tracking_version', [
|
||||
'route' => '/database/tracking',
|
||||
'url_params' => $url_params,
|
||||
'last_version' => 0,
|
||||
'db' => $db,
|
||||
'selected' => $_POST['selected_tbl'],
|
||||
'type' => 'both',
|
||||
'default_statements' => $cfg['Server']['tracking_default_statements'],
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
echo Message::notice(
|
||||
__('No tables selected.')
|
||||
)->getDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
// Get tracked data about the database
|
||||
$data = Tracker::getTrackedData($db, '', '1');
|
||||
|
||||
// No tables present and no log exist
|
||||
if ($num_tables == 0 && count($data['ddlog']) === 0) {
|
||||
echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
|
||||
|
||||
if (empty($isSystemSchema)) {
|
||||
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
|
||||
$checkUserPrivileges->getPrivileges();
|
||||
|
||||
echo $this->template->render('database/create_table', ['db' => $db]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
echo $this->tracking->getHtmlForDbTrackingTables(
|
||||
$db,
|
||||
$url_params,
|
||||
$PMA_Theme->getImgPath(),
|
||||
$text_dir
|
||||
);
|
||||
|
||||
// If available print out database log
|
||||
if (count($data['ddlog']) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$log = '';
|
||||
foreach ($data['ddlog'] as $entry) {
|
||||
$log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
|
||||
. $entry['statement'] . "\n";
|
||||
}
|
||||
echo Generator::getMessage(__('Database Log'), $log);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Database;
|
||||
|
||||
use PhpMyAdmin\Database\Triggers;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\DbTableExists;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use function in_array;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Triggers management.
|
||||
*/
|
||||
class TriggersController extends AbstractController
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string $db Database name.
|
||||
* @param DatabaseInterface $dbi
|
||||
*/
|
||||
public function __construct($response, Template $template, $db, $dbi)
|
||||
{
|
||||
parent::__construct($response, $template, $db);
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part;
|
||||
global $tooltip_truename, $tooltip_aliasname, $pos;
|
||||
global $errors, $url_params, $err_url, $cfg;
|
||||
|
||||
if (! $this->response->isAjax()) {
|
||||
/**
|
||||
* Displays the header and tabs
|
||||
*/
|
||||
if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
|
||||
Util::checkParameters(['db', 'table']);
|
||||
|
||||
$url_params = ['db' => $db, 'table' => $table];
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
|
||||
$err_url .= Url::getCommon($url_params, '&');
|
||||
|
||||
DbTableExists::check();
|
||||
} else {
|
||||
$table = '';
|
||||
|
||||
Util::checkParameters(['db']);
|
||||
|
||||
$err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
|
||||
$err_url .= Url::getCommon(['db' => $db], '&');
|
||||
|
||||
if (! $this->hasDatabase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
[
|
||||
$tables,
|
||||
$num_tables,
|
||||
$total_num_tables,
|
||||
$sub_part,,,
|
||||
$tooltip_truename,
|
||||
$tooltip_aliasname,
|
||||
$pos,
|
||||
] = Util::getDbInfo($db, $sub_part ?? '');
|
||||
}
|
||||
} elseif (strlen($db) > 0) {
|
||||
$this->dbi->selectDb($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep a list of errors that occurred while
|
||||
* processing an 'Add' or 'Edit' operation.
|
||||
*/
|
||||
$errors = [];
|
||||
|
||||
$triggers = new Triggers($this->dbi, $this->template, $this->response);
|
||||
$triggers->main();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue