|
2 | 2 | namespace Drush\Commands\pm; |
3 | 3 |
|
4 | 4 | use Composer\Semver\Comparator; |
| 5 | +use Composer\Semver\Semver; |
5 | 6 | use Consolidation\AnnotatedCommand\CommandData; |
6 | 7 | use Consolidation\OutputFormatters\StructuredData\RowsOfFields; |
7 | 8 | use Drush\Commands\DrushCommands; |
@@ -35,8 +36,7 @@ class SecurityUpdateCommands extends DrushCommands |
35 | 36 | * @field-labels |
36 | 37 | * name: Name |
37 | 38 | * version: Installed Version |
38 | | - * min-version: Suggested version |
39 | | - * @default-fields name,version,min-version |
| 39 | + * @default-fields name,version |
40 | 40 | * |
41 | 41 | * @filter-default-field name |
42 | 42 | * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields |
@@ -69,7 +69,7 @@ public function suggestComposerCommand($result, CommandData $commandData) |
69 | 69 | if (!empty($this->securityUpdates)) { |
70 | 70 | $suggested_command = 'composer require '; |
71 | 71 | foreach ($this->securityUpdates as $package) { |
72 | | - $suggested_command .= $package['name'] . ':^' . $package['min-version'] . ' '; |
| 72 | + $suggested_command .= $package['name'] . ' '; |
73 | 73 | } |
74 | 74 | $suggested_command .= '--update-with-dependencies'; |
75 | 75 | $this->logger()->warning("One or more of your dependencies has an outstanding security update. Please apply update(s) immediately."); |
@@ -137,104 +137,15 @@ protected function loadSiteComposerLock() |
137 | 137 | protected function registerAllSecurityUpdates($composer_lock_data, $security_advisories_composer_json) |
138 | 138 | { |
139 | 139 | $both = array_merge($composer_lock_data['packages-dev'], $composer_lock_data['packages']); |
| 140 | + $conflict = $security_advisories_composer_json['conflict']; |
140 | 141 | foreach ($both as $package) { |
141 | 142 | $name = $package['name']; |
142 | | - $this->registerPackageSecurityUpdates($security_advisories_composer_json, $name, $package); |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - /** |
147 | | - * Determines if update is available based on a conflict constraint. |
148 | | - * |
149 | | - * @param string $conflict_constraint |
150 | | - * The constraint for the conflicting, insecure package version. |
151 | | - * E.g., <1.0.0. |
152 | | - * @param array $package |
153 | | - * The package to be evaluated. |
154 | | - * @param string $name |
155 | | - * The human readable display name for the package. |
156 | | - * |
157 | | - * @return array |
158 | | - * An associative array containing name, version, and min-version keys. |
159 | | - */ |
160 | | - public static function determineUpdatesFromConstraint( |
161 | | - $conflict_constraint, |
162 | | - $package, |
163 | | - $name |
164 | | - ) { |
165 | | - // Only parse constraints that follow pattern like "<1.0.0". |
166 | | - if (substr($conflict_constraint, 0, 1) == '<') { |
167 | | - $min_version = substr($conflict_constraint, 1); |
168 | | - if (Comparator::lessThan( |
169 | | - $package['version'], |
170 | | - $min_version |
171 | | - )) { |
172 | | - return [ |
| 143 | + if (!empty($conflict[$name]) && Semver::satisfies($package['version'], $security_advisories_composer_json['conflict'][$name])) { |
| 144 | + $this->securityUpdates[$name] = [ |
173 | 145 | 'name' => $name, |
174 | 146 | 'version' => $package['version'], |
175 | | - // Assume that conflict constraint of <1.0.0 indicates that |
176 | | - // 1.0.0 is the available, secure version. |
177 | | - 'min-version' => $min_version, |
178 | 147 | ]; |
179 | 148 | } |
180 | | - } // Compare exact versions that are insecure. |
181 | | - elseif (preg_match( |
182 | | - '/^[[:digit:]](?![-*><=~ ])/', |
183 | | - $conflict_constraint |
184 | | - )) { |
185 | | - $exact_version = $conflict_constraint; |
186 | | - if (Comparator::equalTo( |
187 | | - $package['version'], |
188 | | - $exact_version |
189 | | - )) { |
190 | | - $version_parts = explode('.', $package['version']); |
191 | | - if (count($version_parts) == 3) { |
192 | | - $version_parts[2]++; |
193 | | - $min_version = implode('.', $version_parts); |
194 | | - return [ |
195 | | - 'name' => $name, |
196 | | - 'version' => $package['version'], |
197 | | - // Assume that conflict constraint of 1.0.0 indicates that |
198 | | - // 1.0.1 is the available, secure version. |
199 | | - 'min-version' => $min_version, |
200 | | - ]; |
201 | | - } |
202 | | - } |
203 | | - } |
204 | | - return []; |
205 | | - } |
206 | | - |
207 | | - /** |
208 | | - * Registers available security updates for a given package. |
209 | | - * |
210 | | - * @param array $security_advisories_composer_json |
211 | | - * The composer.json array from drupal-security-advisories. |
212 | | - * @param string $name |
213 | | - * The human readable display name for the package. |
214 | | - * @param array $package |
215 | | - * The package to be evaluated. |
216 | | - */ |
217 | | - protected function registerPackageSecurityUpdates( |
218 | | - $security_advisories_composer_json, |
219 | | - $name, |
220 | | - $package |
221 | | - ) { |
222 | | - if (empty($this->securityUpdates[$name]) && |
223 | | - !empty($security_advisories_composer_json['conflict'][$name])) { |
224 | | - $conflict_constraints = explode( |
225 | | - ',', |
226 | | - $security_advisories_composer_json['conflict'][$name] |
227 | | - ); |
228 | | - foreach ($conflict_constraints as $conflict_constraint) { |
229 | | - $available_update = $this->determineUpdatesFromConstraint( |
230 | | - $conflict_constraint, |
231 | | - $package, |
232 | | - $name |
233 | | - ); |
234 | | - if ($available_update) { |
235 | | - $this->securityUpdates[$name] = $available_update; |
236 | | - } |
237 | | - } |
238 | 149 | } |
239 | 150 | } |
240 | 151 | } |
0 commit comments