-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathUpdateCommand.php
77 lines (59 loc) · 2.1 KB
/
UpdateCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Statamic\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
class UpdateCommand extends Command
{
use Concerns\RunsCommands;
protected $input;
protected $output;
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this
->setName('update')
->setDescription('Update the current directory\'s Statamic install to the latest version');
}
/**
* Execute the command.
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->input = $input;
$this->output = $output;
$please = new Please($output);
if ($please->isV2()) {
$output->writeln(PHP_EOL.'<error>Statamic v2 is no longer supported!</error>'.PHP_EOL);
return 1;
}
$output->writeln(PHP_EOL.'<comment>NOTE: If you have previously updated using the CP, you may need to update the version in your composer.json before running this update!</comment>'.PHP_EOL);
$command = $this->updateCommand();
$this->runCommand($command);
return 0;
}
/**
* Determine the update command.
*
* @return string
*/
protected function updateCommand()
{
$helper = $this->getHelper('question');
$options = [
'Update Statamic and its dependencies [composer update statamic/cms --with-dependencies]',
'Update all project dependencies [composer update]',
];
$question = new ChoiceQuestion('How would you like to update Statamic?', $options, 0);
$selection = $helper->ask($this->input, new SymfonyStyle($this->input, $this->output), $question);
return strpos($selection, 'statamic/cms --with-dependencies')
? 'composer update statamic/cms --with-dependencies'
: 'composer update';
}
}