From 9d0f67d98d3fcb021e1098128f2e42a6bf411bfb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Tue, 8 Dec 2020 01:21:39 +0100 Subject: [PATCH] Add bin/console airlibre:attribute command --- Command/AttributeCommand.php | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Command/AttributeCommand.php 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; + } +} -- 2.41.1