| 1 |
<?php
|
| 2 |
// $Id: deadwood.inc,v 1.7 2008/08/19 22:00:12 solotandem Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Generate version upgrade code from 5.x to 6.x.
|
| 7 |
*
|
| 8 |
* Copyright 2008 by Jim Berry ("solotandem", http://drupal.org/user/240748)
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* The default directory to store modules to be converted.
|
| 13 |
* Relative to file_directory_path().
|
| 14 |
*/
|
| 15 |
define('DEADWOOD_IN', 'deadwood');
|
| 16 |
|
| 17 |
/**
|
| 18 |
* The default directory to store converted modules.
|
| 19 |
* Relative to file_directory_path().
|
| 20 |
*/
|
| 21 |
define('DEADWOOD_OUT', 'goodwood');
|
| 22 |
|
| 23 |
/**
|
| 24 |
* The values for the availability status of conversion code for a category.
|
| 25 |
* NOTE: This should be for an item not a category.
|
| 26 |
*/
|
| 27 |
define('DEADWOOD_CONVERSION_CODE_NOT_AVAILABLE', 0);
|
| 28 |
define('DEADWOOD_CONVERSION_CODE_AVAILABLE', 1);
|
| 29 |
define('DEADWOOD_CONVERSION_CODE_PARTIALLY_AVAILABLE', 2);
|
| 30 |
define('DEADWOOD_CONVERSION_CODE_REQUIRES_MANUAL', 3);
|
| 31 |
define('DEADWOOD_CONVERSION_CODE_NOTIFY_ONLY', 4);
|
| 32 |
define('DEADWOOD_CONVERSION_CODE_NOT_NEEDED', 5);
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Pass a string through t() and wrap the result in html entity <p>.
|
| 36 |
*/
|
| 37 |
function tp($string, $args = array()) {
|
| 38 |
return '<p>' . t($string, $args) . '</p>';
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
* Convert a category's code availability status (integer) to a string.
|
| 43 |
*
|
| 44 |
* @param integer $status Availability status code.
|
| 45 |
* @return string Representation of availability status code.
|
| 46 |
*/
|
| 47 |
function deadwood_get_code_availability_status($status) {
|
| 48 |
switch ($status) {
|
| 49 |
case DEADWOOD_CONVERSION_CODE_AVAILABLE:
|
| 50 |
return t('Available');
|
| 51 |
case DEADWOOD_CONVERSION_CODE_PARTIALLY_AVAILABLE:
|
| 52 |
return t('Partially available');
|
| 53 |
case DEADWOOD_CONVERSION_CODE_REQUIRES_MANUAL:
|
| 54 |
return t('Manual intervention');
|
| 55 |
case DEADWOOD_CONVERSION_CODE_NOTIFY_ONLY:
|
| 56 |
return t('Notification only');
|
| 57 |
case DEADWOOD_CONVERSION_CODE_NOT_NEEDED:
|
| 58 |
return t('Not needed');
|
| 59 |
default:
|
| 60 |
return t('Not available');
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
/**
|
| 65 |
* Convert a category's code availability status (integer) to a string.
|
| 66 |
*
|
| 67 |
* @param integer $status Availability status code.
|
| 68 |
* @return string class representation of availability status code.
|
| 69 |
*/
|
| 70 |
function deadwood_get_code_availability_class($status) {
|
| 71 |
switch ($status) {
|
| 72 |
case DEADWOOD_CONVERSION_CODE_AVAILABLE:
|
| 73 |
return 'available';
|
| 74 |
case DEADWOOD_CONVERSION_CODE_PARTIALLY_AVAILABLE:
|
| 75 |
return 'available';
|
| 76 |
case DEADWOOD_CONVERSION_CODE_REQUIRES_MANUAL:
|
| 77 |
return 'notify';
|
| 78 |
case DEADWOOD_CONVERSION_CODE_NOTIFY_ONLY:
|
| 79 |
return 'notify';
|
| 80 |
case DEADWOOD_CONVERSION_CODE_NOT_NEEDED:
|
| 81 |
return 'notify';
|
| 82 |
default:
|
| 83 |
return 'missing';
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
/**
|
| 88 |
* Get conversion code availability status values.
|
| 89 |
*
|
| 90 |
* @return array of statuses.
|
| 91 |
*/
|
| 92 |
function deadwood_get_code_statuses() {
|
| 93 |
return array(
|
| 94 |
'0' => 'Not available',
|
| 95 |
'1' => 'Available',
|
| 96 |
'2' => 'Partially available',
|
| 97 |
'3' => 'Requires manual',
|
| 98 |
'4' => 'Notify only',
|
| 99 |
'5' => 'Not needed'
|
| 100 |
);
|
| 101 |
}
|
| 102 |
|
| 103 |
/**
|
| 104 |
* Scan a specified directory and find all first-level directories beneath it.
|
| 105 |
*
|
| 106 |
* TODO Replace this with a call to file_scan_directory in include/files.inc.
|
| 107 |
*
|
| 108 |
* @param string $path Directory path.
|
| 109 |
* @return Array of directory names.
|
| 110 |
*/
|
| 111 |
function deadwood_scan_directory($path) {
|
| 112 |
static $ignore = array('.', '..', '.svn');
|
| 113 |
$dirs = array();
|
| 114 |
|
| 115 |
$path = $path .'/';
|
| 116 |
$files = scandir($path);
|
| 117 |
foreach ($files as $file) {
|
| 118 |
$file_path = $path . $file;
|
| 119 |
if (is_dir($file_path) && !in_array(basename($file_path), $ignore)) {
|
| 120 |
$dirs[] = $file;
|
| 121 |
}
|
| 122 |
}
|
| 123 |
return $dirs;
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Remove all files from specified directory and optionally remove the directory.
|
| 128 |
*
|
| 129 |
* @param string $path Directory path.
|
| 130 |
*/
|
| 131 |
function deadwood_clean_directory($path, $remove_me = FALSE) {
|
| 132 |
$path = $path .'/';
|
| 133 |
$files = scandir($path);
|
| 134 |
foreach ($files as $file) {
|
| 135 |
if ($file != '.' && $file != '..') {
|
| 136 |
$file_path = $path . $file;
|
| 137 |
if (is_dir($file_path)) {
|
| 138 |
deadwood_clean_directory($file_path, TRUE);
|
| 139 |
}
|
| 140 |
else {
|
| 141 |
file_delete($file_path);
|
| 142 |
}
|
| 143 |
}
|
| 144 |
}
|
| 145 |
if ($remove_me) {
|
| 146 |
rmdir($path);
|
| 147 |
}
|
| 148 |
}
|
| 149 |
|
| 150 |
/**
|
| 151 |
* Print debug information if debug flag is on.
|
| 152 |
*
|
| 153 |
* @param mixed $text
|
| 154 |
* A string or array to print.
|
| 155 |
*/
|
| 156 |
function deadwood_debug_print($text) {
|
| 157 |
global $debug;
|
| 158 |
|
| 159 |
if (!$debug) {
|
| 160 |
return;
|
| 161 |
}
|
| 162 |
if (is_array($text) || is_object($text)) {
|
| 163 |
file_put_contents(deadwood_log_path(), print_r($text, 1), FILE_APPEND);
|
| 164 |
}
|
| 165 |
else {
|
| 166 |
file_put_contents(deadwood_log_path(), $text . "\n", FILE_APPEND);
|
| 167 |
}
|
| 168 |
}
|
| 169 |
|
| 170 |
/**
|
| 171 |
* Return path to log file.
|
| 172 |
*
|
| 173 |
* @return string
|
| 174 |
* Path to file.
|
| 175 |
*/
|
| 176 |
function deadwood_log_path() {
|
| 177 |
static $path = '';
|
| 178 |
|
| 179 |
if (!$path) {
|
| 180 |
$path = file_directory_path() . '/' . DEADWOOD_IN . '/debug.txt';
|
| 181 |
}
|
| 182 |
return $path;
|
| 183 |
}
|