Merge pull request #18911 from kamil-tekiela/Refactor-Relation-2
Refactor relation 2
This commit is contained in:
commit
08deb34b05
@ -154,52 +154,50 @@ class Relation
|
||||
}
|
||||
|
||||
$config = Config::getInstance();
|
||||
$tabQuery = 'SHOW TABLES FROM '
|
||||
. Util::backquote($config->selectedServer['pmadb']);
|
||||
$tableRes = $this->dbi->tryQueryAsControlUser($tabQuery);
|
||||
if ($tableRes === false) {
|
||||
$tables = $this->dbi->getTables($config->selectedServer['pmadb'], Connection::TYPE_CONTROL);
|
||||
if ($tables === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
while ($currTable = $tableRes->fetchRow()) {
|
||||
if ($currTable[0] == $config->selectedServer['bookmarktable']) {
|
||||
$relationParams['bookmark'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['relation']) {
|
||||
$relationParams['relation'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['table_info']) {
|
||||
$relationParams['table_info'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['table_coords']) {
|
||||
$relationParams['table_coords'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['column_info']) {
|
||||
$relationParams['column_info'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['pdf_pages']) {
|
||||
$relationParams['pdf_pages'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['history']) {
|
||||
$relationParams['history'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['recent']) {
|
||||
$relationParams['recent'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['favorite']) {
|
||||
$relationParams['favorite'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['table_uiprefs']) {
|
||||
$relationParams['table_uiprefs'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['tracking']) {
|
||||
$relationParams['tracking'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['userconfig']) {
|
||||
$relationParams['userconfig'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['users']) {
|
||||
$relationParams['users'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['usergroups']) {
|
||||
$relationParams['usergroups'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['navigationhiding']) {
|
||||
$relationParams['navigationhiding'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['savedsearches']) {
|
||||
$relationParams['savedsearches'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['central_columns']) {
|
||||
$relationParams['central_columns'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['designer_settings']) {
|
||||
$relationParams['designer_settings'] = (string) $currTable[0];
|
||||
} elseif ($currTable[0] == $config->selectedServer['export_templates']) {
|
||||
$relationParams['export_templates'] = (string) $currTable[0];
|
||||
foreach ($tables as $table) {
|
||||
if ($table == $config->selectedServer['bookmarktable']) {
|
||||
$relationParams['bookmark'] = $table;
|
||||
} elseif ($table == $config->selectedServer['relation']) {
|
||||
$relationParams['relation'] = $table;
|
||||
} elseif ($table == $config->selectedServer['table_info']) {
|
||||
$relationParams['table_info'] = $table;
|
||||
} elseif ($table == $config->selectedServer['table_coords']) {
|
||||
$relationParams['table_coords'] = $table;
|
||||
} elseif ($table == $config->selectedServer['column_info']) {
|
||||
$relationParams['column_info'] = $table;
|
||||
} elseif ($table == $config->selectedServer['pdf_pages']) {
|
||||
$relationParams['pdf_pages'] = $table;
|
||||
} elseif ($table == $config->selectedServer['history']) {
|
||||
$relationParams['history'] = $table;
|
||||
} elseif ($table == $config->selectedServer['recent']) {
|
||||
$relationParams['recent'] = $table;
|
||||
} elseif ($table == $config->selectedServer['favorite']) {
|
||||
$relationParams['favorite'] = $table;
|
||||
} elseif ($table == $config->selectedServer['table_uiprefs']) {
|
||||
$relationParams['table_uiprefs'] = $table;
|
||||
} elseif ($table == $config->selectedServer['tracking']) {
|
||||
$relationParams['tracking'] = $table;
|
||||
} elseif ($table == $config->selectedServer['userconfig']) {
|
||||
$relationParams['userconfig'] = $table;
|
||||
} elseif ($table == $config->selectedServer['users']) {
|
||||
$relationParams['users'] = $table;
|
||||
} elseif ($table == $config->selectedServer['usergroups']) {
|
||||
$relationParams['usergroups'] = $table;
|
||||
} elseif ($table == $config->selectedServer['navigationhiding']) {
|
||||
$relationParams['navigationhiding'] = $table;
|
||||
} elseif ($table == $config->selectedServer['savedsearches']) {
|
||||
$relationParams['savedsearches'] = $table;
|
||||
} elseif ($table == $config->selectedServer['central_columns']) {
|
||||
$relationParams['central_columns'] = $table;
|
||||
} elseif ($table == $config->selectedServer['designer_settings']) {
|
||||
$relationParams['designer_settings'] = $table;
|
||||
} elseif ($table == $config->selectedServer['export_templates']) {
|
||||
$relationParams['export_templates'] = $table;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +247,6 @@ class Relation
|
||||
|| $config->selectedServer['pmadb'] === ''
|
||||
|| ! $this->dbi->selectDb($config->selectedServer['pmadb'], Connection::TYPE_CONTROL)
|
||||
) {
|
||||
// No server selected -> no bookmark table
|
||||
$config->selectedServer['pmadb'] = '';
|
||||
|
||||
return $relationParams;
|
||||
@ -258,22 +255,13 @@ class Relation
|
||||
$relationParams['user'] = $config->selectedServer['user'];
|
||||
$relationParams['db'] = $config->selectedServer['pmadb'];
|
||||
|
||||
// Now I just check if all tables that i need are present so I can for
|
||||
// example enable relations but not pdf...
|
||||
// I was thinking of checking if they have all required columns but I
|
||||
// fear it might be too slow
|
||||
|
||||
$relationParamsFilled = $this->fillRelationParamsWithTableNames($relationParams);
|
||||
|
||||
if ($relationParamsFilled === null) {
|
||||
// query failed ... ?
|
||||
return $relationParams;
|
||||
}
|
||||
|
||||
// Filling did success
|
||||
$relationParams = $relationParamsFilled;
|
||||
|
||||
$relationParams = $this->checkTableAccess($relationParams);
|
||||
$relationParams = $this->checkTableAccess($relationParamsFilled);
|
||||
|
||||
$allWorks = true;
|
||||
foreach ($workToTable as $work => $table) {
|
||||
@ -1553,8 +1541,7 @@ class Relation
|
||||
|
||||
$config->selectedServer['pmadb'] = $db;
|
||||
|
||||
//NOTE: I am unsure why we do that, as it defeats the purpose of the session cache
|
||||
// Unset the cache
|
||||
// Unset the cache as new tables might have been added
|
||||
self::$cache = null;
|
||||
// Fill back the cache
|
||||
$this->getRelationParameters();
|
||||
|
||||
@ -122,7 +122,7 @@ class RecentFavoriteTables
|
||||
private function getFromDb(): array
|
||||
{
|
||||
// Read from phpMyAdmin database, if recent tables is not in session
|
||||
$sqlQuery = ' SELECT `tables` FROM ' . $this->getPmaTable()
|
||||
$sqlQuery = 'SELECT `tables` FROM ' . $this->getPmaTable()
|
||||
. ' WHERE `username` = '
|
||||
. $this->dbi->quoteString(Config::getInstance()->selectedServer['user'], Connection::TYPE_CONTROL);
|
||||
|
||||
|
||||
@ -234,7 +234,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `db_pma`',
|
||||
'SHOW TABLES FROM `db_pma`;',
|
||||
[['pma__userconfig']],
|
||||
['Tables_in_db_pma'],
|
||||
);
|
||||
@ -296,7 +296,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `db_pma`',
|
||||
'SHOW TABLES FROM `db_pma`;',
|
||||
[['pma__userconfig']],
|
||||
['Tables_in_db_pma'],
|
||||
);
|
||||
@ -573,7 +573,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `db_pma`',
|
||||
'SHOW TABLES FROM `db_pma`;',
|
||||
[
|
||||
['pma__userconfig'],
|
||||
// This is important as it tricks default existing table detection
|
||||
@ -897,7 +897,7 @@ class RelationTest extends AbstractTestCase
|
||||
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', true);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `phpmyadmin`',
|
||||
'SHOW TABLES FROM `phpmyadmin`;',
|
||||
[],
|
||||
);
|
||||
$dummyDbi->addSelectDb('phpmyadmin');
|
||||
@ -1483,7 +1483,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `phpmyadmin`',
|
||||
'SHOW TABLES FROM `phpmyadmin`;',
|
||||
[['pma__userconfig']],
|
||||
['Tables_in_phpmyadmin'],
|
||||
);
|
||||
@ -1570,7 +1570,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `phpmyadmin`',
|
||||
'SHOW TABLES FROM `phpmyadmin`;',
|
||||
[['pma__userconfig']],
|
||||
['Tables_in_phpmyadmin'],
|
||||
);
|
||||
@ -1656,7 +1656,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `PMA-storage`',
|
||||
'SHOW TABLES FROM `PMA-storage`;',
|
||||
[['pma__userconfig_custom', 'pma__usergroups']],
|
||||
['Tables_in_PMA-storage'],
|
||||
);
|
||||
@ -1681,7 +1681,7 @@ class RelationTest extends AbstractTestCase
|
||||
$dummyDbi->assertAllSelectsConsumed();
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `PMA-storage`',
|
||||
'SHOW TABLES FROM `PMA-storage`;',
|
||||
[['pma__userconfig_custom', 'pma__usergroups']],
|
||||
['Tables_in_PMA-storage'],
|
||||
);
|
||||
@ -1766,7 +1766,7 @@ class RelationTest extends AbstractTestCase
|
||||
['Tables_in_PMA-storage'],
|
||||
);
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `PMA-storage`',
|
||||
'SHOW TABLES FROM `PMA-storage`;',
|
||||
[
|
||||
['pma__tracking'],
|
||||
],
|
||||
@ -1796,7 +1796,7 @@ class RelationTest extends AbstractTestCase
|
||||
$dummyDbi->assertAllSelectsConsumed();
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `PMA-storage`',
|
||||
'SHOW TABLES FROM `PMA-storage`;',
|
||||
[
|
||||
[
|
||||
'pma__userconfig_custom',
|
||||
@ -1888,7 +1888,7 @@ class RelationTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW TABLES FROM `PMA-storage`',
|
||||
'SHOW TABLES FROM `PMA-storage`;',
|
||||
[
|
||||
['pma__favorite_custom'],
|
||||
],
|
||||
|
||||
@ -852,7 +852,7 @@ class DbiDummy implements DbiExtension
|
||||
'result' => [['utf8_general_ci']],
|
||||
],
|
||||
['query' => 'SELECT @@collation_database', 'columns' => ['@@collation_database'], 'result' => [['bar']]],
|
||||
['query' => 'SHOW TABLES FROM `phpmyadmin`', 'result' => []],
|
||||
['query' => 'SHOW TABLES FROM `phpmyadmin`;', 'result' => []],
|
||||
[
|
||||
'query' => 'SELECT tracking_active FROM `pmadb`.`tracking`' .
|
||||
" WHERE db_name = 'pma_test_db'" .
|
||||
|
||||
Loading…
Reference in New Issue
Block a user