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

[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
parent d05f19ed
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
<?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
......@@ -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(
......
......@@ -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
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