setName('Core:InitData') // the short description shown while running "php bin/console list" ->setDescription('Init Data for Core') // the full command description shown when running the command with // the "--help" option ->setHelp('This command Init Data for Core') ; } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(''); $output->writeln('CORE = Default Data'); $em = $this->getContainer()->get('doctrine')->getManager(); $finder = new Finder(); $finder->in('src/Cadoles/CoreBundle/Command/data'); // Init 01 = ce qui templetisé $finder->name('core-init-01.sql'); foreach( $finder as $file ){ $content = $file->getContents(); $stmt = $em->getConnection()->prepare($content); $stmt->execute(); } $stmt->closeCursor(); // afin de forcer les ID sur certaines entités $metadata = $em->getClassMetaData('CadolesCoreBundle:Etab'); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $metadata->setIdGenerator(new AssignedGenerator()); // Etab inconnu $entity = $em->getRepository('CadolesCoreBundle:Etab')->find(-100); if(!$entity) { $entity = new Etab; $entity->setId(-100); } $entity->setLatitude(50); $entity->setLongitude(-30); $em->persist($entity); $em->flush(); } protected static function determineKernelRootDir(Event $event) { $extra = $event->getComposer()->getPackage()->getExtra(); $rootdir = rtrim(getcwd(), '/'); return $rootdir . '/' . trim($extra['symfony-app-dir'], '/'); } }