Skip to content

Commit

Permalink
Introduce public corporation history updater
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent committed Jan 17, 2019
1 parent b34a2ad commit c23fecd
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/Jobs/Character/PublicCorporationHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Eveapi\Jobs\Character;

use Seat\Eveapi\Jobs\EsiBase;
use Seat\Eveapi\Models\Character\CharacterCorporationHistory;
use Seat\Web\Models\User;

class PublicCorporationHistory extends EsiBase
{
/**
* @var string
*/
protected $method = 'get';

/**
* @var string
*/
protected $endpoint = '/characters/{character_id}/corporationhistory/';

/**
* @var int
*/
protected $version = 'v1';

/**
* @var array
*/
protected $tags = ['character', 'corporation_history'];

/**
* Execute the job.
*
* @return void
* @throws \Exception
* @throws \Throwable
*/
public function handle()
{

if (! $this->preflighted()) return;

$character_ids = User::doesntHave('refresh_token')
->select('id')
->where('id', '<>', 1)
->get()
->pluck('id');

$character_ids->each(function ($character_id) {

$corporation_history = $this->retrieve([
'character_id' => $character_id,
]);

if ($corporation_history->isCachedLoad()) return;

collect($corporation_history)->each(function ($corporation) use ($character_id) {

CharacterCorporationHistory::firstOrCreate([
'character_id' => $character_id,
'record_id' => $corporation->record_id,
], [
'start_date' => carbon($corporation->start_date),
'corporation_id' => $corporation->corporation_id,
'is_deleted' => isset($corporation->is_deleted) ? $corporation->is_deleted : false,
]);
});
});


}
}

0 comments on commit c23fecd

Please sign in to comment.