public function submitUpdateVersion() { //获取post数据 调用 $this->log->info("START FUNCTION " . __FUNCTION__); $data = Flight::request()->data->getData(); $this->log->info('data:' . json_encode($data)); // var_dump($data); $errorArray = array('error' => ''); //参数检查 if (!isset($data['confProduct']) || !isset($data['confName']) || !isset($data['confVersion']) || !isset($data['path']) || !isset($data['confUser']) || !isset($data['confRemark']) || !isset($data['confFrameworkType']) || !isset($data['confAuthor']) || !isset($data['isShell']) || !isset($data['confContent'])) { $errorArray['error'] = "missing parameters, please check. confProduct confName confVersion path..."; Flight::json($errorArray, 400); } $confProduct = $data['confProduct']; $confName = $data['confName']; $confVersion = $data['confVersion']; $confContent = $data['confContent']; $confUser = $data['confUser']; $confRemark = $data['confRemark']; $confAuthor = $data['confAuthor']; $confFrameworkType = $data['confFrameworkType']; $isShell = $data['isShell']; $path = $data['path']; $packageItem = new Package(); $packageInfo = $packageItem->getInfo($confProduct, $confName, $confVersion); $packagePath = $this->pkgHome . $data['path']; $realPackagePath = realpath($packagePath); if (empty($realPackagePath) || !is_dir($realPackagePath)) { $errorArray['error'] = "目录不存在:{$data['path']}"; Flight::json($errorArray, 404); } //运行脚本提交 $shellRun = new ExecShell('check_svn_dir.sh', Conf::get('tool_operate')); $shellRun->run($realPackagePath); $this->log->info('shell run result:' . json_encode($shellRun->getOutput())); $shellRunCode = $shellRun->rtCode(); //提交出错 if ($shellRunCode != 0) { $errorArray['error'] = "目录中存在无效文件,如:管道文件、块设备文件、字符设备文件等"; Flight::json($errorArray, 400); } $confContent = str_replace("\r\n", "\n", $confContent); $confContent = iconv("UTF-8", "GBK//IGNORE", $confContent); $xmlPath = $realPackagePath . "/init.xml"; if (!file_exists($xmlPath)) { $errorArray['error'] = "配置文件init.xml不存在:{$path}/init.xml"; Flight::json($errorArray, 404); } $xmlTmp = $xmlPath . date("U") . rand(1000, 100000); if (!copy($xmlPath, $xmlTmp)) { $errorArray['error'] = "备份文件失败, 取消保存"; Flight::json($errorArray, 400); } $copyLen = file_put_contents($xmlPath, $confContent); if ($copyLen != strlen($confContent)) { $rollBack = unlink($realPackagePath) && rename($xmlTmp, $xmlPath); if ($rollBack) { $errorArray['error'] = "保存文件失败,文件已回滚"; } else { $errorArray['error'] = "原始文件已被清空,无法恢复.备份文件名为:" . basename($xmlTmp) . ",请手工处理"; } Flight::json($errorArray, 400); } unlink($xmlTmp); $packageItem->packageInfo['product'] = $confProduct; $packageItem->packageInfo['name'] = $confName; $packageItem->packageInfo['version'] = $confVersion; $packageItem->packageInfo['path'] = $packageItem->getSvnPath($confProduct, $confName); $packageItem->packageInfo['user'] = $confUser; $packageItem->packageInfo['remark'] = $confRemark; $packageItem->packageInfo['author'] = $confAuthor; $packageItem->packageInfo['status'] = 200; if ($isShell != 'true') { $packageItem->packageInfo['frameworkType'] = $confFrameworkType; } else { $packageItem->packageInfo['frameworkType'] = "undefined"; } $pkgSvnScript = new PkgSvn(); $shellRunRes = $pkgSvnScript->buildUpdatePackage($path, $realPackagePath); $shellRunCode = $shellRunRes['code']; $shellRunMsg = $shellRunRes['msg']; $this->log->info('shell run code:' . $shellRunCode); $this->log->info('shell run result:' . $shellRunMsg); if ($shellRunCode != 0) { $errorArray['error'] = '升级失败' . $shellRunMsg; Flight::json($errorArray, 400); } else { $svnVersion = $shellRunRes['data']['svnVersion']; $packageItem->packageInfo['status'] = 1; $packageItem->packageInfo['svnVersion'] = $svnVersion; $packageItem->savePackage(); } //用户信息获取没确认! // $user = new UserFavorite; // $user->insert($data['userId'], $confProduct, $confName); Flight::json($errorArray, 200); }