Use enum for undo mode

This commit is contained in:
Jan Böhmer 2023-06-18 21:26:28 +02:00
parent 218b0adb8f
commit 8a20584e27
14 changed files with 140 additions and 180 deletions

View file

@ -33,6 +33,8 @@ use InvalidArgumentException;
#[ORM\Entity]
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface, LogWithEventUndoInterface, LogWithNewDataInterface
{
use LogWithEventUndoTrait;
protected string $typeString = 'element_edited';
public function __construct(AbstractDBElement $changed_element)
@ -139,39 +141,4 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
return $this;
}
public function isUndoEvent(): bool
{
return isset($this->extra['u']);
}
public function getUndoEventID(): ?int
{
return $this->extra['u'] ?? null;
}
public function setUndoneEvent(AbstractLogEntry $event, string $mode = 'undo'): LogWithEventUndoInterface
{
$this->extra['u'] = $event->getID();
if ('undo' === $mode) {
$this->extra['um'] = 1;
} elseif ('revert' === $mode) {
$this->extra['um'] = 2;
} else {
throw new InvalidArgumentException('Passed invalid $mode!');
}
return $this;
}
public function getUndoMode(): string
{
$mode_int = $this->extra['um'] ?? 1;
if (1 === $mode_int) {
return 'undo';
}
return 'revert';
}
}