forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidateHook.php
135 lines (120 loc) · 4.25 KB
/
ValidateHook.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Acquia\Blt\Robo\Hooks;
use Acquia\Blt\Robo\Common\IO;
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Acquia\Blt\Robo\Exceptions\BltException;
use Acquia\Blt\Robo\Inspector\InspectorAwareInterface;
use Acquia\Blt\Robo\Inspector\InspectorAwareTrait;
use Consolidation\AnnotatedCommand\CommandData;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Contract\ConfigAwareInterface;
/**
* This class provides hooks that validate configuration or state.
*
* These hooks should not directly provide user interaction. They should throw
* and exception if a required condition is not met.
*
* Typically, each validation hook has an accompanying interact hook (which
* runs prior to the validation hook). The interact hooks provide an
* opportunity to the user to resolve the invalid configuration prior to an
* exception being thrown.
*
* @see https://github.com/consolidation/annotated-command#validate-hook
*/
class ValidateHook implements ConfigAwareInterface, LoggerAwareInterface, InspectorAwareInterface {
use ConfigAwareTrait;
use LoggerAwareTrait;
use InspectorAwareTrait;
use IO;
/**
* Validates that the Drupal docroot exists.
*
* @hook validate @validateDocrootIsPresent
*/
public function validateDocrootIsPresent(CommandData $commandData) {
if (!$this->getInspector()->isDocrootPresent()) {
throw new BltException("Unable to find Drupal docroot.");
}
}
/**
* Validates that the repository root exists.
*
* @hook validate @validateRepoRootIsPresent
*/
public function validateRepoRootIsPresent(CommandData $commandData) {
if (empty($this->getInspector()->isRepoRootPresent())) {
throw new BltException("Unable to find repository root.");
}
}
/**
* Validates that Drupal is installed.
*
* @hook validate @validateDrupalIsInstalled
*/
public function validateDrupalIsInstalled(CommandData $commandData) {
if (!$this->getInspector()
->isDrupalInstalled()
) {
throw new BltException("Drupal is not installed");
}
}
/**
* Checks active settings.php file.
*
* @hook validate @validateSettingsFileIsValid
*/
public function validateSettingsFileIsValid(CommandData $commandData) {
if (!$this->getInspector()->isDrupalSettingsFilePresent()) {
throw new BltException("Could not find settings.php for this site.");
}
if (!$this->getInspector()->isDrupalSettingsFileValid()) {
throw new BltException("BLT settings are not included in settings file.");
}
}
/**
* Validates that Behat is properly configured on the local machine.
*
* @hook validate @validateBehatIsConfigured
*/
public function validateBehatIsConfigured(CommandData $commandData) {
if (!$this->getInspector()->isBehatConfigured()) {
throw new BltException("Behat is not configured properly. Please run `blt doctor` to diagnose the issue.");
}
}
/**
* Validates that MySQL is available.
*
* @hook validate @validateMySqlAvailable
*/
public function validateMySqlAvailable() {
if (!$this->getInspector()->isMySqlAvailable()) {
// @todo Prompt to fix.
throw new BltException("MySql is not available. Please run `blt doctor` to diagnose the issue.");
}
}
/**
* Validates that required settings files exist.
*
* @hook validate @validateSettingsFilesPresent
*/
public function validateSettingsFilesPresent() {
if (!$this->getInspector()->isHashSaltPresent()) {
throw new BltException("salt.txt is not present. Please run `blt setup:settings` to generate it.");
}
if (!$this->getInspector()->isDrupalLocalSettingsFilePresent()) {
throw new BltException("Could not find settings.php for this site.");
}
// @todo Look for local.drushrc.php.
}
/**
* Validates that current PHP process is being executed inside of the VM.
*
* @hook validate validateInsideVm
*/
public function validateInsideVm() {
if ($this->getInspector()->isDrupalVmLocallyInitialized() && !$this->getInspector()->isVmCli()) {
throw new BltException("You must run this command inside Drupal VM, or else do not use Drupal VM at all. Execute `vagrant ssh` and then execute the command, or else change drush.aliases.local in blt/project.local.yml.");
}
}
}