1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[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 Puli\Cli\Handler; |
13
|
|
|
|
14
|
|
|
use Puli\Manager\Api\Module\RootModuleFileManager; |
15
|
|
|
use Webmozart\Console\Api\Args\Args; |
16
|
|
|
use Webmozart\Console\Api\IO\IO; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Handles the "upgrade" command. |
20
|
|
|
* |
21
|
|
|
* @since 1.0 |
22
|
|
|
* |
23
|
|
|
* @author Bernhard Schussek <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class UpgradeCommandHandler |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var RootModuleFileManager |
29
|
|
|
*/ |
30
|
|
|
private $moduleFileManager; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates the command handler. |
34
|
|
|
* |
35
|
|
|
* @param RootModuleFileManager $moduleFileManager The manager of the |
36
|
|
|
* puli.json file |
37
|
|
|
*/ |
38
|
3 |
|
public function __construct(RootModuleFileManager $moduleFileManager) |
39
|
|
|
{ |
40
|
3 |
|
$this->moduleFileManager = $moduleFileManager; |
41
|
3 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Handles the "upgrade" command. |
45
|
|
|
* |
46
|
|
|
* @param Args $args The console arguments |
47
|
|
|
* @param IO $io The I/O |
48
|
|
|
* |
49
|
|
|
* @return int The status code |
50
|
|
|
*/ |
51
|
3 |
|
public function handle(Args $args, IO $io) |
52
|
|
|
{ |
53
|
3 |
|
$moduleFile = $this->moduleFileManager->getModuleFile(); |
54
|
3 |
|
$originVersion = $moduleFile->getVersion(); |
55
|
3 |
|
$targetVersion = $args->getArgument('version'); |
56
|
|
|
|
57
|
3 |
|
if (version_compare($originVersion, $targetVersion, '=')) { |
58
|
1 |
|
$io->writeLine(sprintf('Your puli.json is already at version %s.', $targetVersion)); |
59
|
|
|
|
60
|
1 |
|
return 0; |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
$this->moduleFileManager->migrate($targetVersion); |
64
|
|
|
|
65
|
2 |
|
$io->writeLine(sprintf( |
66
|
2 |
|
'Migrated your puli.json from version %s to version %s.', |
67
|
|
|
$originVersion, |
68
|
|
|
$targetVersion |
69
|
|
|
)); |
70
|
|
|
|
71
|
2 |
|
return 0; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|