1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Packy. |
5
|
|
|
* |
6
|
|
|
* (c) Peter Nijssen |
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 AppBundle\Command; |
13
|
|
|
|
14
|
|
|
use AppBundle\Entity\Dependency; |
15
|
|
|
use AppBundle\Entity\Package; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class ProjectUpdateCommand extends ContainerAwareCommand |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Configure the command. |
24
|
|
|
*/ |
25
|
|
|
protected function configure() |
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('packy:project:update') |
29
|
|
|
->setDescription('Update the dependencies of projects'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Execute the command. |
34
|
|
|
* |
35
|
|
|
* @param InputInterface $input |
36
|
|
|
* @param OutputInterface $output |
37
|
|
|
* |
38
|
|
|
* @throws \Exception |
39
|
|
|
*/ |
40
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
41
|
|
|
{ |
42
|
|
|
$projectRepository = $this->getContainer()->get('packy.repository.project'); |
43
|
|
|
$packageRepository = $this->getContainer()->get('packy.repository.package'); |
44
|
|
|
$repositoryManagers = $this->getContainer()->get('packy.repository_managers'); |
45
|
|
|
$dependencyManagers = $this->getContainer()->get('packy.dependency_managers'); |
46
|
|
|
$packageManagers = $this->getContainer()->get('packy.package_managers'); |
47
|
|
|
$versionFormatter = $this->getContainer()->get('packy.service.version_formatter'); |
48
|
|
|
|
49
|
|
|
$projects = $projectRepository->findAll(); |
50
|
|
|
|
51
|
|
|
foreach ($projects as $project) { |
52
|
|
|
$repository = $repositoryManagers->get($project->getRepositoryType()); |
53
|
|
|
|
54
|
|
|
foreach ($dependencyManagers->getAll() as $dependencyManager) { |
55
|
|
|
$dependencies = $dependencyManager->fetchDependencies($repository, $project); |
56
|
|
|
|
57
|
|
|
foreach ($dependencies as $name => $version) { |
58
|
|
|
$package = $packageRepository->findOne($name, $dependencyManager->getName()); |
59
|
|
|
if (null === $package) { |
60
|
|
|
$package = new Package(); |
61
|
|
|
$package->setName($name); |
62
|
|
|
$package->setManager($dependencyManager->getName()); |
63
|
|
|
$packageRepository->create($package); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$packageManager = $packageManagers->get($package->getManager()); |
67
|
|
|
|
68
|
|
|
$package = $packageManager->analyzePackage($package); |
69
|
|
|
$packageRepository->update($package); |
70
|
|
|
|
71
|
|
|
$dependency = new Dependency(); |
72
|
|
|
$dependency->setPackage($package); |
73
|
|
|
$dependency->setRawVersion($version); |
74
|
|
|
$dependency->setCurrentVersion($versionFormatter->normalizeVersion($version)); |
75
|
|
|
$project->addDependency($dependency); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$projectRepository->update($project); |
80
|
|
|
|
81
|
|
|
$output->writeln('<info>Project ' . $project->getName() . ' updated!</info>'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|