summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Berry2010-11-19 18:19:55 (GMT)
committer Jim Berry2010-11-19 18:19:55 (GMT)
commitf4aefdcc9b15ae54cee2e2f38a7dd0605a424f87 (patch)
tree2878ebf0e207d3eec7039c7787a10a4d970e002d
parentddd54aa2381f4a03118f726b831da88449730265 (diff)
coder_upgrade.main.inc: #245471 (comment #7): remove base directory path from patch file in coder_upgrade_make_patch_file(); inc, install, help.inc, main.inc, module, test: refactor file_directory_path() references to coder_upgrade_directory_path(); coder_upgrade.run.php: add php memory and time limits.
-rw-r--r--coder_upgrade/CHANGELOG.txt8
-rw-r--r--coder_upgrade/coder_upgrade.help.inc4
-rw-r--r--coder_upgrade/coder_upgrade.inc37
-rw-r--r--coder_upgrade/coder_upgrade.install18
-rw-r--r--coder_upgrade/coder_upgrade.module24
-rw-r--r--coder_upgrade/coder_upgrade.test6
-rw-r--r--coder_upgrade/conversions/coder_upgrade.main.inc10
-rw-r--r--coder_upgrade/scripts/coder_upgrade.run.php13
8 files changed, 85 insertions, 35 deletions
diff --git a/coder_upgrade/CHANGELOG.txt b/coder_upgrade/CHANGELOG.txt
index 15fd749..077e08a 100644
--- a/coder_upgrade/CHANGELOG.txt
+++ b/coder_upgrade/CHANGELOG.txt
@@ -2,6 +2,14 @@
coder_upgrade 7.x-1.x, 2009-xx-xx (development version)
---------------------------------
+- Changes (2010-11-19):
+ * coder_upgrade.main.inc
+ * - #245471 (comment #7): remove base directory path from patch file in coder_upgrade_make_patch_file()
+ * inc, install, help.inc, main.inc, module, test
+ * - refactor file_directory_path() references to coder_upgrade_directory_path()
+ * coder_upgrade.run.php
+ * - add php memory and time limits
+
- Changes (2010-10-30):
* coder_upgrade.module
* - refactor form submission code to coder_upgrade_conversions_apply()
diff --git a/coder_upgrade/coder_upgrade.help.inc b/coder_upgrade/coder_upgrade.help.inc
index 25c0595..509f629 100644
--- a/coder_upgrade/coder_upgrade.help.inc
+++ b/coder_upgrade/coder_upgrade.help.inc
@@ -12,8 +12,8 @@
* Implements hook_help().
*/
function coder_upgrade_help($path, $arg) {
- $input = file_directory_path() . '/' . variable_get('coder_upgrade_dir_old', DEADWOOD_OLD);
- $output = file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW);
+ $input = coder_upgrade_directory_path('old', FALSE);
+ $output = coder_upgrade_directory_path('new', FALSE);
switch ($path) {
case 'admin/config/development/coder/upgrade/settings':
return tp('This is a list of the variables used by the automated module conversion suite.');
diff --git a/coder_upgrade/coder_upgrade.inc b/coder_upgrade/coder_upgrade.inc
index 03b6c6a..af35001 100644
--- a/coder_upgrade/coder_upgrade.inc
+++ b/coder_upgrade/coder_upgrade.inc
@@ -93,6 +93,39 @@ function coder_upgrade_clean_directory($path, $remove_me = FALSE) {
}
/**
+ * Returns full directory path relative to sites directory.
+ *
+ * @param string $name
+ * Name of the directory.
+ * @param boolean $add_slash
+ * Indicates whether to add a trailing slash.
+ * @param boolean $stream_format
+ * Indicates whether to use the actual path or a stream protocol.
+ * @return string
+ * A string of the directory path.
+ */
+function coder_upgrade_directory_path($name, $add_slash = TRUE, $stream_format = FALSE) {
+ $slash = $add_slash ? '/' : '';
+ $prefix_no_slash = $stream_format ? file_default_scheme() . ':/' : file_directory_path();
+ $prefix = $prefix_no_slash . '/';
+
+ switch ($name) {
+ case 'base':
+ return $prefix . variable_get('coder_upgrade_dir', DEADWOOD_DIR) . $slash;
+ case 'old':
+ return $prefix . variable_get('coder_upgrade_dir_old', DEADWOOD_OLD) . $slash;
+ case 'new':
+ return $prefix . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW) . $slash;
+ case 'patch':
+ return $prefix . variable_get('coder_upgrade_dir_patch', DEADWOOD_PATCH) . $slash;
+ case '':
+ return $prefix_no_slash; // @todo Is this correct with a stream format?
+ default:
+ return $prefix . $name . $slash;
+ }
+}
+
+/**
* Returns the local public directory path.
*
* Adapted from function removed from core on 2010-09-01
@@ -127,10 +160,6 @@ if (!function_exists('file_directory_path')) {
if (!function_exists('drupal_get_path')) {
function drupal_get_path($type, $name) {
global $modules_base;
-
-// if ($name == 'coder_upgrade') {
-// $name = 'coder/coder_upgrade';
-// }
return $modules_base . "/$name";
}
}
diff --git a/coder_upgrade/coder_upgrade.install b/coder_upgrade/coder_upgrade.install
index f72c0c1..c52fd79 100644
--- a/coder_upgrade/coder_upgrade.install
+++ b/coder_upgrade/coder_upgrade.install
@@ -17,19 +17,19 @@ function coder_upgrade_install() {
// Create the top-level module directory.
// Because the core function is now recursive, we could start with the
// subdirectories. However, this code is clean and allows for one else block.
- $dir = file_directory_path() . '/' . DEADWOOD_DIR;
+ $dir = coder_upgrade_directory_path('base', FALSE);
if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
// Create the old and new module directories.
- $dir = file_directory_path() . '/' . DEADWOOD_OLD;
+ $dir = coder_upgrade_directory_path('old', FALSE);
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
drupal_set_message(st('The files directory at %directory can not be written to. This is the default directory searched by Coder Upgrade for modules to be converted.', array('%directory' => $dir)), 'error');
}
- $dir = file_directory_path() . '/' . DEADWOOD_NEW;
+ $dir = coder_upgrade_directory_path('new', FALSE);
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
drupal_set_message(st('The files directory at %directory can not be written to. This is the default directory to which Coder Upgrade writes converted module code.', array('%directory' => $dir)), 'error');
}
// Create the patch directory.
- $dir = file_directory_path() . '/' . DEADWOOD_PATCH;
+ $dir = coder_upgrade_directory_path('patch', FALSE);
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
drupal_set_message(st('The files directory at %directory can not be written to. This is the default directory to which Coder Upgrade writes patch files.', array('%directory' => $dir)), 'error');
}
@@ -48,11 +48,11 @@ function coder_upgrade_install() {
*/
function coder_upgrade_uninstall() {
// Remove the module input and output directories.
- $dir = file_directory_path() . '/' . variable_get('coder_upgrade_dir_old', DEADWOOD_OLD);
+ $dir = coder_upgrade_directory_path('old', FALSE);
coder_upgrade_clean_directory($dir, TRUE);
- $dir = file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW);
+ $dir = coder_upgrade_directory_path('new', FALSE);
coder_upgrade_clean_directory($dir, TRUE);
- $dir = file_directory_path() . '/' . variable_get('coder_upgrade_dir_patch', DEADWOOD_PATCH);
+ $dir = coder_upgrade_directory_path('patch', FALSE);
coder_upgrade_clean_directory($dir, TRUE);
// Remove items from {variables} table.
@@ -87,7 +87,7 @@ function coder_upgrade_requirements($phase) {
'severity' => REQUIREMENT_ERROR
);
}
- $dir = file_directory_path();
+ $dir = coder_upgrade_directory_path('', FALSE);
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
$requirements['coder_upgrade_files'] = array(
'title' => $t('Files directory'),
@@ -97,7 +97,7 @@ function coder_upgrade_requirements($phase) {
}
}
else {
- $dir = file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW);
+ $dir = coder_upgrade_directory_path('new', FALSE);
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
$requirements['coder_upgrade_files'] = array(
'title' => $t('Coder Upgrade directory'),
diff --git a/coder_upgrade/coder_upgrade.module b/coder_upgrade/coder_upgrade.module
index 9ab4e87..b4a4477 100644
--- a/coder_upgrade/coder_upgrade.module
+++ b/coder_upgrade/coder_upgrade.module
@@ -100,7 +100,7 @@ function coder_upgrade_settings_form($form, &$form_state) {
module_load_include('inc', 'coder_upgrade', 'conversions/coder_upgrade.main');
$parser = new PGPParser();
- $path = file_directory_path();
+ $path = coder_upgrade_directory_path('', FALSE);
$form['coder_upgrade_dir'] = array(
'#title' => t('Module base directory'),
'#type' => 'textfield',
@@ -185,7 +185,7 @@ function coder_upgrade_settings_form_submit($form, &$form_state) {
$cur = variable_get('coder_upgrade_dir', DEADWOOD_DIR);
$new = $op == t('Reset to defaults') ? DEADWOOD_DIR : $values['coder_upgrade_dir'];
if ($new != $cur) {
- if (rename(file_directory_path() . '/' . $cur, file_directory_path() . '/' . $new)) {
+ if (rename(coder_upgrade_directory_path($cur, FALSE), coder_upgrade_directory_path($new, FALSE))) {
variable_set('coder_upgrade_dir_old', $new . '/old');
variable_set('coder_upgrade_dir_new', $new . '/new');
variable_set('coder_upgrade_dir_patch', $new . '/patch');
@@ -369,7 +369,7 @@ function coder_upgrade_extensions_build(&$extensions) {
function coder_upgrade_directories_build(&$directories) {
// Build the directory list.
$deadwood_dir = variable_get('coder_upgrade_dir_old', DEADWOOD_OLD);
- $path = realpath(file_directory_path() . '/' . $deadwood_dir);
+ $path = realpath(coder_upgrade_directory_path('old', FALSE));
$dirs = coder_upgrade_scan_directory($path);
if (!$dirs) {
drupal_set_message(t('Please place modules to be converted in @path.', array('@path' => $path)), 'error');
@@ -510,10 +510,10 @@ function coder_upgrade_conversions_apply($form_state) {
module_load_include('inc', 'coder_upgrade', 'conversions/coder_upgrade.main');
if (variable_get('coder_upgrade_use_separate_process', TRUE)) {
// Conversion code will be run in a separate process.
- drupal_set_message('Conversion code will be run in a separate process.');
+ drupal_set_message('Module conversion code will run in a separate process.');
$path = coder_upgrade_parameters_save($upgrades, $extensions, $items);
$script = drupal_get_path('module', 'coder_upgrade') . '/scripts/coder_upgrade.run.php';
-// $output = file_directory_path() . '/coder_upgrade/coder-upgrade-run.txt';
+// $output = coder_upgrade_directory_path('base') . 'coder-upgrade-run.txt';
$command = "php $script -- file=$path 2>&1"; // $command = "php $script -- file=$path > $output 2>&1";
// Execute the command and capture the output.
$output = shell_exec($command);
@@ -524,7 +524,7 @@ function coder_upgrade_conversions_apply($form_state) {
}
else {
// Conversion code will be run in the same process.
- drupal_set_message('Conversion code will be run in the same process.');
+ drupal_set_message('Module conversion code will run in the same process.');
$success = coder_upgrade_start($upgrades, $extensions, $items);
}
@@ -546,8 +546,8 @@ function coder_upgrade_conversions_prepare($form_state) {
);
}
- $old_dir = DRUPAL_ROOT . '/' . file_directory_path() . '/' . variable_get('coder_upgrade_dir_old', DEADWOOD_OLD) . '/';
- $new_dir = DRUPAL_ROOT . '/' . file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW) . '/';
+ $old_dir = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('old');
+ $new_dir = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('new');
// Combine directory and module items into a single list.
// Omit name from key so as to allow for duplicate names.
@@ -595,8 +595,8 @@ function coder_upgrade_parameters_save($upgrades, $extensions, $items) {
}
// Create paths array.
$paths = array(
- 'files_base' => file_directory_path(),
- 'modules_base' => str_replace('files', 'modules', file_directory_path()),
+ 'files_base' => coder_upgrade_directory_path('', FALSE),
+ 'modules_base' => str_replace('files', 'modules', coder_upgrade_directory_path('', FALSE)),
);
// Create variables array.
$variables = array(
@@ -793,7 +793,7 @@ function coder_upgrade_patch_path($filename) {
static $dirname = '';
if (!$dirname) {
- $dirname = file_directory_path() . '/' . variable_get('coder_upgrade_dir_patch', DEADWOOD_PATCH);
+ $dirname = coder_upgrade_directory_path('patch');
}
- return $dirname . "/$filename";
+ return $dirname . "$filename";
}
diff --git a/coder_upgrade/coder_upgrade.test b/coder_upgrade/coder_upgrade.test
index 5698fcb..a1d6d93 100644
--- a/coder_upgrade/coder_upgrade.test
+++ b/coder_upgrade/coder_upgrade.test
@@ -40,7 +40,7 @@ class CoderUpgradeUnitTestCase extends DrupalUnitTestCase {
$this->captureThemeInfo();
file_put_contents('output.html', "after captureThemeInfo\n", FILE_APPEND);
// Save the live site files directory path.
- $this->site_directory = DRUPAL_ROOT . '/' . file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW) . '/';
+ $this->site_directory = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('new');
file_put_contents('output.html', $this->site_directory . "\n", FILE_APPEND);
parent::setUp('grammar_parser', 'coder_upgrade');
@@ -79,7 +79,7 @@ class CoderUpgradeUnitTestCase extends DrupalUnitTestCase {
coder_upgrade_debug_print("module = $module_dirname");
$in_dirname = $module_dirname . '/tests/old/';
- $out_dirname = DRUPAL_ROOT . '/' . file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW) . '/';
+ $out_dirname = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('new');
$directories = array($this->test_directory => 1);
foreach ($directories as $key => $directory) {
@@ -111,7 +111,7 @@ class CoderUpgradeUnitTestCase extends DrupalUnitTestCase {
$module_dirname = DRUPAL_ROOT . '/' . drupal_get_path('module', 'coder_upgrade');
$in_dirname = $module_dirname . '/tests/old/';
$expected_dirname = $module_dirname . '/tests/new/';
- $out_dirname = DRUPAL_ROOT . '/' . file_directory_path() . '/' . variable_get('coder_upgrade_dir_new', DEADWOOD_NEW) . '/';
+ $out_dirname = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('new');
file_put_contents('output.html', "$out_dirname\n", FILE_APPEND);
$upgrades = coder_upgrade_upgrade_info();
diff --git a/coder_upgrade/conversions/coder_upgrade.main.inc b/coder_upgrade/conversions/coder_upgrade.main.inc
index f6a641b..1fbdb58 100644
--- a/coder_upgrade/conversions/coder_upgrade.main.inc
+++ b/coder_upgrade/conversions/coder_upgrade.main.inc
@@ -551,7 +551,7 @@ function coder_upgrade_module_name($dirname, &$item) {
*/
function coder_upgrade_make_patch_file($item, $replace_files = FALSE) {
// Patch directory.
- $patch_dir = file_directory_path() . '/' . variable_get('coder_upgrade_dir_patch', DEADWOOD_PATCH) . '/';
+ $patch_dir = coder_upgrade_directory_path('patch');
// Make a patch file.
coder_upgrade_log_print("\n*************************");
@@ -563,6 +563,12 @@ function coder_upgrade_make_patch_file($item, $replace_files = FALSE) {
$new_dir = $replace_files ? $item['old_dir'] : $item['new_dir'];
coder_upgrade_log_print("Making patch file: diff -up -r {$old_dir} {$new_dir} > {$patch_filename}");
shell_exec("diff -up -r {$old_dir} {$new_dir} > {$patch_filename}");
+
+ // Remove the path strings from the patch file (for usability purposes).
+ $old1 = $old_dir . '/';
+ $new1 = $new_dir . '/';
+ $contents = file_get_contents($patch_filename);
+ file_put_contents($patch_filename, str_replace(array($old1, $new1), '', $contents));
}
/**
@@ -751,7 +757,7 @@ function coder_upgrade_path($type = '') {
static $path = '';
if (!$path) {
- $path = file_directory_path() . '/' . variable_get('coder_upgrade_dir', DEADWOOD_DIR);
+ $path = coder_upgrade_directory_path('base', FALSE);
}
return $type ? $path . '/' . $type . '.txt' : $path;
}
diff --git a/coder_upgrade/scripts/coder_upgrade.run.php b/coder_upgrade/scripts/coder_upgrade.run.php
index 0de9a57..7fc8736 100644
--- a/coder_upgrade/scripts/coder_upgrade.run.php
+++ b/coder_upgrade/scripts/coder_upgrade.run.php
@@ -44,6 +44,8 @@ echo 'Curr 1: ' . number_format(memory_get_usage(TRUE), 0, '.', ',') . " bytes\n
define('DRUPAL_ROOT', getcwd());
ini_set('display_errors', 1);
+ini_set('memory_limit', '128M');
+ini_set('max_execution_time', 180);
set_error_handler("error_handler");
set_exception_handler("exception_handler");
@@ -126,13 +128,18 @@ function extract_arguments() {
break;
case 'cli':
- if ($_SERVER['argc'] < 3) {
+ $skip_args = 2;
+ if ($_SERVER['argc'] == 2) {
+ $skip_args = 1;
+ }
+ elseif ($_SERVER['argc'] < 2) {
echo 'file parameter is not set' . "\n";
return;
}
foreach ($_SERVER['argv'] as $index => $arg) {
- // First two arguments are script filename and '--'.
- if ($index < 2) continue;
+ // First two arguments are usually script filename and '--'.
+ // Sometimes the '--' is omitted.
+ if ($index < $skip_args) continue;
list($key, $value) = explode('=', $arg);
$arguments[$key] = $value;
}