Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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');
         })->pluck('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 ($message_ids->chunk(10) as $message_id_chunk) {
             try {
                 $result = $pheal->MailBodies(['characterID' => $character->characterID, 'ids' => $message_id_chunk->implode(',')]);
                 foreach ($result->messages as $body) {
                     MailMessageBody::firstOrCreate(['messageID' => $body->messageID, 'body' => mb_convert_encoding($body->__toString(), 'HTML-ENTITIES', 'UTF-8')]);
                 }
             } catch (PhealException $e) {
                 // TODO: Log this into some form of job log.
                 continue;
             }
         }
         // Foreach messageID chunk
     }
     return;
 }