/** * Execute the console command. * * @return void */ public function fire() { $api = new ItemAPI(); // Get the list of all available items and see which // ones are not in the database yet $available_ids = $api->getList(); $existing_ids = Item::lists('id'); $new_ids = array_diff($available_ids, $existing_ids); $this->info('Found ' . count($new_ids) . ' new items'); // For each new item, add a queue to grab the detail stuff foreach ($new_ids as $id) { Queue::push(new UpdateItemDetails($id)); } $this->info('Done adding queue entries'); }
/** * Execute the job. */ public function handle() { $api = new ItemAPI(); $item = Item::findOrNew($this->id); // Item didn't exist yet, so set the model id if (!$item->exists) { $item->id = $this->id; } // Let's grab some details from the API $details['en'] = $api->getDetails($this->id, 'en'); $details['de'] = $api->getDetails($this->id, 'de'); $details['fr'] = $api->getDetails($this->id, 'fr'); $details['es'] = $api->getDetails($this->id, 'es'); // Save the details in the model after some transformation $item = $this->processDetails($item, $details); // Fire off post processing events $response = Event::fire(new ItemDetailsUpdated($item)); // Save the item after post processing $item = array_pop($response); $item->save(); }