mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 19:28:51 +02:00
Use enum for undo mode
This commit is contained in:
parent
218b0adb8f
commit
8a20584e27
14 changed files with 140 additions and 180 deletions
|
@ -27,12 +27,15 @@ use App\Entity\Contracts\LogWithCommentInterface;
|
|||
use App\Entity\Contracts\LogWithEventUndoInterface;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\LogSystem\EventUndoMode;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
|
||||
#[ORM\Entity]
|
||||
class ElementCreatedLogEntry extends AbstractLogEntry implements LogWithCommentInterface, LogWithEventUndoInterface
|
||||
{
|
||||
use LogWithEventUndoTrait;
|
||||
|
||||
protected string $typeString = 'element_created';
|
||||
|
||||
public function __construct(AbstractDBElement $new_element)
|
||||
|
@ -79,39 +82,4 @@ class ElementCreatedLogEntry extends AbstractLogEntry implements LogWithCommentI
|
|||
|
||||
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