|
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
|
|
|
if (file_exists('var/logs/deploy.version')) { |
|
38
|
|
|
$version = file_get_contents('var/logs/deploy.version'); |
|
39
|
|
|
} else { |
|
40
|
|
|
$version = 0; |
|
41
|
|
|
file_put_contents('var/logs/deploy.version', $version); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (false == $input->getOption('success')) { |
|
45
|
|
|
$version++; |
|
46
|
|
|
file_put_contents('var/logs/deploy.version', $version); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** @var Game $game */ |
|
50
|
|
|
foreach ($games as $game) { |
|
51
|
|
|
if ($input->getOption('success')) { |
|
52
|
|
|
$tgApi->sendMessage( |
|
53
|
|
|
$game->chatId, |
|
54
|
|
|
'Bot is back online (updated to build '.$version.')! The game continues...' |
|
55
|
|
|
); |
|
56
|
|
|
} else { |
|
57
|
|
|
$tgApi->sendMessage( |
|
58
|
|
|
$game->chatId, |
|
59
|
|
|
'Bot rebooting due to deploy (build '.$version |
|
60
|
|
|
.'), sorry. The game will continue once bot boots again.' |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|