Update timestamp of the associated element.

For example the lastModified timestamp of a part is now updated, when the user changes a price information. This should represent more what a user expects under a last Modified field and should improve also sorting...
This commit is contained in:
Jan Böhmer 2020-05-20 23:36:44 +02:00
parent 2b21d4039a
commit dbf770f784
7 changed files with 68 additions and 4 deletions

View file

@ -116,6 +116,14 @@ abstract class Attachment extends AbstractNamedDBElement
}
}
public function updateTimestamps(): void
{
parent::updateTimestamps();
if ($this->element instanceof AttachmentContainingDBElement) {
$this->element->updateTimestamps();
}
}
/***********************************************************
* Various function
***********************************************************/

View file

@ -92,7 +92,7 @@ trait TimestampTrait
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps(): void
public function updateTimestamps(): void
{
$this->lastModified = new DateTime('now');
if (null === $this->addedDate) {

View file

@ -120,6 +120,14 @@ abstract class AbstractParameter extends AbstractNamedDBElement
}
}
public function updateTimestamps(): void
{
parent::updateTimestamps();
if ($this->element instanceof AbstractNamedDBElement) {
$this->element->updateTimestamps();
}
}
/**
* Returns the element this parameter belongs to.
*

View file

@ -56,6 +56,7 @@ use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parts\Part;
use App\Entity\Parts\Supplier;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -134,6 +135,24 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
parent::__clone();
}
/**
* Helper for updating the timestamp. It is automatically called by doctrine before persisting.
*
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updateTimestamps(): void
{
$this->lastModified = new DateTime('now');
if (null === $this->addedDate) {
$this->addedDate = new DateTime('now');
}
if ($this->part instanceof Part) {
$this->part->updateTimestamps();
}
}
/********************************************************************************
*
* Getters

View file

@ -57,6 +57,7 @@ use App\Validator\Constraints\BigDecimal\BigDecimalPositive;
use App\Validator\Constraints\Selectable;
use Brick\Math\BigDecimal;
use Brick\Math\RoundingMode;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
@ -132,6 +133,24 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
parent::__clone();
}
/**
* Helper for updating the timestamp. It is automatically called by doctrine before persisting.
*
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updateTimestamps(): void
{
$this->lastModified = new DateTime('now');
if (null === $this->addedDate) {
$this->addedDate = new DateTime('now');
}
if ($this->orderdetail instanceof Orderdetail) {
$this->orderdetail->updateTimestamps();
}
}
/********************************************************************************
*
* Getters