|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Jobs; |
|
4
|
|
|
|
|
5
|
|
|
use App\Exceptions\GithubAuthenticationException; |
|
6
|
|
|
use App\Models\Release; |
|
7
|
|
|
use App\Notifications\Frontend\ReleaseWasPublished; |
|
8
|
|
|
use App\Services\Publish\Git; |
|
9
|
|
|
use App\Services\Publish\GitHubService; |
|
10
|
|
|
use Illuminate\Bus\Queueable; |
|
11
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
12
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
|
13
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
14
|
|
|
use Illuminate\Queue\SerializesModels; |
|
15
|
|
|
use Illuminate\Support\Carbon; |
|
16
|
|
|
use Illuminate\Support\Facades\Redirect; |
|
17
|
|
|
|
|
18
|
|
|
class Publish implements ShouldQueue |
|
19
|
|
|
{ |
|
20
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Release |
|
23
|
|
|
*/ |
|
24
|
|
|
private $release; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $disk; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Create a new job instance. |
|
32
|
|
|
* |
|
33
|
|
|
* @param Release $release |
|
34
|
|
|
* @param string $disk |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(Release $release, $disk = GenerateRdf::REPO_ROOT) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->release = $release; |
|
39
|
|
|
$this->disk = $disk; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Execute the job. |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
* @throws \InvalidArgumentException |
|
47
|
|
|
* @throws \GitWrapper\GitException |
|
48
|
|
|
* @throws \Symfony\Component\Process\Exception\RuntimeException |
|
49
|
|
|
* @throws \Symfony\Component\Process\Exception\ProcessFailedException |
|
50
|
|
|
* @throws \Symfony\Component\Process\Exception\LogicException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function handle() |
|
53
|
|
|
{ |
|
54
|
|
|
//todo:lot's more try/catch here |
|
55
|
|
|
$project = $this->release->project; |
|
56
|
|
|
$repo = $project->repo; |
|
|
|
|
|
|
57
|
|
|
$user = $this->release->user; |
|
58
|
|
|
|
|
59
|
|
|
//todo: rdf generator shouldn't responsible for storage management |
|
60
|
|
|
Git::initDir($project, $this->disk, $user); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
//todo: this section should be in a transaction |
|
63
|
|
|
$this->release->published_at = Carbon::now(); |
|
64
|
|
|
$this->release->save(); |
|
65
|
|
|
//foreach selected vocabulary |
|
66
|
|
|
$vocabs = $this->release->vocabularies()->get(); |
|
67
|
|
|
foreach ($vocabs as $vocab) { |
|
68
|
|
|
$job = new GenerateRdf($vocab, $this->release, $this->disk); |
|
69
|
|
|
$job->handle(); |
|
70
|
|
|
} |
|
71
|
|
|
$vocabs = $this->release->elementsets()->get(); |
|
72
|
|
|
foreach ($vocabs as $vocab) { |
|
73
|
|
|
$job = new GenerateRdf($vocab, $this->release, $this->disk); |
|
74
|
|
|
$job->handle(); |
|
75
|
|
|
} |
|
76
|
|
|
//when the jobs are complete: |
|
77
|
|
|
//commit the generated rdf with the version as the commit message |
|
78
|
|
|
Git::commitDir($project, $this->release->name, $this->disk); |
|
79
|
|
|
|
|
80
|
|
|
if ($project->repo) { |
|
81
|
|
|
//push the repo to github |
|
82
|
|
|
Git::updateRemote($this->release, $this->disk, $user); |
|
83
|
|
|
//push the release to GitHub |
|
84
|
|
|
$gitHub = new GitHubService($this->release); |
|
85
|
|
|
try { |
|
86
|
|
|
$gitHub->setRelease(); |
|
87
|
|
|
} |
|
88
|
|
|
catch (GithubAuthenticationException $e) { |
|
89
|
|
|
Redirect::back()->withErrors([ |
|
90
|
|
|
'You\'re trying to access GitHub, but you don\'t seem to have any current GitHub credentials.', |
|
91
|
|
|
'You must logout of the OMR, and login to the OMR again using the \'Login with GitHub\' link.', |
|
92
|
|
|
]); |
|
93
|
|
|
} |
|
94
|
|
|
} else { |
|
95
|
|
|
//tag the commit with the version |
|
96
|
|
|
Git::tagDir($project, $this->release->tag_name, $this->disk); |
|
97
|
|
|
} |
|
98
|
|
|
//todo: run the GenerateDocs job |
|
99
|
|
|
//notify the user that it's done |
|
100
|
|
|
$this->release->User->notify(new ReleaseWasPublished($this->release)); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|