1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ReliqArts\Docweaver\Console\Commands; |
6
|
|
|
|
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use Illuminate\Console\Command; |
9
|
|
|
use ReliqArts\Docweaver\Contracts\Documentation\Publisher; |
10
|
|
|
|
11
|
|
|
class UpdateAll extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The name and signature of the console command. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $signature = 'docweaver:update-all |
19
|
|
|
{--y|y : Whether to skip confirmation} |
20
|
|
|
'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Update documentation for all products'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Publisher |
31
|
|
|
*/ |
32
|
|
|
protected $publisher; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create a new command instance. |
36
|
|
|
* |
37
|
|
|
* @param Publisher $publisher |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Publisher $publisher) |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
|
43
|
|
|
$this->publisher = $publisher; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Execute the console command. |
48
|
|
|
*/ |
49
|
|
|
public function handle(): void |
50
|
|
|
{ |
51
|
|
|
$skipConfirmation = $this->option('y'); |
52
|
|
|
$confirmationMessage = 'This command will attempt to update documentation for all products.' |
53
|
|
|
. "\nPlease ensure your internet connection is stable. Ready?"; |
54
|
|
|
|
55
|
|
|
$this->comment(PHP_EOL |
56
|
|
|
. "<info>♣♣♣</info> Docweaver DocumentationPublisher \n" |
57
|
|
|
. 'Help is here, try: php artisan docweaver:update-all --help'); |
58
|
|
|
|
59
|
|
|
if ($skipConfirmation || $this->confirm($confirmationMessage)) { |
60
|
|
|
$this->info("Updating products.\nT: " . Carbon::now()->toCookieString() . "\n----------"); |
61
|
|
|
|
62
|
|
|
$result = $this->publisher->updateAll($this); |
63
|
|
|
|
64
|
|
|
if ($result->isSuccess()) { |
65
|
|
|
$this->info(PHP_EOL . '----------'); |
66
|
|
|
$this->comment("<info>✔</info> Done. {$result->getMessage()}"); |
67
|
|
|
|
68
|
|
|
// Display results |
69
|
|
|
$this->line(''); |
70
|
|
|
$headers = ['Time', 'Products', 'Updated']; |
71
|
|
|
$data = $result->getData(); |
72
|
|
|
$rows = [[$data->executionTime, count($data->products), count($data->productsUpdated)]]; |
73
|
|
|
$this->table($headers, $rows); |
74
|
|
|
$this->line(PHP_EOL); |
75
|
|
|
} else { |
76
|
|
|
$this->line(PHP_EOL . "<error>✘</error> {$result->getError()}"); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|