Skip to content
Snippets Groups Projects
Commit 0447d8ed authored by Tim Steiner's avatar Tim Steiner
Browse files

Cron based automated site creation tools. Only does sub-sites right now, not subdomains.

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@143 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 16feffb8
No related branches found
No related tags found
No related merge requests found
<?php
if (PHP_SAPI != 'cli') {
echo 'This script must be run from the shell!';
exit;
}
chdir(dirname(__FILE__) . '/../../../..');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_override_server_variables();
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$query = db_query('SELECT * FROM {unl_sites} WHERE installed=0');
while ($row = $query->fetchAssoc()) {
db_update('unl_sites')
->fields(array('installed' => 1))
->condition('site_id', $row['site_id'])
->execute();
unl_add_site($row['site_path_prefix'], $row['site_path'], $row['uri']);
db_update('unl_sites')
->fields(array('installed' => 2))
->condition('site_id', $row['site_id'])
->execute();
}
function unl_add_site($site_path_prefix, $site_path, $uri)
{
if (substr($site_path, 0, 1) == '/') {
$site_path = substr($site_path, 1);
}
if (substr($site_path, -1) == '/') {
$site_path = substr($site_path, 0, -1);
}
if (substr($site_path_prefix, 0, 1) == '/') {
$site_path_prefix = substr($site_path_prefix, 1);
}
if (substr($site_path_prefix, -1) == '/') {
$site_path_prefix = substr($site_path_prefix, 0, -1);
}
$full_path = $site_path;
if ($site_path_prefix) {
$full_path = $site_path_prefix . '/' . $full_path;
}
$path_parts = parse_url($uri);
$sites_subdir = $path_parts['host'] . $path_parts['path'];
$sites_subdir = strtr($sites_subdir, array('/' => '.'));
$database = $GLOBALS['databases']['default']['default'];
$db_url = $database['driver']
. '://' . $database['username']
. ':' . $database['password']
. '@' . $database['host']
. ($database['port'] ? ':' . $database['port'] : '')
. '/' . $database['database']
;
$db_prefix = explode('/', $site_path);
$db_prefix = array_reverse($db_prefix);
$db_prefix = implode('_', $db_prefix) . '_' . $database['prefix'];
$php_path = escapeshellarg($_SERVER['_']);
$drupal_root = escapeshellarg(DRUPAL_ROOT);
$uri = escapeshellarg($uri);
$sites_subdir = escapeshellarg($sites_subdir);
$db_url = escapeshellarg($db_url);
$db_prefix = escapeshellarg($db_prefix);
$subdir = explode('/', $full_path);
$symlink_name = array_pop($subdir);
$subdir_levels = count($subdir);
$subdir = implode('/', $subdir);
$symlink_target = array();
for ($i = 0; $i < $subdir_levels; $i++) {
$symlink_target[] = '..';
}
$symlink_target = implode('/', $symlink_target);
$command = "$php_path sites/all/modules/drush/drush.php -y --uri=$uri site-install unl_profile --sites-subdir=$sites_subdir --db-url=$db_url --db-prefix=$db_prefix --clean-url=0";
mkdir($subdir, 0755, TRUE);
symlink($symlink_target, $subdir . '/' . $symlink_name);
shell_exec($command);
}
\ No newline at end of file
; $Id$
name = UNL WDN
description = Adds features to allow wysiwyg editing of WDN Templated sites.
core = 7.x
version = "7.x-1.0-20100720"
dependencies[] = wysiwyg
files[] = unl.install
files[] = unl.module
<?php
function unl_schema()
{
$schema = array();
$schema['unl_sites'] = array(
'description' => 'Table of tables to be programatically created',
'fields' => array(
'site_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
),
'site_path_prefix' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'site_path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'uri' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'installed' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0
)
),
'primary key' => array('site_id'),
'unique keys' => array(
'sub_site' => array('site_path_prefix', 'site_path')
)
);
return $schema;
}
function unl_update_7100()
{
$table = array(
'description' => 'Table of tables to be programatically created',
'fields' => array(
'site_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
),
'site_path_prefix' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'site_path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'uri' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'installed' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0
)
),
'primary key' => array('site_id'),
'unique keys' => array(
'sub_site' => array('site_path_prefix', 'site_path')
)
);
db_create_table('unl_sites', $table);
}
......@@ -15,14 +15,6 @@ function unl_site_creation($form, &$form_state)
'#title' => 'Site Creation Tool'
);
$form['root']['php_path'] = array(
'#type' => 'textfield',
'#title' => t('PHP Path'),
'#description' => t('Full Path to the server\'s PHP binary'),
'#default_value' => t('/usr/bin/php'),
'#required' => TRUE
);
$form['root']['site_path_prefix'] = array(
'#type' => 'textfield',
'#title' => t('Site path prefix'),
......@@ -69,40 +61,13 @@ function unl_site_creation_submit($form, &$form_state)
$full_path = $site_path_prefix . '/' . $full_path;
}
$uri = url($full_path, array('absolute' => TRUE));
$path_parts = parse_url($uri);
$sites_subdir = $path_parts['host'] . $path_parts['path'];
$sites_subdir = strtr($sites_subdir, array('/' => '.'));
$database = $GLOBALS['databases']['default']['default'];
$db_url = $database['driver']
. '://' . $database['username']
. ':' . $database['password']
. '@' . $database['host']
. ($database['port'] ? ':' . $database['port'] : '')
. '/' . $database['database']
;
$db_prefix = explode('/', $site_path);
$db_prefix = array_reverse($db_prefix);
$db_prefix = implode('_', $db_prefix) . '_' . $database['prefix'];
$php_path = escapeshellarg($php_path);
$drupal_root = escapeshellarg(DRUPAL_ROOT);
$uri = escapeshellarg($uri);
$sites_subdir = escapeshellarg($sites_subdir);
$db_url = escapeshellarg($db_url);
$db_prefix = escapeshellarg($db_prefix);
$command = "$php_path sites/all/modules/drush/drush.php --uri=$uri site-install unl_profile --sites-subdir=$sites_subdir --db-url=$db_url --db-prefix=$db_prefix";
header('Content-Type: text/plain');
echo 'Run the following commands on the drupal server:' . PHP_EOL;
echo 'cd ' . $drupal_root . PHP_EOL;
echo $command . PHP_EOL;
db_insert('unl_sites')->fields(array(
'site_path_prefix' => $site_path_prefix,
'site_path' => $site_path,
'uri' => $uri
))->execute();
exit;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment