Esempio n. 1
0
 /**
  * @return same result with _downloadUpgradePackage but getting information from local repo
  */
 function _downloadUpgradePackageLocal($product, $upgradeVersion)
 {
     @set_time_limit(0);
     $FileSystemHelper = new FileSystemHelper();
     if ($product->version == $upgradeVersion) {
         jaucRaiseMessage("UpdaterService: cannot upgrade to same version", true);
         return false;
     }
     if (!($productDir = $this->getLocalVersionsPath($product))) {
         return false;
     }
     //
     $newVerDir = $productDir . $upgradeVersion . '/';
     if (!JFolder::exists($newVerDir)) {
         return false;
     }
     $vUpgrade = new stdClass();
     $vUpgrade->crc = $this->getVersionChecksum($newVerDir);
     //
     $orgVerDir = $productDir . $product->version . '/';
     if (JFolder::exists($orgVerDir)) {
         $vServer = new stdClass();
         $vServer->crc = $this->getVersionChecksum($orgVerDir);
     }
     //
     $pro = new jaProducts($product, $this->config, true);
     $oldPro = $pro->getFullInfo();
     //
     $pathPackageStore = $this->getLocalPatchPath($product);
     $package = sprintf("%s_%s_%s.zip", $product->extKey, $product->version, $upgradeVersion);
     $package = $pathPackageStore . $package;
     if (!isset($vServer)) {
         //clear cached package file
         if (JFile::exists($package)) {
             JFile::delete($package);
         }
     }
     if (!JFile::exists($package)) {
         $compare = new jaCompareTool();
         if (isset($vServer)) {
             $vResult = $compare->checkToBuildUpgradePackage($vServer, $vUpgrade);
         } else {
             $vResult = $compare->checkToBuildUpgradePackage($oldPro, $vUpgrade);
         }
         $tmpDir = $FileSystemHelper->tmpDir(null, 'ja', 0755);
         $tmpDir = $tmpDir . $oldPro->extKey . '/';
         if (JFolder::create($tmpDir, 0755) === false) {
             jaucRaiseMessage("UpdaterService: cannot build upgrade package", true);
             return false;
         }
         $infoFile = $tmpDir . "jaupdater.info.json";
         JFile::write($infoFile, json_encode($vResult));
         //echo $tmpDir;
         $this->_buildUpgradePackage($newVerDir, $tmpDir, $vResult);
         ArchiveHelper::zip($package, $tmpDir, true);
     }
     return $package;
 }
Esempio n. 2
0
 function doBackup()
 {
     $config = $this->config;
     $workingDir = FileSystemHelper::tmpDir(null, 'ja', 0777);
     $workingDir .= $this->extKey . DS;
     if (mkdir($workingDir, 0777) === false) {
         return false;
     }
     $backupDir = $this->getBackupPath();
     if ($backupDir === false) {
         return false;
     }
     $locations = $this->getLocation();
     $cnt = count($locations);
     foreach ($locations as $name => $path) {
         if ($name != 'location') {
             FileSystemHelper::cp($path, $workingDir . $name, true, 0777);
         } else {
             FileSystemHelper::cp($path, $workingDir, true, 0777);
         }
     }
     $this->_backupDatabase($workingDir);
     //save all to backup file
     $createDate = date("Y-m-d H:i:s");
     $fileName = $this->extKey . "_" . date("dMY_His", strtotime($createDate));
     $fileNameBak = $fileName . ".zip";
     $fileBak = $backupDir . $fileNameBak;
     ArchiveHelper::zip($fileBak, $workingDir, true);
     //
     $comment = (string) (isset($this->message) ? $this->message : "");
     $info = "extKey={$this->extKey}" . "\r\n";
     $info .= "version={$this->version}" . "\r\n";
     $info .= "createDate={$createDate}" . "\r\n";
     $info .= "comment={$comment}" . "\r\n";
     $fileInfo = $backupDir . $fileName . ".txt";
     $fp = fopen($fileInfo, 'wb');
     fwrite($fp, $info);
     fclose($fp);
     //
     return $fileNameBak;
 }
 private function _getUpgradePackage($oldPro, $newVersion, $refresh = false)
 {
     if ($oldPro->version == $newVersion) {
         $this->doResponse("Cannot upgrade if you are using this version", true);
     }
     $pathPackageStore = $this->config->get("UPKG_LOCATION") . DS;
     $package = sprintf("%s_%s_%s.zip", $oldPro->extKey, $oldPro->version, $newVersion);
     $package = $pathPackageStore . $package;
     if (!is_file($package) || $refresh) {
         //build package
         $vServer = $this->getProduct($oldPro);
         $newPro = $oldPro;
         $newPro->version = $newVersion;
         $vUpgrade = $this->getProduct($newPro);
         $compare = new jaCompareTool();
         if ($vServer !== false) {
             $savePackage = true;
             $vResult = $compare->checkToBuildUpgradePackage($vServer, $vUpgrade);
         } else {
             //if not found original version on server
             //the system will build upgrade package from user' version and new version
             //but this package will not be stored on server
             $savePackage = false;
             $vResult = $compare->checkToBuildUpgradePackage($oldPro, $vUpgrade);
             //store package to tmp folder
             $packageName = basename($package);
             $storeDir = FileSystemHelper::tmpDir(null, 'ja', 0777);
             $package = $storeDir . $packageName;
         }
         //$this->doResponse(print_r(scandir($vUpgrade->getLocation()), 1) . "---COMPARE_OBJECT:" . print_r($vResult, 1), true);
         $tmpDir = FileSystemHelper::tmpDir(null, 'ja', 0777);
         $tmpDir = $tmpDir . $oldPro->extKey . DS;
         if (mkdir($tmpDir, 0777) === false) {
             $this->doResponse("Cannot build upgrade package", true);
         }
         $infoFile = $tmpDir . "jaupdater.info.json";
         $fp = fopen($infoFile, 'wb');
         fwrite($fp, json_encode($vResult));
         fclose($fp);
         $this->_buildUpgradePackage($vUpgrade->getLocation(), $tmpDir, $vResult);
         ArchiveHelper::zip($package, $tmpDir, true);
     }
     return $package;
 }