1
0
mirror of https://github.com/flarum/core.git synced 2025-08-05 07:57:46 +02:00

fix(em): breaks when composer deps get updated

This commit is contained in:
Sami Mazouz
2024-02-04 13:56:09 +01:00
parent 50dd73b07c
commit b2044ff312
8 changed files with 44 additions and 8 deletions

View File

@@ -64,7 +64,8 @@ class GlobalUpdateHandler
$output = $this->composer->run(
new ArrayInput($input),
$command->task ?? null
$command->task ?? null,
true
);
if ($output->getExitCode() !== 0) {

View File

@@ -115,7 +115,7 @@ class MajorUpdateHandler
$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);

View File

@@ -60,7 +60,8 @@ class MinorUpdateHandler
$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) {

View File

@@ -76,7 +76,8 @@ class RemoveExtensionHandler
$output = $this->composer->run(
new StringInput("remove $extension->name"),
$command->task ?? null
$command->task ?? null,
true
);
if ($output->getExitCode() !== 0) {

View File

@@ -75,7 +75,8 @@ class RequireExtensionHandler
$output = $this->composer->run(
new StringInput("require $packageName -W"),
$command->task ?? null
$command->task ?? null,
true
);
if ($output->getExitCode() !== 0) {

View File

@@ -92,7 +92,8 @@ class UpdateExtensionHandler
$output = $this->composer->run(
new StringInput($input),
$command->task ?? null
$command->task ?? null,
true
);
if ($output->getExitCode() !== 0) {

View File

@@ -15,6 +15,7 @@ use Flarum\Foundation\Paths;
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;
@@ -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();
@@ -59,7 +66,29 @@ class ComposerAdapter
// 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);

View File

@@ -24,6 +24,7 @@ use Flarum\ExtensionManager\Listener\ClearCacheAfterUpdate;
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;
@@ -56,6 +57,7 @@ class ExtensionManagerServiceProvider extends AbstractServiceProvider
$composer,
$container->make(OutputLogger::class),
$container->make(Paths::class),
$container->make(Filesystem::class)
);
});