|
5 | 5 | use Composer\Repository\InstalledRepositoryInterface;
|
6 | 6 | use Composer\Package\PackageInterface;
|
7 | 7 | use Composer\Util\Filesystem;
|
| 8 | +use React\Promise\PromiseInterface; |
8 | 9 |
|
9 | 10 | /**
|
10 | 11 | * SiteProfileInstaller class
|
@@ -35,21 +36,32 @@ public function supports($packageType)
|
35 | 36 | */
|
36 | 37 | public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
37 | 38 | {
|
38 |
| - parent::install($repo, $package); |
39 |
| - |
40 | 39 | // check if there's a nested site- prefixed directory, in which case we
|
41 | 40 | // must assume that it's the real site profile directory and move it up
|
42 | 41 | // one level
|
43 |
| - $path = $this->getInstallPath($package); |
44 |
| - $site = $this->getNestedSiteDirectoryName($path); |
45 |
| - if ($site) { |
46 |
| - $basePath = $this->getBasePath(static::BASE_PATH); |
47 |
| - $tempPath = $basePath . 'temp-' . \basename($path); |
48 |
| - $filesystem = new Filesystem(); |
49 |
| - $filesystem->rename($path, $tempPath); |
50 |
| - $filesystem->rename($tempPath . '/' . $site, $basePath . $site); |
51 |
| - $filesystem->remove($tempPath); |
| 42 | + $adjustProfilePath = function() use ($package) { |
| 43 | + $path = $this->getInstallPath($package); |
| 44 | + $site = $this->getNestedSiteDirectoryName($path); |
| 45 | + if ($site) { |
| 46 | + $basePath = $this->getBasePath(static::BASE_PATH); |
| 47 | + $tempPath = $basePath . 'temp-' . \basename($path); |
| 48 | + $filesystem = new Filesystem(); |
| 49 | + $filesystem->rename($path, $tempPath); |
| 50 | + $filesystem->rename($tempPath . '/' . $site, $basePath . $site); |
| 51 | + $filesystem->remove($tempPath); |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + $promise = parent::install($repo, $package); |
| 56 | + |
| 57 | + // Composer v2 might return a promise here |
| 58 | + if ($promise instanceof PromiseInterface) { |
| 59 | + return $promise->then($adjustProfilePath); |
52 | 60 | }
|
| 61 | + |
| 62 | + // if not, execute the code right away as parent::install executed synchronously |
| 63 | + // (composer v1, or v2 without async) |
| 64 | + $adjustProfilePath(); |
53 | 65 | }
|
54 | 66 |
|
55 | 67 | /**
|
|
0 commit comments