diff --git a/sites/all/modules/unl/unl.module b/sites/all/modules/unl/unl.module index ea9f95736119f8136a641eeae94de84a8cd0c496..0da780b8448d70ce725b5a2378f25424ddabaa93 100644 --- a/sites/all/modules/unl/unl.module +++ b/sites/all/modules/unl/unl.module @@ -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; } diff --git a/sites/all/modules/unl/unl_site_creation.php b/sites/all/modules/unl/unl_site_creation.php new file mode 100644 index 0000000000000000000000000000000000000000..0cf8992e8035cba98ceb6d017b38fc8a58e5d14a --- /dev/null +++ b/sites/all/modules/unl/unl_site_creation.php @@ -0,0 +1,108 @@ +<?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