I have entity that can be archived. All data from current object is copied to new archive object and current object is deleted. Now it is realized in entity:
class Entity
{
...
public function archive($em)
{
$objectArchive = new EntityArchive($this->toArray()); // all archive object properties are set in constructor
$em->persist($objectArchive);
$em->remove($this);
return $objectArchive;
}
...
}
Recently I've read that functions that modify more than one entity should be placed in services and now I'm confused. Should I move this function to service? Something like this:
class ServiceEntityArchiver
{
private $em;
public function __construct($em)
{
$this->em = $em;
}
public function archive($object)
{
$objectArchive = new EntityArchive($object->toArray());
$this->em->persist($objectArchive);
$this->em->remove($object);
return $objectArchive;
}
}
What do you think about this?