-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
DeployCommands.php
65 lines (53 loc) · 2.26 KB
/
DeployCommands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Drush\Commands\core;
use Consolidation\SiteAlias\SiteAlias;
use Consolidation\SiteAlias\SiteAliasManagerInterface;
use Drush\Attributes as CLI;
use Drush\Boot\DrupalBootLevels;
use Drush\Commands\AutowireTrait;
use Drush\Commands\config\ConfigImportCommands;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Drush\SiteAlias\ProcessManager;
#[CLI\Bootstrap(DrupalBootLevels::NONE)]
final class DeployCommands extends DrushCommands
{
use AutowireTrait;
const DEPLOY = 'deploy';
public function __construct(
private readonly SiteAliasManagerInterface $siteAliasManager
) {
parent::__construct();
}
/**
* Run several commands after performing a code deployment.
*/
#[CLI\Command(name: self::DEPLOY)]
#[CLI\Usage(name: 'drush deploy -v -y', description: 'Run updates with verbose logging and accept all prompts.')]
#[CLI\Version(version: '10.3')]
#[CLI\Topics(topics: [DocsCommands::DEPLOY])]
public function deploy(): void
{
$self = $this->siteAliasManager->getSelf();
$redispatchOptions = Drush::redispatchOptions();
$manager = $this->processManager();
$this->logger()->notice("Database updates start.");
$process = $manager->drush($self, UpdateDBCommands::UPDATEDB, [], $redispatchOptions);
$process->mustRun($process->showRealtime());
$this->logger()->success("Config import start.");
$process = $manager->drush($self, ConfigImportCommands::IMPORT, [], $redispatchOptions);
$process->mustRun($process->showRealtime());
$this->cacheRebuild($manager, $self, $redispatchOptions);
$this->logger()->success("Deploy hook start.");
$process = $manager->drush($self, DeployHookCommands::HOOK, [], $redispatchOptions);
$process->mustRun($process->showRealtime());
}
public function cacheRebuild(ProcessManager $manager, SiteAlias $self, array $redispatchOptions): void
{
// It is possible that no updates were pending and thus no caches cleared yet.
$this->logger()->success("Cache rebuild start.");
$process = $manager->drush($self, CacheRebuildCommands::REBUILD, [], $redispatchOptions);
$process->mustRun($process->showRealtime());
}
}