| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Wrapper management functions for Category.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* The category wrapper install / uninstall script.
|
| 11 |
*
|
| 12 |
* @param $type
|
| 13 |
* The wrapper being installed or uninstalled ('taxonomy' or 'book').
|
| 14 |
* @param $op
|
| 15 |
* The operation being performed ('install' or 'uninstall').
|
| 16 |
*/
|
| 17 |
function _category_wrapper($type = NULL, $op = NULL, $goto = NULL, $rebuild = TRUE) {
|
| 18 |
if (!isset($goto)) {
|
| 19 |
$goto = 'admin/content/category/settings';
|
| 20 |
}
|
| 21 |
$generic_error = ' '. t('Unable to perform the specified operation.');
|
| 22 |
|
| 23 |
// Various validation checks
|
| 24 |
if (!($type == 'taxonomy' || $type == 'book') || !($op == 'install' || $op == 'uninstall')) {
|
| 25 |
drupal_set_message(t('Invalid parameters supplied to wrapper install / uninstall script.') . $generic_error, 'error');
|
| 26 |
drupal_goto($goto);
|
| 27 |
}
|
| 28 |
if (!module_exists($type)) {
|
| 29 |
drupal_set_message(t('The %type module is not currently enabled. You must enable it before performing an install or uninstall.', array('%type' => $type)), 'error');
|
| 30 |
drupal_goto($goto);
|
| 31 |
}
|
| 32 |
$status = category_get_wrapper_status($type);
|
| 33 |
if (($status && $op == 'install') || (!$status && $op == 'uninstall')) {
|
| 34 |
drupal_set_message(t('The %type module is already @status.', array('%type' => $type, '@status' => ($status ? t('installed') : t('uninstalled')))) . $generic_error, 'error');
|
| 35 |
drupal_goto($goto);
|
| 36 |
}
|
| 37 |
|
| 38 |
$module_path = drupal_get_path('module', $type);
|
| 39 |
$module_file = $type .'.module';
|
| 40 |
$module_file_path = $module_path .'/'. $module_file;
|
| 41 |
if (!file_exists($module_file_path)) {
|
| 42 |
drupal_set_message(t('The file %filename could not be found.', array('%filename' => $module_file)) . $generic_error, 'error');
|
| 43 |
drupal_goto($goto);
|
| 44 |
}
|
| 45 |
$info_file = $type .'.info';
|
| 46 |
$info_file_path = $module_path .'/'. $info_file;
|
| 47 |
if (!file_exists($info_file_path)) {
|
| 48 |
drupal_set_message(t('The file %filename could not be found.', array('%filename' => $info_file)) . $generic_error, 'error');
|
| 49 |
drupal_goto($goto);
|
| 50 |
}
|
| 51 |
if ($op == 'install') {
|
| 52 |
$wrapper_file = $type .'.module.copyme';
|
| 53 |
$wrapper_file_path = drupal_get_path('module', 'category') .'/wrappers/'. $wrapper_file;
|
| 54 |
if (!file_exists($wrapper_file_path)) {
|
| 55 |
drupal_set_message(t('The file %filename could not be found.', array('%filename' => $wrapper_file)) . $generic_error, 'error');
|
| 56 |
drupal_goto($goto);
|
| 57 |
}
|
| 58 |
$wrapper_info_file = $type .'.info.copyme';
|
| 59 |
$wrapper_info_file_path = drupal_get_path('module', 'category') .'/wrappers/'. $wrapper_info_file;
|
| 60 |
if (!file_exists($wrapper_info_file_path)) {
|
| 61 |
drupal_set_message(t('The file %filename could not be found.', array('%filename' => $wrapper_info_file)) . $generic_error, 'error');
|
| 62 |
drupal_goto($goto);
|
| 63 |
}
|
| 64 |
if (!@copy($wrapper_file_path, $module_path .'/'. $wrapper_file)) {
|
| 65 |
drupal_set_message(t('The file %filename could not be copied.', array('%filename' => $wrapper_file)) . $generic_error, 'error');
|
| 66 |
drupal_goto($goto);
|
| 67 |
}
|
| 68 |
if (!@rename($module_file_path, $module_file_path .'.old')) {
|
| 69 |
drupal_set_message(t('The file %filename could not be renamed.', array('%filename' => $module_file)) . $generic_error, 'error');
|
| 70 |
drupal_goto($goto);
|
| 71 |
}
|
| 72 |
$wrapper_new_path = $module_path .'/'. $wrapper_file;
|
| 73 |
if (!@rename($wrapper_new_path, $module_file_path)) {
|
| 74 |
drupal_set_message(t('The file %filename could not be renamed.', array('%filename' => $wrapper_file)) . $generic_error, 'error');
|
| 75 |
drupal_goto($goto);
|
| 76 |
}
|
| 77 |
if (!@copy($wrapper_info_file_path, $module_path .'/'. $wrapper_info_file)) {
|
| 78 |
drupal_set_message(t('The file %filename could not be copied.', array('%filename' => $wrapper_info_file)) . $generic_error, 'error');
|
| 79 |
drupal_goto($goto);
|
| 80 |
}
|
| 81 |
if (!@rename($info_file_path, $info_file_path .'.old')) {
|
| 82 |
drupal_set_message(t('The file %filename could not be renamed.', array('%filename' => $info_file)) . $generic_error, 'error');
|
| 83 |
drupal_goto($goto);
|
| 84 |
}
|
| 85 |
$wrapper_info_new_path = $module_path .'/'. $wrapper_info_file;
|
| 86 |
if (!@rename($wrapper_info_new_path, $info_file_path)) {
|
| 87 |
drupal_set_message(t('The file %filename could not be renamed.', array('%filename' => $wrapper_info_file)) . $generic_error, 'error');
|
| 88 |
drupal_goto($goto);
|
| 89 |
}
|
| 90 |
}
|
| 91 |
else {
|
| 92 |
$old_file = $type .'.module.old';
|
| 93 |
$old_file_path = drupal_get_path('module', $type) .'/'. $old_file;
|
| 94 |
if (!file_exists($old_file_path)) {
|
| 95 |
drupal_set_message(t('The file %filename could not be found.', array('%filename' => $old_file)) . $generic_error, 'error');
|
| 96 |
drupal_goto($goto);
|
| 97 |
}
|
| 98 |
$old_info_file = $type .'.info.old';
|
| 99 |
$old_info_file_path = drupal_get_path('module', $type) .'/'. $old_info_file;
|
| 100 |
if (!file_exists($old_info_file_path)) {
|
| 101 |
drupal_set_message(t('The file %filename could not be found.', array('%filename' => $old_info_file)) . $generic_error, 'error');
|
| 102 |
drupal_goto($goto);
|
| 103 |
}
|
| 104 |
if (!@unlink($module_file_path)) {
|
| 105 |
drupal_set_message(t('The file %filename could not be deleted.', array('%filename' => $module_file)) . $generic_error, 'error');
|
| 106 |
drupal_goto($goto);
|
| 107 |
}
|
| 108 |
if (!@rename($old_file_path, $module_file_path)) {
|
| 109 |
drupal_set_message(t('The file %filename could not be renamed.', array('%filename' => $old_file)) . $generic_error, 'error');
|
| 110 |
drupal_goto($goto);
|
| 111 |
}
|
| 112 |
if (!@unlink($info_file_path)) {
|
| 113 |
drupal_set_message(t('The file %filename could not be deleted.', array('%filename' => $info_file)) . $generic_error, 'error');
|
| 114 |
drupal_goto($goto);
|
| 115 |
}
|
| 116 |
if (!@rename($old_info_file_path, $info_file_path)) {
|
| 117 |
drupal_set_message(t('The file %filename could not be renamed.', array('%filename' => $old_info_file)) . $generic_error, 'error');
|
| 118 |
drupal_goto($goto);
|
| 119 |
}
|
| 120 |
}
|
| 121 |
|
| 122 |
if ($type == 'taxonomy') {
|
| 123 |
if ($op == 'install') {
|
| 124 |
db_query("UPDATE {system} SET weight = 10 WHERE name = 'taxonomy' AND type = 'module'");
|
| 125 |
}
|
| 126 |
else {
|
| 127 |
db_query("UPDATE {system} SET weight = 0 WHERE name = 'taxonomy' AND type = 'module'");
|
| 128 |
}
|
| 129 |
}
|
| 130 |
|
| 131 |
drupal_set_message(t('The @type wrapper was @op successfully.', array('@type' => $type, '@op' => ($op == 'install' ? t('installed') : t('uninstalled')))));
|
| 132 |
|
| 133 |
if ($rebuild) {
|
| 134 |
module_list(TRUE, FALSE);
|
| 135 |
menu_rebuild();
|
| 136 |
drupal_goto($goto);
|
| 137 |
}
|
| 138 |
}
|