Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep update commands compatible with drush 11 #23

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading