|
|
|
|
|
|
|
|
namespace Lc\SovBundle\Component; |
|
|
namespace Lc\SovBundle\Component; |
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
use Lc\SovBundle\Doctrine\Extension\BlameableInterface; |
|
|
|
|
|
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; |
|
|
|
|
|
use Lc\SovBundle\Doctrine\Extension\SeoInterface; |
|
|
|
|
|
use Lc\SovBundle\Doctrine\Extension\SortableInterface; |
|
|
|
|
|
use Lc\SovBundle\Doctrine\Extension\TimestampableInterface; |
|
|
use Lc\SovBundle\Event\EntityComponentEvent; |
|
|
use Lc\SovBundle\Event\EntityComponentEvent; |
|
|
use Lc\SovBundle\Model\File\FileInterface; |
|
|
use Lc\SovBundle\Model\File\FileInterface; |
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
|
|
|
|
|
|
$newEntity = clone $entity; |
|
|
$newEntity = clone $entity; |
|
|
$classMetadata = $this->entityManager->getClassMetadata(get_class($newEntity)); |
|
|
$classMetadata = $this->entityManager->getClassMetadata(get_class($newEntity)); |
|
|
|
|
|
|
|
|
|
|
|
//Dupplication de l'image ou du fichier lier |
|
|
foreach ($classMetadata->getAssociationMappings() as $associationMapping){ |
|
|
foreach ($classMetadata->getAssociationMappings() as $associationMapping){ |
|
|
if(in_array(FileInterface::class, class_implements($associationMapping['targetEntity']))){ |
|
|
if(in_array(FileInterface::class, class_implements($associationMapping['targetEntity']))){ |
|
|
$methodGet = 'get'.ucfirst($associationMapping['fieldName']); |
|
|
$methodGet = 'get'.ucfirst($associationMapping['fieldName']); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($newEntity instanceof DevAliasInterface){ |
|
|
|
|
|
$newEntity->setDevAlias(null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if($newEntity instanceof SeoInterface) { |
|
|
|
|
|
$newEntity->setOldUrls(array()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO dispatch event duplicate |
|
|
|
|
|
/* if ($newEntity instanceof ProductFamilyInterface) { |
|
|
|
|
|
// @TODO : à adapter |
|
|
|
|
|
//$newEntity = $this->productFamilyUtils->processBeforePersistProductFamily($newEntity, false, true); |
|
|
|
|
|
|
|
|
if($newEntity instanceof BlameableInterface) { |
|
|
|
|
|
$newEntity->setUpdatedBy(null); |
|
|
|
|
|
$newEntity->setCreatedBy(null); |
|
|
} |
|
|
} |
|
|
*/ |
|
|
|
|
|
$this->entityManager->create($newEntity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($newEntity instanceof TimestampableInterface) { |
|
|
|
|
|
$newEntity->setUpdatedAt(new \DateTime()); |
|
|
|
|
|
$newEntity->setCreatedAt(new \DateTime()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->entityManager->create($newEntity); |
|
|
$this->eventDispatcher->dispatch(new EntityComponentEvent($newEntity), EntityComponentEvent::DUPLICATE_EVENT); |
|
|
$this->eventDispatcher->dispatch(new EntityComponentEvent($newEntity), EntityComponentEvent::DUPLICATE_EVENT); |
|
|
|
|
|
|
|
|
return $newEntity; |
|
|
return $newEntity; |