Fix some cases of database download in GeolocationDbUpdater

This commit is contained in:
Alejandro Celaya
2024-12-15 11:34:38 +01:00
parent f10a9d3972
commit 853c50a819
5 changed files with 46 additions and 33 deletions

View File

@@ -49,17 +49,11 @@ class GeolocationDbUpdate extends AbstractEntity
}
/**
* This update would require a new download if:
* - It is successful and older than 30 days
* - It is error and older than 2 days
* @param positive-int $days
*/
public function needsUpdate(): bool
public function isOlderThan(int $days): bool
{
return match ($this->status) {
GeolocationDbUpdateStatus::SUCCESS => Chronos::now()->greaterThan($this->dateUpdated->addDays(30)),
GeolocationDbUpdateStatus::ERROR => Chronos::now()->greaterThan($this->dateUpdated->addDays(2)),
default => false,
};
return Chronos::now()->greaterThan($this->dateUpdated->addDays($days));
}
public function isInProgress(): bool
@@ -71,4 +65,9 @@ class GeolocationDbUpdate extends AbstractEntity
{
return $this->status === GeolocationDbUpdateStatus::ERROR;
}
public function isSuccess(): bool
{
return $this->status === GeolocationDbUpdateStatus::SUCCESS;
}
}