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\Package\RootPackageFileManager; |
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 RootPackageFileManager |
29
|
|
|
*/ |
30
|
|
|
private $packageFileManager; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates the command handler. |
34
|
|
|
* |
35
|
|
|
* @param RootPackageFileManager $packageFileManager The manager of the |
36
|
|
|
* puli.json file. |
37
|
|
|
*/ |
38
|
|
|
public function __construct(RootPackageFileManager $packageFileManager) |
39
|
|
|
{ |
40
|
|
|
$this->packageFileManager = $packageFileManager; |
41
|
|
|
} |
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
|
|
|
public function handle(Args $args, IO $io) |
52
|
|
|
{ |
53
|
|
|
$packageFile = $this->packageFileManager->getPackageFile(); |
54
|
|
|
$originVersion = $packageFile->getVersion(); |
55
|
|
|
$targetVersion = $args->getArgument('version'); |
56
|
|
|
|
57
|
|
|
if (version_compare($originVersion, $targetVersion, '=')) { |
58
|
|
|
$io->writeLine(sprintf('Your puli.json is already at version %s.', $targetVersion)); |
59
|
|
|
|
60
|
|
|
return 0; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->packageFileManager->migrate($targetVersion); |
64
|
|
|
|
65
|
|
|
$io->writeLine(sprintf( |
66
|
|
|
'Migrated your puli.json from version %s to version %s.', |
67
|
|
|
$originVersion, |
68
|
|
|
$targetVersion |
69
|
|
|
)); |
70
|
|
|
|
71
|
|
|
return 0; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|