Cleanup of cli

This commit is contained in:
2023-06-09 00:54:34 -04:00
parent 9307ba330c
commit 03c1dac2f2
36 changed files with 614 additions and 272 deletions

View File

@ -3,29 +3,31 @@ namespace ProVM\Emails\Model;
use DateTimeInterface;
use ProVM\Common\Define\Model;
use ProVM\Common\Exception\Database\BlankResult;
use ProVM\Common\Exception\Job\Stateless;
use ProVM\Emails;
class Job implements Model
{
protected int $id;
protected Message $message;
protected DateTimeInterface $dateTime;
protected bool $executed;
protected string $command;
protected string $arguments;
public function getId(): int
{
return $this->id;
}
public function getMessage(): Message
public function getCommand(): string
{
return $this->message;
return $this->command;
}
public function getDateTime(): DateTimeInterface
public function getArguments(): string
{
return $this->dateTime;
return $this->arguments ?? '';
}
public function isExecuted(): bool
{
return $this->executed ?? false;
return $this->lastState()->getStatus() === State\Job::Executed;
}
public function setId(int $id): Job
@ -33,22 +35,61 @@ class Job implements Model
$this->id = $id;
return $this;
}
public function setMessage(Message $message): Job
public function setCommand(string $message): Job
{
$this->message = $message;
return $this;
}
public function setDateTime(DateTimeInterface $dateTime): Job
public function setArguments(string $dateTime): Job
{
$this->dateTime = $dateTime;
return $this;
}
public function wasExecuted(): Job
protected Emails\Repository\State\Job $stateRepository;
public function getStateRepository(): Emails\Repository\State\Job
{
$this->executed = true;
return $this->stateRepository;
}
public function setStateRepository(Emails\Repository\State\Job $repository): Job
{
$this->stateRepository = $repository;
return $this;
}
protected array $states;
public function getStates(): array
{
if (!isset($this->states)) {
try {
$this->setStates($this->getStateRepository()->fetchByJob($this->getId()));
} catch (BlankResult $e) {
return [];
}
}
return $this->states;
}
public function addState(State\Job $state): Job
{
$this->states []= $state;
return $this;
}
public function setStates(array $states): Job
{
foreach ($states as $state) {
$this->addState($state);
}
return $this;
}
public function lastState(): State\Job
{
if (count($this->getStates()) === 0) {
throw new Stateless($this);
}
return $this->getStates()[array_key_last($this->getStates())];
}
public function toArray(): array
{
return [