2022-09-30 10:48:14 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Repository;
|
|
|
|
|
|
|
|
use Doctrine\ORM\{EntityRepository};
|
|
|
|
|
|
|
|
use ReflectionObject;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
abstract class AcquireRepository extends EntityRepository
|
|
|
|
{
|
2022-09-30 10:49:02 -04:00
|
|
|
abstract public function reacquire(mixed $currentRecord): void;
|
|
|
|
|
|
|
|
abstract public function deacquire(mixed $currentRecord): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move a record from the table represented by $currentRecord
|
|
|
|
* into the table represented by $newRecord
|
|
|
|
*/
|
|
|
|
protected function moveRecord(mixed $currentRecord, mixed $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) {
|
|
|
|
dump($newRecord);
|
|
|
|
}
|
|
|
|
}
|
2022-09-30 10:48:14 -04:00
|
|
|
}
|