mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
UpdateChecker: improve type handling
This commit is contained in:
parent
e113981750
commit
e43d39c0bc
@ -39,8 +39,6 @@ class UpdateChecker{
|
|||||||
protected $endpoint;
|
protected $endpoint;
|
||||||
/** @var UpdateInfo|null */
|
/** @var UpdateInfo|null */
|
||||||
protected $updateInfo = null;
|
protected $updateInfo = null;
|
||||||
/** @var VersionString|null */
|
|
||||||
protected $newVersion;
|
|
||||||
|
|
||||||
/** @var \Logger */
|
/** @var \Logger */
|
||||||
private $logger;
|
private $logger;
|
||||||
@ -63,8 +61,7 @@ class UpdateChecker{
|
|||||||
* Callback used at the end of the update checking task
|
* Callback used at the end of the update checking task
|
||||||
*/
|
*/
|
||||||
public function checkUpdateCallback(UpdateInfo $updateInfo) : void{
|
public function checkUpdateCallback(UpdateInfo $updateInfo) : void{
|
||||||
$this->updateInfo = $updateInfo;
|
$this->checkUpdate($updateInfo);
|
||||||
$this->checkUpdate();
|
|
||||||
if($this->hasUpdate()){
|
if($this->hasUpdate()){
|
||||||
(new UpdateNotifyEvent($this))->call();
|
(new UpdateNotifyEvent($this))->call();
|
||||||
if($this->server->getConfigGroup()->getPropertyBool("auto-updater.on-update.warn-console", true)){
|
if($this->server->getConfigGroup()->getPropertyBool("auto-updater.on-update.warn-console", true)){
|
||||||
@ -83,15 +80,19 @@ class UpdateChecker{
|
|||||||
* Returns whether there is an update available.
|
* Returns whether there is an update available.
|
||||||
*/
|
*/
|
||||||
public function hasUpdate() : bool{
|
public function hasUpdate() : bool{
|
||||||
return $this->newVersion !== null;
|
return $this->updateInfo !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts a warning to the console to tell the user there is an update available
|
* Posts a warning to the console to tell the user there is an update available
|
||||||
*/
|
*/
|
||||||
public function showConsoleUpdate() : void{
|
public function showConsoleUpdate() : void{
|
||||||
|
if($this->updateInfo === null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$newVersion = new VersionString($this->updateInfo->base_version, $this->updateInfo->is_dev, $this->updateInfo->build);
|
||||||
$messages = [
|
$messages = [
|
||||||
"Your version of " . $this->server->getName() . " is out of date. Version " . $this->newVersion->getFullVersion(true) . " was released on " . date("D M j h:i:s Y", $this->updateInfo->date)
|
"Your version of " . $this->server->getName() . " is out of date. Version " . $newVersion->getFullVersion(true) . " was released on " . date("D M j h:i:s Y", $this->updateInfo->date)
|
||||||
];
|
];
|
||||||
|
|
||||||
$messages[] = "Details: " . $this->updateInfo->details_url;
|
$messages[] = "Details: " . $this->updateInfo->details_url;
|
||||||
@ -140,13 +141,10 @@ class UpdateChecker{
|
|||||||
/**
|
/**
|
||||||
* Checks the update information against the current server version to decide if there's an update
|
* Checks the update information against the current server version to decide if there's an update
|
||||||
*/
|
*/
|
||||||
protected function checkUpdate() : void{
|
protected function checkUpdate(UpdateInfo $updateInfo) : void{
|
||||||
if($this->updateInfo === null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$currentVersion = VersionInfo::VERSION();
|
$currentVersion = VersionInfo::VERSION();
|
||||||
try{
|
try{
|
||||||
$newVersion = new VersionString($this->updateInfo->base_version, $this->updateInfo->is_dev, $this->updateInfo->build);
|
$newVersion = new VersionString($updateInfo->base_version, $updateInfo->is_dev, $updateInfo->build);
|
||||||
}catch(\InvalidArgumentException $e){
|
}catch(\InvalidArgumentException $e){
|
||||||
//Invalid version returned from API, assume there's no update
|
//Invalid version returned from API, assume there's no update
|
||||||
$this->logger->debug("Assuming no update because \"" . $e->getMessage() . "\"");
|
$this->logger->debug("Assuming no update because \"" . $e->getMessage() . "\"");
|
||||||
@ -154,7 +152,7 @@ class UpdateChecker{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($currentVersion->compare($newVersion) > 0 and ($currentVersion->getFullVersion() !== $newVersion->getFullVersion() or $currentVersion->getBuild() > 0)){
|
if($currentVersion->compare($newVersion) > 0 and ($currentVersion->getFullVersion() !== $newVersion->getFullVersion() or $currentVersion->getBuild() > 0)){
|
||||||
$this->newVersion = $newVersion;
|
$this->updateInfo = $updateInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,26 +245,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: ../../../src/scheduler/DumpWorkerMemoryTask.php
|
path: ../../../src/scheduler/DumpWorkerMemoryTask.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot access property \\$date on pocketmine\\\\updater\\\\UpdateInfo\\|null\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../../src/updater/UpdateChecker.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot access property \\$details_url on pocketmine\\\\updater\\\\UpdateInfo\\|null\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../../src/updater/UpdateChecker.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot access property \\$download_url on pocketmine\\\\updater\\\\UpdateInfo\\|null\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../../src/updater/UpdateChecker.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot call method getFullVersion\\(\\) on pocketmine\\\\utils\\\\VersionString\\|null\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../../src/updater/UpdateChecker.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method pocketmine\\\\utils\\\\Config\\:\\:fixYAMLIndexes\\(\\) should return string but returns string\\|null\\.$#"
|
message: "#^Method pocketmine\\\\utils\\\\Config\\:\\:fixYAMLIndexes\\(\\) should return string but returns string\\|null\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user