1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Juanber84\Console\Command; |
4
|
|
|
|
5
|
|
|
use Juanber84\Services\ApplicationService; |
6
|
|
|
use Juanber84\Services\DownloadService; |
7
|
|
|
use Juanber84\Services\GitHubService; |
8
|
|
|
use Juanber84\Texts\SelfUpdateCommandText; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
13
|
|
|
|
14
|
|
|
class SelfUpdateCommand extends Command |
15
|
|
|
{ |
16
|
|
|
const COMMAND_NAME = 'self-update'; |
17
|
|
|
const COMMAND_DESC = 'Update Dep application to last release.'; |
18
|
|
|
|
19
|
|
|
private $applicationService; |
20
|
|
|
|
21
|
|
|
private $gitHubService; |
22
|
|
|
|
23
|
|
|
private $downloadService; |
24
|
|
|
|
25
|
|
|
public function __construct(ApplicationService $applicationService, GitHubService $gitHubService, DownloadService $downloadService) |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
|
29
|
|
|
$this->applicationService = $applicationService; |
30
|
|
|
$this->gitHubService = $gitHubService; |
31
|
|
|
$this->downloadService = $downloadService; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setName(self::COMMAND_NAME) |
38
|
|
|
->setDescription(self::COMMAND_DESC); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
42
|
|
|
{ |
43
|
|
|
$currentVersion = $this->applicationService->currentTimeVersion(); |
44
|
|
|
$latestVersion = $this->gitHubService->latestTimeVersion(); |
45
|
|
|
|
46
|
|
|
if ($currentVersion < $latestVersion) { |
47
|
|
|
|
48
|
|
|
$helper = $this->getHelper('question'); |
49
|
|
|
$question = new ConfirmationQuestion('Continue with this action? <question>Y/n</question> ', true); |
50
|
|
|
if (!$helper->ask($input, $output, $question)) { |
51
|
|
|
return $output->writeln('<info> '.SelfUpdateCommandText::OK_CANCEL.'</info>'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($this->downloadService->download($this->gitHubService->latestBrowserDownloadUrl())){ |
55
|
|
|
$output->writeln('<info> '.SelfUpdateCommandText::OK_INSTALLED.'</info>'); |
56
|
|
|
} else { |
57
|
|
|
$output->writeln('<info> '.SelfUpdateCommandText::KO_INSTALLED.'</info>'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} else { |
61
|
|
|
$output->writeln('<info> '.SelfUpdateCommandText::OK_CURRENT.'</info>'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |