Skip to content

Commit 08deb34

Browse files
Merge pull request #18911 from kamil-tekiela/Refactor-Relation-2
Refactor relation 2
2 parents f42bd22 + a4e4c4b commit 08deb34

4 files changed

Lines changed: 56 additions & 69 deletions

File tree

‎src/ConfigStorage/Relation.php‎

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -154,52 +154,50 @@ private function fillRelationParamsWithTableNames(array $relationParams): array|
154154
}
155155

156156
$config = Config::getInstance();
157-
$tabQuery = 'SHOW TABLES FROM '
158-
. Util::backquote($config->selectedServer['pmadb']);
159-
$tableRes = $this->dbi->tryQueryAsControlUser($tabQuery);
160-
if ($tableRes === false) {
157+
$tables = $this->dbi->getTables($config->selectedServer['pmadb'], Connection::TYPE_CONTROL);
158+
if ($tables === []) {
161159
return null;
162160
}
163161

164-
while ($currTable = $tableRes->fetchRow()) {
165-
if ($currTable[0] == $config->selectedServer['bookmarktable']) {
166-
$relationParams['bookmark'] = (string) $currTable[0];
167-
} elseif ($currTable[0] == $config->selectedServer['relation']) {
168-
$relationParams['relation'] = (string) $currTable[0];
169-
} elseif ($currTable[0] == $config->selectedServer['table_info']) {
170-
$relationParams['table_info'] = (string) $currTable[0];
171-
} elseif ($currTable[0] == $config->selectedServer['table_coords']) {
172-
$relationParams['table_coords'] = (string) $currTable[0];
173-
} elseif ($currTable[0] == $config->selectedServer['column_info']) {
174-
$relationParams['column_info'] = (string) $currTable[0];
175-
} elseif ($currTable[0] == $config->selectedServer['pdf_pages']) {
176-
$relationParams['pdf_pages'] = (string) $currTable[0];
177-
} elseif ($currTable[0] == $config->selectedServer['history']) {
178-
$relationParams['history'] = (string) $currTable[0];
179-
} elseif ($currTable[0] == $config->selectedServer['recent']) {
180-
$relationParams['recent'] = (string) $currTable[0];
181-
} elseif ($currTable[0] == $config->selectedServer['favorite']) {
182-
$relationParams['favorite'] = (string) $currTable[0];
183-
} elseif ($currTable[0] == $config->selectedServer['table_uiprefs']) {
184-
$relationParams['table_uiprefs'] = (string) $currTable[0];
185-
} elseif ($currTable[0] == $config->selectedServer['tracking']) {
186-
$relationParams['tracking'] = (string) $currTable[0];
187-
} elseif ($currTable[0] == $config->selectedServer['userconfig']) {
188-
$relationParams['userconfig'] = (string) $currTable[0];
189-
} elseif ($currTable[0] == $config->selectedServer['users']) {
190-
$relationParams['users'] = (string) $currTable[0];
191-
} elseif ($currTable[0] == $config->selectedServer['usergroups']) {
192-
$relationParams['usergroups'] = (string) $currTable[0];
193-
} elseif ($currTable[0] == $config->selectedServer['navigationhiding']) {
194-
$relationParams['navigationhiding'] = (string) $currTable[0];
195-
} elseif ($currTable[0] == $config->selectedServer['savedsearches']) {
196-
$relationParams['savedsearches'] = (string) $currTable[0];
197-
} elseif ($currTable[0] == $config->selectedServer['central_columns']) {
198-
$relationParams['central_columns'] = (string) $currTable[0];
199-
} elseif ($currTable[0] == $config->selectedServer['designer_settings']) {
200-
$relationParams['designer_settings'] = (string) $currTable[0];
201-
} elseif ($currTable[0] == $config->selectedServer['export_templates']) {
202-
$relationParams['export_templates'] = (string) $currTable[0];
162+
foreach ($tables as $table) {
163+
if ($table == $config->selectedServer['bookmarktable']) {
164+
$relationParams['bookmark'] = $table;
165+
} elseif ($table == $config->selectedServer['relation']) {
166+
$relationParams['relation'] = $table;
167+
} elseif ($table == $config->selectedServer['table_info']) {
168+
$relationParams['table_info'] = $table;
169+
} elseif ($table == $config->selectedServer['table_coords']) {
170+
$relationParams['table_coords'] = $table;
171+
} elseif ($table == $config->selectedServer['column_info']) {
172+
$relationParams['column_info'] = $table;
173+
} elseif ($table == $config->selectedServer['pdf_pages']) {
174+
$relationParams['pdf_pages'] = $table;
175+
} elseif ($table == $config->selectedServer['history']) {
176+
$relationParams['history'] = $table;
177+
} elseif ($table == $config->selectedServer['recent']) {
178+
$relationParams['recent'] = $table;
179+
} elseif ($table == $config->selectedServer['favorite']) {
180+
$relationParams['favorite'] = $table;
181+
} elseif ($table == $config->selectedServer['table_uiprefs']) {
182+
$relationParams['table_uiprefs'] = $table;
183+
} elseif ($table == $config->selectedServer['tracking']) {
184+
$relationParams['tracking'] = $table;
185+
} elseif ($table == $config->selectedServer['userconfig']) {
186+
$relationParams['userconfig'] = $table;
187+
} elseif ($table == $config->selectedServer['users']) {
188+
$relationParams['users'] = $table;
189+
} elseif ($table == $config->selectedServer['usergroups']) {
190+
$relationParams['usergroups'] = $table;
191+
} elseif ($table == $config->selectedServer['navigationhiding']) {
192+
$relationParams['navigationhiding'] = $table;
193+
} elseif ($table == $config->selectedServer['savedsearches']) {
194+
$relationParams['savedsearches'] = $table;
195+
} elseif ($table == $config->selectedServer['central_columns']) {
196+
$relationParams['central_columns'] = $table;
197+
} elseif ($table == $config->selectedServer['designer_settings']) {
198+
$relationParams['designer_settings'] = $table;
199+
} elseif ($table == $config->selectedServer['export_templates']) {
200+
$relationParams['export_templates'] = $table;
203201
}
204202
}
205203

@@ -249,7 +247,6 @@ private function checkRelationsParam(): array
249247
|| $config->selectedServer['pmadb'] === ''
250248
|| ! $this->dbi->selectDb($config->selectedServer['pmadb'], Connection::TYPE_CONTROL)
251249
) {
252-
// No server selected -> no bookmark table
253250
$config->selectedServer['pmadb'] = '';
254251

255252
return $relationParams;
@@ -258,22 +255,13 @@ private function checkRelationsParam(): array
258255
$relationParams['user'] = $config->selectedServer['user'];
259256
$relationParams['db'] = $config->selectedServer['pmadb'];
260257

261-
// Now I just check if all tables that i need are present so I can for
262-
// example enable relations but not pdf...
263-
// I was thinking of checking if they have all required columns but I
264-
// fear it might be too slow
265-
266258
$relationParamsFilled = $this->fillRelationParamsWithTableNames($relationParams);
267259

268260
if ($relationParamsFilled === null) {
269-
// query failed ... ?
270261
return $relationParams;
271262
}
272263

273-
// Filling did success
274-
$relationParams = $relationParamsFilled;
275-
276-
$relationParams = $this->checkTableAccess($relationParams);
264+
$relationParams = $this->checkTableAccess($relationParamsFilled);
277265

278266
$allWorks = true;
279267
foreach ($workToTable as $work => $table) {
@@ -1553,8 +1541,7 @@ public function fixPmaTables(string $db, bool $create = true): void
15531541

15541542
$config->selectedServer['pmadb'] = $db;
15551543

1556-
//NOTE: I am unsure why we do that, as it defeats the purpose of the session cache
1557-
// Unset the cache
1544+
// Unset the cache as new tables might have been added
15581545
self::$cache = null;
15591546
// Fill back the cache
15601547
$this->getRelationParameters();

‎src/Favorites/RecentFavoriteTables.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function getTables(): array
122122
private function getFromDb(): array
123123
{
124124
// Read from phpMyAdmin database, if recent tables is not in session
125-
$sqlQuery = ' SELECT `tables` FROM ' . $this->getPmaTable()
125+
$sqlQuery = 'SELECT `tables` FROM ' . $this->getPmaTable()
126126
. ' WHERE `username` = '
127127
. $this->dbi->quoteString(Config::getInstance()->selectedServer['user'], Connection::TYPE_CONTROL);
128128

‎tests/classes/ConfigStorage/RelationTest.php‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function testFixPmaTablesNormal(): void
234234
);
235235

236236
$dummyDbi->addResult(
237-
'SHOW TABLES FROM `db_pma`',
237+
'SHOW TABLES FROM `db_pma`;',
238238
[['pma__userconfig']],
239239
['Tables_in_db_pma'],
240240
);
@@ -296,7 +296,7 @@ public function testFixPmaTablesNormalFixTables(): void
296296
);
297297

298298
$dummyDbi->addResult(
299-
'SHOW TABLES FROM `db_pma`',
299+
'SHOW TABLES FROM `db_pma`;',
300300
[['pma__userconfig']],
301301
['Tables_in_db_pma'],
302302
);
@@ -573,7 +573,7 @@ public function testFixPmaTablesNormalFixTablesWithCustomOverride(): void
573573
);
574574

575575
$dummyDbi->addResult(
576-
'SHOW TABLES FROM `db_pma`',
576+
'SHOW TABLES FROM `db_pma`;',
577577
[
578578
['pma__userconfig'],
579579
// This is important as it tricks default existing table detection
@@ -897,7 +897,7 @@ public function testCreatePmaDatabase(): void
897897
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', true);
898898

899899
$dummyDbi->addResult(
900-
'SHOW TABLES FROM `phpmyadmin`',
900+
'SHOW TABLES FROM `phpmyadmin`;',
901901
[],
902902
);
903903
$dummyDbi->addSelectDb('phpmyadmin');
@@ -1483,7 +1483,7 @@ public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServer(): v
14831483
);
14841484

14851485
$dummyDbi->addResult(
1486-
'SHOW TABLES FROM `phpmyadmin`',
1486+
'SHOW TABLES FROM `phpmyadmin`;',
14871487
[['pma__userconfig']],
14881488
['Tables_in_phpmyadmin'],
14891489
);
@@ -1570,7 +1570,7 @@ public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerNotWo
15701570
);
15711571

15721572
$dummyDbi->addResult(
1573-
'SHOW TABLES FROM `phpmyadmin`',
1573+
'SHOW TABLES FROM `phpmyadmin`;',
15741574
[['pma__userconfig']],
15751575
['Tables_in_phpmyadmin'],
15761576
);
@@ -1656,7 +1656,7 @@ public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerOverr
16561656
);
16571657

16581658
$dummyDbi->addResult(
1659-
'SHOW TABLES FROM `PMA-storage`',
1659+
'SHOW TABLES FROM `PMA-storage`;',
16601660
[['pma__userconfig_custom', 'pma__usergroups']],
16611661
['Tables_in_PMA-storage'],
16621662
);
@@ -1681,7 +1681,7 @@ public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerOverr
16811681
$dummyDbi->assertAllSelectsConsumed();
16821682

16831683
$dummyDbi->addResult(
1684-
'SHOW TABLES FROM `PMA-storage`',
1684+
'SHOW TABLES FROM `PMA-storage`;',
16851685
[['pma__userconfig_custom', 'pma__usergroups']],
16861686
['Tables_in_PMA-storage'],
16871687
);
@@ -1766,7 +1766,7 @@ public function testInitRelationParamsDisabledTracking(): void
17661766
['Tables_in_PMA-storage'],
17671767
);
17681768
$dummyDbi->addResult(
1769-
'SHOW TABLES FROM `PMA-storage`',
1769+
'SHOW TABLES FROM `PMA-storage`;',
17701770
[
17711771
['pma__tracking'],
17721772
],
@@ -1796,7 +1796,7 @@ public function testInitRelationParamsDisabledTracking(): void
17961796
$dummyDbi->assertAllSelectsConsumed();
17971797

17981798
$dummyDbi->addResult(
1799-
'SHOW TABLES FROM `PMA-storage`',
1799+
'SHOW TABLES FROM `PMA-storage`;',
18001800
[
18011801
[
18021802
'pma__userconfig_custom',
@@ -1888,7 +1888,7 @@ public function testInitRelationParamsDisabledTrackingOthersExist(): void
18881888
);
18891889

18901890
$dummyDbi->addResult(
1891-
'SHOW TABLES FROM `PMA-storage`',
1891+
'SHOW TABLES FROM `PMA-storage`;',
18921892
[
18931893
['pma__favorite_custom'],
18941894
],

‎tests/classes/Stubs/DbiDummy.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ private function init(): void
852852
'result' => [['utf8_general_ci']],
853853
],
854854
['query' => 'SELECT @@collation_database', 'columns' => ['@@collation_database'], 'result' => [['bar']]],
855-
['query' => 'SHOW TABLES FROM `phpmyadmin`', 'result' => []],
855+
['query' => 'SHOW TABLES FROM `phpmyadmin`;', 'result' => []],
856856
[
857857
'query' => 'SELECT tracking_active FROM `pmadb`.`tracking`' .
858858
" WHERE db_name = 'pma_test_db'" .

0 commit comments

Comments
 (0)