mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-28 12:40:08 +02:00
parent
ccdac1a94b
commit
a3c626d0ab
8 changed files with 92 additions and 7 deletions
|
@ -95,4 +95,23 @@ abstract class AttachmentContainingDBElement extends AbstractNamedDBElement impl
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
$attachments = $this->attachments;
|
||||
$this->attachments = new ArrayCollection();
|
||||
//Set master attachment is needed
|
||||
foreach ($attachments as $attachment) {
|
||||
$clone = clone $attachment;
|
||||
if ($attachment === $this->master_picture_attachment) {
|
||||
$this->setMasterPictureAttachment($clone);
|
||||
}
|
||||
$this->addAttachment($clone);
|
||||
}
|
||||
}
|
||||
|
||||
//Parent has to be last call, as it resets the ID
|
||||
parent::__clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,8 +68,10 @@ abstract class AbstractDBElement implements \JsonSerializable
|
|||
|
||||
public function __clone()
|
||||
{
|
||||
//Set ID to null, so that an new entry is created
|
||||
$this->id = null;
|
||||
if ($this->id) {
|
||||
//Set ID to null, so that an new entry is created
|
||||
$this->id = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,7 +89,15 @@ abstract class AbstractNamedDBElement extends AbstractDBElement implements Named
|
|||
public function setName(string $new_name): self
|
||||
{
|
||||
$this->name = $new_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
//We create a new object, so give it a new creation date
|
||||
$this->addedDate = null;
|
||||
}
|
||||
parent::__clone(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,4 +156,24 @@ class Part extends AttachmentContainingDBElement
|
|||
{
|
||||
return $this->devices;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
//Deep clone part lots
|
||||
$lots = $this->partLots;
|
||||
$this->partLots = new ArrayCollection();
|
||||
foreach ($lots as $lot) {
|
||||
$this->addPartLot(clone $lot);
|
||||
}
|
||||
|
||||
//Deep clone order details
|
||||
$orderdetails = $this->orderdetails;
|
||||
$this->orderdetails = new ArrayCollection();
|
||||
foreach ($orderdetails as $orderdetail) {
|
||||
$this->addOrderdetail(clone $orderdetail);
|
||||
}
|
||||
}
|
||||
parent::__clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -325,4 +325,12 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if($this->id) {
|
||||
$this->addedDate = null;
|
||||
}
|
||||
parent::__clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,4 +348,18 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->addedDate = null;
|
||||
$pricedetails = $this->pricedetails;
|
||||
$this->pricedetails = new ArrayCollection();
|
||||
//Set master attachment is needed
|
||||
foreach ($pricedetails as $pricedetail) {
|
||||
$this->addPricedetail(clone $pricedetail);
|
||||
}
|
||||
}
|
||||
parent::__clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,4 +328,12 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
{
|
||||
return 'PD'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->addedDate = null;
|
||||
}
|
||||
parent::__clone();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue