mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Be less dependent on AsyncTask->onCompletion() Server parameter
this is going to get removed soon.
This commit is contained in:
@ -53,6 +53,10 @@ class AutoUpdater{
|
||||
}
|
||||
}
|
||||
|
||||
public function checkUpdateError(string $error) : void{
|
||||
$this->server->getLogger()->debug("[AutoUpdater] Async update check failed due to \"$error\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback used at the end of the update checking task
|
||||
*
|
||||
@ -146,7 +150,7 @@ class AutoUpdater{
|
||||
* Schedules an AsyncTask to check for an update.
|
||||
*/
|
||||
public function doCheck(){
|
||||
$this->server->getAsyncPool()->submitTask(new UpdateCheckTask($this->endpoint, $this->getChannel()));
|
||||
$this->server->getAsyncPool()->submitTask(new UpdateCheckTask($this, $this->endpoint, $this->getChannel()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,8 @@ class UpdateCheckTask extends AsyncTask{
|
||||
/** @var string */
|
||||
private $error = "Unknown error";
|
||||
|
||||
public function __construct(string $endpoint, string $channel){
|
||||
public function __construct(AutoUpdater $updater, string $endpoint, string $channel){
|
||||
$this->storeLocal($updater);
|
||||
$this->endpoint = $endpoint;
|
||||
$this->channel = $channel;
|
||||
}
|
||||
@ -72,16 +73,12 @@ class UpdateCheckTask extends AsyncTask{
|
||||
}
|
||||
|
||||
public function onCompletion(Server $server){
|
||||
if($this->error !== ""){
|
||||
$server->getLogger()->debug("[AutoUpdater] Async update check failed due to \"$this->error\"");
|
||||
/** @var AutoUpdater $updater */
|
||||
$updater = $this->fetchLocal();
|
||||
if($this->hasResult()){
|
||||
$updater->checkUpdateCallback($this->getResult());
|
||||
}else{
|
||||
$updateInfo = $this->getResult();
|
||||
if(is_array($updateInfo)){
|
||||
$server->getUpdater()->checkUpdateCallback($updateInfo);
|
||||
}else{
|
||||
$server->getLogger()->debug("[AutoUpdater] Update info error");
|
||||
}
|
||||
|
||||
$updater->checkUpdateError($this->error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user