mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
Use an adapter class for composer
This commit is contained in:
@@ -9,17 +9,15 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
||||||
use Flarum\PackageManager\LastUpdateCheck;
|
use Flarum\PackageManager\LastUpdateCheck;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class CheckForUpdatesHandler
|
class CheckForUpdatesHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -28,16 +26,10 @@ class CheckForUpdatesHandler
|
|||||||
*/
|
*/
|
||||||
protected $lastUpdateCheck;
|
protected $lastUpdateCheck;
|
||||||
|
|
||||||
/**
|
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck)
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck, OutputLogger $logger)
|
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,23 +101,19 @@ class CheckForUpdatesHandler
|
|||||||
*/
|
*/
|
||||||
protected function runComposerCommand(bool $minorOnly): string
|
protected function runComposerCommand(bool $minorOnly): string
|
||||||
{
|
{
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new ArrayInput([
|
||||||
'command' => 'outdated',
|
'command' => 'outdated',
|
||||||
'-D' => true,
|
'-D' => true,
|
||||||
'--minor-only' => $minorOnly,
|
'--minor-only' => $minorOnly,
|
||||||
'--format' => 'json',
|
'--format' => 'json',
|
||||||
]);
|
])
|
||||||
|
);
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerCommandFailedException('', $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerCommandFailedException('', $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output->getContents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,19 +9,17 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
|
||||||
use Flarum\Bus\Dispatcher as FlarumDispatcher;
|
use Flarum\Bus\Dispatcher as FlarumDispatcher;
|
||||||
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\PackageManager\Event\FlarumUpdated;
|
use Flarum\PackageManager\Event\FlarumUpdated;
|
||||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class GlobalUpdateHandler
|
class GlobalUpdateHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -35,17 +33,11 @@ class GlobalUpdateHandler
|
|||||||
*/
|
*/
|
||||||
protected $commandDispatcher;
|
protected $commandDispatcher;
|
||||||
|
|
||||||
/**
|
public function __construct(ComposerAdapter $composer, Dispatcher $events, FlarumDispatcher $commandDispatcher)
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(Application $composer, Dispatcher $events, FlarumDispatcher $commandDispatcher, OutputLogger $logger)
|
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
$this->commandDispatcher = $commandDispatcher;
|
$this->commandDispatcher = $commandDispatcher;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,22 +47,12 @@ class GlobalUpdateHandler
|
|||||||
{
|
{
|
||||||
$command->actor->assertAdmin();
|
$command->actor->assertAdmin();
|
||||||
|
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new StringInput("update --prefer-dist --no-dev -a --with-all-dependencies")
|
||||||
'command' => 'update',
|
);
|
||||||
'--prefer-dist' => true,
|
|
||||||
'--no-dev' => true,
|
|
||||||
'-a' => true,
|
|
||||||
'--with-all-dependencies' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerUpdateFailedException('*', $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerUpdateFailedException('*', $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->commandDispatcher->dispatch(
|
$this->commandDispatcher->dispatch(
|
||||||
|
@@ -9,21 +9,19 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
|
||||||
use Flarum\Foundation\Paths;
|
use Flarum\Foundation\Paths;
|
||||||
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Flarum\PackageManager\Event\FlarumUpdated;
|
use Flarum\PackageManager\Event\FlarumUpdated;
|
||||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||||
use Flarum\PackageManager\LastUpdateCheck;
|
use Flarum\PackageManager\LastUpdateCheck;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class MajorUpdateHandler
|
class MajorUpdateHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -37,11 +35,6 @@ class MajorUpdateHandler
|
|||||||
*/
|
*/
|
||||||
protected $events;
|
protected $events;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Paths
|
* @var Paths
|
||||||
*/
|
*/
|
||||||
@@ -52,12 +45,11 @@ class MajorUpdateHandler
|
|||||||
*/
|
*/
|
||||||
protected $composerJson;
|
protected $composerJson;
|
||||||
|
|
||||||
public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events, OutputLogger $logger, Paths $paths)
|
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events, Paths $paths)
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
$this->logger = $logger;
|
|
||||||
$this->paths = $paths;
|
$this->paths = $paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +120,7 @@ class MajorUpdateHandler
|
|||||||
protected function revertComposerJson(): void
|
protected function revertComposerJson(): void
|
||||||
{
|
{
|
||||||
$composerJsonPath = $this->paths->base . '/composer.json';
|
$composerJsonPath = $this->paths->base . '/composer.json';
|
||||||
|
// @todo use filesystem for all file_get_contents
|
||||||
file_put_contents($composerJsonPath, $this->composerJson);
|
file_put_contents($composerJsonPath, $this->composerJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,24 +129,20 @@ class MajorUpdateHandler
|
|||||||
*/
|
*/
|
||||||
protected function runCommand(bool $dryRun): void
|
protected function runCommand(bool $dryRun): void
|
||||||
{
|
{
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new ArrayInput([
|
||||||
'command' => 'update',
|
'command' => 'update',
|
||||||
'--prefer-dist' => true,
|
'--prefer-dist' => true,
|
||||||
'--no-plugins' => true,
|
'--no-plugins' => true,
|
||||||
'--no-dev' => true,
|
'--no-dev' => true,
|
||||||
'-a' => true,
|
'-a' => true,
|
||||||
'--with-all-dependencies' => true,
|
'--with-all-dependencies' => true,
|
||||||
'--dry-run' => $dryRun,
|
'--dry-run' => $dryRun,
|
||||||
]);
|
])
|
||||||
|
);
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerUpdateFailedException('*', $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerUpdateFailedException('*', $output);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,19 +9,17 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\PackageManager\Event\FlarumUpdated;
|
use Flarum\PackageManager\Event\FlarumUpdated;
|
||||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||||
use Flarum\PackageManager\LastUpdateCheck;
|
use Flarum\PackageManager\LastUpdateCheck;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class MinorFlarumUpdateHandler
|
class MinorFlarumUpdateHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -35,17 +33,11 @@ class MinorFlarumUpdateHandler
|
|||||||
*/
|
*/
|
||||||
protected $events;
|
protected $events;
|
||||||
|
|
||||||
/**
|
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events)
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events, OutputLogger $logger)
|
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,23 +48,12 @@ class MinorFlarumUpdateHandler
|
|||||||
{
|
{
|
||||||
$command->actor->assertAdmin();
|
$command->actor->assertAdmin();
|
||||||
|
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new StringInput("update flarum/* --prefer-dist --no-dev -a --with-all-dependencies")
|
||||||
'command' => 'update',
|
);
|
||||||
'packages' => ["flarum/*"],
|
|
||||||
'--prefer-dist' => true,
|
|
||||||
'--no-dev' => true,
|
|
||||||
'-a' => true,
|
|
||||||
'--with-all-dependencies' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerUpdateFailedException('flarum/*', $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerUpdateFailedException('flarum/*', $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastUpdateCheck->forget('flarum/*', true);
|
$this->lastUpdateCheck->forget('flarum/*', true);
|
||||||
|
@@ -9,21 +9,18 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
||||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
|
||||||
use Flarum\PackageManager\Exception\ExtensionNotInstalledException;
|
use Flarum\PackageManager\Exception\ExtensionNotInstalledException;
|
||||||
use Flarum\PackageManager\Extension\Event\Removed;
|
use Flarum\PackageManager\Extension\Event\Removed;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class RemoveExtensionHandler
|
class RemoveExtensionHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -37,17 +34,11 @@ class RemoveExtensionHandler
|
|||||||
*/
|
*/
|
||||||
protected $events;
|
protected $events;
|
||||||
|
|
||||||
/**
|
public function __construct(ComposerAdapter $composer, ExtensionManager $extensions, Dispatcher $events)
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(Application $composer, ExtensionManager $extensions, Dispatcher $events, OutputLogger $logger)
|
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->extensions = $extensions;
|
$this->extensions = $extensions;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,19 +55,12 @@ class RemoveExtensionHandler
|
|||||||
throw new ExtensionNotInstalledException($command->extensionId);
|
throw new ExtensionNotInstalledException($command->extensionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new StringInput("remove $extension->name")
|
||||||
'command' => 'remove',
|
);
|
||||||
'packages' => [$extension->name],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerCommandFailedException($extension->name, $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerCommandFailedException($extension->name, $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->events->dispatch(
|
$this->events->dispatch(
|
||||||
|
@@ -9,22 +9,20 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\PackageManager\Exception\ComposerRequireFailedException;
|
use Flarum\PackageManager\Exception\ComposerRequireFailedException;
|
||||||
use Flarum\PackageManager\Exception\ExtensionAlreadyInstalledException;
|
use Flarum\PackageManager\Exception\ExtensionAlreadyInstalledException;
|
||||||
use Flarum\PackageManager\Extension\Event\Installed;
|
use Flarum\PackageManager\Extension\Event\Installed;
|
||||||
use Flarum\PackageManager\Extension\ExtensionUtils;
|
use Flarum\PackageManager\Extension\ExtensionUtils;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
|
||||||
use Flarum\PackageManager\RequirePackageValidator;
|
use Flarum\PackageManager\RequirePackageValidator;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class RequireExtensionHandler
|
class RequireExtensionHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -43,18 +41,12 @@ class RequireExtensionHandler
|
|||||||
*/
|
*/
|
||||||
protected $events;
|
protected $events;
|
||||||
|
|
||||||
/**
|
public function __construct(ComposerAdapter $composer, ExtensionManager $extensions, RequirePackageValidator $validator, Dispatcher $events)
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(Application $composer, ExtensionManager $extensions, RequirePackageValidator $validator, Dispatcher $events, OutputLogger $logger)
|
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->extensions = $extensions;
|
$this->extensions = $extensions;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,19 +66,12 @@ class RequireExtensionHandler
|
|||||||
throw new ExtensionAlreadyInstalledException($extension);
|
throw new ExtensionAlreadyInstalledException($extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new StringInput("require $command->package")
|
||||||
'command' => 'require',
|
);
|
||||||
'packages' => [$command->package],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerRequireFailedException($command->package, $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerRequireFailedException($command->package, $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->events->dispatch(
|
$this->events->dispatch(
|
||||||
|
@@ -9,23 +9,20 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Command;
|
namespace Flarum\PackageManager\Command;
|
||||||
|
|
||||||
use Composer\Console\Application;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||||
use Flarum\PackageManager\Exception\ExtensionNotInstalledException;
|
use Flarum\PackageManager\Exception\ExtensionNotInstalledException;
|
||||||
use Flarum\PackageManager\Extension\Event\Updated;
|
use Flarum\PackageManager\Extension\Event\Updated;
|
||||||
use Flarum\PackageManager\OutputLogger;
|
|
||||||
use Flarum\PackageManager\UpdateExtensionValidator;
|
use Flarum\PackageManager\UpdateExtensionValidator;
|
||||||
use Flarum\PackageManager\LastUpdateCheck;
|
use Flarum\PackageManager\LastUpdateCheck;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
|
||||||
|
|
||||||
class UpdateExtensionHandler
|
class UpdateExtensionHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Application
|
* @var ComposerAdapter
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected $composer;
|
||||||
|
|
||||||
@@ -49,25 +46,18 @@ class UpdateExtensionHandler
|
|||||||
*/
|
*/
|
||||||
protected $events;
|
protected $events;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var OutputLogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Application $composer,
|
ComposerAdapter $composer,
|
||||||
ExtensionManager $extensions,
|
ExtensionManager $extensions,
|
||||||
UpdateExtensionValidator $validator,
|
UpdateExtensionValidator $validator,
|
||||||
LastUpdateCheck $lastUpdateCheck,
|
LastUpdateCheck $lastUpdateCheck,
|
||||||
Dispatcher $events,
|
Dispatcher $events)
|
||||||
OutputLogger $logger)
|
|
||||||
{
|
{
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->extensions = $extensions;
|
$this->extensions = $extensions;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,19 +76,12 @@ class UpdateExtensionHandler
|
|||||||
throw new ExtensionNotInstalledException($command->extensionId);
|
throw new ExtensionNotInstalledException($command->extensionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = new BufferedOutput();
|
$output = $this->composer->run(
|
||||||
$input = new ArrayInput([
|
new StringInput("require $extension->name:*")
|
||||||
'command' => 'require',
|
);
|
||||||
'packages' => ["$extension->name:*"],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$exitCode = $this->composer->run($input, $output);
|
if ($output->getExitCode() !== 0) {
|
||||||
$output = $output->fetch();
|
throw new ComposerUpdateFailedException($extension->name, $output->getContents());
|
||||||
|
|
||||||
$this->logger->log($input->__toString(), $output, $exitCode);
|
|
||||||
|
|
||||||
if ($exitCode !== 0) {
|
|
||||||
throw new ComposerUpdateFailedException($extension->name, $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastUpdateCheck->forget($extension->name);
|
$this->lastUpdateCheck->forget($extension->name);
|
||||||
|
47
extensions/package-manager/src/Composer/ComposerAdapter.php
Normal file
47
extensions/package-manager/src/Composer/ComposerAdapter.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\PackageManager\Composer;
|
||||||
|
|
||||||
|
use Composer\Console\Application;
|
||||||
|
use Flarum\PackageManager\OutputLogger;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
|
||||||
|
class ComposerAdapter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
|
private $application;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OutputLogger
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct(Application $application, OutputLogger $logger)
|
||||||
|
{
|
||||||
|
$this->application = $application;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(InputInterface $input): ComposerOutput
|
||||||
|
{
|
||||||
|
$output = new BufferedOutput();
|
||||||
|
|
||||||
|
$exitCode = $this->application->run($input, $output);
|
||||||
|
|
||||||
|
$outputContents = $output->fetch();
|
||||||
|
|
||||||
|
$this->logger->log($input->__toString(), $outputContents, $exitCode);
|
||||||
|
|
||||||
|
return new ComposerOutput($exitCode, $outputContents);
|
||||||
|
}
|
||||||
|
}
|
39
extensions/package-manager/src/Composer/ComposerOutput.php
Normal file
39
extensions/package-manager/src/Composer/ComposerOutput.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\PackageManager\Composer;
|
||||||
|
|
||||||
|
class ComposerOutput
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $exitCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $contents;
|
||||||
|
|
||||||
|
public function __construct(int $exitCode, string $contents)
|
||||||
|
{
|
||||||
|
$this->exitCode = $exitCode;
|
||||||
|
$this->contents = $contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExitCode(): int
|
||||||
|
{
|
||||||
|
return $this->exitCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContents(): string
|
||||||
|
{
|
||||||
|
return $this->contents;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,6 +16,7 @@ use Flarum\Foundation\AbstractServiceProvider;
|
|||||||
use Flarum\Foundation\Paths;
|
use Flarum\Foundation\Paths;
|
||||||
use Flarum\Frontend\RecompileFrontendAssets;
|
use Flarum\Frontend\RecompileFrontendAssets;
|
||||||
use Flarum\Locale\LocaleManager;
|
use Flarum\Locale\LocaleManager;
|
||||||
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Monolog\Formatter\LineFormatter;
|
use Monolog\Formatter\LineFormatter;
|
||||||
@@ -29,7 +30,7 @@ class PackageManagerServiceProvider extends AbstractServiceProvider
|
|||||||
{
|
{
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->container->singleton(Application::class, function (Container $container) {
|
$this->container->singleton(ComposerAdapter::class, function (Container $container) {
|
||||||
// This should only ever be resolved when running composer commands,
|
// This should only ever be resolved when running composer commands,
|
||||||
// because we modify other environment configurations.
|
// because we modify other environment configurations.
|
||||||
$composer = new Application();
|
$composer = new Application();
|
||||||
@@ -48,10 +49,10 @@ class PackageManagerServiceProvider extends AbstractServiceProvider
|
|||||||
@ini_set('memory_limit', '1G');
|
@ini_set('memory_limit', '1G');
|
||||||
@set_time_limit(5 * 60);
|
@set_time_limit(5 * 60);
|
||||||
|
|
||||||
return $composer;
|
return new ComposerAdapter($composer, $container->make(OutputLogger::class));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->container->alias(Application::class, 'flarum.composer');
|
$this->container->alias(ComposerAdapter::class, 'flarum.composer');
|
||||||
|
|
||||||
$this->container->singleton(OutputLogger::class, function (Container $container) {
|
$this->container->singleton(OutputLogger::class, function (Container $container) {
|
||||||
$logPath = $container->make(Paths::class)->storage.'/logs/composer/output.log';
|
$logPath = $container->make(Paths::class)->storage.'/logs/composer/output.log';
|
||||||
|
@@ -17,6 +17,6 @@ class RequirePackageValidator extends AbstractValidator
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
'package' => 'required|string'
|
'package' => ['required', 'string', 'regex:/^[A-z0-9-_]+\/[A-z-0-9]+(?::[A-z-0-9.->=<_]+){0,1}$/i']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -9,18 +9,13 @@
|
|||||||
|
|
||||||
namespace Flarum\PackageManager\Tests\integration;
|
namespace Flarum\PackageManager\Tests\integration;
|
||||||
|
|
||||||
use Composer\Config;
|
|
||||||
use Composer\Console\Application;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
|
||||||
use Flarum\Foundation\Paths;
|
use Flarum\Foundation\Paths;
|
||||||
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||||
use Flarum\PackageManager\Extension\ExtensionUtils;
|
use Flarum\PackageManager\Extension\ExtensionUtils;
|
||||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||||
use Illuminate\Contracts\Container\Container;
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
|
||||||
use Symfony\Component\Console\Input\StringInput;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
|
||||||
|
|
||||||
class TestCase extends \Flarum\Testing\integration\TestCase
|
class TestCase extends \Flarum\Testing\integration\TestCase
|
||||||
{
|
{
|
||||||
@@ -81,10 +76,9 @@ class TestCase extends \Flarum\Testing\integration\TestCase
|
|||||||
|
|
||||||
protected function composer(string $command): void
|
protected function composer(string $command): void
|
||||||
{
|
{
|
||||||
/** @var Application $composer */
|
/** @var ComposerAdapter $composer */
|
||||||
$composer = $this->app()->getContainer()->make(Application::class);
|
$composer = $this->app()->getContainer()->make(ComposerAdapter::class);
|
||||||
$output = new NullOutput();
|
$composer->run(new StringInput($command));
|
||||||
$composer->run(new StringInput($command), $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function guessedCause(ResponseInterface $response): ?string
|
protected function guessedCause(ResponseInterface $response): ?string
|
||||||
|
Reference in New Issue
Block a user