public function importItems(): void
{
$response = $this->getItemsByApiFistPage();
$newestId = $response->results[0]->id;
if (Item::where('kodik_id', $newestId)->first()) {
return;
} else {
$savedItems = Item::all(['kodik_id', 'shikimori_id', 'worldart_link']);
$savedItemsIds = [];
foreach ($savedItems as $savedItem) {
$savedItemsIds['kodik_id'][$savedItem->kodik_id] = true;
$savedItemsIds['shikimori_id'][$savedItem->shikimori_id] = true;
$savedItemsIds['worldart_link'][$savedItem->worldart_link] = true;
}
}
do {
$items = $response->results;
$nextPage = $response->next_page;
foreach ($items as $item) {
if (
isset($item->shikimori_id) and isset($savedItemsIds['shikimori_id'][$item->shikimori_id])
) {
continue;
} elseif (isset($item->worldart_link) and isset($savedItemsIds['worldart_link'][$item->worldart_link])) {
continue;
}
$itemDTO = new ItemDTO($item);
Item::create($itemDTO());
}
} while (
$nextPage
? ($response = $this->getItemsByApiNextPage($nextPage))
: null
);