Various updates
This commit is contained in:
@ -11,7 +11,7 @@ use ProVM\Emails\Repository\State;
|
||||
|
||||
class Mailboxes extends Base
|
||||
{
|
||||
public function __construct(Mailbox $repository, Remote\Mailboxes $remoteService, State\Mailbox $states, LoggerInterface $logger)
|
||||
public function __construct(Mailbox $repository, Remote\Mailboxes $remoteService, State\Mailbox $states, LoggerInterface $logger, protected int $max_update_days)
|
||||
{
|
||||
$this->setRepository($repository)
|
||||
->setRemoteService($remoteService)
|
||||
@ -35,7 +35,6 @@ class Mailboxes extends Base
|
||||
{
|
||||
return $this->statesRepository;
|
||||
}
|
||||
|
||||
public function setRepository(Mailbox $repository): Mailboxes
|
||||
{
|
||||
$this->repository = $repository;
|
||||
@ -110,6 +109,7 @@ class Mailboxes extends Base
|
||||
$this->getStatesRepository()->save($state);
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
$this->getLogger()->error($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -141,4 +141,13 @@ class Mailboxes extends Base
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public function isUpdated(\ProVM\Emails\Model\Mailbox $mailbox): bool
|
||||
{
|
||||
$states = $mailbox->getStates();
|
||||
if (count($states) === 0) {
|
||||
return false;
|
||||
}
|
||||
$last = $states[count($states) - 1];
|
||||
return abs((int) $last->getDateTime()->diff(new \DateTimeImmutable())->format('%r%a')) < $this->max_update_days;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user