forked from mirror/Part-DB.Part-DB-server
Add the data after the change to a element edited log entry, so you can easily view the changes in log detail pages
This commit is contained in:
parent
3c724a227a
commit
923e40ed8f
14 changed files with 136 additions and 22 deletions
41
src/Entity/Contracts/LogWithNewDataInterface.php
Normal file
41
src/Entity/Contracts/LogWithNewDataInterface.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\Contracts;
|
||||
|
||||
interface LogWithNewDataInterface
|
||||
{
|
||||
/**
|
||||
* Checks if this entry has information about the new data.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasNewDataInformation(): bool;
|
||||
|
||||
/**
|
||||
* Returns the new data for this entry.
|
||||
*/
|
||||
public function getNewData(): array;
|
||||
|
||||
/**
|
||||
* Sets the new data for this entry.
|
||||
* @return $this
|
||||
*/
|
||||
public function setNewData(array $new_data): self;
|
||||
}
|
|
@ -31,7 +31,7 @@ interface TimeTravelInterface
|
|||
*
|
||||
* @return bool true if this entry has information about the changed data
|
||||
*/
|
||||
public function hasOldDataInformations(): bool;
|
||||
public function hasOldDataInformation(): bool;
|
||||
|
||||
/**
|
||||
* Returns the data the entity had before this log entry.
|
||||
|
|
|
@ -88,7 +88,7 @@ class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInter
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function hasOldDataInformations(): bool
|
||||
public function hasOldDataInformation(): bool
|
||||
{
|
||||
return !empty($this->extra['o']);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Entity\LogSystem;
|
|||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\LogWithCommentInterface;
|
||||
use App\Entity\Contracts\LogWithEventUndoInterface;
|
||||
use App\Entity\Contracts\LogWithNewDataInterface;
|
||||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
|
@ -32,7 +33,7 @@ use InvalidArgumentException;
|
|||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface, LogWithEventUndoInterface
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface, LogWithEventUndoInterface, LogWithNewDataInterface
|
||||
{
|
||||
protected string $typeString = 'element_edited';
|
||||
|
||||
|
@ -49,7 +50,7 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
|
|||
*/
|
||||
public function hasChangedFieldsInfo(): bool
|
||||
{
|
||||
return isset($this->extra['f']) || $this->hasOldDataInformations();
|
||||
return isset($this->extra['f']) || $this->hasOldDataInformation();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +60,7 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
|
|||
*/
|
||||
public function getChangedFields(): array
|
||||
{
|
||||
if ($this->hasOldDataInformations()) {
|
||||
if ($this->hasOldDataInformation()) {
|
||||
return array_keys($this->getOldData());
|
||||
}
|
||||
|
||||
|
@ -92,7 +93,29 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function hasOldDataInformations(): bool
|
||||
public function hasNewDataInformation(): bool
|
||||
{
|
||||
return !empty($this->extra['n']);
|
||||
}
|
||||
|
||||
public function getNewData(): array
|
||||
{
|
||||
return $this->extra['n'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the old data for this entry.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setNewData(array $new_data): self
|
||||
{
|
||||
$this->extra['n'] = $new_data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasOldDataInformation(): bool
|
||||
{
|
||||
return !empty($this->extra['d']);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue