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