updated to HttpAsyncRequest Structure

This commit is contained in:
kremsy 2017-03-26 20:21:23 +02:00
parent 8e664879d5
commit da94e8c588
3 changed files with 36 additions and 12 deletions

View File

@ -469,6 +469,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
// Update last updated time // Update last updated time
$map = $this->getMapByUid($mapInfo->uid); $map = $this->getMapByUid($mapInfo->uid);
if (!$map) { if (!$map) {
// TODO: improve this - error reports about not existing maps // TODO: improve this - error reports about not existing maps
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Map not in List after Insert!'); $this->maniaControl->getErrorHandler()->triggerDebugNotice('Map not in List after Insert!');

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Server; namespace ManiaControl\Server;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Logger; use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter; use ManiaControl\Utils\Formatter;
@ -81,11 +82,16 @@ class UsageReporter implements TimerListener {
$usageReport = json_encode($properties); $usageReport = json_encode($properties);
$url = ManiaControl::URL_WEBSERVICE . 'usagereport'; $url = ManiaControl::URL_WEBSERVICE . 'usagereport';
$this->maniaControl->getFileReader()->postData($url, function ($response, $error) {
$asyncRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncRequest->setContent($usageReport);
$asyncRequest->setCallable(function ($response, $error) {
$response = json_decode($response); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
Logger::logError('Error while Sending data: ' . print_r($error, true)); Logger::logError('Error while Sending data: ' . print_r($error, true));
} }
}, $usageReport); });
$asyncRequest->postData();
} }
} }

View File

@ -12,6 +12,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Files\AsynchronousFileReader; use ManiaControl\Files\AsynchronousFileReader;
use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Logger; use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
@ -368,16 +369,23 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$content = json_encode($properties); $content = json_encode($properties);
$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) use (
$url = self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey);
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncHttpRequest->setContent($content);
$asyncHttpRequest->setContentType($asyncHttpRequest::CONTENT_TYPE_JSON);
$asyncHttpRequest->setCallable(function ($json, $error) use (
&$player &$player
) { ) {
if ($error) { if ($error) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error' . $json);
return; return;
} }
@ -403,10 +411,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($data->data->message === 'invalid session') { if ($data->data->message === 'invalid session') {
unset($this->mxKarma['session']); unset($this->mxKarma['session']);
} else { } else {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error ' . $data->data->message . self::MX_KARMA_GET_MAP_RATING . $this->mxKarma['session']);
} }
} }
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); });
$asyncHttpRequest->postData();
} }
/** /**
@ -483,14 +493,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$content = json_encode($properties); $content = json_encode($properties);
$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) { $url = self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey);
$asyncRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncRequest->setContent($content);
$asyncRequest->setContentType($asyncRequest::CONTENT_TYPE_JSON);
$asyncRequest->setCallable(function ($json, $error) {
if ($error) { if ($error) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error ' . $json);
return; return;
} }
if ($data->success) { if ($data->success) {
@ -501,10 +516,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($data->data->message === "invalid session") { if ($data->data->message === "invalid session") {
unset($this->mxKarma['session']); unset($this->mxKarma['session']);
} else { } else {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error ' . $data->data->message . self::MX_KARMA_SAVE_VOTES . $this->mxKarma['session']);
} }
} }
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); });
$asyncRequest->postData();
} }
/** /**