-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.provision.inc
142 lines (115 loc) · 4.88 KB
/
install.provision.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
<?php
/**
* implementation of hook_post_provision_install
*/
function drush_provision_civicrm_post_provision_install($url = null) {
if (! _provision_civicrm_is_site_context(TRUE)) {
return;
}
drush_log(dt("CiviCRM: Starting installation..."));
$db_user = drush_get_option('db_user', NULL, 'site');
$db_passwd = drush_get_option('db_passwd', NULL, 'site');
$db_host = drush_get_option('db_host', NULL, 'site');
$db_name = drush_get_option('db_name', NULL, 'site');
// Inherit the language from Drupal
// see _provision_civicrm_language_uf_to_civicrm() for details.
$lang = '';
$uf_language = d()->language;
drush_log(dt("CiviCRM: Drupal language: %lang", array('%lang' => $uf_language)));
if ($uf_language && $uf_language != 'en') {
$lang = _provision_civicrm_language_uf_to_civicrm($uf_language);
drush_log(dt("CiviCRM: CiviCRM language: %lang", array('%lang' => $lang)));
}
_provision_civicrm_install_civicrm($db_user, $db_passwd, $db_host, $db_name, $lang);
// Deprecated by hosting_civicrm_cron
// _provision_civicrm_create_civicron_user();
// Fix some paths (not really necessary since 4.x, works fine after install).
// _provision_civicrm_fixresourceurls();
// Make sure the template_c and uploads have the correct permissions
_provision_civicrm_fixpermissions();
drush_log(dt("CiviCRM: Installation complete!"), 'ok');
}
/**
* Main function to initialize the CiviCRM database and settings file.
* This has been tested on CiviCRM 4.4.
*
* This is basically a simplified version of drush_civicrm_install()
* from civicrm.drush.inc shipped with CiviCRM.
*
* We had to fork it since it assumes that the civicrmInstallerHelper
* is located in sites/example.org/modules/civicrm/.
*
* Also removed the references to the tar file, since we assume that
* the platform is already created with drush make.
*/
function _provision_civicrm_install_civicrm($dbuser, $dbpass, $dbhost, $dbname, $lang) {
// Various civicrm.drush.inc functions expect the $crmPath to be set.
global $crmPath;
$crmPath = _provision_civicrm_get_package_path();
drush_log('DRUSH_DRUPAL_ROOT: ' . drush_get_context('DRUSH_DRUPAL_ROOT'), 'ok');
drush_log('DRUSH_SITE_ROOT: ' . drush_get_context('DRUSH_DRUPAL_SITE_ROOT', FALSE), 'ok');
// Include civicrm installer helper file
$civicrmInstallerHelper = $crmPath . "/install/civicrm.php";
if (!file_exists($civicrmInstallerHelper)) {
return drush_set_error('CIVICRM_NOT_PRESENT', dt("CiviCRM installer helper file is missing."));
}
// NB: civicrm drush functions expect the parent dir of the civicrm code base.
$modPath = $crmPath . '/../';
// Setup all required files/civicrm/* directories
if (!_civicrm_create_files_dirs($civicrmInstallerHelper, $modPath)) {
return FALSE;
}
// Install the database
drush_log(dt("CiviCRM: Initializing the CiviCRM database."));
_civicrm_install_db($dbuser, $dbpass, $dbhost, $dbname, $modPath, $lang);
// Generate civicrm.settings.php file
drush_log(dt("CiviCRM: Generating the CiviCRM settings file."));
_civicrm_generate_settings_file($dbuser, $dbpass, $dbhost, $dbname, $modPath);
drush_log(dt("CiviCRM: Enabling the CiviCRM module."));
module_enable(array('civicrm'));
// Save the site key, in case we verify later on, it will regenerate
// the civicrm.settings.php
// c.f. duplication from provision_civicrm_regenerate_settings()
drush_log(dt("CiviCRM: Saving sitekey and other settings."));
$civi_opts = _provision_civicrm_drush_options('post verify');
$civi_opts['civicrm_sitekey'] = CIVICRM_SITE_KEY;
foreach ($civi_opts as $opt => $val) {
drush_set_option($opt, $val, 'site');
}
}
/**
* Returns the CiviCRM language (ex: fr_FR) for a Drupal language (ex: fr).
*
* Handles a few exceptions (zh_CN, af_ZA, etc) and can be overridden with a
* constant in your aegir global.inc of the form:
* PROVISION_CIVICRM_LANGUAGE_MAPPING_XX, where XX is the short language code
* from Drupal.
*/
function _provision_civicrm_language_uf_to_civicrm($uf_language) {
if (defined('PROVISION_CIVICRM_LANGUAGE_MAPPING_' . $uf_language)) {
return constant('PROVISION_CIVICRM_LANGUAGE_MAPPING_' . $uf_language);
}
// Taken from l10n/bin/copy-to-svn.sh
$exceptions = array(
'ar' => 'ar_EG', // Arabic/Egypt
'af' => 'af_ZA', // Afrikaans/South Africa
'be' => 'be_BY', // Belarus
'ca' => 'ca_ES', // Catalan/Spain
'cs' => 'cs_CZ', // Czech
'da' => 'da_DK', // Danish
'el' => 'el_GR', // Greek
'et' => 'et_EE', // Estonian
'he' => 'he_IL', // Hebrew/Israel
'hi' => 'hi_IN', // Hindi
'ja' => 'ja_JP', // Japanese/Japan
'sv' => 'sv_SE', // Swedish
'sl' => 'sl_SI', // Slovenian
'sq' => 'sq_AL', // Albenian
'vi' => 'vi_VN', // Vietnam
'zh' => 'zh_CN', // Mandarin/China
);
if (isset($exceptions[$uf_language])) {
return $exceptions[$uf_language];
}
return $uf_language . '_' . strtoupper($uf_language);
}