This repository has been archived by the owner on Nov 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
create.rum.inc
281 lines (234 loc) · 8.26 KB
/
create.rum.inc
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
use Rum\Component\Rum\Rum;
use Rum\Component\Rum\RumDatabase;
use Rum\Component\Rum\RumSettingsFile;
use Rum\Component\Rum\RumFileSystem;
use Rum\Component\Rum\RumVanilla;
use Rum\Component\Rum\RumInstaller;
use Rum\Component\Rum\RumWebServer;
use Rum\Component\Rum\RumDrush;
use Rum\Component\Rum\RumHosts;
use Rum\Component\Rum\RumState;
define('RUM_ORIGIN_VANILLA', 'vanilla');
define('RUM_ORIGIN_REPOSITORY', 'repository');
define('RUM_ORIGIN_SKELETON', 'skeleton');
define('RUM_CORE_VERSION_6', 6);
define('RUM_CORE_VERSION_7', 7);
/**
* Drush command callback
*
* This is the drush command callback for drush rum-create. It depending
* on the installation type, it will create a project environment and setup a
* Drupal installation. There are two types of installation:
*
* - Vanilla: Download Drupal core
* - Repository: Get a Drupal project from a repository i.e. Git
*
* If all went well, you should have an operational Drupal installation after
* issuing this command.
*/
function drush_rum_create($origin = NULL, $project_name = NULL) {
if (count(drush_get_arguments()) > 3) {
drush_log(dt('You provided too many arguments.'), 'error');
return FALSE;
}
if (!$origin) {
drush_set_error(dt('You did not provide an installation origin.'));
return FALSE;
}
if (!$project_name) {
drush_set_error(dt('You did not provide a project name.'));
return FALSE;
}
$project_dir = drush_get_option('project-dir', '');
if (empty($project_dir)) {
// When there is no project_dir, use project_name as project_dir
// will be sanitized.
$project_dir = $project_name;
}
switch ($origin) {
case RUM_ORIGIN_SKELETON :
$result = rum_create_skeleton($project_name, $project_dir);
break;
case RUM_ORIGIN_VANILLA :
$result = rum_create_vanilla($project_name, $project_dir);
break;
case RUM_ORIGIN_REPOSITORY :
$result = rum_create_repository($project_name, $project_dir);
break;
}
return $result;
}
function rum_create_skeleton($project_name, $project_dir) {
try {
// Init
$rum = new Rum($project_name, $project_dir);
// Create the folders in the workspace
_rum_create_workspace_project($rum);
// Create a new host
$host_config = drush_confirm(dt('Do you want to add and configure a new host?'));
if ($host_config) {
_rum_create_host($rum);
}
// Create the Database
$db_config = drush_confirm(dt('Do you want to add and configure a new database?'));
if ($db_config) {
$args = _rum_create_database($rum);
foreach ($args as $key => $arg) {
$args['!' . $key] = $arg;
}
drush_log(dt('Rum created a database called !database. You can access it with user:!user pass:!password', $args), 'success');
}
$url = $rum->getProjectUrl();
drush_log(dt('Done! Point your browser to !url to view your project', array('!url' => $url)), 'success');
} catch(Exception $e) {
drush_set_error($e->getMessage());
}
return TRUE;
}
function rum_create_vanilla($project_name, $project_dir) {
try {
// Init
$rum = new Rum($project_name, $project_dir);
// Create the folders in the workspace
_rum_create_workspace_project($rum);
// Download Drupal core
$rum = new RumVanilla($rum);
$options = array('Drupal 6.x', 'Drupal 7.x');
$versions = array(RUM_CORE_VERSION_6, RUM_CORE_VERSION_7);
$choice = drush_choice($options, dt('What Core version do you want to download?'));
$rum->setCoreVersion($versions[$choice]);
$rum->downloadCore();
// Create a new host
_rum_create_host($rum);
// Create a new drushrc file
$rum = new RumDrush($rum);
$rum->createDrush();
// Bootstrap Drupal to the ROOT phase
$rum->bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
// Create the Database
$args = _rum_create_database($rum);
// Create a settings file
$rum = new RumSettingsFile($rum);
$rum->createSettingsFile($args['database'], $args['user'], $args['password']);
$url = $rum->getProjectUrl() . '/install.php';
drush_log(dt('Done! Point your browser to !url to start installing your project', array('!url' => $url)), 'success');
} catch(Exception $e) {
drush_set_error($e->getMessage());
}
return TRUE;
}
function rum_create_repository($project_name, $project_dir) {
try {
// Init
$rum = new Rum($project_name, $project_dir);
// Create the folders in the workspace
$rum = new RumFileSystem($rum);
$rum->createWorkSpace();
$rum->createProjectDir(FALSE);
// Fetch from a repository
$options = array('Git', 'Subversion');
$choice = drush_choice($options, dt('Choose the type of repository software.'));
$rum = new RumState($rum, $options[$choice]);
$repository = drush_prompt(dt("Enter the url of the projects' repository"), '');
$rum->fetch($repository, $rum->getProjectDir());
// Set the document root of your project
$contents = drush_scan_directory($rum->getProjectDir(), '/.*/', array('.', '..'), 0, FALSE, 'basename', 0, FALSE);
$options = array_keys($contents);
// Only show directories
foreach ($options as $key => $option) {
$path = $rum->getProjectDir() . '/' . $options[$key];
if (!is_dir($path)) {
unset($options[$key]);
}
}
// Add the projectDir as a valid option (no www/db structure)
array_unshift($options, dt('. (Project directory is DocumentRoot)'));
$choice = drush_choice($options, dt('Set the DocumentRoot of your project.'));
$document_root = ($choice == 0) ? '' : $options[$choice];
$rum->setDocumentRoot($document_root);
// Configuration of your hosts file and webserver is optional. The user might
// be running a BIND instance which handles this part of the setup.
//
// @see http://postpostmodern.com/instructional/a-smarter-mamp/
$host_config = drush_confirm(dt('Do you want to add and configure a new host?'));
if ($host_config) {
_rum_create_host($rum);
}
// Create a new drushrc file
$rum = new RumDrush($rum);
$rum->createDrush();
// Bootstrap Drupal to the ROOT phase
$rum->bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
// Create the Database
$args = _rum_create_database($rum);
// Create a settings file
$rum = new RumSettingsFile($rum);
$rum->createSettingsFile($args['database'], $args['user'], $args['password']);
// Import a database from the db/ folder
$import = drush_confirm(dt('Do you want to import a database dump right now?'));
if ($import) {
$db_dir = $rum->getProjectDir() . '/' . $rum->getDatabaseDir();
$contents = drush_scan_directory($db_dir, '/.*/', array('.', '..'), 0, FALSE, 'basename', 0, FALSE);
$options = array_keys($contents);
$choice = drush_choice($options, dt('Select the database dump you want to import.'));
$rum->bootstrap(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
$base_name = $options[$choice];
$contents[$base_name]->filename;
if (isset($contents[$base_name]->filename)) {
$exec = drush_sql_build_exec(NULL, $contents[$base_name]->filename);
if (drush_shell_exec($exec)) {
drush_log(dt('Database dump succesfully imported'), 'success');
}
}
}
$url = $rum->getProjectUrl();
drush_log(dt('Done! Point your browser to !url to view your project', array('!url' => $url)), 'success');
} catch(Exception $e) {
drush_set_error($e->getMessage());
}
return TRUE;
}
/**
* @todo
*
* @param unknown_type $rum
*/
function _rum_create_workspace_project(&$rum) {
$rum = new RumFileSystem($rum);
$rum->createWorkSpace();
$rum->createProjectDir();
}
/**
* @todo
*
* @param unknown_type $rum
*/
function _rum_create_host(&$rum) {
// Add a new entry in the hosts file (if we're run in DEV)
$rum = new RumHosts($rum);
$rum->addHostsEntry();
// Create a new virtual host
$rum = new RumWebServer($rum);
$rum->createVhost();
// Restart webserver
$rum->restart();
}
/**
* @todo
*
* @param unknown_type $rum
* @return unknown|boolean
*/
function _rum_create_database(&$rum) {
$rum = new RumDatabase($rum);
$rum->setProjectDbUser();
$rum->createUser();
$rum->setProjectDb();
$rum->createDatabase();
return array(
'database' => $rum->getProjectDb(),
'password' => $rum->getProjectDbCred(),
'user' => $rum->getProjectDbUser(),
);
}