mirror of
https://github.com/vrana/adminer.git
synced 2025-08-07 23:27:17 +02:00
Pass $tableStatus to indexMethods, rename
This commit is contained in:
@@ -355,12 +355,12 @@ if (isset($_GET["pgsql"])) {
|
|||||||
return "(SELECT oid FROM pg_class WHERE relnamespace = $this->nsOid AND relname = " . q($table) . " AND relkind IN ('r', 'm', 'v', 'f', 'p'))";
|
return "(SELECT oid FROM pg_class WHERE relnamespace = $this->nsOid AND relname = " . q($table) . " AND relkind IN ('r', 'm', 'v', 'f', 'p'))";
|
||||||
}
|
}
|
||||||
|
|
||||||
function indexMethods(): array {
|
function indexAlgorithms(array $tableStatus): array {
|
||||||
static $methods = array();
|
static $return = array();
|
||||||
if (!$methods) {
|
if (!$return) {
|
||||||
$methods = get_vals("SELECT amname FROM pg_am" . (min_version(9.6) ? " WHERE amtype = 'i'" : "") . " ORDER BY amname = 'btree' DESC, amname");
|
$return = get_vals("SELECT amname FROM pg_am" . (min_version(9.6) ? " WHERE amtype = 'i'" : "") . " ORDER BY amname = 'btree' DESC, amname");
|
||||||
}
|
}
|
||||||
return $methods;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function supportsIndex(array $table_status): bool {
|
function supportsIndex(array $table_status): bool {
|
||||||
|
@@ -348,9 +348,11 @@ class Adminer {
|
|||||||
|
|
||||||
/** Print list of indexes on table in tabular format
|
/** Print list of indexes on table in tabular format
|
||||||
* @param Index[] $indexes
|
* @param Index[] $indexes
|
||||||
|
* @param TableStatus $tableStatus
|
||||||
*/
|
*/
|
||||||
function tableIndexesPrint(array $indexes): void {
|
function tableIndexesPrint(array $indexes, array $tableStatus): void {
|
||||||
echo "<table>\n";
|
echo "<table>\n";
|
||||||
|
$default_algorithm = first(driver()->indexAlgorithms($tableStatus));
|
||||||
foreach ($indexes as $name => $index) {
|
foreach ($indexes as $name => $index) {
|
||||||
ksort($index["columns"]); // enforce correct columns order
|
ksort($index["columns"]); // enforce correct columns order
|
||||||
$print = array();
|
$print = array();
|
||||||
@@ -362,7 +364,7 @@ class Adminer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo "<tr title='" . h($name) . "'>";
|
echo "<tr title='" . h($name) . "'>";
|
||||||
echo "<th>$index[type]" . ($index['algorithm'] != first(driver()->indexMethods()) ? " ($index[algorithm])" : "");
|
echo "<th>$index[type]" . ($index['algorithm'] != $default_algorithm ? " ($index[algorithm])" : "");
|
||||||
echo "<td>" . implode(", ", $print);
|
echo "<td>" . implode(", ", $print);
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
@@ -259,10 +259,11 @@ abstract class SqlDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of supported index methods, first one is default
|
* Return list of supported index algorithms, first one is default
|
||||||
|
* @param TableStatus $tableStatus
|
||||||
* @return list<string>
|
* @return list<string>
|
||||||
*/
|
*/
|
||||||
function indexMethods(): array {
|
function indexAlgorithms(array $tableStatus): array {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ namespace Adminer;
|
|||||||
$TABLE = $_GET["indexes"];
|
$TABLE = $_GET["indexes"];
|
||||||
$index_types = array("PRIMARY", "UNIQUE", "INDEX");
|
$index_types = array("PRIMARY", "UNIQUE", "INDEX");
|
||||||
$table_status = table_status1($TABLE, true);
|
$table_status = table_status1($TABLE, true);
|
||||||
|
$index_algorithms = driver()->indexAlgorithms($table_status);
|
||||||
if (preg_match('~MyISAM|M?aria' . (min_version(5.6, '10.0.5') ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
|
if (preg_match('~MyISAM|M?aria' . (min_version(5.6, '10.0.5') ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
|
||||||
$index_types[] = "FULLTEXT";
|
$index_types[] = "FULLTEXT";
|
||||||
}
|
}
|
||||||
@@ -29,7 +30,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
|
|||||||
$columns = array();
|
$columns = array();
|
||||||
$lengths = array();
|
$lengths = array();
|
||||||
$descs = array();
|
$descs = array();
|
||||||
$index_algorithm = (in_array($index["algorithm"], driver()->indexMethods()) ? $index["algorithm"] : "");
|
$index_algorithm = (in_array($index["algorithm"], $index_algorithms) ? $index["algorithm"] : "");
|
||||||
$set = array();
|
$set = array();
|
||||||
ksort($index["columns"]);
|
ksort($index["columns"]);
|
||||||
foreach ($index["columns"] as $key => $column) {
|
foreach ($index["columns"] as $key => $column) {
|
||||||
@@ -108,8 +109,8 @@ $show_options = ($_POST ? $_POST["options"] : get_setting("index_options"));
|
|||||||
<thead><tr>
|
<thead><tr>
|
||||||
<th id="label-type"><?php echo lang('Index Type'); ?>
|
<th id="label-type"><?php echo lang('Index Type'); ?>
|
||||||
<?php
|
<?php
|
||||||
if (driver()->indexMethods()) {
|
if ($index_algorithms) {
|
||||||
echo "<th id='label-method' class='idxopts" . ($show_options ? "" : " hidden") . "'>" . lang('Algorithm');
|
echo "<th id='label-algorithm' class='idxopts" . ($show_options ? "" : " hidden") . "'>" . lang('Algorithm');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<th><input type="submit" class="wayoff"><?php
|
<th><input type="submit" class="wayoff"><?php
|
||||||
@@ -135,8 +136,8 @@ foreach ($row["indexes"] as $index) {
|
|||||||
if (!$_POST["drop_col"] || $j != key($_POST["drop_col"])) {
|
if (!$_POST["drop_col"] || $j != key($_POST["drop_col"])) {
|
||||||
echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow.call(this);" : ""), "label-type");
|
echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow.call(this);" : ""), "label-type");
|
||||||
|
|
||||||
if (driver()->indexMethods()) {
|
if ($index_algorithms) {
|
||||||
echo "<td class='idxopts" . ($show_options ? "" : " hidden") . "'>" . html_select("indexes[$j][algorithm]", array_merge(array(""), driver()->indexMethods()), $index['algorithm'], "label-method");
|
echo "<td class='idxopts" . ($show_options ? "" : " hidden") . "'>" . html_select("indexes[$j][algorithm]", array_merge(array(""), $index_algorithms), $index['algorithm'], "label-algorithm");
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<td>";
|
echo "<td>";
|
||||||
|
@@ -42,7 +42,7 @@ if (support("indexes") && driver()->supportsIndex($table_status)) {
|
|||||||
echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
|
echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
|
||||||
$indexes = indexes($TABLE);
|
$indexes = indexes($TABLE);
|
||||||
if ($indexes) {
|
if ($indexes) {
|
||||||
adminer()->tableIndexesPrint($indexes);
|
adminer()->tableIndexesPrint($indexes, $table_status);
|
||||||
}
|
}
|
||||||
echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
|
echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
|
||||||
}
|
}
|
||||||
|
@@ -8,10 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
class AdminerTableIndexesStructure extends Adminer\Plugin {
|
class AdminerTableIndexesStructure extends Adminer\Plugin {
|
||||||
|
|
||||||
/** Print table structure in tabular format
|
function tableIndexesPrint($indexes, $tableStatus): bool {
|
||||||
* @param Index[] $indexes data about all indexes on a table
|
|
||||||
*/
|
|
||||||
function tableIndexesPrint($indexes): bool {
|
|
||||||
echo "<table>\n";
|
echo "<table>\n";
|
||||||
echo "<thead><tr><th>" . Adminer\lang('Name') . "<th>" . Adminer\lang('Type') . "<th>" . Adminer\lang('Columns') . "</thead>\n";
|
echo "<thead><tr><th>" . Adminer\lang('Name') . "<th>" . Adminer\lang('Type') . "<th>" . Adminer\lang('Columns') . "</thead>\n";
|
||||||
foreach ($indexes as $name => $index) {
|
foreach ($indexes as $name => $index) {
|
||||||
|
Reference in New Issue
Block a user