diff --git a/coder_upgrade/scripts/coder_upgrade.run.php b/coder_upgrade/scripts/coder_upgrade.run.php new file mode 100644 index 0000000000000000000000000000000000000000..0de9a57f2564c626da1d0c3cb584f4b288321795 --- /dev/null +++ b/coder_upgrade/scripts/coder_upgrade.run.php @@ -0,0 +1,164 @@ + coder-upgrade-run.txt + * + * Copyright 2009-10 by Jim Berry ("solotandem", http://drupal.org/user/240748) + */ + +echo "Start\n"; +echo 'Peak 1: ' . number_format(memory_get_peak_usage(TRUE), 0, '.', ',') . " bytes\n"; +echo 'Curr 1: ' . number_format(memory_get_usage(TRUE), 0, '.', ',') . " bytes\n"; + +/** + * Root directory of Drupal installation. + */ +define('DRUPAL_ROOT', getcwd()); + +ini_set('display_errors', 1); +set_error_handler("error_handler"); +set_exception_handler("exception_handler"); + +// Read command line arguments. +$path = extract_arguments(); +if (is_null($path)) { + return 'No path to parameter file'; +} + +// Load runtime parameters. +$parameters = unserialize(file_get_contents($path)); + +// Extract individual array items by key. +foreach ($parameters as $key => $variable) { + $$key = $variable; +} + +// Set directory paths. +$files_base = $paths['files_base']; +$modules_base = $paths['modules_base']; + +// Load parser module so we can log memory use. +require_once DRUPAL_ROOT . '/' . $modules_base . '/grammar_parser/grammar_parser.module'; + +pgp_log_memory_use('', TRUE); +pgp_log_memory_use('load runtime parameters'); + +// Load core theme cache. +$upgrade_theme_registry = array(); +if (is_file($theme_cache)) { +// echo "yea, found the theme cache\n"; + $upgrade_theme_registry = unserialize(file_get_contents($theme_cache)); +} +pgp_log_memory_use('load core theme cache'); + +// Load coder_upgrade bootstrap code. +$path = $modules_base . '/coder/coder_upgrade'; +$files = array( + 'coder_upgrade.inc', + 'coder_upgrade.module', + 'conversions/coder_upgrade.list.inc', + 'conversions/coder_upgrade.main.inc', +); +foreach ($files as $file) { + require_once DRUPAL_ROOT . '/' . $path . "/$file"; +} + +// $trace_base = DRUPAL_ROOT . '/' . $files_base . '/coder_upgrade/coder_upgrade_'; +// $trace_file = $trace_base . '1.trace'; +// xdebug_start_trace($trace_file); +pgp_log_memory_use('load coder_upgrade bootstrap code'); +// xdebug_stop_trace(); + +// Apply conversion functions. +$success = coder_upgrade_start($upgrades, $extensions, $items); + +// $trace_file = $trace_base . '2.trace'; +// xdebug_start_trace($trace_file); +pgp_log_memory_use('finish'); +// xdebug_stop_trace(); + +return $success; + +/** + * Returns command line arguments. + * + * @return mixed + * String or array of command line arguments. + */ +function extract_arguments() { + switch (php_sapi_name()) { + case 'apache': + case 'apache2handler': // This is the value when running curl. + if (!isset($_GET['file'])) { + echo 'file parameter is not set'; + return; + } + $filename = $_GET['file']; + $action = isset($_GET['action']) ? $_GET['action'] : ''; + break; + + case 'cli': + if ($_SERVER['argc'] < 3) { + 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; + list($key, $value) = explode('=', $arg); + $arguments[$key] = $value; + } + if (!isset($arguments['file'])) { + echo 'file parameter is not set' . "\n"; + return; + } + $filename = $arguments['file']; + $action = isset($arguments['action']) ? $arguments['action'] : ''; + break; + } + return $filename; +} + +function exception_handler($e) { + try { + // ... normal exception stuff goes here + } + catch (Exception $e) { + print get_class($e) . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); + } +} + +function error_handler($code, $message, $file, $line) { + if (0 == error_reporting()) { + return; + } + throw new ErrorException($message, 0, $code, $file, $line); +}