diff --git a/coder_upgrade/CHANGELOG.txt b/coder_upgrade/CHANGELOG.txt index 15fd749876d1a50c910de7a11be04b6fc87ff9cd..077e08a87921b8247085db899a681ca1d877a27d 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 25c0595fa47b0897766a291c469727339d3e91f9..509f629ca15418ee0a561148b65a7d1d9a79802b 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 03b6c6a10b769b53dfd682f8de1cb54b27824a4f..af350010560f0409bcbe33b1133f1f05e5e49c76 100644 --- a/coder_upgrade/coder_upgrade.inc +++ b/coder_upgrade/coder_upgrade.inc @@ -92,6 +92,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. * @@ -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 f72c0c1b3f2cfb5ee508086f5c27ca88cb0f7b8c..c52fd792fcd131dfb685b7ebfb715a888db235bd 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 9ab4e87e8099b99dd4c4bed4235fb85cb2e398b7..b4a4477a60e1c4d1ccaeff6d3e309b3b0cacea55 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 5698fcb2619aa6df2025c0159e5212d9b5b9de84..a1d6d93a8bda3e6bd5f64702b139ae661feb1c19 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 f6a641b38579aa21be762240bead6368385e421d..1fbdb588b506a50092113a20c22dcbe78c7c7fdc 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 0de9a57f2564c626da1d0c3cb584f4b288321795..7fc87361fc2ca9ffbedd94bab339e95918fcd2c8 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; }