Skip to content

Commit 2f0a699

Browse files
committed
#53: Support Composer 2 promise based installers
See: composer/installers@5006d0c
1 parent ae00fb0 commit 2f0a699

File tree

1 file changed

+54
-25
lines changed

1 file changed

+54
-25
lines changed

src/Joomlatools/Composer/ComposerInstaller.php

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,48 @@ class ComposerInstaller extends LibraryInstaller
2929
*/
3030
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
3131
{
32-
parent::install($repo, $package);
33-
3432
$platformStr = Util::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla';
33+
$afterInstall = function () use ($package, $platformStr) {
34+
if ($this->io->isVerbose()) {
35+
$this->io->write(sprintf(" - Queuing <comment>%s</comment> for installation in %s", $package->getName(), $platformStr), true);
36+
}
3537

36-
if ($this->io->isVerbose()) {
37-
$this->io->write(sprintf(" - Queuing <comment>%s</comment> for installation in %s", $package->getName(), $platformStr), true);
38+
TaskQueue::getInstance()->enqueue(array('install', $package, $this->getInstallPath($package)));
39+
};
40+
41+
$promise = parent::install($repo, $package);
42+
43+
// Composer v2 might return a promise here
44+
if ($promise instanceof \React\Promise\PromiseInterface) {
45+
return $promise->then($afterInstall);
3846
}
3947

40-
TaskQueue::getInstance()->enqueue(array('install', $package, $this->getInstallPath($package)));
48+
$afterInstall();
4149
}
4250

4351
/**
4452
* {@inheritDoc}
4553
*/
4654
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
4755
{
48-
parent::update($repo, $initial, $target);
49-
5056
$platformStr = Util::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla';
57+
$afterUpdate = function () use ($target, $platformStr) {
58+
if ($this->io->isVerbose()) {
59+
$this->io->write(sprintf(" - Queuing <comment>%s</comment> for upgrading in %s", $target->getName(), $platformStr), true);
60+
}
61+
62+
TaskQueue::getInstance()->enqueue(array('update', $target, $this->getInstallPath($target)));
63+
};
5164

52-
if ($this->io->isVerbose()) {
53-
$this->io->write(sprintf(" - Queuing <comment>%s</comment> for upgrading in %s", $target->getName(), $platformStr), true);
65+
$promise = parent::update($repo, $initial, $target);
66+
67+
// Composer v2 might return a promise here
68+
if ($promise instanceof \React\Promise\PromiseInterface) {
69+
return $promise->then($afterUpdate);
5470
}
5571

56-
TaskQueue::getInstance()->enqueue(array('update', $target, $this->getInstallPath($target)));
72+
$afterUpdate();
73+
5774
}
5875

5976
/**
@@ -66,31 +83,43 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
6683
}
6784

6885
$platformStr = Util::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla';
86+
$afterUninstall = function () use ($package, $platformStr) {
87+
if ($this->io->isVerbose()) {
88+
$this->io->write(sprintf(" - Queuing <comment>%s</comment> for upgrading in %s", $target->getName(), $platformStr), true);
89+
}
90+
91+
TaskQueue::getInstance()->enqueue(array('update', $target, $this->getInstallPath($target)));
92+
};
6993

7094
if ($this->io->isVerbose()) {
7195
$this->io->write(sprintf(" - Queuing <comment>%s</comment> for removal from %s", $package->getName(), $platformStr), true);
7296
}
7397

7498
TaskQueue::getInstance()->enqueue(array('uninstall', $package, $this->getInstallPath($package)));
7599

76-
// Find the manifest and set it aside so we can query it when actually uninstalling the extension
77-
$installPath = $this->getInstallPath($package);
78-
$manifest = Util::getPackageManifest($installPath);
79-
$prefix = str_replace(DIRECTORY_SEPARATOR, '-', $package->getName());
80-
$tmpFile = tempnam(sys_get_temp_dir(), $prefix);
81-
82-
if (copy($manifest, $tmpFile))
83-
{
84-
Util::setPackageManifest($installPath, $tmpFile);
85-
100+
if (Util::isReusableComponent($package)) {
86101
parent::uninstall($repo, $package);
87-
}
88-
else
89-
{
90-
if ($this->io->isVerbose()) {
91-
$this->io->write(sprintf(" [<error>ERROR</error>] Could not copy manifest %s to %s. Skipping uninstall of <info>%s</info>.", $manifest, $tmpFile, $package->getName()), true);
102+
} else {
103+
// Find the manifest and set it aside so we can query it when actually uninstalling the extension
104+
$installPath = $this->getInstallPath($package);
105+
$manifest = Util::getPackageManifest($installPath);
106+
$prefix = str_replace(DIRECTORY_SEPARATOR, '-', $package->getName());
107+
$tmpFile = tempnam(sys_get_temp_dir(), $prefix);
108+
109+
if (copy($manifest, $tmpFile))
110+
{
111+
Util::setPackageManifest($installPath, $tmpFile);
112+
113+
parent::uninstall($repo, $package);
114+
}
115+
else
116+
{
117+
if ($this->io->isVerbose()) {
118+
$this->io->write(sprintf(" [<error>ERROR</error>] Could not copy manifest %s to %s. Skipping uninstall of <info>%s</info>.", $manifest, $tmpFile, $package->getName()), true);
119+
}
92120
}
93121
}
122+
94123
}
95124

96125
/**

0 commit comments

Comments
 (0)