1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of RoboSystemPackage. |
4
|
|
|
* |
5
|
|
|
* @author Aitor García Martínez (Falc) <[email protected]> |
6
|
|
|
* @copyright 2015 Aitor García Martínez (Falc) <[email protected]> |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Falc\Robo\Package; |
11
|
|
|
|
12
|
|
|
use Robo\Contract\CommandInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Package Update |
16
|
|
|
* |
17
|
|
|
* ``` php |
18
|
|
|
* // Updating a single package: |
19
|
|
|
* $this->taskPackageUpdate() |
20
|
|
|
* ->packageManager('yum') |
21
|
|
|
* ->package('package1') |
22
|
|
|
* ->run(); |
23
|
|
|
* |
24
|
|
|
* // Updating many packages: |
25
|
|
|
* $this->taskPackageUpdate() |
26
|
|
|
* ->packageManager('yum') |
27
|
|
|
* ->packages(['package1', 'package2']) |
28
|
|
|
* ->run(); |
29
|
|
|
* |
30
|
|
|
* // Compact form: |
31
|
|
|
* $this->taskPackageUpdate('yum', ['package1', 'package2'])->run(); |
32
|
|
|
* |
33
|
|
|
* // It allows to specify packages conditionally: |
34
|
|
|
* $update = $this->taskPackageUpdate('yum', ['package1']); |
35
|
|
|
* |
36
|
|
|
* if ($requiresPackage2) { |
37
|
|
|
* $update->package('package2'); |
38
|
|
|
* } |
39
|
|
|
* |
40
|
|
|
* $update->run(); |
41
|
|
|
* |
42
|
|
|
* // It is possible to specify a pattern: |
43
|
|
|
* $this->taskPackageUpdate() |
44
|
|
|
* ->packageManager('yum') |
45
|
|
|
* ->package('package1-*') // Updates all packages starting with "package1-" |
46
|
|
|
* ->run(); |
47
|
|
|
* ``` |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
class Update extends BaseTask implements CommandInterface |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
8 |
|
public function getCommand() |
55
|
|
|
{ |
56
|
8 |
|
if ($this->builder === null) { |
57
|
1 |
|
throw new \Exception('Package manager not defined'); |
58
|
|
|
} |
59
|
|
|
|
60
|
7 |
|
$this->builder->update($this->packages)->assumeYes(); |
61
|
|
|
|
62
|
7 |
|
if (!$this->verbose) { |
63
|
6 |
|
$this->builder->quiet(); |
64
|
|
|
} |
65
|
|
|
|
66
|
7 |
|
return $this->builder->getCommand(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
1 |
|
public function run() |
73
|
|
|
{ |
74
|
1 |
|
$command = $this->getCommand(); |
75
|
|
|
|
76
|
1 |
|
$this->printTaskInfo('Updating packages...'); |
77
|
1 |
|
return $this->executeCommand($command); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.