Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
* 1.x:
  Read from symfony.lock when checking for recipe updates
  Fix PHP warning when using Composer 1
  • Loading branch information
nicolas-grekas committed Jun 6, 2022
2 parents f15c99e + 9c61279 commit 581a978
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
17 changes: 12 additions & 5 deletions src/Command/RecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Composer\Command\BaseCommand;
use Composer\Downloader\TransportException;
use Composer\Package\Package;
use Composer\Util\HttpDownloader;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -62,19 +63,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Inspect one or all packages
$package = $input->getArgument('package');
if (null !== $package) {
$packages = [0 => ['name' => strtolower($package)]];
$packages = [strtolower($package)];
} else {
$locker = $this->getComposer()->getLocker();
$lockData = $locker->getLockData();

// Merge all packages installed
$packages = array_merge($lockData['packages'], $lockData['packages-dev']);
$packages = array_column(array_merge($lockData['packages'], $lockData['packages-dev']), 'name');
$packages = array_unique(array_merge($packages, array_keys($this->symfonyLock->all())));
}

$operations = [];
foreach ($packages as $value) {
if (null === $pkg = $installedRepo->findPackage($value['name'], '*')) {
$this->getIO()->writeError(sprintf('<error>Package %s is not installed</error>', $value['name']));
foreach ($packages as $name) {
$pkg = $installedRepo->findPackage($name, '*');

if (!$pkg && $this->symfonyLock->has($name)) {
$pkgVersion = $this->symfonyLock->get($name)['version'];
$pkg = new Package($name, $pkgVersion, $pkgVersion);
} elseif (!$pkg) {
$this->getIO()->writeError(sprintf('<error>Package %s is not installed</error>', $name));

continue;
}
Expand Down
34 changes: 13 additions & 21 deletions src/Command/UpdateRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Composer\Command\BaseCommand;
use Composer\IO\IOInterface;
use Composer\Package\Package;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
Expand Down Expand Up @@ -122,7 +123,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

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

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

$newRecipe = $this->getRecipe($packageName);
$newRecipe = $this->getRecipe($package);

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

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

return new Recipe(
$package,
$packageName,
$package->getName(),
$operation->getOperationType(),
$recipes['manifests'][$packageName],
$recipes['locks'][$packageName] ?? []
$recipes['manifests'][$package->getName()],
$recipes['locks'][$package->getName()] ?? []
);
}

Expand Down Expand Up @@ -358,19 +356,13 @@ private function generateChangelog(Recipe $originalRecipe): ?array
private function askForPackage(IOInterface $io, Lock $symfonyLock): ?string
{
$installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
$locker = $this->getComposer()->getLocker();
$lockData = $locker->getLockData();

// Merge all packages installed
$packages = array_merge($lockData['packages'], $lockData['packages-dev']);

$operations = [];
foreach ($packages as $value) {
if (null === $pkg = $installedRepo->findPackage($value['name'], '*')) {
continue;
foreach ($symfonyLock->all() as $name => $lock) {
if (isset($lock['recipe']['ref'])) {
$package = $installedRepo->findPackage($name, '*') ?? new Package($name, $lock['version'], $lock['version']);
$operations[] = new InformationOperation($package);
}

$operations[] = new InformationOperation($pkg);
}

$recipes = $this->flex->fetchRecipes($operations, false);
Expand Down
1 change: 0 additions & 1 deletion src/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public function getRecipes(array $operations): array
}

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

Expand Down
13 changes: 8 additions & 5 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function configureInstaller()
$this->installer = $trace['object']->setSuggestedPackagesReporter(new SuggestedPackagesReporter(new NullIO()));

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

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

foreach ($transation->getOperations() as $operation) {
if ($this->shouldRecordOperation($operation, $event->isDevMode(), $event->getComposer())) {
if (!$operation instanceof UninstallOperation && $this->shouldRecordOperation($operation, $event->isDevMode(), $event->getComposer())) {
$this->operations[] = $operation;
}
}
Expand Down Expand Up @@ -606,9 +606,7 @@ public function fetchRecipes(array $operations, bool $reset): array
} else {
$recipes[$name] = $recipe;
}
}

if (!isset($manifests[$name])) {
} else {
$bundles = [];

if (null === $devPackages) {
Expand All @@ -626,6 +624,10 @@ public function fetchRecipes(array $operations, bool $reset): array
'manifest' => ['bundles' => $bundles],
];
$recipes[$name] = new Recipe($package, $name, $job, $manifest);

if ($operation instanceof InstallOperation) {
$this->lock->set($name, ['version' => $package->getPrettyVersion()]);
}
}
}
}
Expand Down Expand Up @@ -810,6 +812,7 @@ public static function getSubscribedEvents(): array
$events = [
PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder',
PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall',
PackageEvents::POST_PACKAGE_UNINSTALL => 'record',
InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations',
PluginEvents::PRE_POOL_CREATE => 'truncatePackages',
ScriptEvents::POST_CREATE_PROJECT_CMD => 'configureProject',
Expand Down

0 comments on commit 581a978

Please sign in to comment.