1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\ForgePublish\Commands; |
4
|
|
|
|
5
|
|
|
use Acacha\ForgePublish\Commands\Traits\AborstIfEnvVariableIsnotInstalled; |
6
|
|
|
use Acacha\ForgePublish\Commands\Traits\ItFetchesAssignments; |
7
|
|
|
use GuzzleHttp\Client; |
8
|
|
|
use Illuminate\Console\Command; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PublishAssignments. |
12
|
|
|
* |
13
|
|
|
* @package Acacha\ForgePublish\Commands |
14
|
|
|
*/ |
15
|
|
|
class PublishAssignments extends Command |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
use ItFetchesAssignments, AborstIfEnvVariableIsnotInstalled; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The name and signature of the console command. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $signature = 'publish:assignments'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The console command description. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $description = 'List current teacher assignments'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Assignments. |
36
|
|
|
* |
37
|
|
|
* @var |
38
|
|
|
*/ |
39
|
|
|
protected $assignments; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Server names. |
43
|
|
|
* |
44
|
|
|
* @var Client |
45
|
|
|
*/ |
46
|
|
|
protected $http; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* SaveEnvVariable constructor. |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
|
|
public function __construct(Client $http) |
53
|
|
|
{ |
54
|
|
|
parent::__construct(); |
55
|
|
|
$this->http = $http; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Execute the console command. |
60
|
|
|
* |
61
|
|
|
*/ |
62
|
|
|
public function handle() |
63
|
|
|
{ |
64
|
|
|
$this->abortCommandExecution(); |
65
|
|
|
$this->assignments = $this->fetchAssignments(); |
66
|
|
|
|
67
|
|
|
$headers = ['Id', 'Name','Repository','Repo Type','Forge site','Forge Server','Created','Updated']; |
68
|
|
|
|
69
|
|
|
$rows = []; |
70
|
|
|
foreach ($this->assignments as $assignment) { |
71
|
|
|
$rows[] = [ |
72
|
|
|
$assignment->id, |
73
|
|
|
$assignment->name, |
74
|
|
|
$assignment->repository_uri, |
75
|
|
|
$assignment->repository_type, |
76
|
|
|
$assignment->forge_site, |
77
|
|
|
$assignment->forge_server, |
78
|
|
|
$assignment->created_at, |
79
|
|
|
$assignment->updated_at |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->table($headers, $rows); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Abort command execution. |
88
|
|
|
*/ |
89
|
|
|
protected function abortCommandExecution() |
90
|
|
|
{ |
91
|
|
|
$this->abortsIfEnvVarIsNotInstalled('ACACHA_FORGE_ACCESS_TOKEN'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|