コード例 #1
0
ファイル: upgrade.php プロジェクト: alenoosh/ojs
 /**
  * Perform version check.
  * @param $versionInfo array latest version info
  * @param $displayInfo boolean just display info, don't perform check
  */
 function checkVersion($versionInfo, $displayInfo = false)
 {
     if (!$versionInfo) {
         printf("Failed to load version info from %s\n", VersionCheck::getVersionCheckUrl());
         exit(1);
     }
     $dbVersion = VersionCheck::getCurrentDBVersion();
     $codeVersion = VersionCheck::getCurrentCodeVersion();
     $latestVersion = $versionInfo['version'];
     printf("Code version:      %s\n", $codeVersion->getVersionString());
     printf("Database version:  %s\n", $dbVersion->getVersionString());
     printf("Latest version:    %s\n", $latestVersion->getVersionString());
     $compare1 = $codeVersion->compare($latestVersion);
     $compare2 = $dbVersion->compare($codeVersion);
     if (!$displayInfo) {
         if ($compare2 < 0) {
             printf("Database version is older than code version\n");
             printf("Run \"{$this->scriptName} upgrade\" to update\n");
             exit(0);
         } else {
             if ($compare2 > 0) {
                 printf("Database version is newer than code version!\n");
                 exit(1);
             } else {
                 if ($compare1 == 0) {
                     printf("Your system is up-to-date\n");
                 } else {
                     if ($compare1 < 0) {
                         printf("A newer version is available:\n");
                         $displayInfo = true;
                     } else {
                         printf("Current version is newer than latest!\n");
                         exit(1);
                     }
                 }
             }
         }
     }
     if ($displayInfo) {
         $patch = VersionCheck::getPatch($versionInfo, $codeVersion);
         printf("         tag:     %s\n", $versionInfo['tag']);
         printf("         date:    %s\n", $versionInfo['date']);
         printf("         info:    %s\n", $versionInfo['info']);
         printf("         package: %s\n", $versionInfo['package']);
         printf("         patch:   %s\n", isset($patch) ? $patch : 'N/A');
     }
     return $compare1;
 }