diff --git a/src/Jobs/Contacts/Corporation/Labels.php b/src/Jobs/Contacts/Corporation/Labels.php new file mode 100644 index 00000000..4219b57d --- /dev/null +++ b/src/Jobs/Contacts/Corporation/Labels.php @@ -0,0 +1,91 @@ +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(); + } +} diff --git a/src/Models/Contacts/CorporationContactLabel.php b/src/Models/Contacts/CorporationContactLabel.php new file mode 100644 index 00000000..6c4f81ed --- /dev/null +++ b/src/Models/Contacts/CorporationContactLabel.php @@ -0,0 +1,45 @@ +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'); + } +}