mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-08 12:09:30 +00:00
Use enum for undo mode
This commit is contained in:
parent
218b0adb8f
commit
8a20584e27
14 changed files with 140 additions and 180 deletions
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue