-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare job for missing corporation contact labels according to ccp-z…
…oetrope feedback esi/esi-issues#779 (#68)
- Loading branch information
Showing
3 changed files
with
195 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,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\Contacts\Corporation; | ||
|
||
use Seat\Eveapi\Jobs\EsiBase; | ||
use Seat\Eveapi\Models\Contacts\CorporationContactLabel; | ||
|
||
/** | ||
* Class Labels. | ||
* @package Seat\Eveapi\Jobs\Contacts\Corporation | ||
*/ | ||
class Labels extends EsiBase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $method = 'get'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $endpoint = '/corporations/{corporation_id}/contacts/labels/'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $version = 'v1'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $scope = 'esi-corporations.read_contacts.v1'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $tags = ['corporation', 'contacts', 'labels']; | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
* @throws \Exception | ||
* @throws \Throwable | ||
*/ | ||
public function handle() | ||
{ | ||
|
||
if (! $this->authenticated()) return; | ||
|
||
$labels = $this->retrieve([ | ||
'corporation_id' => $this->getCorporationId(), | ||
]); | ||
|
||
if ($labels->isCachedLoad()) return; | ||
|
||
collect($labels)->each(function ($label) { | ||
|
||
CorporationContactLabel::firstOrNew([ | ||
'corporation_id' => $this->getCorporationId(), | ||
'label_id' => $label->label_id, | ||
])->fill([ | ||
'label_name' => $label->label_name, | ||
])->save(); | ||
}); | ||
|
||
CorporationContactLabel::where('corporation_id', $this->getCorporationId()) | ||
->whereNotIn('label_id', collect($labels)->pluck('label_id')->flatten()->all()) | ||
->delete(); | ||
} | ||
} |
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,45 @@ | ||
<?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\Models\Contacts; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Seat\Eveapi\Traits\HasCompositePrimaryKey; | ||
|
||
/** | ||
* Class CorporationContactLabel. | ||
* @package Seat\Eveapi\Models\Contacts | ||
*/ | ||
class CorporationContactLabel extends Model | ||
{ | ||
use HasCompositePrimaryKey; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected static $unguarded = true; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $primaryKey = ['corporation_id', 'label_id']; | ||
} |
59 changes: 59 additions & 0 deletions
59
src/database/migrations/2018_04_23_221712_create_corporation_contact_labels_table.php
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,59 @@ | ||
<?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. | ||
*/ | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateCorporationContactLabelsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
|
||
Schema::create('corporation_contact_labels', function (Blueprint $table) { | ||
|
||
$table->bigInteger('corporation_id'); | ||
$table->bigInteger('label_id'); | ||
$table->string('label_name'); | ||
|
||
$table->primary(['corporation_id', 'label_id']); | ||
|
||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
|
||
Schema::dropIfExists('corporation_contact_labels'); | ||
} | ||
} |