19 define(
'RUNNING_UPGRADE', 1);
21 import(
'classes.install.Upgrade');
22 import(
'lib.pkp.classes.site.Version');
23 import(
'lib.pkp.classes.site.VersionCheck');
35 parent::__construct(
$argv);
37 if (!isset($this->argv[0]) || !in_array($this->argv[0], array(
'check',
'latest',
'upgrade',
'download'))) {
42 $this->command = $this->argv[0];
51 .
"Usage: {$this->scriptName} command\n"
52 .
"Supported commands:\n"
53 .
" check perform version check\n"
54 .
" latest display latest version info\n"
55 .
" upgrade execute upgrade script\n"
56 .
" download download latest version (does not unpack/install)\n";
85 $installer =
new Upgrade(array());
86 $installer->setLogger($this);
88 if ($installer->execute()) {
89 if (count($installer->getNotes()) > 0) {
90 printf(
"\nRelease Notes\n");
91 printf(
"----------------------------------------\n");
92 foreach ($installer->getNotes() as $note) {
93 printf(
"%s\n\n", $note);
97 $newVersion = $installer->getNewVersion();
98 printf(
"Successfully upgraded to version %s\n", $newVersion->getVersionString(
false));
101 printf(
"ERROR: Upgrade failed: %s\n", $installer->getErrorString());
112 printf(
"Failed to load version info from %s\n",
$application->getVersionDescriptorUrl());
116 $download = $versionInfo[
'package'];
117 $outFile = basename($download);
119 printf(
"Download: %s\n", $download);
120 printf(
"File will be saved to: %s\n", $outFile);
126 $out = fopen($outFile,
'wb');
128 printf(
"Failed to open %s for writing\n", $outFile);
132 $in = fopen($download,
'rb');
134 printf(
"Failed to open %s for reading\n", $download);
139 printf(
'Downloading file...');
141 while(($data = fread($in, 4096)) !==
'') {
157 function checkVersion($versionInfo, $displayInfo =
false) {
160 printf(
"Failed to load version info from %s\n",
$application->getVersionDescriptorUrl());
166 $latestVersion = $versionInfo[
'version'];
168 printf(
"Code version: %s\n", $codeVersion->getVersionString(
false));
169 printf(
"Database version: %s\n", $dbVersion->getVersionString(
false));
170 printf(
"Latest version: %s\n", $latestVersion->getVersionString(
false));
172 $compare1 = $codeVersion->compare($latestVersion);
173 $compare2 = $dbVersion->compare($codeVersion);
177 printf(
"Database version is older than code version\n");
178 printf(
"Run \"{$this->scriptName} upgrade\" to update\n");
181 }
else if($compare2 > 0) {
182 printf(
"Database version is newer than code version!\n");
185 }
else if ($compare1 == 0) {
186 printf(
"Your system is up-to-date\n");
188 }
else if($compare1 < 0) {
189 printf(
"A newer version is available:\n");
192 printf(
"Current version is newer than latest!\n");
198 printf(
" tag: %s\n", $versionInfo[
'tag']);
199 printf(
" date: %s\n", $versionInfo[
'date']);
200 printf(
" info: %s\n", $versionInfo[
'info']);
201 printf(
" package: %s\n", $versionInfo[
'package']);
212 printf(
"%s [y/N] ", $prompt);
213 $continue = fread(STDIN, 255);
214 return (strtolower(substr(trim($continue), 0, 1)) ==
'y');
221 function log($message) {
222 printf(
"[%s]\n", $message);