Be less dependent on AsyncTask->onCompletion() Server parameter

this is going to get removed soon.
This commit is contained in:
Dylan K. Taylor
2018-08-04 15:56:14 +01:00
parent 779d92c656
commit 20f3b82d52
6 changed files with 27 additions and 26 deletions

View File

@ -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()));
}
/**

View File

@ -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);
}
}
}