Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,21 @@ public function register()
'App\Classes\Repositories\SupportingMessageRepositoryInterface',
'App\Classes\Repositories\SupportingMessageRepository'
);

// Legacy Bindings
$this->app->bind(
'App\Legacy\Classes\Repositories\OrganisationRepositoryInterface',
'App\Legacy\Classes\Repositories\OrganisationRepository'
);

$this->app->bind(
'App\Legacy\Classes\Repositories\WhatNowRepositoryInterface',
'App\Legacy\Classes\Repositories\WhatNowRepository'
);

$this->app->bind(
'App\Legacy\Classes\Repositories\WhatNowTranslationRepositoryInterface',
'App\Legacy\Classes\Repositories\WhatNowTranslationRepository'
);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"autoload": {
"psr-4": {
"App\\": "app/"
"App\\": "app/",
"App\\Legacy\\": "legacy/app/"
},
"classmap": [
"database/seeds",
Expand Down
2 changes: 2 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

return [

'bucket_name' => env('BUCKET_NAME', 'smdbstorageaccount'),

/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
Expand Down
141 changes: 141 additions & 0 deletions database/migrations/2026_02_20_000000_create_legacy_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

class CreateLegacyTables extends Migration
{
/**
* Run the migrations.
* Drop all legacy tables in reverse dependency order to respect foreign key constraints.
*
* @return void
*/
public function up()
{
Schema::create('legacy_applications', function ($table) {
$table->increments('id');
$table->integer('tenant_id');
$table->string('tenant_user_id');
$table->string('name');
$table->text('description')->nullable();
$table->string('key')->unique('legacy_applications_key_unique');
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->bigInteger('estimated_users_count')->nullable();
});
Schema::table('legacy_applications', function ($table) {
$table->index(['tenant_id', 'tenant_user_id'], 'legacy_applications_tenant_id_tenant_user_id_index');
});

Schema::create('legacy_organisations', function ($table) {
$table->increments('id');
$table->string('country_code', 3);
$table->string('org_name');
$table->string('oid_code');
$table->string('attribution_url')->nullable();
$table->string('attribution_file_name')->nullable();
});
Schema::table('legacy_organisations', function ($table) {
$table->index('country_code', 'legacy_organisations_country_code_index');
});

Schema::create('legacy_organisation_details', function ($table) {
$table->increments('id');
$table->unsignedInteger('org_id');
$table->string('language_code', 10)->nullable();
$table->string('org_name');
$table->text('attribution_message')->nullable();
$table->tinyInteger('published');
$table->unique(['org_id', 'language_code'], 'legacy_organisation_details_org_id_language_code_unique');
$table->foreign('org_id', 'legacy_organisation_details_org_id_foreign')
->references('id')->on('legacy_organisations')
->onDelete('cascade');
});

Schema::create('legacy_region_translations', function ($table) {
$table->increments('id');
$table->unsignedInteger('region_id');
$table->string('language_code', 10)->nullable();
$table->string('title');
$table->text('description')->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->index('region_id', 'legacy_region_translations_region_id_index');
});

Schema::create('legacy_regions', function ($table) {
$table->increments('id');
$table->unsignedInteger('organisation_id');
$table->string('title');
$table->string('slug');
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->index('organisation_id', 'legacy_regions_organisation_id_index');
$table->index('slug', 'legacy_regions_slug_index');
});

Schema::create('legacy_whatnow_entities', function ($table) {
$table->increments('id');
$table->unsignedInteger('org_id');
$table->integer('region_id')->nullable();
$table->string('event_type');
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->unique(['org_id', 'event_type', 'region_id'], 'legacy_whatnow_entities_org_id_event_type_region_id_unique');
$table->index(['org_id', 'event_type'], 'legacy_whatnow_entities_org_id_event_type_index');
$table->index('region_id', 'legacy_whatnow_entities_region_id_index');
});

Schema::create('legacy_whatnow_entity_translations', function ($table) {
$table->increments('id');
$table->unsignedInteger('entity_id');
$table->string('language_code', 10)->nullable();
$table->string('title')->nullable();
$table->text('description')->nullable();
$table->string('web_url', 512)->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('published_at')->nullable();
$table->foreign('entity_id', 'legacy_whatnow_entity_translations_entity_id_foreign')
->references('id')->on('legacy_whatnow_entities')
->onDelete('cascade');
});

Schema::create('legacy_whatnow_entity_stages', function ($table) {
$table->increments('id');
$table->unsignedInteger('translation_id');
$table->string('language_code', 10)->nullable();
$table->enum('stage', ['warning', 'watch', 'immediate', 'recover', 'mitigation', 'seasonalForecast']);
$table->json('content')->nullable();
$table->foreign('translation_id', 'legacy_whatnow_entity_stages_translation_id_foreign')
->references('id')->on('legacy_whatnow_entity_translations')
->onDelete('cascade');
$table->index('translation_id', 'legacy_whatnow_entity_stages_translation_id_index');
});
}

/**
* Reverse the migrations.
* Drop all legacy tables in reverse dependency order to respect foreign key constraints.
*
* @return void
*/
public function down()
{
Schema::disableForeignKeyConstraints();

Schema::dropIfExists('legacy_whatnow_entity_stages');
Schema::dropIfExists('legacy_whatnow_entity_translations');
Schema::dropIfExists('legacy_whatnow_entities');
Schema::dropIfExists('legacy_region_translations');
Schema::dropIfExists('legacy_regions');
Schema::dropIfExists('legacy_organisation_details');
Schema::dropIfExists('legacy_organisations');
Schema::dropIfExists('legacy_applications');

Schema::enableForeignKeyConstraints();
}
}


11 changes: 11 additions & 0 deletions legacy/app/Classes/Feeds/JsonFeedInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Legacy\Classes\Feeds;

interface JsonFeedInterface
{
/**
* @return array
*/
public function getResponseData();
}
145 changes: 145 additions & 0 deletions legacy/app/Classes/Feeds/WhatNowFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace App\Legacy\Classes\Feeds;

use Illuminate\Database\Eloquent\Collection;
use League\Fractal\Manager;
use App\Legacy\Classes\Repositories\WhatNowRepositoryInterface;
use App\Legacy\Classes\Repositories\WhatNowTranslationRepositoryInterface;
use App\Legacy\Classes\Serializers\CustomDataSerializer;
use App\Legacy\Classes\Transformers\WhatNowEntityTransformer;
use App\Legacy\Models\Organisation;
use App\Legacy\Models\WhatNowEntity;

class WhatNowFeed implements JsonFeedInterface
{
/**
* @var string
*/
protected $language;

/**
* @var Organisation
*/
protected $organisation;

/**
* @var WhatNowRepositoryInterface
*/
protected $whatNowRepo;

/**
* @var WhatNowTranslationRepositoryInterface
*/
protected $whatNowTransRepo;

/**
* @var WhatNowEntityTransformer
*/
protected $transformer;

/**
* @var array
*/
protected $filterEventTypes = [];

/**
* @var Manager
*/
protected $responseManager;

/**
* @var
*/
protected $collection = null;

/**
* @param WhatNowRepositoryInterface $whatNowRepo
* @param WhatNowTranslationRepositoryInterface $whatNowTransRepo
* @param Manager $responseManager
* @param WhatNowEntityTransformer $transformer
*/
public function __construct(
WhatNowRepositoryInterface $whatNowRepo,
WhatNowTranslationRepositoryInterface $whatNowTransRepo,
Manager $responseManager,
WhatNowEntityTransformer $transformer
) {
$this->whatNowRepo = $whatNowRepo;
$this->whatNowTransRepo = $whatNowTransRepo;
$this->responseManager = $responseManager;
$this->transformer = $transformer;

$this->responseManager->setSerializer(new CustomDataSerializer());
}

/**
* @param Organisation $org
* @return $this
*/
public function setOrganisation(Organisation $org)
{
$this->organisation = $org;

return $this;
}

/**
* @param string $lang
* @return $this
*/
public function setLanguage($lang = 'en_US')
{
// @todo validate locale
$this->language = $lang;

return $this;
}

/**
* @param null $types
* @return $this
*/
public function setEventTypeFilter($types = null)
{
if (is_array($types)) {
$this->filterEventTypes = $types;
}

if (is_string($types)) {
$this->filterEventTypes = explode(',', $types);
}

return $this;
}

public function loadData()
{
$data = $this->whatNowRepo->findItemsForOrgId(
$this->organisation->id,
$this->language,
$this->filterEventTypes
);

if ($data instanceof Collection) {


$this->collection = $data->reject(function(WhatNowEntity $entity){

return ($this->whatNowTransRepo->getLatestPublishedTranslations($entity->id)->count() === 0);
});
}
}

public function getCollection()
{
return $this->collection;
}

public function getResponseData()
{
$resource = new \League\Fractal\Resource\Collection($this->collection, $this->transformer);
$rootScope = $this->responseManager->createData($resource);
return $rootScope->toArray();
}
}
Loading
Loading