<?php
namespace Cms\SyncBundle\Entity;
use App\Model\Async\StringSemaphoreInterface;
use App\Model\Async\StringSemaphoreTrait;
use Cms\ContainerBundle\Entity\Container;
use Cms\ImportBundle\Model\Interfaces\Importable\ImportableInterface;
use Cms\ImportBundle\Model\Interfaces\Importable\ImportableTrait;
use Cms\TenantBundle\Entity\TenantedEntity;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Sync
* @package Cms\SyncBundle\Entity
*
* @ORM\Entity(
* repositoryClass = "Cms\SyncBundle\Doctrine\SyncRepository"
* )
* @ORM\HasLifecycleCallbacks
* @ORM\Table(
* name = "cms__sync__sync"
* )
*/
class Sync extends TenantedEntity implements ImportableInterface, StringSemaphoreInterface
{
use ImportableTrait;
use StringSemaphoreTrait;
public const STATUS__STARTED = 'started';
public const STATUS__STOPPED = 'stopped';
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*/
protected ?string $name = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "text",
* nullable = true,
* )
*/
protected ?string $description = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*/
protected ?string $type = null;
/**
* @var string
*
* @ORM\Column(
* type = "string",
* nullable = false,
* options = {
* "default" = self::STATUS__STOPPED,
* },
* )
*/
protected string $status = self::STATUS__STOPPED;
/**
* @var string|null
*
* @ORM\Column(
* type = "text",
* nullable = true,
* )
*/
protected ?string $errors = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*/
protected ?string $url = null;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = true,
* options = {
* "unsigned" = true,
* },
* )
*/
protected int $frequency = 0;
/**
* @var Container|null
*
* @ORM\ManyToOne(
* targetEntity = Container::class,
* )
* @ORM\JoinColumn(
* name = "container",
* referencedColumnName = "id",
* onDelete = "CASCADE",
* )
*/
protected ?Container $container = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $checksum = null;
/**
* @var DateTimeInterface|null
*
* @ORM\Column(
* type = "datetime",
* nullable = true,
* )
*/
protected ?DateTimeInterface $lastSyncAt = null;
/**
* @var DateTimeInterface|null
*
* @ORM\Column(
* type = "datetime",
* nullable = true,
* )
*/
protected ?DateTimeInterface $nextSyncAt = null;
/**
* @var DateTimeInterface|null
*
* @ORM\Column(
* type = "datetime",
* nullable = true,
* )
*/
protected ?DateTimeInterface $lastErrorAt = null;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false,
* options = {
* "unsigned" = true,
* "default" = 0,
* },
* )
*/
protected int $errorCount = 0;
/**
* @return string|null
*/
public function getChecksum(): ?string
{
return $this->checksum;
}
/**
* @param string|null $checksum
* @return $this
*/
public function setChecksum(?string $checksum): self
{
$this->checksum = $checksum ?: null;
return $this;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string|null $name
* @return $this
*/
public function setName(?string $name): self
{
$this->name = $name ?: null;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
* @return $this
*/
public function setDescription(?string $description): self
{
$this->description = $description ?: null;
return $this;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string|null $type
* @return $this
*/
public function setType(?string $type): self
{
$this->type = $type ?: null;
return $this;
}
/**
* @return string|null
*/
public function getErrors(): ?string
{
return $this->errors;
}
/**
* @param string|null $errors
* @return $this
*/
public function setErrors(?string $errors): self
{
$this->errors = $errors ?: null;
return $this;
}
/**
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* @param string|null $url
* @return $this
*/
public function setUrl(?string $url): self
{
$this->url = $url ?: null;
return $this;
}
/**
* @return int
*/
public function getFrequency(): int
{
return $this->frequency;
}
/**
* @param int $frequency
* @return $this
*/
public function setFrequency(int $frequency): self
{
$this->frequency = $frequency;
return $this;
}
/**
* @return Container|null
*/
public function getContainer(): ?Container
{
return $this->container;
}
/**
* @param Container|null $container
* @return $this
*/
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @param string $status
* @return $this
*/
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getLastSyncAt(): ?DateTimeInterface
{
return $this->lastSyncAt;
}
/**
* @param DateTimeInterface|null $lastSyncAt
* @return $this
*/
public function setLastSyncAt(?DateTimeInterface $lastSyncAt): self
{
$this->lastSyncAt = $lastSyncAt;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getNextSyncAt(): ?DateTimeInterface
{
return $this->nextSyncAt;
}
/**
* @param DateTimeInterface|null $nextSyncAt
* @return $this
*/
public function setNextSyncAt(?DateTimeInterface $nextSyncAt): self
{
$this->nextSyncAt = $nextSyncAt;
return $this;
}
/**
* @return bool
*/
public function isStarted(): bool
{
return $this->getStatus() === self::STATUS__STARTED;
}
/**
* @return DateTimeInterface|null
*/
public function getLastErrorAt(): ?DateTimeInterface
{
return $this->lastErrorAt;
}
/**
* @param DateTimeInterface|null $lastErrorAt
* @return $this
*/
public function setLastErrorAt(?DateTimeInterface $lastErrorAt): self
{
$this->lastErrorAt = $lastErrorAt;
return $this;
}
/**
* @return int
*/
public function getErrorCount(): int
{
return $this->errorCount;
}
/**
* @param int $errorCount
* @return $this
*/
public function setErrorCount(int $errorCount): self
{
$this->errorCount = $errorCount;
return $this;
}
}