forked from alexweber/environments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironments.install
209 lines (190 loc) · 5.33 KB
/
environments.install
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* @file
* Installation hooks.
*/
/**
* Implements hook_uninstall().
*/
function environments_uninstall() {
// Remove all of our variables.
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'environments_%', 'LIKE')
->execute();
foreach ($result as $row) {
variable_del($row->name);
}
}
/**
* Implements hook_enable().
*/
function environments_enable() {
// Display a message and link to the configuration page if we're doing this
// through the UI.
if (php_sapi_name() !== 'cli') {
drupal_set_message(t('You\'ve enabled the Environments module. Click <a href="!url">here</a> to configure up your site environments and tasks.', array('!url' => url('admin/config/development/environments', array('absolute' => TRUE)))), 'status', FALSE);
}
// If we don't happen to already have this variable set, try to figure it out
// from other modules which also use Drush.
if (!variable_get('environments_drush', FALSE)) {
_environments_drush_setup();
}
}
/**
* Implements hook_schema().
*/
function environments_schema() {
$schema = array();
$schema['environments'] = array(
'description' => 'Site Environments.',
'export' => array(
'key' => 'name',
'identifier' => 'environment',
'default hook' => 'default_environments_environments',
'api' => array(
'owner' => 'environments',
'api' => 'default_environments_environments',
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'name' => array(
'description' => 'The environment\'s machine-readable name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'admin_title' => array(
'description' => 'The environment\'s human-readable title.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'alias' => array(
'description' => 'The environment\'s alias, to use with Drush.',
'type' => 'char',
// This isn't available here so hard-code it.
// 'length' => ENVIRONMENTS_ALIAS_MAXLENGTH,
'length' => 12,
'not null' => FALSE,
),
'settings' => array(
'description' => 'The environment\'s extra settings.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
'tasks' => array(
'description' => 'The environment\'s tasks.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('name'),
'index' => array(
'alias' => array('alias'),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function environments_requirements($phase) {
$return = array();
$t = get_t();
if ($phase === 'runtime') {
if ($env = variable_get('environments_env')) {
if ($environment = environments_load($env)) {
$return['environments'] = array(
'title' => $t('Environments: Current environment'),
'value' => $environment->admin_title,
'severity' => REQUIREMENT_INFO,
);
}
else {
$return['environments'] = array(
'title' => $t('Environments: Invalid environment'),
'value' => $env,
'severity' => REQUIREMENT_ERROR,
);
}
}
else {
$return['environments'] = array(
'title' => $t('Environments: Current environment'),
'value' => $t('No environment set'),
'severity' => REQUIREMENT_WARNING,
);
}
}
return $return;
}
/**
* Helper function to setup path to Drush.
*/
function _environments_drush_setup() {
// Start with a sensible default.
$path = '/usr/local/bin/drush';
// Migrate module has this setting.
if ($migrate_drush = variable_get('migrate_drush_path')) {
if (file_exists($migrate_drush)) {
$path = $migrate_drush;
}
}
// So does Wordpress Migrate.
elseif ($wp_migrate_drush = variable_get('wordpress_migrate_drush')) {
if (file_exists($wp_migrate_drush)) {
$path = $wp_migrate_drush;
}
}
variable_set('environments_drush', $path);
}
/**
* Fix Environments schema indices.
*/
function environments_update_7100() {
// If either of these fail, our schema is probably already ok so don't let
// the update hook fail. Do, however, run them independently to give them both
// a chance.
try {
db_drop_unique_key('environments', 'alias');
}
catch (Exception $e) {
watchdog('environments', $e->getMessage(), array(), WATCHDOG_NOTICE);
}
try {
db_add_index('environments', 'alias', array('alias'));
}
catch (Exception $e) {
watchdog('environments', $e->getMessage(), array(), WATCHDOG_NOTICE);
}
}
/**
* Fix Environment aliases.
*/
function environments_update_7101() {
try {
db_update('environments')
->fields(array('alias' => NULL))
->condition('alias', '', '=')
->execute();
}
catch (Exception $e) {
watchdog('environments', $e->getMessage(), array(), WATCHDOG_ERROR);
}
}
/**
* Fix Environments Drush path.
*/
function environments_update_7102() {
// Older code didn't check whether the migrate drush path was valid so we
// borrowed broken config in some cases.
$path = variable_get('environments_drush', FALSE);
if (!$path || !file_exists($path)) {
_environments_drush_setup();
}
}