Example #1
0
 /**
  * Execute the job.
  * @throws \RuntimeException
  * @dispatches UpdateGitReferences
  */
 public function handle()
 {
     $private_key = tempnam(storage_path('app/'), 'sshkey');
     file_put_contents($private_key, $this->project->private_key);
     $wrapper = with(new ScriptParser())->parseFile('tools.SSHWrapperScript', ['private_key' => $private_key]);
     $wrapper_file = tempnam(storage_path('app/'), 'gitssh');
     file_put_contents($wrapper_file, $wrapper);
     $process = new Process('tools.MirrorGitRepository', ['wrapper_file' => $wrapper_file, 'mirror_path' => $this->project->mirrorPath(), 'repository' => $this->project->repository]);
     $process->run();
     unlink($wrapper_file);
     unlink($private_key);
     if (!$process->isSuccessful()) {
         throw new \RuntimeException('Could not mirror repository - ' . $process->getErrorOutput());
     }
     $this->project->last_mirrored = date('Y-m-d H:i:s');
     $this->project->save();
     $this->dispatch(new UpdateGitReferences($this->project));
 }