00001 <?php
00002
00015
00016
00017
00018 require(dirname(__FILE__) . '/includes/cliTool.inc.php');
00019
00020 import('site.ImportOJS1');
00021
00022 class migrate extends CommandLineTool {
00023
00025 var $journalPath;
00026
00028 var $importPath;
00029
00031 var $options;
00032
00037 function migrate($argv = array()) {
00038 parent::CommandLineTool($argv);
00039
00040 if (!isset($this->argv[0]) || !isset($this->argv[1])) {
00041 $this->usage();
00042 exit(1);
00043 }
00044
00045 $this->journalPath = $this->argv[0];
00046 $this->importPath = $this->argv[1];
00047 $this->options = array_slice($this->argv, 2);
00048 }
00049
00053 function usage() {
00054 echo "OJS 1 -> OJS 2 migration tool (requires OJS >= 1.1.5 and OJS >= 2.0.1)\n"
00055 . "Use this tool to import data from an OJS 1 system into an OJS 2 system\n\n"
00056 . "Usage: {$this->scriptName} [journal_path] [ojs1_path] [options]\n"
00057 . "journal_path Journal path to create (E.g., \"ojs\")\n"
00058 . " If path already exists, all content except journal settings\n"
00059 . " will be imported into the existing journal\n"
00060 . "ojs1_path Complete local filesystem path to the OJS 1 installation\n"
00061 . " (E.g., \"/var/www/ojs\")\n"
00062 . "options importSubscriptions - import subscription type and subscriber\n"
00063 . " data\n"
00064 . " transcode - convert journal metadata from Latin1 to UTF8\n"
00065 . " redirect - generate files to map OJS 1 URLs to OJS 2 URLs.\n"
00066 . " Requires that the user running this tool has\n"
00067 . " write permission to the OJS 2 files directory.\n"
00068 . " verbose - print additional debugging information\n";
00069 }
00070
00074 function execute() {
00075 $importer = &new ImportOJS1();
00076 if ($importer->import($this->journalPath, $this->importPath, $this->options)) {
00077 $redirects = $importer->getRedirects();
00078 $conflicts = $importer->getConflicts();
00079
00080
00081 $redirectResults = $redirectSummary = '';
00082 if (in_array('redirect', $this->options) && !empty($redirects)) {
00083 $redirectFilesDir = Config::getVar('files', 'files_dir') . DIRECTORY_SEPARATOR . 'redirect' . DIRECTORY_SEPARATOR . $this->journalPath;
00084 $redirectSummary = "\n\nRedirect PHP files have been created in the following directory:\n\n$redirectFilesDir\n\nTo enable redirection, these files will need to be moved to either the OJS 1 filesystem path, or, for single journal installations, to the OJS 2 filesystem path. Once these files are moved, you can safely delete the redirect directory ($redirectFilesDir) created by this tool.\n\nSee $redirectFilesDir" . DIRECTORY_SEPARATOR . "README for more information.\n";
00085 $redirectReadme = "To enable redirection, the following files will need to be moved to either the OJS 1 filesystem path, or, for single journal installations, to the OJS 2 filesystem path. Once these files are moved, you can safely delete the redirect directory ($redirectFilesDir).\n\n";
00086 reset($redirects);
00087 $errors = false;
00088
00089 while (list($key, $redirect) = each($redirects)) {
00090 $redirectFile = $redirect[0];
00091 $redirectDescKey = $redirect[1];
00092 $redirectContents = $redirect[2];
00093
00094 $redirectFilePath = $redirectFilesDir . DIRECTORY_SEPARATOR . $redirectFile;
00095 if (FileManager::writeFile($redirectFilePath, $redirectContents) !== false) {
00096 $redirectReadme .= "$redirectFile\n";
00097 $redirectReadme .= "-- " . Locale::translate($redirectDescKey) . "\n\n";
00098 } else {
00099 $errors = true;
00100 $redirectSummary .= "\n\nError writing $redirectFilePath. Please ensure that the user running this script has write permission to the OJS 2 files directory.";
00101 }
00102 }
00103
00104 if (!$errors) {
00105 FileManager::writeFile($redirectFilesDir . DIRECTORY_SEPARATOR . 'README', $redirectReadme);
00106 }
00107 }
00108
00109
00110 $conflictSummary = '';
00111 if (!empty($conflicts)) {
00112 $conflictSummary = "\n\n" . Locale::translate('admin.journals.importOJS1.conflict.desc') . "\n";
00113 while (list($key, $conflict) = each($conflicts)) {
00114 $firstUser = $conflict[0];
00115 $secondUser = $conflict[1];
00116 $conflictSummary .= "\n* " . Locale::translate('admin.journals.importOJS1.conflict', array(
00117 "firstUsername" => $firstUser->getUsername(),
00118 "firstName" => $firstUser->getFullName(),
00119 "secondUsername" => $secondUser->getUsername(),
00120 "secondName" => $secondUser->getFullName()
00121 ));
00122 }
00123 }
00124
00125 printf("Import completed\n"
00126 . "Users imported: %u\n"
00127 . "Issues imported: %u\n"
00128 . "Articles imported: %u\n"
00129 . "%s\n",
00130 $importer->userCount,
00131 $importer->issueCount,
00132 $importer->articleCount,
00133 $redirectSummary . $conflictSummary
00134 );
00135 } else {
00136 printf("Import failed!\nERROR: %s\n", $importer->error());
00137 }
00138 }
00139
00140 }
00141
00142 $tool = &new migrate(isset($argv) ? $argv : array());
00143 $tool->execute();
00144 ?>