/** * Run the Update * * @return mixed|void */ public function call() { $pheal = $this->setScope('char')->getPheal(); foreach ($this->api_info->characters as $character) { // Get a list of messageIDs that we do not have mail // bodies for. These ID's will be used to try and // pull the bodies using this api key $message_ids = DB::table('character_mail_messages')->where('characterID', $character->characterID)->whereNotIn('messageID', function ($query) { $query->select('messageID')->from('character_mail_message_bodies'); })->lists('messageID'); // It is possible to provide a comma seperated list // of messageIDs to the MailBodies endpoint. Pheal // caches XML's on disk by file name. To prevent file // names from becoming too long, we will chunk the // ids we want to update. foreach (array_chunk($message_ids, 10) as $message_id_chunk) { $result = $pheal->MailBodies(['characterID' => $character->characterID, 'ids' => implode(',', $message_id_chunk)]); foreach ($result->messages as $body) { MailMessageBody::create(['messageID' => $body->messageID, 'body' => $body->__toString()]); } } // Foreach messageID chunk } return; }