diff --git a/libraries/classes/Controllers/Server/ReplicationController.php b/libraries/classes/Controllers/Server/ReplicationController.php
index 17a816554c..8d210a9ed4 100644
--- a/libraries/classes/Controllers/Server/ReplicationController.php
+++ b/libraries/classes/Controllers/Server/ReplicationController.php
@@ -87,12 +87,10 @@ class ReplicationController extends AbstractController
$request->getParsedBodyParam('sr_replica_skip_error') !== null,
(int) $srSkipErrorsCount,
$srReplicaControlParam,
- [
- 'username' => $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('username')),
- 'pma_pw' => $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('pma_pw')),
- 'hostname' => $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('hostname')),
- 'port' => (int) $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('text_port')),
- ]
+ $request->getParsedBodyParam('username', ''),
+ $request->getParsedBodyParam('pma_pw', ''),
+ $request->getParsedBodyParam('hostname', ''),
+ (int) $request->getParsedBodyParam('text_port')
);
}
diff --git a/libraries/classes/Replication.php b/libraries/classes/Replication.php
index ecbb9539b0..f7972e66ee 100644
--- a/libraries/classes/Replication.php
+++ b/libraries/classes/Replication.php
@@ -78,10 +78,10 @@ class Replication
* @return ResultInterface|false output of CHANGE MASTER mysql command
*/
public function replicaChangePrimary(
- $user,
- $password,
- $host,
- $port,
+ string $user,
+ string $password,
+ string $host,
+ int $port,
array $pos,
bool $stop,
bool $start,
@@ -93,10 +93,10 @@ class Replication
$out = $GLOBALS['dbi']->tryQuery(
'CHANGE MASTER TO ' .
- 'MASTER_HOST=\'' . $host . '\',' .
- 'MASTER_PORT=' . ($port * 1) . ',' .
- 'MASTER_USER=\'' . $user . '\',' .
- 'MASTER_PASSWORD=\'' . $password . '\',' .
+ 'MASTER_HOST=\'' . $GLOBALS['dbi']->escapeString($host) . '\',' .
+ 'MASTER_PORT=' . $port . ',' .
+ 'MASTER_USER=\'' . $GLOBALS['dbi']->escapeString($user) . '\',' .
+ 'MASTER_PASSWORD=\'' . $GLOBALS['dbi']->escapeString($password) . '\',' .
'MASTER_LOG_FILE=\'' . $pos['File'] . '\',' .
'MASTER_LOG_POS=' . $pos['Position'] . ';',
$link
diff --git a/libraries/classes/ReplicationGui.php b/libraries/classes/ReplicationGui.php
index 0174c9da0a..8c72de9e98 100644
--- a/libraries/classes/ReplicationGui.php
+++ b/libraries/classes/ReplicationGui.php
@@ -427,7 +427,10 @@ class ReplicationGui
bool $srReplicaSkipError,
int $srSkipErrorsCount,
?string $srReplicaControlParam,
- array $sr
+ string $username,
+ string $pmaPassword,
+ string $hostname,
+ int $port
): void {
if (! $srTakeAction) {
return;
@@ -445,7 +448,7 @@ class ReplicationGui
. ' $cfg[\'AllowArbitraryServer\'] in phpMyAdmin configuration.'
);
} elseif ($replicaChangePrimary) {
- $result = $this->handleRequestForReplicaChangePrimary($sr);
+ $result = $this->handleRequestForReplicaChangePrimary($username, $pmaPassword, $hostname, $port);
} elseif ($srReplicaServerControl) {
$result = $this->handleRequestForReplicaServerControl($srReplicaAction, $srReplicaControlParam);
$refresh = true;
@@ -493,29 +496,33 @@ class ReplicationGui
unset($refresh);
}
- public function handleRequestForReplicaChangePrimary(array $sr): bool
- {
- $_SESSION['replication']['m_username'] = $sr['username'];
- $_SESSION['replication']['m_password'] = $sr['pma_pw'];
- $_SESSION['replication']['m_hostname'] = $sr['hostname'];
- $_SESSION['replication']['m_port'] = $sr['port'];
+ public function handleRequestForReplicaChangePrimary(
+ string $username,
+ string $pmaPassword,
+ string $hostname,
+ int $port
+ ): bool {
+ $_SESSION['replication']['m_username'] = $username;
+ $_SESSION['replication']['m_password'] = $pmaPassword;
+ $_SESSION['replication']['m_hostname'] = $hostname;
+ $_SESSION['replication']['m_port'] = $port;
$_SESSION['replication']['m_correct'] = '';
$_SESSION['replication']['sr_action_status'] = 'error';
$_SESSION['replication']['sr_action_info'] = __('Unknown error');
// Attempt to connect to the new primary server
$linkToPrimary = $this->replication->connectToPrimary(
- $sr['username'],
- $sr['pma_pw'],
- $sr['hostname'],
- $sr['port']
+ $username,
+ $pmaPassword,
+ $hostname,
+ $port
);
if (! $linkToPrimary) {
$_SESSION['replication']['sr_action_status'] = 'error';
$_SESSION['replication']['sr_action_info'] = sprintf(
__('Unable to connect to primary %s.'),
- htmlspecialchars($sr['hostname'])
+ htmlspecialchars($hostname)
);
} else {
// Read the current primary position
@@ -531,10 +538,10 @@ class ReplicationGui
if (
! $this->replication->replicaChangePrimary(
- $sr['username'],
- $sr['pma_pw'],
- $sr['hostname'],
- $sr['port'],
+ $username,
+ $pmaPassword,
+ $hostname,
+ $port,
$position,
true,
false,
@@ -547,7 +554,7 @@ class ReplicationGui
$_SESSION['replication']['sr_action_status'] = 'success';
$_SESSION['replication']['sr_action_info'] = sprintf(
__('Primary server changed successfully to %s.'),
- htmlspecialchars($sr['hostname'])
+ htmlspecialchars($hostname)
);
}
}
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index a45bcaef22..e567bc024d 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1470,6 +1470,26 @@ parameters:
count: 1
path: libraries/classes/Controllers/Server/DatabasesController.php
+ -
+ message: "#^Cannot cast mixed to int\\.$#"
+ count: 1
+ path: libraries/classes/Controllers/Server/ReplicationController.php
+
+ -
+ message: "#^Parameter \\#10 \\$hostname of method PhpMyAdmin\\\\ReplicationGui\\:\\:handleControlRequest\\(\\) expects string, mixed given\\.$#"
+ count: 1
+ path: libraries/classes/Controllers/Server/ReplicationController.php
+
+ -
+ message: "#^Parameter \\#8 \\$username of method PhpMyAdmin\\\\ReplicationGui\\:\\:handleControlRequest\\(\\) expects string, mixed given\\.$#"
+ count: 1
+ path: libraries/classes/Controllers/Server/ReplicationController.php
+
+ -
+ message: "#^Parameter \\#9 \\$pmaPassword of method PhpMyAdmin\\\\ReplicationGui\\:\\:handleControlRequest\\(\\) expects string, mixed given\\.$#"
+ count: 1
+ path: libraries/classes/Controllers/Server/ReplicationController.php
+
-
message: "#^Method PhpMyAdmin\\\\Controllers\\\\Server\\\\Status\\\\Processes\\\\KillController\\:\\:__invoke\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
@@ -7130,16 +7150,6 @@ parameters:
count: 1
path: libraries/classes/ReplicationGui.php
- -
- message: "#^Method PhpMyAdmin\\\\ReplicationGui\\:\\:handleControlRequest\\(\\) has parameter \\$sr with no value type specified in iterable type array\\.$#"
- count: 1
- path: libraries/classes/ReplicationGui.php
-
- -
- message: "#^Method PhpMyAdmin\\\\ReplicationGui\\:\\:handleRequestForReplicaChangePrimary\\(\\) has parameter \\$sr with no value type specified in iterable type array\\.$#"
- count: 1
- path: libraries/classes/ReplicationGui.php
-
-
message: "#^Only numeric types are allowed in \\+, int\\<0, max\\>\\|false given on the left side\\.$#"
count: 1
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 781109bfd7..8ff96fc4b7 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -2802,12 +2802,11 @@
-
+
$replicaInfo['status']
- $request->getParsedBodyParam('hostname')
- $request->getParsedBodyParam('pma_pw')
- $request->getParsedBodyParam('text_port')
- $request->getParsedBodyParam('username')
+ $request->getParsedBodyParam('hostname', '')
+ $request->getParsedBodyParam('pma_pw', '')
+ $request->getParsedBodyParam('username', '')
$GLOBALS['errorUrl']
@@ -12099,20 +12098,10 @@
-
+
$database
$errorMessage
$serverReplicationVariable
- $sr['hostname']
- $sr['hostname']
- $sr['hostname']
- $sr['hostname']
- $sr['pma_pw']
- $sr['pma_pw']
- $sr['port']
- $sr['port']
- $sr['username']
- $sr['username']
$successMessage
$val['Type']
$val['Type']
@@ -12151,11 +12140,7 @@
$_SESSION['replication']['sr_action_status']
$_SESSION['replication']['sr_action_status']
-
- $_SESSION['replication']['m_hostname']
- $_SESSION['replication']['m_password']
- $_SESSION['replication']['m_port']
- $_SESSION['replication']['m_username']
+
$database
$errorMessage
$linkToPrimary