forked from eveseat/eveapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce public corporation history updater
- Loading branch information
1 parent
b34a2ad
commit c23fecd
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]); | ||
}); | ||
}); | ||
|
||
|
||
} | ||
} |