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

Add the site skeleton site creation tool.

Add specific permisions to use it and the migration tool.

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@140 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent f104fd73
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,21 @@ function unl_wysiwyg_plugin($editor)
}
function unl_permission()
{
return array(
'unl migration' => array(
'title' => t('Migration'),
'description' => t('Migrate UNL Template based sites to drupal')
),
'unl site creation' => array(
'title' => t('Site Creation'),
'description' => t('Create new drupal sites using the UNL profile')
)
);
}
/**
* Adds UNL Migration Tool to the Content menu for admin
*/
......@@ -87,11 +102,20 @@ function unl_menu()
$items['admin/content/unl/migration'] = array(
'title' => 'UNL Migration Tool',
'description' => 'Migrate a static UNL template page into drupal',
'access arguments' => array('administer comments'),
'access arguments' => array('unl migration'),
'page callback' => 'unl_migration_page',
'type' => MENU_LOCAL_TASK,
'file' => 'unl_migration.php'
);
$items['admin/sites/unl/add'] = array(
'title' => 'UNL Site Creation Tool',
'description' => 'Create a new UNL Drupal site',
'access arguments' => array('unl site creation'),
'page callback' => 'unl_site_creation_page',
'type' => MENU_LOCAL_TASK,
'file' => 'unl_site_creation.php'
);
return $items;
}
<?php
require_once DRUPAL_ROOT . '/includes/install.core.inc';
function unl_site_creation_page()
{
return drupal_get_form('unl_site_creation');
}
function unl_site_creation($form, &$form_state)
{
$form['root'] = array(
'#type' => 'fieldset',
'#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'),
'#description' => t('A URL path used to separate subsites from the main site.'),
'#default_value' => t('s')
);
$form['root']['site_path'] = array(
'#type' => 'textfield',
'#title' => t('New site path'),
'#description' => t('Relative url for the new site'),
'#default_value' => t('newsite'),
'#required' => TRUE
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Create Site'
);
return $form;
}
function unl_site_creation_submit($form, &$form_state)
{
$php_path = $form_state['values']['php_path'];
$site_path = $form_state['values']['site_path'];
$site_path_prefix = $form_state['values']['site_path_prefix'];
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;
}
$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;
exit;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment