1 | <?php |
||
2 | |||
3 | namespace MyriadDataStore\Actions; |
||
4 | |||
5 | use Illuminate\Support\Str; |
||
6 | use MyriadDataStore\Models\MyriadTitle; |
||
7 | use MyriadSoap\Exceptions\UnexpectedTypeException; |
||
8 | use MyriadSoap\MyriadSoap; |
||
9 | |||
10 | class DownloadMyriadTitles |
||
11 | { |
||
12 | use UsesCollectionFormat; |
||
13 | |||
14 | public static ?array $collectionFormat = null; |
||
15 | |||
16 | 1 | protected function defaultCollectionFormat(): array |
|
17 | { |
||
18 | 1 | return [ |
|
19 | 1 | 'Title_ID' => fn ($i) => (int) tap($i, fn () => throw_if(!is_numeric($i), UnexpectedTypeException::class)), |
|
20 | 1 | 'Title' => fn ($i) => (string) $i, |
|
21 | 1 | 'ProductType_ID' => fn ($i) => (int) tap($i, fn () => throw_if(!is_numeric($i), UnexpectedTypeException::class)), |
|
22 | 1 | 'Current_Issue_ID' => fn ($i) => (int) tap($i, fn () => throw_if(!is_numeric($i), UnexpectedTypeException::class)), |
|
23 | 1 | 'Active' => fn ($i) => $i == 'Yes', |
|
24 | 1 | ]; |
|
25 | } |
||
26 | |||
27 | 1 | public function execute(): int |
|
28 | { |
||
29 | 1 | $formattedCollection = MyriadSoap::SOAP_getTitles_Collection([], $this->collectionFormat()); |
|
30 | |||
31 | 1 | $count = 0; |
|
32 | 1 | foreach ($formattedCollection as $item) { |
|
33 | 1 | $myriadModel = MyriadTitle::find($item['Title_ID']); |
|
34 | 1 | if (!$myriadModel) { |
|
35 | 1 | $myriadModel = new MyriadTitle; |
|
36 | 1 | $myriadModel->id = $item['Title_ID']; |
|
37 | } |
||
38 | 1 | $myriadModel->title = Str::limit($item['Title'], 252); |
|
0 ignored issues
–
show
|
|||
39 | 1 | $myriadModel->product_type_id = $item['ProductType_ID']; |
|
0 ignored issues
–
show
|
|||
40 | 1 | $myriadModel->current_issue_id = $item['Current_Issue_ID']; |
|
0 ignored issues
–
show
|
|||
41 | 1 | $myriadModel->active = $item['Active']; |
|
0 ignored issues
–
show
|
|||
42 | 1 | $myriadModel->save(); |
|
43 | 1 | $count++; |
|
44 | } |
||
45 | |||
46 | 1 | return $count; |
|
47 | } |
||
48 | } |
||
49 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.