| 1 |
<?php
|
| 2 |
// $Id: provisionator.module,v 1.9 2007/01/08 03:48:48 dnorman Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Provisionator is a module that allows administrators to easily deploy (or provision) new Drupal sites on a shared hosting environment.
|
| 7 |
* It will take care of creating a database, populating it with a selected database profile, creating and modifying the Drupal site directory,
|
| 8 |
* creating a symlink to expose the site to Apache (assuming Drupal is installed outside of the wwwroot of Apache), and (soon) will also
|
| 9 |
* manage a database table to keep track of deployed sites. It will eventually provide additional functions, allowing admins to de-provision
|
| 10 |
* sites, freeze-dry them as static html, and delete them from the system.
|
| 11 |
*/
|
| 12 |
|
| 13 |
include_once('provisionator_site.inc');
|
| 14 |
include_once('provisionator_client.inc');
|
| 15 |
include_once('provisionator_helper.inc');
|
| 16 |
|
| 17 |
// once functionality is migrated over, drop this include and delete the legacy.inc file
|
| 18 |
include_once('provisionator_legacy.inc');
|
| 19 |
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_help().
|
| 23 |
*/
|
| 24 |
function provisionator_help($section) {
|
| 25 |
switch ($section) {
|
| 26 |
case 'admin/help#provisionator':
|
| 27 |
return t('help text goes here');
|
| 28 |
case 'admin/modules#description':
|
| 29 |
return t('Drupal site creation utility.');
|
| 30 |
|
| 31 |
case 'node/add#provisionatorsite':
|
| 32 |
return t('Use Provisionator to deploy a new Drupal site, using a specified template, and configuring it to be visible at an appropriate URL');
|
| 33 |
|
| 34 |
case 'node/add#provisionatorclient':
|
| 35 |
return t('Configure a client organization or institution, with custom settings for domain, etc...');
|
| 36 |
}
|
| 37 |
}
|
| 38 |
|
| 39 |
|
| 40 |
/**
|
| 41 |
* Implementation of hook_link().
|
| 42 |
*/
|
| 43 |
function provisionator_link($type, $node = NULL, $teaser = FALSE) {
|
| 44 |
$links = array();
|
| 45 |
|
| 46 |
// TODO: Perform logic to determine when link should appear
|
| 47 |
$links[] = l(t('TODO: Fill in link title'), 'TODO: Fill in link path', array('title' => t('TODO: Fill in link title attribute.')));
|
| 48 |
// OPTIONAL: Add additional links
|
| 49 |
|
| 50 |
return $links;
|
| 51 |
}
|
| 52 |
|
| 53 |
|
| 54 |
/**
|
| 55 |
* Implementation of hook_menu().
|
| 56 |
*/
|
| 57 |
function provisionator_menu($may_cache) {
|
| 58 |
$items = array();
|
| 59 |
|
| 60 |
if ($may_cache) {
|
| 61 |
$items[] = array(
|
| 62 |
'path' => 'provisionator',
|
| 63 |
'title' => t('provisionator'),
|
| 64 |
'callback' => 'provisionator_page',
|
| 65 |
'access' => user_access('access provisionator'),
|
| 66 |
'description' => t('Provisionator (legacy interface)')
|
| 67 |
);
|
| 68 |
|
| 69 |
$items[] = array(
|
| 70 |
'path' => 'node/add/provisionatorsite',
|
| 71 |
'title' => t('provisionator site'),
|
| 72 |
'access' => user_access('deploy new site')
|
| 73 |
);
|
| 74 |
|
| 75 |
$items[] = array(
|
| 76 |
'path' => 'node/add/provisionatorclient',
|
| 77 |
'title' => t('provisionator client'),
|
| 78 |
'access' => user_access('administer provisionator')
|
| 79 |
);
|
| 80 |
}
|
| 81 |
|
| 82 |
return $items;
|
| 83 |
}
|
| 84 |
|
| 85 |
|
| 86 |
function provisionator_settings() {
|
| 87 |
// only administrators can access this function
|
| 88 |
if (!user_access('access provisionator')) {
|
| 89 |
return t('No provisionator for you!');
|
| 90 |
}
|
| 91 |
|
| 92 |
$form['provisionator_mysqlhost'] = array(
|
| 93 |
'#type' => 'textfield',
|
| 94 |
'#title' => 'MySQL Server Host',
|
| 95 |
'#size' => 30,
|
| 96 |
'#maxlength' => 256,
|
| 97 |
'#required' => TRUE,
|
| 98 |
'#default_value' => variable_get('provisionator_mysqlhost','localhost'),
|
| 99 |
'#description' => t('Server to use for MySQL.'),
|
| 100 |
);
|
| 101 |
|
| 102 |
$form['provisionator_mysqlbin'] = array(
|
| 103 |
'#type' => 'textfield',
|
| 104 |
'#title' => 'MySQL binary location',
|
| 105 |
'#size' => 30,
|
| 106 |
'#maxlength' => 64,
|
| 107 |
'#required' => TRUE,
|
| 108 |
'#default_value' => variable_get('provisionator_mysqlbin','/usr/bin/mysql'),
|
| 109 |
'#description' => t('Location of the mysql command. Like /usr/bin/mysql'),
|
| 110 |
);
|
| 111 |
|
| 112 |
$form['provisionator_mysqluser'] = array(
|
| 113 |
'#type' => 'textfield',
|
| 114 |
'#title' => 'MySQL Username',
|
| 115 |
'#size' => 30,
|
| 116 |
'#maxlength' => 64,
|
| 117 |
'#required' => TRUE,
|
| 118 |
'#default_value' => variable_get('provisionator_mysqluser','mysqluser'),
|
| 119 |
'#description' => t('MySQL Username for creating new databases.'),
|
| 120 |
);
|
| 121 |
|
| 122 |
$form['provisionator_mysqlpass'] = array(
|
| 123 |
'#type' => 'textfield',
|
| 124 |
'#title' => 'MySQL Password',
|
| 125 |
'#size' => 30,
|
| 126 |
'#maxlength' => 64,
|
| 127 |
'#required' => TRUE,
|
| 128 |
'#default_value' => variable_get('provisionator_mysqlpass','mysqlpassword'),
|
| 129 |
'#description' => t('MySQL Password for creating new databases.'),
|
| 130 |
);
|
| 131 |
|
| 132 |
$form['provisionator_dbprefix'] = array(
|
| 133 |
'#type' => 'textfield',
|
| 134 |
'#title' => 'Database Prefix',
|
| 135 |
'#size' => 30,
|
| 136 |
'#maxlength' => 64,
|
| 137 |
'#required' => TRUE,
|
| 138 |
'#default_value' => variable_get('provisionator_dbprefix','drupal_'),
|
| 139 |
'#description' => t('Prefix to prepend new database names.'),
|
| 140 |
);
|
| 141 |
|
| 142 |
$form['provisionator_profilesdir'] = array(
|
| 143 |
'#type' => 'textfield',
|
| 144 |
'#title' => 'Profiles SQL directory',
|
| 145 |
'#size' => 30,
|
| 146 |
'#maxlength' => 512,
|
| 147 |
'#required' => TRUE,
|
| 148 |
'#default_value' => variable_get('provisionator_profilesdir','./'),
|
| 149 |
'#description' => t('Directory containing the .sql files for the profiles.'),
|
| 150 |
);
|
| 151 |
|
| 152 |
$form['provisionator_drupal_site_template_dir'] = array(
|
| 153 |
'#type' => 'textfield',
|
| 154 |
'#title' => 'Drupal Site template directory',
|
| 155 |
'#size' => 30,
|
| 156 |
'#maxlength' => 512,
|
| 157 |
'#required' => TRUE,
|
| 158 |
'#default_value' => variable_get('provisionator_drupal_site_template_dir','../../sites/template'),
|
| 159 |
'#description' => t('Directory containing the template of the Drupal site directory.'),
|
| 160 |
);
|
| 161 |
|
| 162 |
$form['provisionator_drupal_site_dir_prefix'] = array(
|
| 163 |
'#type' => 'textfield',
|
| 164 |
'#title' => 'Drupal Site directory prefix',
|
| 165 |
'#size' => 30,
|
| 166 |
'#maxlength' => 512,
|
| 167 |
'#required' => TRUE,
|
| 168 |
'#default_value' => variable_get('provisionator_drupal_site_dir_prefix','localhost'),
|
| 169 |
'#description' => t('Should match the Drupal site directory naming convention. Something like "blogs.bcit.ca".'),
|
| 170 |
);
|
| 171 |
|
| 172 |
$form['provisionator_drupal_installed_path'] = array(
|
| 173 |
'#type' => 'textfield',
|
| 174 |
'#title' => 'Drupal installation directory',
|
| 175 |
'#size' => 30,
|
| 176 |
'#maxlength' => 512,
|
| 177 |
'#required' => TRUE,
|
| 178 |
'#default_value' => variable_get('provisionator_drupal_installed_path','/Library/WebServer/Drupal'),
|
| 179 |
'#description' => t('Where is Drupal installed on the server\'s filesystem? use that.'),
|
| 180 |
);
|
| 181 |
|
| 182 |
$form['provisionator_apache_target_dir'] = array(
|
| 183 |
'#type' => 'textfield',
|
| 184 |
'#title' => 'Apache target directory',
|
| 185 |
'#size' => 30,
|
| 186 |
'#maxlength' => 512,
|
| 187 |
'#required' => TRUE,
|
| 188 |
'#default_value' => variable_get('provisionator_apache_target_dir','/Library/WebServer/Documents'),
|
| 189 |
'#description' => t('Directory where the symlink to expose the new site should be made. It will point to the Drupal directory.'),
|
| 190 |
);
|
| 191 |
|
| 192 |
$form['provisionator_manifest_index_filename'] = array(
|
| 193 |
'#type' => 'textfield',
|
| 194 |
'#title' => 'Manifest Index File Location',
|
| 195 |
'#size' => 30,
|
| 196 |
'#maxlength' => 512,
|
| 197 |
'#required' => TRUE,
|
| 198 |
'#default_value' => variable_get('provisionator_manifest_index_filename','/Library/WebServer/Documents/provisionator.html'),
|
| 199 |
'#description' => t('Location of the file to be used as an index of all provisioned sites. Handy for a table of contents for the server, etc... If you don\'t really want one, stick it in /tmp/output.html or something.'),
|
| 200 |
);
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
return $form;
|
| 206 |
}
|
| 207 |
|
| 208 |
/**
|
| 209 |
* Implementation of hook_perm().
|
| 210 |
*/
|
| 211 |
function provisionator_perm() {
|
| 212 |
return array(
|
| 213 |
'administer provisionator',
|
| 214 |
'deploy new site',
|
| 215 |
'freezedry deployed site',
|
| 216 |
'delete own deployed sites',
|
| 217 |
'administer deployed sites',
|
| 218 |
'edit own deployed sites'
|
| 219 |
);
|
| 220 |
}
|
| 221 |
|
| 222 |
|
| 223 |
/**
|
| 224 |
* Implementation of hook_cron().
|
| 225 |
*/
|
| 226 |
function provisionator_cron() {
|
| 227 |
|
| 228 |
}
|
| 229 |
|
| 230 |
|
| 231 |
/**
|
| 232 |
* Implementation of hook_node_access_records().
|
| 233 |
*/
|
| 234 |
function provisionator_node_access_records($node) {
|
| 235 |
|
| 236 |
}
|
| 237 |
|
| 238 |
|
| 239 |
/**
|
| 240 |
* Implementation of hook_node_grants().
|
| 241 |
*/
|
| 242 |
function provisionator_node_grants($account, $op) {
|
| 243 |
|
| 244 |
}
|
| 245 |
|
| 246 |
|
| 247 |
/**
|
| 248 |
* Implementation of hook_node_operations().
|
| 249 |
*/
|
| 250 |
function provisionator_node_operations() {
|
| 251 |
|
| 252 |
}
|
| 253 |
|
| 254 |
|
| 255 |
/**
|
| 256 |
* Implementation of hook_nodeapi().
|
| 257 |
*/
|
| 258 |
function provisionator_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
| 259 |
switch ($op) {
|
| 260 |
case 'delete revision':
|
| 261 |
// TODO: Enter revision deletion query here, for example:
|
| 262 |
// db_query('DELETE FROM {node_example} WHERE vid = %d', $node->vid);
|
| 263 |
break;
|
| 264 |
}
|
| 265 |
}
|
| 266 |
|
| 267 |
|
| 268 |
/**
|
| 269 |
* Implementation of hook_node_info().
|
| 270 |
*/
|
| 271 |
function provisionator_node_info() {
|
| 272 |
return array(
|
| 273 |
'provisionatorsite' => array('name' => t('provisionator deployed site'), 'base' => 'provisionatorsite'),
|
| 274 |
'provisionatorclient' => array('name' => t('provisionator client'), 'base' => 'provisionatorclient')
|
| 275 |
);
|
| 276 |
}
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
function provisionator_views_tables() {
|
| 282 |
|
| 283 |
$tables['provisionatorsite'] = array(
|
| 284 |
"name" => "provisionatorsite",
|
| 285 |
"join" => array(
|
| 286 |
"left" => array(
|
| 287 |
"table" => "node",
|
| 288 |
"field" => "nid"
|
| 289 |
),
|
| 290 |
"right" => array(
|
| 291 |
"field" => "nid"
|
| 292 |
),
|
| 293 |
),
|
| 294 |
"fields" => array(
|
| 295 |
"shortname" => array(
|
| 296 |
'name' => "Provisionator: TEST Site Shortname",
|
| 297 |
'sortable' => true,
|
| 298 |
),
|
| 299 |
"sitestatus" => array(
|
| 300 |
'name' => "Provisionator: Site Status",
|
| 301 |
'sortable' => true,
|
| 302 |
),
|
| 303 |
"fullurl" => array(
|
| 304 |
'name' => "Provisionator: Site URL",
|
| 305 |
'sortable' => true,
|
| 306 |
),
|
| 307 |
"profile" => array(
|
| 308 |
'name' => "Provisionator: Site Profile",
|
| 309 |
'sortable' => true,
|
| 310 |
),
|
| 311 |
"clientid" => array(
|
| 312 |
'name' => "Provisionator: Client ID",
|
| 313 |
'sortable' => true,
|
| 314 |
),
|
| 315 |
),
|
| 316 |
"sorts" => array(
|
| 317 |
"shortname" => array( 'name' => "Shortname" ),
|
| 318 |
"sitestatus" => array( 'name' => "Status" ),
|
| 319 |
"fullurl" => array( 'name' => "Site URL" ),
|
| 320 |
"profile" => array( 'name' => "Site Profile" ),
|
| 321 |
"clientid" => array( 'name' => 'Client ID' ),
|
| 322 |
),
|
| 323 |
"filters" => array(
|
| 324 |
"clientid" => array(
|
| 325 |
'name' => 'Provisionator: Client ID',
|
| 326 |
'help' => t('ID of the Provisionator Client to restrict view list to.'),
|
| 327 |
'field' => 'clientid',
|
| 328 |
'operator' => array("="),
|
| 329 |
'value' => 'integer',
|
| 330 |
),
|
| 331 |
),
|
| 332 |
);
|
| 333 |
return $tables;
|
| 334 |
}
|
| 335 |
|
| 336 |
function provisionator_views_arguments() {
|
| 337 |
$arguments['clientid'] = array(
|
| 338 |
'name' => t('Provisionator: Client ID'),
|
| 339 |
'handler' => 'views_handler_clientid',
|
| 340 |
'option' => array(
|
| 341 |
'#type' => 'select',
|
| 342 |
'#options' => array('equal', 'not equal'),
|
| 343 |
),
|
| 344 |
'help' => t('This argument is a single Node ID.'),
|
| 345 |
);
|
| 346 |
|
| 347 |
return $arguments;
|
| 348 |
}
|
| 349 |
|
| 350 |
|
| 351 |
function views_handler_clientid($op, &$query, $argtype, $arg = '') {
|
| 352 |
switch($op) {
|
| 353 |
case 'summary':
|
| 354 |
$query->add_field('nid');
|
| 355 |
$query->add_field("title");
|
| 356 |
$fieldinfo['field'] = 'node.nid';
|
| 357 |
return $fieldinfo;
|
| 358 |
case 'sort':
|
| 359 |
// do nothing here.
|
| 360 |
break;
|
| 361 |
case 'filter':
|
| 362 |
$args = _views_break_phrase($arg);
|
| 363 |
if ($args[0] == 'and') {
|
| 364 |
$operator = $argtype['options'] ? '!=' : '=';
|
| 365 |
foreach ($args[1] as $arg) {
|
| 366 |
$query->add_where("provisionatorsite.clientid $operator %d", $arg);
|
| 367 |
}
|
| 368 |
}
|
| 369 |
else {
|
| 370 |
$query->add_where("provisionatorsite.clientid IN (%s)", implode(',', $args[1]));
|
| 371 |
}
|
| 372 |
break;
|
| 373 |
case 'link':
|
| 374 |
return l($query->title, "$arg/$query->nid");
|
| 375 |
case 'title':
|
| 376 |
list($type, $info) = _views_break_phrase($query);
|
| 377 |
if (!$info) {
|
| 378 |
return t('Untitled');
|
| 379 |
}
|
| 380 |
$nids = implode(',', $info); // only does numbers so safe
|
| 381 |
|
| 382 |
//$result = db_query("select * from node,provisionatorsite where (node.nid = provisionatorsite.nid) and (provisionatorsite.clientid in (%s))", $nids)
|
| 383 |
$result = db_query("SELECT title FROM {node} WHERE nid IN (%s)", $nids);
|
| 384 |
while ($node = db_fetch_object($result)) {
|
| 385 |
$title .= ($title ? ($type == 'or' ? ' + ' : ', ') : '') . check_plain($node->title);
|
| 386 |
}
|
| 387 |
return $title;
|
| 388 |
}
|
| 389 |
}
|