From 0e47eea0caa13bfe1809f7bf94d76258e841bb04 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 28 Feb 2024 11:15:53 +0200 Subject: [PATCH 1/2] Keep update commands compatible with drush 11 --- src/Drush/Commands/UpdateDrushCommands.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Drush/Commands/UpdateDrushCommands.php b/src/Drush/Commands/UpdateDrushCommands.php index dc745ca..da4b8d4 100644 --- a/src/Drush/Commands/UpdateDrushCommands.php +++ b/src/Drush/Commands/UpdateDrushCommands.php @@ -44,12 +44,24 @@ final class UpdateDrushCommands extends DrushCommands { * Constructs a new instance. */ public function __construct( - private readonly Filesystem $filesystem, - private readonly ClientInterface $httpClient, - private readonly FileManager $fileManager, - private readonly UpdateHookManager $updateHookManager, - private readonly OutputStyle $style, + private ?Filesystem $filesystem = NULL, + private ?ClientInterface $httpClient = NULL, + private ?FileManager $fileManager = NULL, + private ?UpdateHookManager $updateHookManager = NULL, + private ?OutputStyle $style = NULL, ) { + if (!$this->filesystem) { + $this->filesystem = new Filesystem(); + } + if (!$this->httpClient) { + $this->httpClient = new Client(['base_uri' => self::BASE_URL]); + } + if (!$this->fileManager) { + $this->fileManager = new FileManager(new HttpFileManager($this->httpClient), $this->filesystem); + } + if (!$this->style) { + $this->style = new SymfonyStyle($this->input(), $this->output()); + } parent::__construct(); } From e2e312cade8be5a7c3b38f0fde988758c94d6341 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 28 Feb 2024 11:22:50 +0200 Subject: [PATCH 2/2] Fixed missing property --- src/Drush/Commands/UpdateDrushCommands.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Drush/Commands/UpdateDrushCommands.php b/src/Drush/Commands/UpdateDrushCommands.php index da4b8d4..ffcfcba 100644 --- a/src/Drush/Commands/UpdateDrushCommands.php +++ b/src/Drush/Commands/UpdateDrushCommands.php @@ -11,6 +11,7 @@ use DrupalTools\Update\UpdateOptions; use Drush\Attributes\Command; use Drush\Commands\DrushCommands; +use Drush\Drush; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use Psr\Container\ContainerInterface; @@ -50,6 +51,8 @@ public function __construct( private ?UpdateHookManager $updateHookManager = NULL, private ?OutputStyle $style = NULL, ) { + // @todo createEarly() method was added in Drush 12. + // Remove these once we drop support for Drush 11. if (!$this->filesystem) { $this->filesystem = new Filesystem(); } @@ -59,8 +62,11 @@ public function __construct( if (!$this->fileManager) { $this->fileManager = new FileManager(new HttpFileManager($this->httpClient), $this->filesystem); } + if (!$this->updateHookManager) { + $this->updateHookManager = new UpdateHookManager($this->filesystem, $this->fileManager); + } if (!$this->style) { - $this->style = new SymfonyStyle($this->input(), $this->output()); + $this->style = new SymfonyStyle(Drush::input(), Drush::output()); } parent::__construct(); } @@ -74,7 +80,7 @@ public static function createEarly(ContainerInterface $container) : self { $fileManager = new FileManager(new HttpFileManager($client), $fileSystem); return new self( - new Filesystem(), + $fileSystem, $client, $fileManager, new UpdateHookManager($fileSystem, $fileManager),