From 17b23c1e162426c33895766b09ddf77444376c28 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Mon, 10 Oct 2011 20:30:27 +0000 Subject: [PATCH] [gh-198] Merging from testing into staging git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1141 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/includes/common.php | 36 ++++++++- sites/all/modules/unl/includes/reset_site.php | 78 +++++++++++++++++++ sites/all/modules/unl/unl.module | 10 +++ sites/all/modules/unl/unl_cas/unl_cas.module | 10 +-- 4 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 sites/all/modules/unl/includes/reset_site.php diff --git a/sites/all/modules/unl/includes/common.php b/sites/all/modules/unl/includes/common.php index dfca91b8..d332620c 100644 --- a/sites/all/modules/unl/includes/common.php +++ b/sites/all/modules/unl/includes/common.php @@ -98,4 +98,38 @@ function unl_get_site_settings($uri) { unset($settings_file); return get_defined_vars(); -} \ No newline at end of file +} + +/** + * Custom function that returns TRUE if the given table is shared with another site. + * @param string $table_name + */ +function unl_table_is_shared($table_name) { + $db_config = $GLOBALS['databases']['default']['default']; + if (is_array($db_config['prefix']) && + isset($db_config['prefix']['role']) && + $db_config['prefix']['default'] != $db_config['prefix'][$table_name]) { + return TRUE; + } + return FALSE; +} + +/** + * A shared-table safe method that returns TRUE if the user is a member of the super-admin role. + */ +function unl_user_is_administrator() { + $user = $GLOBALS['user']; + + // If the role table is shared, use parent site's user_admin role, otherwise use the local value. + if (unl_table_is_shared('role')) { + $admin_role_id = unl_shared_variable_get('user_admin_role'); + } else { + $admin_role_id = variable_get('user_admin_role'); + } + + if ($user && in_array($admin_role_id, array_keys($user->roles))) { + return TRUE; + } + + return FALSE; +} diff --git a/sites/all/modules/unl/includes/reset_site.php b/sites/all/modules/unl/includes/reset_site.php new file mode 100644 index 00000000..7a8bb366 --- /dev/null +++ b/sites/all/modules/unl/includes/reset_site.php @@ -0,0 +1,78 @@ +<?php + +function unl_reset_site($form, &$form_state) { + $form = array(); + + $form['root'] = array( + '#type' => 'fieldset', + '#title' => 'Reset Site', + '#description' => 'WARNING: Performing the following action will permanently remove all content on your site!', + ); + + $form['root']['confirm'] = array( + '#type' => 'checkbox', + '#title' => t('Confirm'), + '#description' => t("I am sure I want to permanently remove all content from this site."), + '#required' => TRUE, + ); + + $form['root']['confirm_again'] = array( + '#type' => 'checkbox', + '#title' => t('Confirm Again'), + '#description' => t("Yes, I am absolutely sure I want to permanently remove all content from this site."), + '#required' => TRUE, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Reset' + ); + return $form; +} + +function unl_reset_site_submit($form, &$form_state) { + + $nids = db_select('node', 'n') + ->fields('n', array('nid')) + ->execute() + ->fetchCol(); + node_delete_multiple($nids); + + variable_set('site_frontpage', 'node'); + + + $mlids = db_select('menu_links', 'm') + ->fields('m', array('mlid')) + ->condition('m.menu_name', 'main-menu') + ->execute() + ->fetchCol(); + foreach ($mlids as $mlid) { + menu_link_delete($mlid); + } + + $home_link = array( + 'link_path' => '<front>', + 'link_title' => 'Home', + 'menu_name' => 'main-menu', + 'module' => 'menu', + ); + menu_link_save($home_link); + + + $fids = db_select('file_managed', 'f') + ->fields('f', array('fid')) + ->execute() + ->fetchCol(); + $files = file_load_multiple($fids); + foreach ($files as $file) { + file_delete($file); + } + + $files_dir = DRUPAL_ROOT . '/' . conf_path() . '/files/'; + $cmd = 'rm -rf ' . $files_dir . '*'; + echo shell_exec($cmd); + drupal_mkdir('public://styles/'); + + variable_set('site_name', 'Site Name'); + +} \ No newline at end of file diff --git a/sites/all/modules/unl/unl.module b/sites/all/modules/unl/unl.module index 6a1f2d09..4d166f8a 100644 --- a/sites/all/modules/unl/unl.module +++ b/sites/all/modules/unl/unl.module @@ -302,6 +302,16 @@ function unl_menu() { 'type' => MENU_LOCAL_TASK, 'file' => 'unl_migration.php', ); + + $items['admin/content/unl/reset'] = array( + 'title' => 'Reset Site', + 'description' => 'Remove all nodes, menu items, etc from this site.', + 'access callback' => 'unl_user_is_administrator', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('unl_reset_site'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'includes/reset_site.php', + ); // Redirect the Appearance link away from admin/appearance for users who can't Administer themes but can Change Theme Settings $items['admin/themes'] = array( diff --git a/sites/all/modules/unl/unl_cas/unl_cas.module b/sites/all/modules/unl/unl_cas/unl_cas.module index a92c9022..96a8d1f8 100644 --- a/sites/all/modules/unl/unl_cas/unl_cas.module +++ b/sites/all/modules/unl/unl_cas/unl_cas.module @@ -70,7 +70,7 @@ function unl_cas_menu() { $items['admin/config/people/unl_cas'] = array( 'title' => 'UNL CAS', 'description' => 'Configure the UNL CAS module', - 'access callback' => 'unl_cas_user_is_administrator', + 'access callback' => 'unl_user_is_administrator', 'page callback' => 'drupal_get_form', 'page arguments' => array('unl_cas_config'), 'file' => 'unl_cas.admin.inc', @@ -327,11 +327,3 @@ function unl_cas_set_setting($name, $value) { ->execute(); } } - -function unl_cas_user_is_administrator() { - $user = $GLOBALS['user']; - if ($user && in_array(unl_shared_variable_get('user_admin_role'), array_keys($user->roles))) { - return TRUE; - } - return FALSE; -} \ No newline at end of file -- GitLab