Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce public corporation history updater #143

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/Jobs/Character/PublicCorporationHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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,
]);
});
});

}
}