Example #1
0
 /**
  * [copyMethod 拷贝包]
  * @param  [type] $srcPath    [description]
  * @param  [type] $srcVersion [description]
  * @param  [type] $targetPath [description]
  * @return [array]             [resukt:bool-true/false error:string]
  */
 public function copyMethod($srcPath, $srcVersion, $targetPath)
 {
     $packageItem = new Package();
     $srcInfo = $packageItem->getInfoByPath($srcPath, $srcVersion);
     $targetInfo = $packageItem->getLastValidPackageByPath($targetPath);
     if (empty($srcInfo) || empty($targetInfo)) {
         $resultArray['error'] = '包不存在';
         $resultArray['result'] = false;
         return $resultArray;
     }
     $svnVersion = $srcInfo['svnVersion'];
     $svnBase = $this->svnBase;
     $tmpPath = $this->svnBaseTmp . $srcPath;
     $targetPackageArray = explode('/', trim($targetPath, '/'));
     if (count($targetPackageArray) == 3) {
         $targetName = $targetPackageArray[2];
     } else {
         $targetName = $targetPackageArray[1];
     }
     $targetProduct = $targetPackageArray[0];
     $srcPackageArray = explode('/', trim($srcPath, '/'));
     if (count($srcPackageArray) == 3) {
         $srcName = $srcPackageArray[2];
     } else {
         $srcName = $srcPackageArray[1];
     }
     $srcProduct = $srcPackageArray[0];
     //版本号处理
     $targetVersion = $targetInfo['version'];
     $versionArray = explode('.', $targetVersion);
     $versionArray[count($versionArray) - 1]++;
     $targetVersion = implode('.', $versionArray);
     $baseVersion = $versionArray;
     unset($baseVersion[count($versionArray) - 1]);
     $baseVersion = implode('.', $baseVersion);
     $cmdArray = array();
     $cmdArray[] = "rm {$tmpPath} -r ;" . "/usr/local/bin/svn export --config-dir /etc/subversion -r {$svnVersion} svn://" . $this->svnServer . rtrim($srcPath, '/') . "/ {$tmpPath} --force >/dev/null 2>&1;echo \$?";
     $cmdArray[] = '/usr/bin/sed -i s:^name=\\"' . $srcName . '\\":name=\\"' . $targetName . '\\": ' . $tmpPath . '/init.xml; echo $?';
     $cmdArray[] = '/usr/bin/sed -i s:^product=\\"' . $srcProduct . '\\":product=\\"' . $targetProduct . '\\": ' . $tmpPath . '/init.xml; echo $?';
     $cmdArray[] = '/usr/bin/sed -i s:^version=\\"[0-9.]*\\":version=\\"' . $baseVersion . '\\": ' . $tmpPath . '/init.xml; echo $?';
     $cmdArray[] = "/usr/bin/rsync -a --delete --exclude=.svn " . rtrim($tmpPath, '/') . "/ {$svnBase}{$targetPath}  2>&1;echo \$?";
     foreach ($cmdArray as $index => $singleCommand) {
         $singleCommand = escapeshellcmd($singleCommand);
         $this->log($singleCommand);
         $shellRunResult = shell_exec($singleCommand);
         $this->log($shellRunResult);
         if ($shellRunResult != '0') {
             $resultArray['error'] = '执行命令出错:命令' . ($index + 1);
             $resultArray['result'] = false;
             return $resultArray;
         }
     }
     //修改包数据信息
     $packageItem = new Package();
     $packageItem->packageInfo['product'] = $targetInfo['product'];
     $packageItem->packageInfo['name'] = $targetInfo['name'];
     $packageItem->packageInfo['version'] = $targetVersion;
     $packageItem->packageInfo['path'] = $targetInfo['path'];
     $packageItem->packageInfo['user'] = $srcInfo['version'];
     $packageItem->packageInfo['remark'] = "从{$srcPath} {$srcVersion} " . "{$srcInfo['remark']} 拷贝";
     $packageItem->packageInfo['author'] = $srcInfo['author'];
     $packageItem->packageInfo['status'] = 1;
     $packageItem->packageInfo['frameworkType'] = $srcInfo['frameworkType'];
     $packageItem->packageInfo['stateless'] = $srcInfo['stateless'];
     $packageItem->packageInfo['os'] = $srcInfo['os'];
     //运行升级脚本
     $shellRun = new ExecShell('update_package.sh');
     $shellRun->run($this->pkgHome . $targetPath, $targetProduct, $targetName, $targetVersion);
     $resultArray = array();
     $shellRunCode = $shellRun->rtCode();
     if ($shellRun->result(0) != 'result' || $shellRun->result(1) != 'success' && $shellRun->result(1) != 'failed') {
         $resultArray['error'] = '后台异常返回';
         $resultArray['result'] = false;
         return $resultArray;
     }
     if ($shellRun->result(1) === 'success') {
         $packageItem->packageInfo['svnVersion'] = $shellRun->result(3);
         $packageItem->savePackage();
     } else {
         $resultArray['error'] = '升级失败' . $shellRun->result(2);
         $resultArray['result'] = false;
         return $resultArray;
     }
     $resultArray['error'] = '';
     $resultArray['result'] = true;
     return $resultArray;
 }
Example #2
0
 public function getUpdateFileList()
 {
     $this->log->info("START FUNCTION " . __FUNCTION__);
     $errorArray = array('error' => '');
     // get
     $data = Flight::request()->query->getData();
     //参数检查
     $needPara = array('product', 'name', 'fromVersion', 'toVersion');
     $optionalPara = array();
     $error = $this->checkParameter($needPara, $data, $optionalPara);
     $product = $data['product'];
     $name = $data['name'];
     $fromVersion = $data['fromVersion'];
     $toVersion = $data['toVersion'];
     $this->log->info("{$product} {$name} {$fromVersion} {$toVersion}");
     $packageItem = new Package();
     //检查包合法性
     $packageOldInfo = $packageItem->getInfo($product, $name, $fromVersion);
     $packageNewInfo = $packageItem->getInfo($product, $name, $toVersion);
     if ($packageOldInfo == null) {
         $errorArray['error'] = "package not exists {$product} {$name} {$fromVersion}";
         $this->log->info("{$errorArray['error']}");
         Flight::json($errorArray, 404);
     } elseif ($packageNewInfo == null) {
         $errorArray['error'] = "package not exists {$product} {$name} {$toVersion}";
         $this->log->info("{$errorArray['error']}");
         Flight::json($errorArray, 404);
     }
     //start to generate list
     $uploadPkgPath = $this->updatePkgPath;
     $confPath = $uploadPkgPath . "/{$product}/{$name}/{$name}-update-{$fromVersion}-{$toVersion}/update.conf";
     $copyPath = $confPath;
     $svnPath = $packageNewInfo['path'];
     $shellRun = new PkgSvn();
     $shellRunRes = $shellRun->exportUpdatePkg($svnPath, $packageOldInfo['svnVersion'], $packageNewInfo['svnVersion'], $fromVersion, $toVersion, $packageNewInfo['frameworkType']);
     $this->log->info('shell run result:' . json_encode($shellRunRes));
     $shellRunCode = $shellRunRes['code'];
     if ($shellRunCode != 0) {
         $errorArray['error'] = "导出包失败:" . $shellRunRes['msg'];
         Flight::json($errorArray, 400);
     }
     $this->log->info($confPath);
     $confContent = file($confPath);
     $realConf = false;
     $fileList = array();
     //解析文本
     foreach ($confContent as $line) {
         if (strpos($line, '##End--') !== false) {
             $realConf = true;
             continue;
         }
         if ($realConf == false) {
             continue;
         }
         if (strpos($line, 'A /') !== 0 && strpos($line, 'D /') !== 0 && strpos($line, 'M /') !== 0) {
             var_dump($line . "!!!");
             continue;
         }
         $line = trim($line);
         $file = array();
         if (strpos($line, 'A /') === 0) {
             $file['type'] = 'add';
             var_dump($line);
         } elseif (strpos($line, 'D /') === 0) {
             $file['type'] = 'delete';
         } elseif (strpos($line, 'M /') === 0) {
             $file['type'] = 'modify';
         }
         $file['path'] = strstr($line, '/');
         $fileList[] = $file;
     }
     $errorArray = $fileList;
     Flight::json($errorArray, 200);
 }
Example #3
0
 public function checkPackageExistMethod($product, $name)
 {
     $result = array();
     $packageItem = new Package();
     $resultArray = $packageItem->getVersionList($name, $product);
     if (!empty($resultArray)) {
         $result = array('exist' => true, 'msg' => '指定包名已存在');
         return $result;
     }
     $directory = $this->pkgHome . "/{$product}/{$name}/.svn";
     if (is_dir($directory)) {
         $result = array('exist' => true, 'msg' => '指定包名已存在svn服务器');
         return $result;
     }
     $result = array('exist' => false, 'msg' => '包不存在');
     return $result;
 }
Example #4
0
 /**
  * [deleteProductMap 删除业务映射]
  * @return [type] [description]
  */
 public function deleteProductMap()
 {
     $this->log('START FUNCTION ' . __FUNCTION__);
     $errorArray = array('error' => '');
     $data = Flight::request()->query->getData();
     $needPara = array('productList');
     $error = $this->checkParameter($needPara, $data);
     $productList = explode(";", $data['productList']);
     $package = new Package();
     foreach ($productList as $value) {
         $hasPackage = $package->searchPackage(null, $value);
         if (!empty($hasPackage)) {
             $errorArray['error'] = "{$value} 产品下有已经存在的包, 无法删除";
             Flight::json($errorArray, 400);
         }
     }
     $result = $package->deleteProductMap($productList);
     if ($result) {
         Flight::json($errorArray, 200);
     }
     $errorArray['error'] = '修改数据库出错';
     Flight::json($errorArray, 400);
 }