mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Create new table to track geolocation updates
This commit is contained in:
42
module/Core/src/Geolocation/Entity/GeolocationDbUpdate.php
Normal file
42
module/Core/src/Geolocation/Entity/GeolocationDbUpdate.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Geolocation\Entity;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
|
||||
use function stat;
|
||||
|
||||
class GeolocationDbUpdate extends AbstractEntity
|
||||
{
|
||||
private function __construct(
|
||||
private readonly string $filesystemId,
|
||||
private GeolocationDbUpdateStatus $status = GeolocationDbUpdateStatus::IN_PROGRESS,
|
||||
private readonly Chronos $dateCreated = new Chronos(),
|
||||
private Chronos $dateUpdated = new Chronos(),
|
||||
private string|null $filename = null,
|
||||
private string|null $error = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function createForCurrentFilesystem(): self
|
||||
{
|
||||
return new self(stat(__FILE__)['dev']);
|
||||
}
|
||||
|
||||
public function finishSuccessfully(string $filename): void
|
||||
{
|
||||
$this->dateUpdated = Chronos::now();
|
||||
$this->filename = $filename;
|
||||
$this->status = GeolocationDbUpdateStatus::SUCCESS;
|
||||
}
|
||||
|
||||
public function finishWithError(string $error): void
|
||||
{
|
||||
$this->dateUpdated = Chronos::now();
|
||||
$this->error = $error;
|
||||
$this->status = GeolocationDbUpdateStatus::ERROR;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Geolocation\Entity;
|
||||
|
||||
enum GeolocationDbUpdateStatus: string
|
||||
{
|
||||
case IN_PROGRESS = 'in-progress';
|
||||
case SUCCESS = 'success';
|
||||
case ERROR = 'error';
|
||||
}
|
||||
Reference in New Issue
Block a user