mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 19:58:53 +02:00
Added some simple time travel mechanism for part view.
In the moment it is not possible to show elements that were deleted.
This commit is contained in:
parent
a9fd1f9c68
commit
464a487a17
15 changed files with 450 additions and 27 deletions
|
@ -56,7 +56,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
* "user" = "App\Entity\User"
|
||||
* })
|
||||
*/
|
||||
abstract class AbstractDBElement
|
||||
abstract class AbstractDBElement implements \JsonSerializable
|
||||
{
|
||||
/** @var int|null The Identification number for this part. This value is unique for the element in this table.
|
||||
* Null if the element is not saved to DB yet.
|
||||
|
@ -93,4 +93,9 @@ abstract class AbstractDBElement
|
|||
* @return string The ID as a string;
|
||||
*/
|
||||
abstract public function getIDString(): string;
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return ['@id' => $this->getID()];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Entity\Base;
|
||||
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
@ -34,7 +35,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
* @ORM\MappedSuperclass(repositoryClass="App\Repository\UserRepository")
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
abstract class AbstractNamedDBElement extends AbstractDBElement implements NamedElementInterface
|
||||
abstract class AbstractNamedDBElement extends AbstractDBElement implements NamedElementInterface, TimeStampableInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
|
|
44
src/Entity/Contracts/TimeStampableInterface.php
Normal file
44
src/Entity/Contracts/TimeStampableInterface.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 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 General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
namespace App\Entity\Contracts;
|
||||
|
||||
|
||||
use DateTime;
|
||||
|
||||
interface TimeStampableInterface
|
||||
{
|
||||
/**
|
||||
* Returns the last time when the element was modified.
|
||||
* Returns null if the element was not yet saved to DB yet.
|
||||
*
|
||||
* @return DateTime|null the time of the last edit
|
||||
*/
|
||||
public function getLastModified(): ?DateTime;
|
||||
|
||||
/**
|
||||
* Returns the date/time when the element was created.
|
||||
* Returns null if the element was not yet saved to DB yet.
|
||||
*
|
||||
* @return DateTime|null the creation time of the part
|
||||
*/
|
||||
public function getAddedDate(): ?DateTime;
|
||||
}
|
41
src/Entity/Contracts/TimeTravelInterface.php
Normal file
41
src/Entity/Contracts/TimeTravelInterface.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 - 2020 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 General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
namespace App\Entity\Contracts;
|
||||
|
||||
|
||||
interface TimeTravelInterface
|
||||
{
|
||||
/**
|
||||
* Checks if this entry has informations which data has changed.
|
||||
* @return bool True if this entry has informations about the changed data.
|
||||
*/
|
||||
public function hasOldDataInformations(): bool;
|
||||
|
||||
/** Returns the data the entity had before this log entry. */
|
||||
public function getOldData(): array;
|
||||
|
||||
/**
|
||||
* Returns the the timestamp associated with this change.
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getTimestamp(): \DateTime;
|
||||
}
|
|
@ -26,12 +26,13 @@ namespace App\Entity\LogSystem;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementDeletedLogEntry extends AbstractLogEntry
|
||||
class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInterface
|
||||
{
|
||||
protected $typeString = 'element_deleted';
|
||||
|
||||
|
@ -65,4 +66,31 @@ class ElementDeletedLogEntry extends AbstractLogEntry
|
|||
{
|
||||
return $this->extra['n'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the old data for this entry.
|
||||
* @param array $old_data
|
||||
* @return $this
|
||||
*/
|
||||
public function setOldData(array $old_data): self
|
||||
{
|
||||
$this->extra['o'] = $old_data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function hasOldDataInformations(): bool
|
||||
{
|
||||
return !empty($this->extra['d']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOldData(): array
|
||||
{
|
||||
return $this->extra['d'] ?? [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@ declare(strict_types=1);
|
|||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementEditedLogEntry extends AbstractLogEntry
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface
|
||||
{
|
||||
protected $typeString = 'element_edited';
|
||||
|
||||
|
@ -42,6 +43,17 @@ class ElementEditedLogEntry extends AbstractLogEntry
|
|||
$this->setTargetElement($changed_element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the old data for this entry.
|
||||
* @param array $old_data
|
||||
* @return $this
|
||||
*/
|
||||
public function setOldData(array $old_data): self
|
||||
{
|
||||
$this->extra['d'] = $old_data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message associated with this edit change.
|
||||
*
|
||||
|
@ -51,4 +63,20 @@ class ElementEditedLogEntry extends AbstractLogEntry
|
|||
{
|
||||
return $this->extra['m'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function hasOldDataInformations(): bool
|
||||
{
|
||||
return !empty($this->extra['d']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOldData(): array
|
||||
{
|
||||
return $this->extra['d'] ?? [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Entity\Parts;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use App\Validator\Constraints\ValidPartLot;
|
||||
use DateTime;
|
||||
|
@ -42,7 +43,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
* @ORM\HasLifecycleCallbacks()
|
||||
* @ValidPartLot()
|
||||
*/
|
||||
class PartLot extends AbstractDBElement
|
||||
class PartLot extends AbstractDBElement implements TimeStampableInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace App\Entity\PriceInformations;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
@ -67,7 +68,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
* @ORM\Entity()
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
class Orderdetail extends AbstractDBElement
|
||||
class Orderdetail extends AbstractDBElement implements TimeStampableInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace App\Entity\PriceInformations;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
@ -66,7 +67,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
* @ORM\HasLifecycleCallbacks()
|
||||
* @UniqueEntity(fields={"orderdetail", "min_discount_quantity"})
|
||||
*/
|
||||
class Pricedetail extends AbstractDBElement
|
||||
class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue