1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Command
;
14 use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand
;
16 use Symfony\Component\Console\Input\InputInterface
;
17 use Symfony\Component\Console\Output\OutputInterface
;
19 use Rapsys\AirBundle\Entity\Session
;
21 class AttributeCommand
extends DoctrineCommand
{
22 //Set failure constant
25 ///Set success constant
28 ///Configure attribute command
29 protected function configure() {
33 ->setName('rapsysair:attribute')
34 //Set description shown with bin/console list
35 ->setDescription('Attribute sessions')
36 //Set description shown with bin/console --help airlibre:attribute
37 ->setHelp('This command attribute sessions without application');
40 ///Process the attribution
41 protected function execute(InputInterface
$input, OutputInterface
$output): int {
43 $doctrine = $this->getDoctrine();
46 $manager = $doctrine->getManager();
48 //Fetch sessions to attribute
49 $sessions = $doctrine->getRepository(Session
::class)->findAllPendingApplication();
51 //Iterate on each session
52 foreach($sessions as $sessionId => $session) {
54 if (!empty($sessionId)) {
55 //Fetch application id of the best candidate
56 if (!empty($application = $doctrine->getRepository(Session
::class)->findBestApplicationById($sessionId))) {
58 $session->setUpdated(new \
DateTime('now'));
61 $session->setApplication($application);
64 $manager->persist($session);
70 //Flush to get the ids