From: Raphaƫl Gertz Date: Tue, 8 Dec 2020 00:21:39 +0000 (+0100) Subject: Add bin/console airlibre:attribute command X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/7512aac9851e99f1e438bcae55a220a24d58caa9 Add bin/console airlibre:attribute command --- diff --git a/Command/AttributeCommand.php b/Command/AttributeCommand.php new file mode 100644 index 0000000..8f26e26 --- /dev/null +++ b/Command/AttributeCommand.php @@ -0,0 +1,65 @@ +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; + } +}