Exemple #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  *
  * TODO Remove the if/else
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->bootstrap($input, $output);
     $mapper = $this->getMapper();
     $relational = new RespectRelational($mapper);
     $fieldRepository = new FieldRepository($relational);
     $collectionRepository = new CollectionRepository($relational);
     $collectionFieldRepository = new CollectionFieldRepository($relational);
     $entity = $input->getArgument('Field|Collection');
     if ($entity === 'Field') {
         $entity = new Field();
         $entity->setType($input->getArgument('type'));
         $entity->setName($input->getArgument('name'));
         $entity->setLabel($input->getArgument('label'));
         $fieldRepository->save($entity);
         if ($input->getArgument('collection') != null) {
             $collection = $collectionRepository->findOne(['name' => $input->getArgument('collection')]);
             if (!$collection) {
                 $output->writeln('<error>The Collection ' . $input->getArgument('collection') . ' not found.</error>');
                 return;
             }
             $collectionField = new CollectionField();
             $collectionField->setFieldId($entity);
             $collectionField->setCollectionId($collection);
             $collectionFieldRepository->save($collectionField);
         }
     } else {
         $entity = new Collection();
         $entity->setName($input->getArgument('name'));
         $entity->setLabel($input->getArgument('label'));
         $collectionRepository->save($entity);
     }
 }