Completed
Push — master ( 08e6f3...81e954 )
by Kirill
02:15
created

DeployCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Chrl\AppBundle\Command;
4
5
use Chrl\AppBundle\Entity\Game;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputDefinition;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Input\InputInterface;
11
12
class DeployCommand extends ContainerAwareCommand
13
{
14
    // This is just a normal Command::configure() method
15
    protected function configure()
16
    {
17
        $this->setName('buktopuha:deploy')
18
                ->setDescription('Tell all active games about deploy')
19
                ->setDefinition(
20
                    new InputDefinition(
21
                        [
22
                            new InputOption('success')
23
                        ]
24
                    )
25
                );
26
    }
27
28
    // Execute will be called in a endless loop
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $output->writeln('Executing...');
32
33
        $gs = $this->getContainer()->get('app.gameservice');
34
        $tgApi = $this->getContainer()->get('buktopuha.telegram_bot_api');
35
        $games = $gs->getActiveGames();
36
37
        /** @var Game $game */
38
        foreach ($games as $game) {
39
            if($input->getOption('success')) {
40
                $tgApi->sendMessage($game->chatId, 'Bot is back online! The game continues...');
41
            } else {
42
                $tgApi->sendMessage($game->chatId, 'Bot rebooting due to deploy, sorry. The game will continue once bot boots again.');
43
            }
44
        }
45
    }
46
}
47