Skip to content

Commit

Permalink
Merge pull request #1000 from owlchester/module-config-export-import
Browse files Browse the repository at this point in the history
Exporting and importing custom entity types
  • Loading branch information
ilestis authored Jan 28, 2025
2 parents ca5f31c + 75664e2 commit 0160602
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Services/Campaign/ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function export(): self
->info()
->campaignJson()
->campaignModules()
->customCampaignModules()
->entities()
->gallery()
->finish()
Expand Down Expand Up @@ -146,6 +147,15 @@ protected function campaignModules(): self
return $this;
}

protected function customCampaignModules(): self
{
$settings = $this->campaign->entityTypes->where('is_special', 1)->select('id', 'code', 'is_enabled', 'singular', 'plural', 'icon')->toArray();
$this->archive->add(json_encode($settings), 'settings/custom-modules.json', );
$this->files++;

return $this;
}

protected function prepare(): self
{
$this->exportPath = '/exports/campaigns/';
Expand Down
17 changes: 17 additions & 0 deletions app/Services/Campaign/Import/ImportIdMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class ImportIdMapper
{
protected array $misc = [];
protected array $customEntityTypes = [];
protected array $entities = [];
protected array $gallery = [];
protected array $posts = [];
Expand All @@ -23,6 +24,12 @@ public function putEntity(int $old, int $new): self
return $this;
}

public function putCustomEntityType(int $old, int $new): self
{
$this->customEntityTypes[$old] = $new;
return $this;
}

public function putGallery(string $old, string $new): self
{
$this->gallery[$old] = $new;
Expand Down Expand Up @@ -64,6 +71,16 @@ public function hasEntity(int $old): bool
return !empty($this->entities[$old]);
}

public function getCustomEntityType(int $old): int
{
return $this->customEntityTypes[$old];
}

public function hasOldEntityType(int $old): bool
{
return !empty($this->customEntityTypes[$old]);
}

public function getGallery(string $old): string
{
return $this->gallery[$old];
Expand Down
29 changes: 29 additions & 0 deletions app/Services/Campaign/Import/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use App\Facades\MapMarkerCache;
use App\Facades\QuestCache;
use App\Facades\TimelineElementCache;
use App\Facades\ImportIdMapper;
use App\Models\CampaignImport;
use App\Models\EntityType;
use App\Notifications\Header;
use App\Services\Campaign\Import\Mappers\AbilityMapper;
use App\Services\Campaign\Import\Mappers\CalendarMapper;
Expand Down Expand Up @@ -165,6 +167,7 @@ protected function process()
try {
$this->importCampaign()
->moduleSettings()
->customModules()
->gallery()
->entities()
->secondCampaign()
Expand Down Expand Up @@ -288,6 +291,32 @@ protected function moduleSettings(): self
return $this;
}

protected function customModules(): self
{
// Open the campaign settings file
$data = $this->open('settings/custom-modules.json');

if (!$data || !$this->campaign->premium()) {
return $this;
}

foreach ($data as $module) {
$newModule = new EntityType();
$newModule->campaign_id = $this->campaign->id;
$newModule->is_special = true;
$newModule->is_enabled = $module['is_enabled'];
$newModule->singular = $module['singular'];
$newModule->plural = $module['plural'];
$newModule->icon = $module['icon'];
$newModule->icon = $module['code'];
$newModule->save();

ImportIdMapper::putCustomEntityType($module['id'], $newModule->id);
}

return $this;
}

protected function entities(): self
{
/**
Expand Down

0 comments on commit 0160602

Please sign in to comment.