|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AnimeDb package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Peter Gribanov <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
|
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace AnimeDb\Bundle\AppBundle\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use AnimeDb\Bundle\AppBundle\Entity\Notice; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Propose to update the application. |
|
18
|
|
|
*/ |
|
19
|
|
|
class ProposeUpdateCommand extends ContainerAwareCommand |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Interval offers updates. |
|
23
|
|
|
* |
|
24
|
|
|
* 30 days |
|
25
|
|
|
* |
|
26
|
|
|
* @var int |
|
27
|
|
|
*/ |
|
28
|
|
|
const INERVAL_UPDATE = 2592000; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Interval notification. |
|
32
|
|
|
* |
|
33
|
|
|
* 5 days |
|
34
|
|
|
* |
|
35
|
|
|
* @var int |
|
36
|
|
|
*/ |
|
37
|
|
|
const INERVAL_NOTIFICATION = 432000; |
|
38
|
|
|
|
|
39
|
|
|
protected function configure() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->setName('animedb:propose-update') |
|
42
|
|
|
->setDescription('Propose to update the application'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param InputInterface $input |
|
47
|
|
|
* @param OutputInterface $output |
|
48
|
|
|
* |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
52
|
|
|
{ |
|
53
|
|
|
$root = $this->getContainer()->getParameter('kernel.root_dir').'/../'; |
|
54
|
|
|
$time = filemtime($root.'composer.json'); |
|
55
|
|
|
|
|
56
|
|
|
if (file_exists($root.'composer.lock')) { |
|
57
|
|
|
$time = max($time, filemtime($root.'composer.lock')); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// need update |
|
61
|
|
|
if ($time + self::INERVAL_UPDATE < time()) { |
|
62
|
|
|
$output->writeln('Application must be updated'); |
|
63
|
|
|
|
|
64
|
|
|
// send notice |
|
65
|
|
|
$notice = new Notice(); |
|
66
|
|
|
$notice->setMessage( |
|
67
|
|
|
$this->getContainer()->get('templating')->render('AnimeDbAppBundle:Notice:propose_update.html.twig') |
|
68
|
|
|
); |
|
69
|
|
|
$em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
|
70
|
|
|
$em->persist($notice); |
|
71
|
|
|
$em->flush(); |
|
72
|
|
|
|
|
73
|
|
|
touch($root.'composer.json', time() + self::INERVAL_NOTIFICATION - self::INERVAL_UPDATE); |
|
74
|
|
|
} else { |
|
75
|
|
|
$output->writeln('Application is already updated'); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|