43 lines
967 B
PHP
43 lines
967 B
PHP
|
<?php declare(strict_types=1);
|
||
|
|
||
|
namespace CameraBundle\Repository;
|
||
|
|
||
|
trait AcquireTrait {
|
||
|
|
||
|
/**
|
||
|
* Move a record from the table represented by $currentRecord
|
||
|
* into the table represented by $newRecord
|
||
|
*
|
||
|
* @param mixed $currentRecord
|
||
|
* @param mixed $newRecord
|
||
|
*/
|
||
|
protected function moveRecord($currentRecord, $newRecord): void
|
||
|
{
|
||
|
$em = $this->getEntityManager();
|
||
|
|
||
|
$old = new \ReflectionObject($currentRecord);
|
||
|
$new = new \ReflectionObject($newRecord);
|
||
|
|
||
|
foreach ($old->getProperties() as $property) {
|
||
|
$propertyName = $property->getName();
|
||
|
if ($new->hasProperty($propertyName)) {
|
||
|
$newProperty = $new->getProperty($propertyName);
|
||
|
$newProperty->setAccessible(true);
|
||
|
$property->setAccessible(true);
|
||
|
$newProperty->setValue($newRecord, $property->getValue($currentRecord));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
$em->persist($newRecord);
|
||
|
$em->remove($currentRecord);
|
||
|
$em->flush();
|
||
|
}
|
||
|
catch (\Throwable $e)
|
||
|
{
|
||
|
dump($newRecord);
|
||
|
}
|
||
|
}
|
||
|
}
|