|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MyriadDataStore\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use MyriadSoap\MyriadSoapException; |
|
7
|
|
|
|
|
8
|
|
|
class DownloadMyriadContacts extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The name and signature of the console command. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $signature = 'myriad-download:contacts |
|
16
|
|
|
{start=1 : Start contact ID} |
|
17
|
|
|
{--count=1000 : Count identifiers} |
|
18
|
|
|
{--queue=sync : Queue name} |
|
19
|
|
|
'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The console command description. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $description = 'Download/Update myriad contact'; |
|
27
|
|
|
|
|
28
|
4 |
|
public function handle() |
|
29
|
|
|
{ |
|
30
|
4 |
|
$start = (int) $this->argument('start'); |
|
31
|
4 |
|
if ($start <= 0) { |
|
32
|
1 |
|
$this->error("Invalid start value [$start]"); |
|
33
|
|
|
|
|
34
|
1 |
|
return 1; |
|
35
|
|
|
} |
|
36
|
4 |
|
$count = (int) $this->option('count'); |
|
37
|
4 |
|
if ($count <= 0 || $count > 100000) { |
|
38
|
1 |
|
$this->error("Invalid count value [$count]"); |
|
39
|
|
|
|
|
40
|
1 |
|
return 1; |
|
41
|
|
|
} |
|
42
|
3 |
|
$queue = (string) $this->option('queue'); |
|
43
|
|
|
|
|
44
|
3 |
|
if ($queue === 'sync') { |
|
45
|
2 |
|
$successDownloads = 0; |
|
46
|
2 |
|
$errorDownloads = 0; |
|
47
|
|
|
|
|
48
|
2 |
|
for ($i = $start; $i < ($start + $count); $i++) { |
|
49
|
|
|
try { |
|
50
|
2 |
|
$myriadContact = (new \MyriadDataStore\Actions\DownloadMyriadContact()) |
|
51
|
2 |
|
->execute($i); |
|
52
|
1 |
|
if ($myriadContact) { |
|
53
|
1 |
|
$successDownloads++; |
|
54
|
|
|
} else { |
|
55
|
1 |
|
$errorDownloads++; |
|
56
|
|
|
} |
|
57
|
1 |
|
} catch (MyriadSoapException $e) { |
|
58
|
1 |
|
$this->error("Contact [$i] error: " . $e->getMessage()); |
|
59
|
1 |
|
$errorDownloads++; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
if ($errorDownloads == 0) { |
|
|
|
|
|
|
64
|
1 |
|
$this->info("Successful downloaded: {$successDownloads} contacts."); |
|
65
|
|
|
} else { |
|
66
|
1 |
|
$this->warn("Successful downloaded: {$successDownloads} contacts."); |
|
67
|
2 |
|
$this->warn("Downloads fails: {$errorDownloads} contacts."); |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
1 |
|
\MyriadDataStore\Jobs\DownloadMyriadContacts::dispatch($start, $count)->onQueue($queue); |
|
71
|
1 |
|
$this->info("Job sent to queue [$queue]."); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
return 0; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|