diff --git a/publisher/.gitignore b/publisher/.gitignore index b5363f0..6deb519 100644 --- a/publisher/.gitignore +++ b/publisher/.gitignore @@ -6,3 +6,4 @@ composer.lock .env.php .DS_Store Thumbs.db +app/storage \ No newline at end of file diff --git a/publisher/app/lib/TaskHelper.php b/publisher/app/lib/TaskHelper.php index 04bb9d2..e0322d5 100644 --- a/publisher/app/lib/TaskHelper.php +++ b/publisher/app/lib/TaskHelper.php @@ -67,7 +67,7 @@ public function run($task_id) return $this->err('供执行的任务必须是初始状态'); } //TODO 检查前置任务pre_task 的状态 - if($task->pre_task && $task->pre()->status != 'success') + if($task->pre_task && $task->pre->status != 'success') { return $this->err('前置任务尚未完成'); } @@ -75,7 +75,9 @@ public function run($task_id) $task->execute_time = date('Y-m-d H:i:s'); $task->save(); $func = '_run'.ucfirst($task->type); - return $this->$func($task); + $result = $this->$func($task); + $task->status = $result['result'] ? 'success':'failed'; + $task->save(); } /** @@ -86,7 +88,7 @@ private function _runCheckout($task) { if($task->project_id) { - $pj_dir = Project::getTempDir($task->project_id);//项目代码存放目录 + $pj_dir = \Project::getTempDir($task->project_id);//项目代码存放目录 if(!file_exists($pj_dir)) { if(!mkdir($pj_dir,0750)) @@ -94,17 +96,17 @@ private function _runCheckout($task) return array('result'=>false,'output'=>"mkdir $pj_dir failed!"); } } - $project = Project::find($project_id); + $project = \Project::find($task->project_id); switch ($project->vcs_type) { case 'svn': - if(function_exists('svn_checkout')) + if(false)//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); + $result = svn_checkout($project->src_addr,$pj_dir); if($result) { $project->current_version = $this->get_dir_version($pj_dir); @@ -114,8 +116,11 @@ private function _runCheckout($task) } else { - $command = "svn checkout {$project->svn_addr} {$pj_dir} "; - $command .= " --no-auth-cache --username={$project->username} --password={$project->password}"; + $command = "svn checkout {$project->src_addr} {$pj_dir} --no-auth-cache"; + if($project->username) + { + $command .= " --username={$project->username} --password={$project->password}"; + } exec($command,$output,$return_var); if($return_var == 0) { @@ -140,8 +145,8 @@ private function _runUpdate($task) if($task->project_id) { - $pj_dir = Project::getTempDir($task->project_id); - $project = Project::find($project_id); + $pj_dir = \Project::getTempDir($task->project_id); + $project = \Project::find($task->project_id); switch ($project->vcs_type) { case 'svn': if(function_exists('svn_update')) @@ -151,7 +156,7 @@ private function _runUpdate($task) svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, $project->username); svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, $project->password); } - $result = svn_update($project->svn_addr,$pj_dir,$task->version); + $result = svn_update($pj_dir,$task->version); if($result !== false) { $project->current_version = $this->get_dir_version($pj_dir); @@ -161,7 +166,7 @@ private function _runUpdate($task) } else { - $command = "svn update {$project->svn_addr} {$pj_dir} -r {$task->version}"; + $command = "svn update {$pj_dir} -r {$task->version}"; $command .= " --no-auth-cache --username={$project->username} --password={$project->password}"; exec($command,$output,$return_var); if($return_var == 0) @@ -187,7 +192,7 @@ private function _runDelete($task) { if($task->project_id) { - $pj_dir = Project::getTempDir($task->project_id); + $pj_dir = \Project::getTempDir($task->project_id); if(!file_exists($pj_dir)) { if(!mkdir($pj_dir,0750)) @@ -201,7 +206,7 @@ private function _runDelete($task) exec($delete_cmd,$output,$return_var); if($return_var == 0) { - $project = Project::find($project_id); + $project = \Project::find($project_id); $project->current_version = ''; $project->save(); } @@ -218,12 +223,12 @@ private function _runDelete($task) */ private function _runRsync($task) { - $server = Server::find($task->server_id); - $pj_dir = Project::getTempDir($server->project_id); + $server = \Server::find($task->server_id); + $pj_dir = \Project::getTempDir($server->project_id); //目前就记录个日志就得了 $rsync_cmd = sprintf("rsync -avzP publisher@%s::%s %s",$server->ip,$server->rsync_name,$pj_dir); //忽略文件、 发布时要添加del选项 - file_put_contents(app_path()."/storage/rsync.log",$rsync_cmd,FILE_APPEND); + file_put_contents(app_path()."/storage/rsync.log",$rsync_cmd."\n",FILE_APPEND); if(true) { $server->current_version = $this->get_dir_version($pj_dir); diff --git a/publisher/app/models/Project.php b/publisher/app/models/Project.php index edd3e51..960e53f 100644 --- a/publisher/app/models/Project.php +++ b/publisher/app/models/Project.php @@ -20,7 +20,7 @@ public function servers() } //project临时目录 - public function getTempDir($_id) + public static function getTempDir($_id) { return app_path().'/storage/pjfolder_'.intval($_id); } diff --git a/publisher/app/views/projects/publish.blade.php b/publisher/app/views/projects/publish.blade.php index ece0c79..fc76cfb 100644 --- a/publisher/app/views/projects/publish.blade.php +++ b/publisher/app/views/projects/publish.blade.php @@ -120,7 +120,7 @@ for (var _key in _data.logs ) { _order[_order.length] = _key; - if(isNan(_key)) is_numeric = false; + if(isNaN(_key)) is_numeric = false; } if(is_numeric) _order.reverse(); for (var _key in _order ) {