forked from kraftwagen/kraftwagen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.setup.kw.inc
66 lines (54 loc) · 2.7 KB
/
env.setup.kw.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
<?php
/**
* @file
* This file contains the functions that are required to execute
* `drush kw-setup-env`.
*/
/**
* Implements drush_COMMAND_init() for `drush kw-setup-env`.
*/
function drush_kw_setup_env_init() {
kraftwagen_context_init_kraftwagen_root();
}
/**
* Implements drush_COMMAND for `drush kw-setup-env`.
*/
function drush_kraftwagen_kw_setup_env() {
// Find out where the Kraftwagen root is.
$root = kraftwagen_context_get_option('root-path');
// Determine config directory.
if (!($dir_cnf = kraftwagen_context_get_option('cnf-dir'))) {
return drush_set_error(dt('No cnf dir name set.'));
}
if (!is_dir($root . DIRECTORY_SEPARATOR . $dir_cnf)) {
drush_mkdir($root . DIRECTORY_SEPARATOR . $dir_cnf);
drush_log(dt('Config directory !dir created', array('!dir' => $root . DIRECTORY_SEPARATOR . $dir_cnf)), 'success');
}
else {
drush_log(dt('Config directory !dir already exists', array('!dir' => $root . DIRECTORY_SEPARATOR . $dir_cnf)), 'warning');
}
// determine builds directory
if (!($dir_builds = kraftwagen_context_get_option('builds-dir'))) {
return drush_set_error(dt('No builds dir name set.'));
}
if (!is_dir($root . DIRECTORY_SEPARATOR . $dir_builds)) {
drush_mkdir($root . DIRECTORY_SEPARATOR . $dir_builds);
drush_log(dt('Config directory !dir created', array('!dir' => $root . DIRECTORY_SEPARATOR . $dir_builds)), 'success');
} else {
drush_log(dt('Config directory !dir already exists', array('!dir' => $root . DIRECTORY_SEPARATOR . $dir_builds)), 'warning');
}
if (!($file_environment = kraftwagen_context_get_option('environment-file'))) {
return drush_set_error(dt('No environment file set.'));
}
if (!file_exists($root . DIRECTORY_SEPARATOR . $dir_cnf . DIRECTORY_SEPARATOR . $file_environment)) {
if (!($default_environment = kraftwagen_context_get_option('environment-default'))) {
return drush_set_error(dt('No default environment set.'));
}
file_put_contents($root . DIRECTORY_SEPARATOR . $dir_cnf . DIRECTORY_SEPARATOR . $file_environment, $default_environment);
drush_log(dt('Setup environment in !file to !environment', array('!file' => $root . DIRECTORY_SEPARATOR . $dir_cnf . DIRECTORY_SEPARATOR . $file_environment, '!environment' => $default_environment)), 'success');
drush_log(dt('If you are on a development machine, you\'ll want to change !path to \'development\'.', array('!path' => $root . DIRECTORY_SEPARATOR . $dir_cnf . DIRECTORY_SEPARATOR . $file_environment, '!environment' => $default_environment)), 'ok');
}
else {
drush_log(dt('Environment already set in !file', array('!file' => $root . DIRECTORY_SEPARATOR . $dir_cnf . DIRECTORY_SEPARATOR . $file_environment)), 'warning');
}
}