3 namespace Rapsys\AirBundle\Command
;
5 use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand
;
6 use Symfony\Component\Console\Input\InputInterface
;
7 use Symfony\Component\Console\Output\OutputInterface
;
8 use Rapsys\AirBundle\Entity\Session
;
10 class AttributeCommand
extends DoctrineCommand
{
11 //Set failure constant
14 ///Set success constant
17 ///Configure attribute command
18 protected function configure() {
22 ->setName('rapsysair:attribute')
23 //Set description shown with bin/console list
24 ->setDescription('Attribute sessions')
25 //Set description shown with bin/console --help airlibre:attribute
26 ->setHelp('This command attribute sessions without application');
29 ///Process the attribution
30 protected function execute(InputInterface
$input, OutputInterface
$output) {
32 $doctrine = $this->getDoctrine();
35 $manager = $doctrine->getManager();
37 //Fetch sessions to attribute
38 $sessions = $doctrine->getRepository(Session
::class)->findAllPendingApplication();
40 //Iterate on each session
41 foreach($sessions as $sessionId => $session) {
43 if (!empty($sessionId)) {
44 //Fetch application id of the best candidate
45 if (!empty($application = $doctrine->getRepository(Session
::class)->findBestApplicationById($sessionId))) {
47 $session->setUpdated(new \
DateTime('now'));
50 $session->setApplication($application);
53 $manager->persist($session);
59 //Flush to get the ids