|
3 | 3 | namespace Drupal\Composer\Plugin\Scaffold;
|
4 | 4 |
|
5 | 5 | use Composer\Composer;
|
| 6 | +use Composer\DependencyResolver\Operation\OperationInterface; |
6 | 7 | use Composer\Installer\PackageEvent;
|
7 | 8 | use Composer\IO\IOInterface;
|
8 | 9 | use Composer\Package\PackageInterface;
|
@@ -96,8 +97,12 @@ public function getAllowedPackages() {
|
96 | 97 | */
|
97 | 98 | public function event(PackageEvent $event) {
|
98 | 99 | $operation = $event->getOperation();
|
99 |
| - // Determine the package. |
100 |
| - $package = $operation->getJobType() == 'update' ? $operation->getTargetPackage() : $operation->getPackage(); |
| 100 | + // Determine the package. Later, in evaluateNewPackages(), we will report |
| 101 | + // which of the newly-installed packages have scaffold operations, and |
| 102 | + // whether or not they are allowed to scaffold by the allowed-packages |
| 103 | + // option in the root-level composer.json file. |
| 104 | + $operationType = $this->getOperationType($operation); |
| 105 | + $package = $operationType === 'update' ? $operation->getTargetPackage() : $operation->getPackage(); |
101 | 106 | if (ScaffoldOptions::hasOptions($package->getExtra())) {
|
102 | 107 | $this->newPackages[$package->getName()] = $package;
|
103 | 108 | }
|
@@ -176,6 +181,26 @@ protected function evaluateNewPackages(array $allowed_packages) {
|
176 | 181 | return $allowed_packages;
|
177 | 182 | }
|
178 | 183 |
|
| 184 | + /** |
| 185 | + * Determine the type of the provided operation. |
| 186 | + * |
| 187 | + * Adjusts API used for Composer 1 or Composer 2. |
| 188 | + * |
| 189 | + * @param \Composer\DependencyResolver\Operation\OperationInterface $operation |
| 190 | + * The operation object. |
| 191 | + * |
| 192 | + * @return string |
| 193 | + * The operation type. |
| 194 | + */ |
| 195 | + protected function getOperationType(OperationInterface $operation) { |
| 196 | + // Use Composer 2 method. |
| 197 | + if (method_exists($operation, 'getOperationType')) { |
| 198 | + return $operation->getOperationType(); |
| 199 | + } |
| 200 | + // Fallback to Composer 1 method. |
| 201 | + return $operation->getJobType(); |
| 202 | + } |
| 203 | + |
179 | 204 | /**
|
180 | 205 | * Retrieves a package from the current composer process.
|
181 | 206 | *
|
|
0 commit comments