Skip to content

Commit

Permalink
Merge pull request #23 from City-of-Helsinki/UHF-9718
Browse files Browse the repository at this point in the history
Keep update commands compatible with drush 11
  • Loading branch information
tuutti authored Feb 28, 2024
2 parents a5443b2 + e2e312c commit fa9ef62
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Drush/Commands/UpdateDrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,12 +45,29 @@ 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,
) {
// @todo createEarly() method was added in Drush 12.
// Remove these once we drop support for Drush 11.
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->updateHookManager) {
$this->updateHookManager = new UpdateHookManager($this->filesystem, $this->fileManager);
}
if (!$this->style) {
$this->style = new SymfonyStyle(Drush::input(), Drush::output());
}
parent::__construct();
}

Expand All @@ -62,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),
Expand Down

0 comments on commit fa9ef62

Please sign in to comment.