diff --git a/lib/pkp/classes/cliTool/CliTool.inc.php b/lib/pkp/classes/cliTool/CliTool.inc.php --- a/lib/pkp/classes/cliTool/CliTool.inc.php +++ b/lib/pkp/classes/cliTool/CliTool.inc.php @@ -19,15 +19,16 @@ * to bootstrap and route tool requests. */ -// $Id$ - - /** Initialization code */ -define('PWD', getcwd()); -chdir(dirname(INDEX_FILE_LOCATION)); /* Change to base directory */ +define('INDEX_FILE_LOCATION', getcwd() . '/index.php'); +if (!file_exists(getcwd() . '/config.TEMPLATE.inc.php')) { + die("This script must be executed from the installation base directory.\n"); +} + if (!defined('STDIN')) { define('STDIN', fopen('php://stdin','r')); } + define('SESSION_DISABLE_INIT', 1); require('./lib/pkp/includes/bootstrap.inc.php'); diff --git a/lib/pkp/classes/cliTool/XmlToSqlTool.inc.php b/lib/pkp/classes/cliTool/XmlToSqlTool.inc.php --- a/lib/pkp/classes/cliTool/XmlToSqlTool.inc.php +++ b/lib/pkp/classes/cliTool/XmlToSqlTool.inc.php @@ -54,16 +54,9 @@ class XmlToSqlTool extends CommandLineTool { $this->command = $this->argv[$argOffset]; - $file = isset($this->argv[$argOffset+1]) ? $this->argv[$argOffset+1] : DATABASE_XML_FILE; + $this->inputFile = isset($this->argv[$argOffset+1]) ? $this->argv[$argOffset+1] : DATABASE_XML_FILE; - if (!file_exists($file) && !file_exists(($file2 = PWD . '/' . $file))) { - printf("Input file \"%s\" does not exist!\n", $file); - exit(1); - } - - $this->inputFile = isset($file2) ? $file2 : $file; - - $this->outputFile = isset($this->argv[$argOffset+2]) ? PWD . '/' . $this->argv[$argOffset+2] : null; + $this->outputFile = isset($this->argv[$argOffset+2]) ? $this->argv[$argOffset+2] : null; if (in_array($this->command, array('save', 'save_upgrade')) && ($this->outputFile == null || (file_exists($this->outputFile) && (is_dir($this->outputFile) || !is_writeable($this->outputFile))) || !is_writable(dirname($this->outputFile)))) { printf("Invalid output file \"%s\"!\n", $this->outputFile); exit(1); diff --git a/lib/pkp/tests/phpunit.php b/lib/pkp/tests/phpunit.php --- a/lib/pkp/tests/phpunit.php +++ b/lib/pkp/tests/phpunit.php @@ -8,9 +8,10 @@ */ // Configure the index file location, assume that pkp-lib is // included within a PKP application. -// FIXME: This doesn't work if lib/pkp is symlinked. realpath($_['SCRIPT_FILENAME'].'/../../index.php') could work but see http://bugs.php.net/bug.php?id=50366 -define('INDEX_FILE_LOCATION', dirname(dirname(dirname(dirname(__FILE__)))).'/index.php'); -chdir(dirname(INDEX_FILE_LOCATION)); +define('INDEX_FILE_LOCATION', getcwd() . '/index.php'); +if (!file_exists(getcwd() . '/config.TEMPLATE.inc.php')) { + die("This script must be executed from the installation base directory.\n"); +} // Configure PKP error handling for tests define('DONT_DIE_ON_ERROR', true); diff --git a/lib/pkp/tools/phpCompat.php b/lib/pkp/tools/phpCompat.php --- a/lib/pkp/tools/phpCompat.php +++ b/lib/pkp/tools/phpCompat.php @@ -40,10 +40,11 @@ * for information about detection accuracy. */ -// $Id$ +define('INDEX_FILE_LOCATION', getcwd() . '/index.php'); +if (!file_exists(getcwd() . '/config.TEMPLATE.inc.php')) { + die("This script must be executed from the installation base directory.\n"); +} -// FIXME: This doesn't work if lib/pkp is symlinked. realpath($_['SCRIPT_FILENAME'].'/../../index.php') could work but see http://bugs.php.net/bug.php?id=50366 -define('INDEX_FILE_LOCATION', dirname(dirname(dirname(dirname(__FILE__)))) . '/index.php'); require_once(dirname(dirname(__FILE__)) . '/classes/cliTool/CliTool.inc.php'); require_once('PHP/CompatInfo.php'); diff --git a/plugins/importexport/native/NativeImportDom.inc.php b/plugins/importexport/native/NativeImportDom.inc.php --- a/plugins/importexport/native/NativeImportDom.inc.php +++ b/plugins/importexport/native/NativeImportDom.inc.php @@ -324,11 +324,6 @@ class NativeImportDom { if (($href = $node->getChildByName('href'))) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { - if ($isCommandLine && NativeImportDom::isRelativePath($url)) { - // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. - $url = PWD . '/' . $url; - } - $originalName = basename($url); $newName .= $publicFileManager->getExtension($originalName); if (!$publicFileManager->copyJournalFile($journal->getId(), $url, $newName)) { @@ -394,11 +389,6 @@ class NativeImportDom { if (($href = $node->getChildByName('href'))) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { - if ($isCommandLine && NativeImportDom::isRelativePath($url)) { - // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. - $url = PWD . '/' . $url; - } - $originalName = basename($url); $newName .= $publicFileManager->getExtension($originalName); if (!$publicFileManager->copyJournalFile($journal->getId(), $url, $newName)) { @@ -996,11 +986,6 @@ class NativeImportDom { if (($href = $node->getChildByName('href'))) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { - if ($isCommandLine && NativeImportDom::isRelativePath($url)) { - // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. - $url = PWD . '/' . $url; - } - if (($fileId = $articleFileManager->copyPublicFile($url, $href->getAttribute('mime_type')))===false) { $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url)); return false; @@ -1050,11 +1035,6 @@ class NativeImportDom { if (($href = $node->getChildByName('href'))) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { - if ($isCommandLine && NativeImportDom::isRelativePath($url)) { - // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. - $url = PWD . '/' . $url; - } - if (($fileId = $articleFileManager->copyPublicFile($url, $href->getAttribute('mime_type')))===false) { $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url)); return false; @@ -1206,11 +1186,6 @@ class NativeImportDom { if (($href = $fileNode->getChildByName('href'))) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { - if ($isCommandLine && NativeImportDom::isRelativePath($url)) { - // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. - $url = PWD . '/' . $url; - } - if (($fileId = $articleFileManager->copySuppFile($url, $href->getAttribute('mime_type')))===false) { $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url)); return false; diff --git a/plugins/importexport/native/NativeImportExportPlugin.inc.php b/plugins/importexport/native/NativeImportExportPlugin.inc.php --- a/plugins/importexport/native/NativeImportExportPlugin.inc.php +++ b/plugins/importexport/native/NativeImportExportPlugin.inc.php @@ -343,10 +343,6 @@ class NativeImportExportPlugin extends ImportExportPlugin { } $this->import('NativeImportDom'); - if ($xmlFile && NativeImportDom::isRelativePath($xmlFile)) { - $xmlFile = PWD . '/' . $xmlFile; - } - switch ($command) { case 'import': $userName = array_shift($args);