mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 11:48:49 +02:00
Allow to undo a change from event log.
This commit is contained in:
parent
15d25cf2b2
commit
5a5d7b24be
24 changed files with 659 additions and 30 deletions
|
@ -44,13 +44,14 @@ namespace App\Entity\LogSystem;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\LogWithCommentInterface;
|
||||
use App\Entity\Contracts\LogWithEventUndoInterface;
|
||||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface, LogWithEventUndoInterface
|
||||
{
|
||||
protected $typeString = 'element_edited';
|
||||
|
||||
|
@ -150,4 +151,51 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
|
|||
$this->extra['m'] = $new_comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isUndoEvent(): bool
|
||||
{
|
||||
return isset($this->extra['u']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUndoEventID(): ?int
|
||||
{
|
||||
return $this->extra['u'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUndoneEvent(AbstractLogEntry $event, string $mode = 'undo'): LogWithEventUndoInterface
|
||||
{
|
||||
$this->extra['u'] = $event->getID();
|
||||
|
||||
if ($mode === 'undo') {
|
||||
$this->extra['um'] = 1;
|
||||
} elseif ($mode === 'revert') {
|
||||
$this->extra['um'] = 2;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Passed invalid $mode!');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUndoMode(): string
|
||||
{
|
||||
$mode_int = $this->extra['um'] ?? 1;
|
||||
if ($mode_int === 1) {
|
||||
return 'undo';
|
||||
} else {
|
||||
return 'revert';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue