|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Moodle component manager. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Luke Carrier <[email protected]> |
|
7
|
|
|
* @copyright 2016 Luke Carrier |
|
8
|
|
|
* @license GPL-3.0+ |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ComponentManager\Step; |
|
12
|
|
|
|
|
13
|
|
|
use ComponentManager\Exception\InvalidProjectException; |
|
14
|
|
|
use ComponentManager\Project\Project; |
|
15
|
|
|
use ComponentManager\ResolvedComponentVersion; |
|
16
|
|
|
use ComponentManager\Task\InstallTask; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Resolve component version specifications to available versions. |
|
21
|
|
|
*/ |
|
22
|
|
|
class ResolveComponentVersionsStep implements Step { |
|
23
|
|
|
/** |
|
24
|
|
|
* Project. |
|
25
|
|
|
* |
|
26
|
|
|
* @var Project |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $project; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Initialiser. |
|
32
|
|
|
* |
|
33
|
|
|
* @param Project $project |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(Project $project) { |
|
36
|
|
|
$this->project = $project; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc Step |
|
41
|
|
|
* |
|
42
|
|
|
* @param InstallTask $task |
|
43
|
|
|
*/ |
|
44
|
|
|
public function execute($task, LoggerInterface $logger) { |
|
45
|
|
|
$componentSpecifications = $this->project->getProjectFile()->getComponentSpecifications(); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($componentSpecifications as $componentSpecification) { |
|
48
|
|
|
$packageRepository = $this->project->getPackageRepository( |
|
49
|
|
|
$componentSpecification->getPackageRepository()); |
|
50
|
|
|
|
|
51
|
|
|
$logger->info('Resolving component version', [ |
|
52
|
|
|
'component' => $componentSpecification->getName(), |
|
53
|
|
|
'packageRepository' => $componentSpecification->getPackageRepository(), |
|
54
|
|
|
'version' => $componentSpecification->getVersion(), |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$componentName = $componentSpecification->getName(); |
|
58
|
|
|
$componentVersion = $componentSpecification->getVersion(); |
|
59
|
|
|
$packageRepositoryName = $componentSpecification->getPackageRepository(); |
|
60
|
|
|
|
|
61
|
|
|
$component = $packageRepository->resolveComponent( |
|
62
|
|
|
$componentSpecification, $logger); |
|
63
|
|
|
if (!$component) { |
|
64
|
|
|
throw new InvalidProjectException( |
|
65
|
|
|
"The component \"{$componentName}\" could not be found within repository \"{$packageRepositoryName}\"", |
|
|
|
|
|
|
66
|
|
|
InvalidProjectException::CODE_MISSING_COMPONENT); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/* Note that even at this late stage, we still might not have a final |
|
70
|
|
|
* version for the component: |
|
71
|
|
|
* -> If the package repository provides us with the Moodle |
|
72
|
|
|
* $plugin->version value, we'll be using it here. |
|
73
|
|
|
* -> If the package repository is a version control system, the version |
|
74
|
|
|
* will contain the name of a branch or tag and will need to be |
|
75
|
|
|
* resolved to an individual commit. */ |
|
76
|
|
|
$version = $component->getVersion($componentVersion); |
|
77
|
|
|
|
|
78
|
|
|
$task->addResolvedComponentVersion(new ResolvedComponentVersion( |
|
79
|
|
|
$componentSpecification, $packageRepository, $component, |
|
80
|
|
|
$version)); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.