|
1 <?php |
|
2 |
|
3 /** |
|
4 * @file |
|
5 * Enables modules and site configuration for a DruStack installation. |
|
6 */ |
|
7 |
|
8 /** |
|
9 * Implements hook_install_tasks(). |
|
10 */ |
|
11 function drustack_install_tasks($install_state) { |
|
12 return array( |
|
13 'drustack_batch' => array( |
|
14 'type' => 'batch', |
|
15 ), |
|
16 ); |
|
17 } |
|
18 |
|
19 /** |
|
20 * Installation step callback. |
|
21 */ |
|
22 function drustack_batch(&$install_state) { |
|
23 return array( |
|
24 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_distribution_name())), |
|
25 'error_message' => st('The installation has encountered an error.'), |
|
26 'operations' => array( |
|
27 array('_drustack_configure_avatar', array()), |
|
28 array('_drustack_configure_modules', array()), |
|
29 array('_drustack_configure_variables', array()), |
|
30 array('_drustack_configure_cleanup', array()), |
|
31 ), |
|
32 ); |
|
33 } |
|
34 |
|
35 /** |
|
36 * Implements hook_form_FORM_ID_alter(). |
|
37 * |
|
38 * Allows the profile to alter the site configuration form. |
|
39 */ |
|
40 function drustack_form_install_configure_form_alter(&$form, $form_state) { |
|
41 // Clear drupal message queue for non-errors. |
|
42 drupal_get_messages('status', TRUE); |
|
43 drupal_get_messages('warning', TRUE); |
|
44 |
|
45 // Site information form. |
|
46 $form['site_information']['#weight'] = -20; |
|
47 $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; |
|
48 $form['site_information']['site_mail']['#default_value'] = 'admin@example.com'; |
|
49 |
|
50 // Administrator account form. |
|
51 $form['admin_account']['#weight'] = -19; |
|
52 $form['admin_account']['account']['name']['#default_value'] = 'admin'; |
|
53 $form['admin_account']['account']['mail']['#default_value'] = 'admin@example.com'; |
|
54 |
|
55 // Power user account form. |
|
56 $form['webmaster_account'] = array( |
|
57 '#type' => 'fieldset', |
|
58 '#title' => st('Site power user account'), |
|
59 '#collapsible' => FALSE, |
|
60 ); |
|
61 |
|
62 $form['webmaster_account']['#weight'] = -18; |
|
63 $form['webmaster_account']['webmaster_account']['#tree'] = TRUE; |
|
64 $form['webmaster_account']['webmaster_account']['name'] = array( |
|
65 '#title' => st('Username'), |
|
66 '#type' => 'textfield', |
|
67 '#default_value' => 'webmaster', |
|
68 '#maxlength' => USERNAME_MAX_LENGTH, |
|
69 '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), |
|
70 '#required' => TRUE, |
|
71 '#weight' => -10, |
|
72 '#attributes' => array('class' => array('username')), |
|
73 ); |
|
74 |
|
75 $form['webmaster_account']['webmaster_account']['mail'] = array( |
|
76 '#title' => st('E-mail address'), |
|
77 '#type' => 'textfield', |
|
78 '#default_value' => 'webmaster@example.com', |
|
79 '#maxlength' => EMAIL_MAX_LENGTH, |
|
80 '#required' => TRUE, |
|
81 '#weight' => -5, |
|
82 ); |
|
83 |
|
84 // Just alter the weight. |
|
85 $form['server_settings']['#weight'] = -17; |
|
86 $form['update_notifications']['#weight'] = -16; |
|
87 $form['actions']['#weight'] = -15; |
|
88 |
|
89 // Add our own validation. |
|
90 $form['#validate'][] = '_drustack_form_install_configure_form_validate'; |
|
91 |
|
92 // Add our own submit handler. |
|
93 $form['#submit'][] = '_drustack_form_install_configure_form_submit'; |
|
94 } |
|
95 |
|
96 /** |
|
97 * Validate Power user account. |
|
98 */ |
|
99 function _drustack_form_install_configure_form_validate($form, &$form_state) { |
|
100 // Check admin account name. |
|
101 if ($error = user_validate_name($form_state['values']['webmaster_account']['name'])) { |
|
102 form_error($form['webmaster_account']['webmaster_account']['name'], $error); |
|
103 } |
|
104 if ($form_state['values']['webmaster_account']['name'] == $form_state['values']['account']['name']) { |
|
105 form_error($form['webmaster_account']['webmaster_account']['name'], t('The admin name is not valid.')); |
|
106 } |
|
107 |
|
108 // Check admin account e-mail address. |
|
109 if ($error = user_validate_mail($form_state['values']['webmaster_account']['mail'])) { |
|
110 form_error($form['webmaster_account']['webmaster_account']['mail'], $error); |
|
111 } |
|
112 if ($form_state['values']['webmaster_account']['mail'] == $form_state['values']['account']['mail']) { |
|
113 form_error($form['webmaster_account']['webmaster_account']['mail'], t('The admin e-email address is not valid.')); |
|
114 } |
|
115 } |
|
116 |
|
117 /** |
|
118 * Create Power user account and change root password. |
|
119 */ |
|
120 function _drustack_form_install_configure_form_submit($form, &$form_state) { |
|
121 // Add the user and associate role here. |
|
122 $power_user_role = user_role_load_by_name('power user'); |
|
123 if (!$power_user_role) { |
|
124 $power_user_role = new stdClass(); |
|
125 $power_user_role->name = 'power user'; |
|
126 user_role_save($power_user_role); |
|
127 $power_user_role = user_role_load_by_name('power user'); |
|
128 } |
|
129 |
|
130 // We keep power user and administrator account password in sync by default. |
|
131 $user_data = array( |
|
132 'mail' => $form_state['values']['webmaster_account']['mail'], |
|
133 'name' => $form_state['values']['webmaster_account']['name'], |
|
134 'pass' => $form_state['values']['account']['pass'], |
|
135 'init' => $form_state['values']['webmaster_account']['mail'], |
|
136 'status' => 1, |
|
137 'roles' => array( |
|
138 $power_user_role->rid => $power_user_role->name, |
|
139 ), |
|
140 ); |
|
141 $account = user_save(new StdClass(), $user_data); |
|
142 } |
|
143 |
|
144 /** |
|
145 * Set a default user avatar as a managed file object. |
|
146 */ |
|
147 function _drustack_configure_avatar() { |
|
148 $picture = 'user.png'; |
|
149 |
|
150 $source_dir = 'profiles/drustack/files/pictures'; |
|
151 $source_file = $source_dir . '/' . $picture; |
|
152 |
|
153 variable_set('user_picture_path', 'pictures'); |
|
154 $destination_dir = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); |
|
155 $destination_file = $destination_dir . '/' . $picture; |
|
156 |
|
157 @drupal_mkdir($destination_dir); |
|
158 file_unmanaged_copy($source_file, $destination_file, FILE_EXISTS_REPLACE); |
|
159 variable_set('user_picture_default', $destination_file); |
|
160 |
|
161 variable_set('user_pictures', 1); |
|
162 variable_set('user_picture_style', 'thumbnail'); |
|
163 variable_set('user_picture_dimensions', '1024x1024'); |
|
164 variable_set('user_picture_file_size', '1024'); |
|
165 } |
|
166 |
|
167 /** |
|
168 * Configure non-backward-compatibile modules. |
|
169 */ |
|
170 function _drustack_configure_modules() { |
|
171 // Enable modules. |
|
172 module_enable(array( |
|
173 'drustack_article', |
|
174 'drustack_blog', |
|
175 'drustack_core', |
|
176 'drustack_devel', |
|
177 'drustack_page', |
|
178 'drustack_wysiwyg', |
|
179 )); |
|
180 |
|
181 // Revert all features. |
|
182 features_revert(); |
|
183 } |
|
184 |
|
185 /** |
|
186 * Configure extra variables. |
|
187 */ |
|
188 function _drustack_configure_variables() { |
|
189 variable_set('block_cache', 0); |
|
190 variable_set('cache', 0); |
|
191 variable_set('cache_lifetime', 0); |
|
192 variable_set('dblog_row_limit', 1000); |
|
193 variable_set('error_level', 2); |
|
194 variable_set('page_cache_maximum_age', 0); |
|
195 variable_set('preprocess_css', 0); |
|
196 variable_set('preprocess_js', 0); |
|
197 variable_set('update_check_disabled', 1); |
|
198 } |
|
199 |
|
200 /** |
|
201 * Various actions needed to clean up after the installation. |
|
202 */ |
|
203 function _drustack_configure_cleanup() { |
|
204 // Clear the APC cache to ensure APC class loader is reset. |
|
205 if (function_exists('apc_fetch')) { |
|
206 apc_clear_cache('user'); |
|
207 } |
|
208 |
|
209 // Flush all existing path aliases. |
|
210 db_delete('url_alias'); |
|
211 |
|
212 // Rebuild node access database. |
|
213 node_access_rebuild(); |
|
214 |
|
215 // Rebuild node types. |
|
216 node_types_rebuild(); |
|
217 |
|
218 // Rebuild the menu. |
|
219 menu_rebuild(); |
|
220 |
|
221 // Clear out caches. |
|
222 drupal_flush_all_caches(); |
|
223 |
|
224 // Clear out JS and CSS caches. |
|
225 drupal_clear_css_cache(); |
|
226 drupal_clear_js_cache(); |
|
227 |
|
228 // Revert all features. |
|
229 features_revert(); |
|
230 |
|
231 // Clear drupal message queue for non-errors. |
|
232 drupal_get_messages('status', TRUE); |
|
233 drupal_get_messages('warning', TRUE); |
|
234 } |