Skip to content

Commit 581a978

Browse files
Merge branch '1.x' into 2.x
* 1.x: Read from symfony.lock when checking for recipe updates Fix PHP warning when using Composer 1
2 parents f15c99e + 9c61279 commit 581a978

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

src/Command/RecipesCommand.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Composer\Command\BaseCommand;
1515
use Composer\Downloader\TransportException;
16+
use Composer\Package\Package;
1617
use Composer\Util\HttpDownloader;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
@@ -62,19 +63,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
6263
// Inspect one or all packages
6364
$package = $input->getArgument('package');
6465
if (null !== $package) {
65-
$packages = [0 => ['name' => strtolower($package)]];
66+
$packages = [strtolower($package)];
6667
} else {
6768
$locker = $this->getComposer()->getLocker();
6869
$lockData = $locker->getLockData();
6970

7071
// Merge all packages installed
71-
$packages = array_merge($lockData['packages'], $lockData['packages-dev']);
72+
$packages = array_column(array_merge($lockData['packages'], $lockData['packages-dev']), 'name');
73+
$packages = array_unique(array_merge($packages, array_keys($this->symfonyLock->all())));
7274
}
7375

7476
$operations = [];
75-
foreach ($packages as $value) {
76-
if (null === $pkg = $installedRepo->findPackage($value['name'], '*')) {
77-
$this->getIO()->writeError(sprintf('<error>Package %s is not installed</error>', $value['name']));
77+
foreach ($packages as $name) {
78+
$pkg = $installedRepo->findPackage($name, '*');
79+
80+
if (!$pkg && $this->symfonyLock->has($name)) {
81+
$pkgVersion = $this->symfonyLock->get($name)['version'];
82+
$pkg = new Package($name, $pkgVersion, $pkgVersion);
83+
} elseif (!$pkg) {
84+
$this->getIO()->writeError(sprintf('<error>Package %s is not installed</error>', $name));
7885

7986
continue;
8087
}

src/Command/UpdateRecipesCommand.php

+13-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Composer\Command\BaseCommand;
1515
use Composer\IO\IOInterface;
16+
use Composer\Package\Package;
1617
use Composer\Util\ProcessExecutor;
1718
use Symfony\Component\Console\Exception\RuntimeException;
1819
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
@@ -122,7 +123,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
122123
return 1;
123124
}
124125

125-
$originalRecipe = $this->getRecipe($packageName, $recipeRef, $recipeVersion);
126+
$installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
127+
$package = $installedRepo->findPackage($packageName, '*') ?? new Package($packageName, $packageLockData['version'], $packageLockData['version']);
128+
$originalRecipe = $this->getRecipe($package, $recipeRef, $recipeVersion);
126129

127130
if (null === $originalRecipe) {
128131
$io->writeError([
@@ -134,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134137
return 1;
135138
}
136139

137-
$newRecipe = $this->getRecipe($packageName);
140+
$newRecipe = $this->getRecipe($package);
138141

139142
if ($newRecipe->getRef() === $originalRecipe->getRef()) {
140143
$io->write(sprintf('This recipe for <info>%s</info> is already at the latest version.', $packageName));
@@ -259,13 +262,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
259262
return 0;
260263
}
261264

262-
private function getRecipe(string $packageName, string $recipeRef = null, string $recipeVersion = null): ?Recipe
265+
private function getRecipe(Package $package, string $recipeRef = null, string $recipeVersion = null): ?Recipe
263266
{
264-
$installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
265-
$package = $installedRepo->findPackage($packageName, '*');
266-
if (null === $package) {
267-
throw new RuntimeException(sprintf('Could not find package "%s". Try running "composer install".', $packageName));
268-
}
269267
$operation = new InformationOperation($package);
270268
if (null !== $recipeRef) {
271269
$operation->setSpecificRecipeVersion($recipeRef, $recipeVersion);
@@ -278,10 +276,10 @@ private function getRecipe(string $packageName, string $recipeRef = null, string
278276

279277
return new Recipe(
280278
$package,
281-
$packageName,
279+
$package->getName(),
282280
$operation->getOperationType(),
283-
$recipes['manifests'][$packageName],
284-
$recipes['locks'][$packageName] ?? []
281+
$recipes['manifests'][$package->getName()],
282+
$recipes['locks'][$package->getName()] ?? []
285283
);
286284
}
287285

@@ -358,19 +356,13 @@ private function generateChangelog(Recipe $originalRecipe): ?array
358356
private function askForPackage(IOInterface $io, Lock $symfonyLock): ?string
359357
{
360358
$installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
361-
$locker = $this->getComposer()->getLocker();
362-
$lockData = $locker->getLockData();
363-
364-
// Merge all packages installed
365-
$packages = array_merge($lockData['packages'], $lockData['packages-dev']);
366359

367360
$operations = [];
368-
foreach ($packages as $value) {
369-
if (null === $pkg = $installedRepo->findPackage($value['name'], '*')) {
370-
continue;
361+
foreach ($symfonyLock->all() as $name => $lock) {
362+
if (isset($lock['recipe']['ref'])) {
363+
$package = $installedRepo->findPackage($name, '*') ?? new Package($name, $lock['version'], $lock['version']);
364+
$operations[] = new InformationOperation($package);
371365
}
372-
373-
$operations[] = new InformationOperation($pkg);
374366
}
375367

376368
$recipes = $this->flex->fetchRecipes($operations, false);

src/Downloader.php

-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ public function getRecipes(array $operations): array
239239
}
240240

241241
if (null !== $this->endpoints) {
242-
$data['locks'][$package->getName()]['version'] = $version;
243242
continue;
244243
}
245244

src/Flex.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function configureInstaller()
206206
$this->installer = $trace['object']->setSuggestedPackagesReporter(new SuggestedPackagesReporter(new NullIO()));
207207

208208
$updateAllowList = \Closure::bind(function () {
209-
return $this->updateWhitelist ?? $this->updateAllowList;
209+
return $this->updateWhitelist ?? $this->updateAllowList ?? null;
210210
}, $this->installer, $this->installer)();
211211

212212
if (['php' => 0] === $updateAllowList) {
@@ -284,7 +284,7 @@ public function recordOperations(InstallerEvent $event)
284284
}, null, Transaction::class)();
285285

286286
foreach ($transation->getOperations() as $operation) {
287-
if ($this->shouldRecordOperation($operation, $event->isDevMode(), $event->getComposer())) {
287+
if (!$operation instanceof UninstallOperation && $this->shouldRecordOperation($operation, $event->isDevMode(), $event->getComposer())) {
288288
$this->operations[] = $operation;
289289
}
290290
}
@@ -606,9 +606,7 @@ public function fetchRecipes(array $operations, bool $reset): array
606606
} else {
607607
$recipes[$name] = $recipe;
608608
}
609-
}
610-
611-
if (!isset($manifests[$name])) {
609+
} else {
612610
$bundles = [];
613611

614612
if (null === $devPackages) {
@@ -626,6 +624,10 @@ public function fetchRecipes(array $operations, bool $reset): array
626624
'manifest' => ['bundles' => $bundles],
627625
];
628626
$recipes[$name] = new Recipe($package, $name, $job, $manifest);
627+
628+
if ($operation instanceof InstallOperation) {
629+
$this->lock->set($name, ['version' => $package->getPrettyVersion()]);
630+
}
629631
}
630632
}
631633
}
@@ -810,6 +812,7 @@ public static function getSubscribedEvents(): array
810812
$events = [
811813
PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder',
812814
PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall',
815+
PackageEvents::POST_PACKAGE_UNINSTALL => 'record',
813816
InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations',
814817
PluginEvents::PRE_POOL_CREATE => 'truncatePackages',
815818
ScriptEvents::POST_CREATE_PROJECT_CMD => 'configureProject',

0 commit comments

Comments
 (0)