示例#1
0
 /**
  * [checkOutMethod 导出/更新包库中的文件]
  * @param  [type] $product [产品]
  * @param  [type] $name    [包名]
  * @param  [type] $version [版本]
  * @return [array]          [code:0成功 1失败 error:失败信息 2找不到失败]
  */
 public function checkOutMethod($product, $name, $version)
 {
     $result = array('code' => 0, 'error' => '');
     $packageItem = new Package();
     $packageInfo = $packageItem->getInfo($product, $name, $version);
     if (empty($packageInfo)) {
         $result['code'] = 2;
         $result['error'] = "找不到包记录";
         return $result;
     }
     $path = $packageInfo['path'];
     $packagePath = $this->pkgHome . "/" . $path;
     $packageSvnPath = $packagePath . "/.svn";
     //跑脚本导出
     if (!is_dir($packagePath) || !is_dir($packageSvnPath)) {
         //use pkgsvn script
         $shellRun = new PkgSvn();
         $shellRunRes = $shellRun->checkout($path);
         if ($shellRunRes['code'] != 0) {
             $result['code'] = 1;
             $result['error'] = "导出包副本到workplace失败:{$path}" . $shellRunRes['msg'];
             return $result;
         }
     } else {
         $shellRun = new PkgSvn();
         $shellRunRes = $shellRun->update($path);
         if ($shellRunRes['code'] != 0) {
             $result['code'] = 1;
             $result['error'] = "更新包副本到workplace失败:{$path};" . $shellRunRes['msg'];
             return $result;
         }
     }
     return $result;
 }
示例#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);
 }