improved master admins config loading

This commit is contained in:
Steffen Schröder 2014-05-27 10:59:14 +02:00
parent cd9b522bfa
commit 48fed27ad0

View File

@ -146,6 +146,13 @@ class AuthenticationManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function updateMasterAdmins() { private function updateMasterAdmins() {
$masterAdminsElements = $this->maniaControl->config->xpath('masteradmins');
if (!$masterAdminsElements) {
$this->maniaControl->log("Missing MasterAdmins configuration!", true);
return false;
}
$masterAdminsElement = $masterAdminsElements[0];
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
// Remove all MasterAdmins // Remove all MasterAdmins
@ -166,8 +173,8 @@ class AuthenticationManager implements CallbackListener {
} }
$adminStatement->close(); $adminStatement->close();
// Set MasterAdmins // Set configured MasterAdmins
$masterAdmins = $this->maniaControl->config->masteradmins->xpath('login'); $loginElements = $masterAdminsElement->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` ( $adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`, `login`,
`authLevel` `authLevel`
@ -181,8 +188,8 @@ class AuthenticationManager implements CallbackListener {
return false; return false;
} }
$success = true; $success = true;
foreach ($masterAdmins as $masterAdmin) { foreach ($loginElements as $loginElement) {
$login = (string)$masterAdmin; $login = (string)$loginElement;
$adminStatement->bind_param('si', $login, $masterAdminLevel); $adminStatement->bind_param('si', $login, $masterAdminLevel);
$adminStatement->execute(); $adminStatement->execute();
if ($adminStatement->error) { if ($adminStatement->error) {
@ -191,6 +198,7 @@ class AuthenticationManager implements CallbackListener {
} }
} }
$adminStatement->close(); $adminStatement->close();
return $success; return $success;
} }