setName('rapsysair:attribute') //Set description shown with bin/console list ->setDescription('Attribute sessions') //Set description shown with bin/console --help airlibre:attribute ->setHelp('This command attribute sessions without application'); } ///Process the attribution protected function execute(InputInterface $input, OutputInterface $output) { //Fetch doctrine $doctrine = $this->getDoctrine(); //Get manager $manager = $doctrine->getManager(); //Fetch sessions to attribute $sessions = $doctrine->getRepository(Session::class)->findAllPendingApplication(); //Iterate on each session foreach($sessions as $sessionId => $session) { //Extract session id if (!empty($sessionId)) { //Fetch application id of the best candidate if (!empty($application = $doctrine->getRepository(Session::class)->findBestApplicationById($sessionId))) { //Set updated $session->setUpdated(new \DateTime('now')); //Set application_id $session->setApplication($application); //Queue session save $manager->persist($session); } } } //Flush to get the ids $manager->flush(); //Return success return self::SUCCESS; } }