improved error handling and query param binding
This commit is contained in:
parent
0012cb8ab9
commit
3b4b2f2cce
@ -17,7 +17,6 @@ use ManiaControl\Callbacks\CallbackListener;
|
|||||||
use ManiaControl\Callbacks\Callbacks;
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,10 +109,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$serverId = $this->maniaControl->server->index;
|
$serverIndex = $this->maniaControl->server->index;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "` WHERE serverIndex = " . $serverId . ";";
|
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`
|
||||||
$result = $mysqli->query($query);
|
WHERE serverIndex = {$serverIndex};";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
@ -128,17 +128,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
if (!$loadedSettings) {
|
if (empty($loadedSettings)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return $this->maniaControl->client->setModeScriptSettings($loadedSettings);
|
||||||
$this->maniaControl->client->setModeScriptSettings($loadedSettings);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
trigger_error('Error occurred: ' . $e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -330,18 +324,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||||
if (!$newSettings) {
|
if (empty($newSettings)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
$this->maniaControl->client->setModeScriptSettings($newSettings);
|
||||||
$this->maniaControl->client->setModeScriptSettings($newSettings);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
//TODO temp added 19.04.2014
|
|
||||||
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 416 ScriptSettings.php" . $e->getMessage(), $e);
|
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save Settings into Database
|
// Save Settings into Database
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
@ -358,6 +345,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$settingName = null;
|
||||||
|
$settingValue = null;
|
||||||
|
$statement->bind_param('iss', $this->maniaControl->server->index, $settingName, $settingValue);
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
$settingsCount = count($newSettings);
|
$settingsCount = count($newSettings);
|
||||||
@ -373,7 +363,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add To Database
|
// Add To Database
|
||||||
$statement->bind_param('iss', $this->maniaControl->server->index, $setting, $value);
|
$settingName = $setting;
|
||||||
|
$settingValue = $value;
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if ($statement->error) {
|
||||||
trigger_error($statement->error);
|
trigger_error($statement->error);
|
||||||
|
Loading…
Reference in New Issue
Block a user