/[drupal]/contributions/profiles/hostmaster/hostmaster.profile
ViewVC logotype

Contents of /contributions/profiles/hostmaster/hostmaster.profile

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.50 - (show annotations) (download) (as text)
Tue Oct 20 10:06:52 2009 UTC (5 weeks, 3 days ago) by adrian
Branch: MAIN
Changes since 1.49: +2 -2 lines
File MIME type: text/x-php
Add dependencies to jquery_ui and modalframe. the .make file already downloads these for you
1 <?php
2 // $Id: hostmaster.profile,v 1.49 2009/09/23 02:06:57 adrian Exp $
3
4 /**
5 * Return an array of the modules to be enabled when this profile is installed.
6 *
7 * @return
8 * An array of modules to be enabled.
9 */
10 function hostmaster_profile_modules() {
11 return array(
12 /* core */ 'block', 'color', 'filter', 'help', 'menu', 'node', 'system', 'user',
13 /* aegir contrib */ 'hosting', 'hosting_task', 'hosting_client', 'hosting_db_server', 'hosting_package', 'hosting_platform', 'hosting_site', 'hosting_web_server',
14 /* other contrib */ 'install_profile_api' /* needs >= 2.1 */, 'jquery_ui', 'modalframe'
15 );
16 }
17
18
19 /**
20 * Return a description of the profile for the initial installation screen.
21 *
22 * @return
23 * An array with keys 'name' and 'description' describing this profile.
24 */
25 function hostmaster_profile_details() {
26 return array(
27 'name' => 'Hostmaster',
28 'description' => 'Select this profile to manage the installation and maintenance of hosted Drupal sites.'
29 );
30 }
31
32 function pr($var) {
33 echo "<pre>";
34 print_r($var);
35 echo "</pre>";
36 }
37
38 function hostmaster_profile_task_list() {
39 return array(
40 'intro' => st('Getting started'),
41 'webserver' => st('Web server'),
42 'filesystem' => st('Filesystem'),
43 'dbserver' => st('Database server'),
44 'features' => st('Features'),
45 'init' => st('Initialize system'),
46 'verify' => st('Verify settings'),
47 'import' => st('Import sites'),
48 'finalize' => st('Finalize')
49 );
50 }
51
52 function hostmaster_get_task($task, $offset = 0) {
53 static $tasks;
54 static $keys;
55 if (!$tasks) {
56 $tasks = hostmaster_profile_task_list();
57 $keys = array_keys($tasks);
58 }
59
60
61 if (($task == $keys[sizeof($keys) - 1]) && ($offset > 0)) {
62 return 'profile-finished';
63 }
64
65 // finish if the task is the last one and the offset is positive
66 if (($tid = array_search($task, $keys)) === FALSE ) {
67 // at beginning
68 $tid = 0;
69 }
70
71 $tid = $tid + $offset;
72
73 // reset to beginning if it tries to go back too far
74 if ($tid < 0) {
75 $tid = 0;
76 }
77
78
79 return $keys[$tid];
80 }
81
82
83
84 function hostmaster_profile_tasks(&$task, $url) {
85 install_include(hostmaster_profile_modules());
86 include_once(dirname(__FILE__) . '/hostmaster.forms.inc');
87 define("HOSTMASTER_FORM_REDIRECT", $url);
88 if ($task == 'profile') {
89 hostmaster_bootstrap();
90 }
91 include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
92 $task = hostmaster_get_task($task, variable_get('hostmaster_wizard_offset', 0));
93 variable_del('hostmaster_wizard_offset');
94 define("HOSTMASTER_CURRENT_TASK", $task);
95
96
97 $func = sprintf("hostmaster_task_%s", $task);
98 if (function_exists($func)) {
99 return drupal_get_form($func);
100 }
101
102
103 return $task;
104 return "123";
105
106
107 if ($tid == (sizeof($keys) - 1)) {
108 # $task = 'profile-finished';
109 }
110 }
111
112 function hostmaster_requirement_help($requirement, $options = array()) {
113 $form = array_merge(_element_info('requirement_help'), $options);
114 $form['#requirement'] = $requirement;
115 $form['#help'] = hosting_get_requirement($requirement);
116 $form['#value'] = theme_requirement_help($form);
117 return $form;
118 }
119
120 /**
121 * modify the settings.php
122 *
123 * add the install_profile variable to the settings.php so that Drupal
124 * picks up the theme in our install profile
125 *
126 * This is a bug in the Drupal core: http://drupal.org/node/330297
127 */
128 function hostmaster_settings_php() {
129 $settings_file = realpath(conf_path() . '/settings.php');
130 drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
131 $fp = fopen($settings_file, "a");
132 fwrite($fp, "\n\n\$conf['install_profile'] = 'hostmaster';\n");
133 fclose($fp);
134 drupal_verify_install_file($settings_file, FILE_READABLE|FILE_NOT_WRITABLE);
135 }
136
137 /**
138 * Form modifier similar to confirm_form
139 *
140 * Handles some bookkeeping like adding the js and css,
141 * embedded the right classes, and most importantly : adding the wizard_form_submit
142 * to the #submit element. Without this, you would never be forwarded to the next
143 * page.
144 */
145 function hostmaster_form($form) {
146 global $task;
147
148 $form['#redirect'] = HOSTMASTER_FORM_REDIRECT;
149
150 $form['#prefix'] = '<div id="hosting-wizard-form">';
151 $form['#suffix'] = '</div>';
152
153
154 $form['wizard_form'] = array(
155 '#prefix' => '<div id="hosting-wizard-form-buttons">',
156 '#suffix' => '</div>',
157 '#weight' => 100
158 );
159
160 if (HOSTMASTER_CURRENT_TASK != 'intro') {
161 // add a back button
162 $button = array(
163 '#type' => 'submit',
164 '#value' => '<- Previous',
165 );
166 $button['#submit'][] = 'hostmaster_form_previous';
167
168 $form['wizard_form']['back'] = $button;
169 }
170
171 // add a next button
172 $button = array(
173 '#type' => 'submit',
174 '#value' => 'Next ->',
175 );
176
177 // only validate when next is pressed
178 // also inherit the whole form's validate callback
179 $button['#validate'] = $form['#validate'];
180 $button['#validate'][] = 'hostmaster_form_validate';
181 unset($form['#validate']);
182
183 $button['#submit'] = array();
184 if ($form['#node']) {
185 $button['#submit'][] = 'node_form_submit';
186 }
187 // hook the regular form submit hooks on the wizard submit hook
188 if ($form['#submit']) {
189 $button['#submit'] = array_merge($button['#submit'], $form['#submit']);
190 }
191 $button['#submit'][] = 'hostmaster_form_next';
192
193 $form['wizard_form']['submit'] = $button;
194 return $form;
195 }
196
197 function hostmaster_form_next($form, $form_state) {
198 // move forward a page
199 variable_set('hostmaster_wizard_offset', 1);
200 }
201
202 function hostmaster_form_previous($form, $form_state) {
203 // move forward a page
204 variable_set('hostmaster_wizard_offset', -1);
205 }
206
207 function hostmaster_bootstrap() {
208 /* Default node types and default node */
209 $types = node_types_rebuild();
210
211 variable_set('install_profile', 'hostmaster');
212 global $user;
213 // Initialize the hosting defines
214 hosting_init();
215
216 /* Default client */
217 $node = new stdClass();
218 $node->uid = 1;
219 $node->type = 'client';
220 $node->email = $user->mail;
221 $node->client_name = $user->name;
222 $node->status = 1;
223 node_save($node);
224 variable_set('hosting_default_client', $node->nid);
225
226 /* Default database server */
227 global $db_url;
228 $url = parse_url($db_url);
229
230 $node = new stdClass();
231 $node->uid = 1;
232 $node->type = 'db_server';
233 $node->title = $url['host'];
234 $node->db_type = $url['scheme'];
235 $node->db_user = $url['user'];
236 $node->db_passwd = $url['pass'];
237 $node->status = 1;
238
239 node_save($node);
240 variable_set('hosting_default_db_server', $node->nid);
241 variable_set('hosting_own_db_server', $node->nid);
242
243 $node = new stdClass();
244 $node->uid = 1;
245 $node->type = 'web_server';
246 $node->title = $_SERVER['HTTP_HOST'];
247 $node->script_user = HOSTING_DEFAULT_SCRIPT_USER;
248 $node->web_group = HOSTING_DEFAULT_WEB_GROUP;
249 $node->status = 1;
250 node_save($node);
251 variable_set('hosting_default_web_server', $node->nid);
252
253 $node = new stdClass();
254 $node->uid = 1;
255 $node->title = 'Drupal';
256 $node->type = 'package';
257 $node->package_type = 'platform';
258 $node->short_name = 'drupal';
259 $node->status = 1;
260 node_save($node);
261 $package_id = $node->nid;
262
263 $node = new stdClass();
264 $node->uid = 1;
265 $node->type = 'platform';
266 $node->title = $_SERVER['HTTP_HOST'] . ' (Drupal ' . VERSION . ')';
267 $node->publish_path = $_SERVER['DOCUMENT_ROOT'];
268 $node->web_server = variable_get('hosting_default_web_server', 3);
269 $node->status = 1;
270 $node->no_verify = TRUE;
271 node_save($node);
272 variable_set('hosting_default_platform', $node->nid);
273 variable_set('hosting_own_platform', $node->nid);
274
275
276 $instance = new stdClass();
277 $instance->rid = $node->nid;
278 $instance->version = VERSION;
279 $instance->schema_version = drupal_get_installed_schema_version('system');
280 $instance->package_id = $package_id;
281 $instance->status = 0;
282 hosting_package_instance_save($instance);
283
284 variable_set('site_frontpage', 'hosting/sites');
285
286 // do not allow user registration: the signup form will do that
287 variable_set('user_register', 0);
288
289 // This is saved because the config generation script is running via drush, and does not have access to this value
290 variable_set('install_url' , $GLOBALS['base_url']);
291
292 }
293
294
295 /**
296 * Enable optional modules, if present
297 */
298 function hostmaster_setup_optional_modules() {
299 $optional = array('admin_menu');
300
301 foreach ($optional as $name) {
302 $exists = db_result(db_query("SELECT name FROM {system} WHERE type='module' and name='%s'", $name));
303
304 drupal_install_modules(array($name));
305
306 if ($exists == $name) {
307 drupal_set_message(st("Enabling module !module", array('!module' => $name)));
308 switch ($name) {
309 case 'admin_menu' :
310 variable_set('admin_menu_margin_top', 1);
311 variable_set('admin_menu_position_fixed', 1);
312 variable_set('admin_menu_tweak_menu', 0);
313 variable_set('admin_menu_tweak_modules', 0);
314 variable_set('admin_menu_tweak_tabs', 0);
315
316 $menu_name = install_menu_create_menu(t('Administration'));
317 $admin = install_menu_get_items('admin');
318 $admin = install_menu_get_item($admin[0]['mlid']);
319 $admin['menu_name'] = $menu_name;
320 $admin['customized'] = 1;
321 menu_link_save($admin);
322 menu_rebuild();
323
324 break;
325 }
326 }
327 }
328 }
329
330
331 /**
332 * Take a node form and get rid of all the crud that we don't
333 * need on a wizard form, in a non destructive manner.
334 */
335 function _hostmaster_clean_node_form(&$form) {
336 $form['revision_information']['revision']['#type'] = 'value';
337 $form['revision_information']['log']['#type'] = 'value';
338 $form['revision_information']['#type'] = 'markup';
339
340 $form['author']['name']['#type'] = 'value';
341 $form['author']['date']['#type'] = 'value';
342 $form['author']['#type'] = 'markup';
343
344 $form['options']['sticky']['#type'] = 'value';
345 $form['options']['status']['#type'] = 'value';
346 $form['options']['promote']['#type'] = 'value';
347 $form['options']['#type'] = 'markup';
348
349 unset($form['buttons']);
350 }
351
352 function hostmaster_form_alter($form, $values, $form_id) {
353 if ($form_id == 'install_configure') {
354 // Put the install profile into settings.php so that it will pick up
355 // the eldir theme in profiles/hostmaster/themes
356 if (!variable_get('hostmaster_settings_php_alter', FALSE)) {
357 hostmaster_settings_php();
358 variable_set('hostmaster_settings_php_alter', TRUE);
359 }
360 }
361 }

  ViewVC Help
Powered by ViewVC 1.1.2