Skip to content

Commit

Permalink
fix(em): breaks when composer deps get updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Feb 4, 2024
1 parent b9e2985 commit 4393278
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Command/GlobalUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function handle(GlobalUpdate $command)

$output = $this->composer->run(
new ArrayInput($input),
$command->task ?? null
$command->task ?? null,
true
);

if ($output->getExitCode() !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MajorUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function runCommand(MajorUpdate $command, string $majorVersion): void
$input['--dry-run'] = true;
}

$output = $this->composer->run(new ArrayInput($input), $command->task ?? null);
$output = $this->composer->run(new ArrayInput($input), $command->task ?? null, true);

if ($output->getExitCode() !== 0) {
throw new MajorUpdateFailedException('*', $output->getContents(), $majorVersion);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/MinorUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function handle(MinorUpdate $command)

$output = $this->composer->run(
new StringInput('update --prefer-dist --no-dev -a --with-all-dependencies'),
$command->task ?? null
$command->task ?? null,
true
);

if ($output->getExitCode() !== 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/RemoveExtensionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function handle(RemoveExtension $command)

$output = $this->composer->run(
new StringInput("remove $extension->name"),
$command->task ?? null
$command->task ?? null,
true
);

if ($output->getExitCode() !== 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/RequireExtensionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function handle(RequireExtension $command)

$output = $this->composer->run(
new StringInput("require $packageName -W"),
$command->task ?? null
$command->task ?? null,
true
);

if ($output->getExitCode() !== 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/UpdateExtensionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public function handle(UpdateExtension $command)

$output = $this->composer->run(
new StringInput($input),
$command->task ?? null
$command->task ?? null,
true
);

if ($output->getExitCode() !== 0) {
Expand Down
33 changes: 31 additions & 2 deletions src/Composer/ComposerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Flarum\ExtensionManager\OutputLogger;
use Flarum\ExtensionManager\Support\Util;
use Flarum\ExtensionManager\Task\Task;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;

Expand Down Expand Up @@ -43,14 +44,20 @@ class ComposerAdapter
*/
private $output = null;

public function __construct(Application $application, OutputLogger $logger, Paths $paths)
/**
* @var Filesystem
*/
private $filesystem;

public function __construct(Application $application, OutputLogger $logger, Paths $paths, Filesystem $filesystem)
{
$this->application = $application;
$this->logger = $logger;
$this->paths = $paths;
$this->filesystem = $filesystem;
}

public function run(InputInterface $input, ?Task $task = null): ComposerOutput
public function run(InputInterface $input, ?Task $task = null, bool $safeMode = false): ComposerOutput
{
$this->application->resetComposer();

Expand All @@ -59,7 +66,29 @@ public function run(InputInterface $input, ?Task $task = null): ComposerOutput
// This hack is necessary so that relative path repositories are resolved properly.
$currDir = getcwd();
chdir($this->paths->base);

if ($safeMode) {
$temporaryVendorDir = $this->paths->base . DIRECTORY_SEPARATOR . 'temp-vendor';
if (! $this->filesystem->isDirectory($temporaryVendorDir)) {
$this->filesystem->makeDirectory($temporaryVendorDir);
}
Config::$defaultConfig['vendor-dir'] = $temporaryVendorDir;
}

$exitCode = $this->application->run($input, $this->output);

if ($safeMode) {
// Move the temporary vendor directory to the real vendor directory.
if ($this->filesystem->isDirectory($temporaryVendorDir) && count($this->filesystem->allFiles($temporaryVendorDir))) {
$vendorDir = $this->paths->vendor;
if (file_exists($vendorDir)) {
$this->filesystem->deleteDirectory($vendorDir);
}
$this->filesystem->moveDirectory($temporaryVendorDir, $vendorDir);
}
Config::$defaultConfig['vendor-dir'] = $this->paths->vendor;
}

chdir($currDir);

$command = Util::readableConsoleInput($input);
Expand Down
2 changes: 2 additions & 0 deletions src/ExtensionManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Flarum\ExtensionManager\Listener\ReCheckForUpdates;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function register()
$composer,
$container->make(OutputLogger::class),
$container->make(Paths::class),
$container->make(Filesystem::class)
);
});

Expand Down

0 comments on commit 4393278

Please sign in to comment.