Skip to content

Commit bf8b404

Browse files
committed
Merge branch 'QA_5_2'
2 parents c4d9095 + 20f1656 commit bf8b404

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ phpMyAdmin - ChangeLog
3232

3333
5.1.4 (not yet released)
3434
- issue #17287 Fixed sorting the database list with "statistics" enabled on "Data" column creates a PHP type error
35+
- issue #17368 Fix for invalid cache when losing access to config storage after it being cached
3536

3637
5.1.3 (2022-02-10)
3738
- issue #17308 Fix broken pagination links in the navigation sidebar

libraries/classes/UserPreferences.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use PhpMyAdmin\Config\ConfigFile;
88
use PhpMyAdmin\Config\Forms\User\UserFormList;
99
use PhpMyAdmin\ConfigStorage\Relation;
10+
use PhpMyAdmin\Dbal\DatabaseName;
1011

1112
use function __;
1213
use function array_flip;
1314
use function array_merge;
1415
use function basename;
16+
use function htmlspecialchars;
1517
use function http_build_query;
1618
use function is_array;
1719
use function json_decode;
@@ -120,7 +122,11 @@ public function save(array $config_array)
120122
$relationParameters = $this->relation->getRelationParameters();
121123
$server = $GLOBALS['server'] ?? $GLOBALS['cfg']['ServerDefault'];
122124
$cache_key = 'server_' . $server;
123-
if ($relationParameters->userPreferencesFeature === null || $relationParameters->user === null) {
125+
if (
126+
$relationParameters->userPreferencesFeature === null
127+
|| $relationParameters->user === null
128+
|| $relationParameters->db === null
129+
) {
124130
// no pmadb table, use session storage
125131
$_SESSION['userconfig'] = [
126132
'db' => $config_array,
@@ -165,17 +171,37 @@ public function save(array $config_array)
165171

166172
if (! $dbi->tryQuery($query, DatabaseInterface::CONNECT_CONTROL)) {
167173
$message = Message::error(__('Could not save configuration'));
168-
$message->addMessage(
169-
Message::rawError($dbi->getError(DatabaseInterface::CONNECT_CONTROL)),
170-
'<br><br>'
171-
);
174+
$message->addMessage(Message::error($dbi->getError(DatabaseInterface::CONNECT_CONTROL)), '<br><br>');
175+
if (! $this->hasAccessToDatabase($relationParameters->db)) {
176+
/**
177+
* When phpMyAdmin cached the configuration storage parameters, it checked if the database can be
178+
* accessed, so if it could not be accessed anymore, then the cache must be cleared as it's out of date.
179+
*
180+
* @psalm-suppress MixedArrayAssignment
181+
*/
182+
$_SESSION['relation'][$GLOBALS['server']] = [];
183+
$message->addMessage(Message::error(htmlspecialchars(
184+
__('The phpMyAdmin configuration storage database could not be accessed.')
185+
)), '<br><br>');
186+
}
172187

173188
return $message;
174189
}
175190

176191
return true;
177192
}
178193

194+
private function hasAccessToDatabase(DatabaseName $database): bool
195+
{
196+
$escapedDb = $GLOBALS['dbi']->escapeString($database->getName());
197+
$query = 'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \'' . $escapedDb . '\';';
198+
if ($GLOBALS['cfg']['Server']['DisableIS']) {
199+
$query = 'SHOW DATABASES LIKE \'' . Util::escapeMysqlWildcards($escapedDb) . '\';';
200+
}
201+
202+
return (bool) $GLOBALS['dbi']->fetchSingleRow($query, 'ASSOC', DatabaseInterface::CONNECT_CONTROL);
203+
}
204+
179205
/**
180206
* Returns a user preferences array filtered by $cfg['UserprefsDisallow']
181207
* (exclude list) and keys from user preferences form (allow list)

test/classes/UserPreferencesTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public function testLoad(): void
140140
*/
141141
public function testSave(): void
142142
{
143+
$GLOBALS['cfg']['Server']['DisableIS'] = true;
143144
$GLOBALS['server'] = 2;
144145
$_SESSION['relation'] = [];
145146
$_SESSION['relation'][$GLOBALS['server']] = RelationParameters::fromArray([])->toArray();
@@ -246,7 +247,8 @@ public function testSave(): void
246247

247248
$this->assertInstanceOf(Message::class, $result);
248249
$this->assertEquals(
249-
'Could not save configuration<br><br>err1',
250+
'Could not save configuration<br><br>err1'
251+
. '<br><br>The phpMyAdmin configuration storage database could not be accessed.',
250252
$result->getMessage()
251253
);
252254
}

0 commit comments

Comments
 (0)