Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions Service/InstallationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Psr\Log\LoggerInterface;

class InstallationService
{
Expand Down Expand Up @@ -336,15 +335,18 @@ public function handleInstaller($file)
}

/**
* Handles forced id's on object entities
* Handles forced id's on object entities.
*
* @param ObjectEntity $objectEntity
*
* @return ObjectEntity
*/
private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity{
private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity
{
// This savetey dosn't make sense but we need it
if(!$objectEntity->getEntity()){
if (!$objectEntity->getEntity()) {
$this->io->writeln(['', 'Object can\'t be persisted due to missing schema']);

return $objectEntity;
}

Expand All @@ -353,8 +355,7 @@ private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity{
$objectEntity->clearAllValues();

// We have an object entity with a fixed id that isn't in the database, so we need to act
if($objectEntity->getId() && !$this->em->contains($objectEntity)){

if ($objectEntity->getId() && !$this->em->contains($objectEntity)) {
$this->io->writeln(['', 'Creating new object ('.$objectEntity->getEntity()->getName().') on a fixed id ('.$objectEntity->getId().')']);

// Sve the id
Expand All @@ -368,34 +369,29 @@ private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity{
$this->em->persist($objectEntity);
$this->em->flush();
$objectEntity = $this->em->getRepository('App:ObjectEntity')->findOneBy(['id' => $id]);
}
else{
} else {
$this->io->writeln(['', 'Creating new object ('.$objectEntity->getEntity()->getName().') on a generated id']);
}

// Loop trough the values
foreach ($values as $objectValue){
foreach ($values as $objectValue) {
$objectEntity->addObjectValue($objectValue);
// If the value itsself is an object it might also contain fixed id's
foreach ($objectValue->getObjects() as $subobject){
foreach ($objectValue->getObjects() as $subobject) {
$this->io->writeln(['', 'Found sub object ('.$subobject->getEntity()->getName().')']);
$subobject = $this->saveOnFixedId($subobject);

// This savetey dosn't make sense but we need it
if(!$subobject->getEntity()){
if (!$subobject->getEntity()) {
// todo: Throw error
$objectEntity->removeObjectValue($objectValue);
}
}

}

$this->em->persist($objectEntity);
$this->em->flush();

return $objectEntity;
}



}