|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of CacheTool. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Samuel Gordalina <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CacheTool\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Herrera\Phar\Update\Manager; |
|
15
|
|
|
use Herrera\Phar\Update\Manifest; |
|
16
|
|
|
use Herrera\Phar\Update\Update; |
|
17
|
|
|
use Herrera\Version\Parser; |
|
18
|
|
|
use Symfony\Component\Console\Command\Command; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
|
|
22
|
|
|
class SelfUpdateCommand extends Command |
|
23
|
|
|
{ |
|
24
|
|
|
const MANIFEST_FILE = 'http://gordalina.github.io/cachetool/manifest.json'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
|
|
->setName('self-update') |
|
33
|
|
|
->setAliases(array('selfupdate')) |
|
34
|
|
|
->setDescription('Updates cachetool.phar to the latest version') |
|
35
|
|
|
; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
42
|
|
|
{ |
|
43
|
|
|
$manifest = Manifest::loadFile(self::MANIFEST_FILE); |
|
44
|
|
|
|
|
45
|
|
|
$currentVersion = Parser::toVersion($this->getApplication()->getVersion()); |
|
46
|
|
|
$update = $manifest->findRecent($currentVersion, true); |
|
47
|
|
|
|
|
48
|
|
|
if (false === $update instanceof Update) { |
|
49
|
|
|
$output->writeln(sprintf('You are already using the latest version: <info>%s</info>', $currentVersion)); |
|
50
|
|
|
|
|
51
|
|
|
return 0; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$output->writeln(sprintf('Updating to version <info>%s</info>', $update->getVersion())); |
|
55
|
|
|
|
|
56
|
|
|
$manager = new Manager($manifest); |
|
57
|
|
|
$manager->update($this->getApplication()->getVersion(), true); |
|
58
|
|
|
|
|
59
|
|
|
$output->writeln(sprintf('SHA1 verified <info>%s</info>', $update->getSha1())); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|