Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
RequireUpdateDryRunCommand Class Reference

Public Member Functions

 __construct (MagentoComposerApplication $magentoComposerApplication, InfoCommand $infoCommand)
 
 run ($packages, $workingDir=null)
 

Protected Member Functions

 generateAdditionalErrorMessage ($message, $inputPackages)
 
 explodePackagesAndVersions ($packages)
 

Protected Attributes

 $magentoComposerApplication
 
 $infoCommand
 

Detailed Description

Class RequireUpdateDryRunCommand calls composer require and update –dry-run commands

Definition at line 12 of file RequireUpdateDryRunCommand.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( MagentoComposerApplication  $magentoComposerApplication,
InfoCommand  $infoCommand 
)

Constructor

Parameters
MagentoComposerApplication$magentoComposerApplication
InfoCommand$infoCommand

Definition at line 30 of file RequireUpdateDryRunCommand.php.

Member Function Documentation

◆ explodePackagesAndVersions()

explodePackagesAndVersions (   $packages)
protected

Returns array that contains package as key and version as value

Parameters
array$packages
Returns
array

Definition at line 143 of file RequireUpdateDryRunCommand.php.

144  {
145  $packagesAndVersions = [];
146  foreach ($packages as $package) {
147  $package = explode(' ', $package);
148  $packagesAndVersions[$package[0]] = $package[1];
149  }
150 
151  return $packagesAndVersions;
152  }

◆ generateAdditionalErrorMessage()

generateAdditionalErrorMessage (   $message,
  $inputPackages 
)
protected

Generates additional explanation for error message

Parameters
array$message
array$inputPackages
Returns
string

Definition at line 79 of file RequireUpdateDryRunCommand.php.

80  {
81  $matches = [];
82  $errorMessage = '';
83  $packages = [];
84  $rawLines = explode(PHP_EOL, $message);
85 
86  foreach ($rawLines as $line) {
87  if (preg_match('/- (.*) requires (.*) -> no matching package/', $line, $matches)) {
88  $packages[] = $matches[1];
89  $packages[] = $matches[2];
90  }
91  }
92 
93  if (!empty($packages)) {
94  $packages = array_unique($packages);
95  $packages = $this->explodePackagesAndVersions($packages);
96  $inputPackages = $this->explodePackagesAndVersions($inputPackages);
97 
98  $update = [];
99  $conflicts = [];
100 
101  foreach ($inputPackages as $package => $version) {
102  if (isset($packages[$package])) {
103  $update[] = $package . ' to ' . $version;
104  }
105  }
106 
107  foreach (array_diff_key($packages, $inputPackages) as $package => $version) {
108 
109  if (!$packageInfo = $this->infoCommand->run($package, true)) {
110  return false;
111  }
112 
113  $currentVersion = $packageInfo[InfoCommand::CURRENT_VERSION];
114 
115  if (empty($packageInfo[InfoCommand::AVAILABLE_VERSIONS])) {
116  $packageInfo = $this->infoCommand->run($package);
117  if (empty($packageInfo[InfoCommand::AVAILABLE_VERSIONS])) {
118  return false;
119  }
120  }
121 
122  $conflicts[] = ' - ' . $package . ' version ' . $currentVersion . '. '
123  . 'Please try to update it to one of the following package versions: '
124  . implode(', ', $packageInfo['available_versions']);
125  }
126 
127  $errorMessage = 'You are trying to update package(s) '
128  . implode(', ', $update) . PHP_EOL
129  . "We've detected conflicts with the following packages:" . PHP_EOL
130  . implode(PHP_EOL, $conflicts)
131  . PHP_EOL;
132  }
133 
134  return $errorMessage;
135  }
$message

◆ run()

run (   $packages,
  $workingDir = null 
)

Runs composer update –dry-run command

Parameters
array$packages
string | null$workingDir
Returns
string
Exceptions

Definition at line 46 of file RequireUpdateDryRunCommand.php.

47  {
48  try {
49  // run require
50  $this->magentoComposerApplication->runComposerCommand(
51  ['command' => 'require', 'packages' => $packages, '--no-update' => true],
52  $workingDir
53  );
54 
55  $output = $this->magentoComposerApplication->runComposerCommand(
56  ['command' => 'update', '--dry-run' => true],
57  $workingDir
58  );
59  } catch (\RuntimeException $e) {
60  $errorMessage = $this->generateAdditionalErrorMessage($e->getMessage(), $packages);
61  if ($errorMessage) {
62  throw new \RuntimeException($errorMessage, $e->getCode(), $e);
63  } else {
64  throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
65  }
66 
67  }
68 
69  return $output;
70  }

Field Documentation

◆ $infoCommand

$infoCommand
protected

Definition at line 22 of file RequireUpdateDryRunCommand.php.

◆ $magentoComposerApplication

$magentoComposerApplication
protected

Definition at line 17 of file RequireUpdateDryRunCommand.php.


The documentation for this class was generated from the following file: