mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-18 00:49:31 +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
|
|
@ -29,6 +29,7 @@ use App\Entity\Contracts\NamedElementInterface;
|
|||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\LogSystem\EventUndoMode;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
|
||||
|
|
@ -37,6 +38,8 @@ class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInter
|
|||
{
|
||||
protected string $typeString = 'element_deleted';
|
||||
|
||||
use LogWithEventUndoTrait;
|
||||
|
||||
public function __construct(AbstractDBElement $deleted_element)
|
||||
{
|
||||
parent::__construct();
|
||||
|
|
@ -112,39 +115,4 @@ class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInter
|
|||
|
||||
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