From fc55642869177ef262c6420ee048804405c18676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=8A=BC?= Date: Sat, 29 Nov 2014 14:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9helper=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publisher/app/lib/TaskHelper.php | 70 +++++++++++++++++++++++++------- publisher/app/start/global.php | 2 + 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/publisher/app/lib/TaskHelper.php b/publisher/app/lib/TaskHelper.php index c283112..2c69fdd 100644 --- a/publisher/app/lib/TaskHelper.php +++ b/publisher/app/lib/TaskHelper.php @@ -67,13 +67,9 @@ public function run($task_id) return $this->err('供执行的任务必须是初始状态'); } //TODO 检查前置任务pre_task 的状态 - if($task->pre_id) + if($task->pre_task && $task->pre()->status != 'success') { - $pre_task = \Tasks::find($task->pre_id); - if(!$pre_task || $pre_task->status != 'success') - { - return $this->err('前置任务尚未完成,跳过此任务'); - } + return $this->err('前置任务尚未完成'); } $task->status = 'execute'; $task->execute_time = date('Y-m-d H:i:s'); @@ -103,22 +99,34 @@ private function _runCheckout($task) case 'svn': if(function_exists('svn_checkout')) { + if($project->username) + { + svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, $project->username); + svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, $project->password); + } $result = svn_checkout($project->svn_addr,$pj_dir); - return array('result'=>$result,'output'=> implode("\n", $output)); + if($result) + { + $project->current_version = $this->get_dir_version($pj_dir); + $project->save(); + } + return array('result'=>$result,'output'=> ''); } else { $command = "svn checkout {$project->svn_addr} {$pj_dir} "; $command .= " --no-auth-cache --username={$project->username} --password={$project->password}"; exec($command,$output,$return_var); + if($return_var == 0) + { + $project->current_version = $this->get_dir_version($pj_dir); + $project->save(); + } return array('result'=>($return_var == 0),'output'=> implode("\n", $output)); } break; case 'git': break; - default: - # code... - break; } } //返回 @@ -140,7 +148,30 @@ private function _runUpdate($task) */ private function _runDelete($task) { - + if($task->project_id) + { + $pj_dir = Project::getTempDir($task->project_id); + if(!file_exists($pj_dir)) + { + if(!mkdir($pj_dir,0750)) + { + return array('result'=>false,'output'=>"mkdir $pj_dir failed!"); + } + } + else + { + $delete_cmd = "rm -rf {$pj_dir}/*"; + exec($delete_cmd,$output,$return_var); + if($return_var == 0) + { + $project = Project::find($project_id); + $project->current_version = ''; + $project->save(); + } + + return array('result'=>($return_var == 0),'output'=> implode("\n", $output)); + } + } } /** @@ -204,7 +235,6 @@ public function get_log($src_path,$type='svn',$auth=null,$limit=10,$last='') $cmd .= " --limit {$limit}"; } $cmdresult = exec($cmd); - /*//$cmdresult = '测试用户测试文字测试用户测试文字';*/ $loadxml = simplexml_load_string(trim($cmdresult), 'SimpleXMLElement', LIBXML_NOCDATA); foreach($loadxml->children() as $elem) { @@ -221,8 +251,20 @@ public function get_log($src_path,$type='svn',$auth=null,$limit=10,$last='') } } - private function get_current_version($src_path,$type='svn') + private function get_dir_version($src_path,$type='svn') { - + switch ($type) { + case 'svn': + exec("svn info {$src_path}",$output); + foreach($output as $_row) + { + if(preg_match('/^Revision:\s?(\d+)/i', $_row,$match)) + return $match[1]; + } + return ''; + case 'git': + # code... + break; + } } } diff --git a/publisher/app/start/global.php b/publisher/app/start/global.php index c0e2057..03b2df6 100644 --- a/publisher/app/start/global.php +++ b/publisher/app/start/global.php @@ -59,6 +59,8 @@ return Response::view('errors.default', array('msg' => '您要访问的页面不存在'), $code); case 500: return Response::view('errors.default', array('msg' => '服务器内部错误,请联系管理员'), $code); + default: + return Response::view('errors.default', array('msg' => '出错了:代码'.$code), $code); } });