Skip to content

Commit 715ba2d

Browse files
authored
Merge pull request #57 from IFRCGo/staging
Staging
2 parents 76db396 + bfbd7f0 commit 715ba2d

26 files changed

Lines changed: 2228 additions & 3 deletions

app/Providers/RepositoryServiceProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,21 @@ public function register()
5050
'App\Classes\Repositories\SupportingMessageRepositoryInterface',
5151
'App\Classes\Repositories\SupportingMessageRepository'
5252
);
53+
54+
// Legacy Bindings
55+
$this->app->bind(
56+
'App\Legacy\Classes\Repositories\OrganisationRepositoryInterface',
57+
'App\Legacy\Classes\Repositories\OrganisationRepository'
58+
);
59+
60+
$this->app->bind(
61+
'App\Legacy\Classes\Repositories\WhatNowRepositoryInterface',
62+
'App\Legacy\Classes\Repositories\WhatNowRepository'
63+
);
64+
65+
$this->app->bind(
66+
'App\Legacy\Classes\Repositories\WhatNowTranslationRepositoryInterface',
67+
'App\Legacy\Classes\Repositories\WhatNowTranslationRepository'
68+
);
5369
}
5470
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
},
4646
"autoload": {
4747
"psr-4": {
48-
"App\\": "app/"
48+
"App\\": "app/",
49+
"App\\Legacy\\": "legacy/app/"
4950
},
5051
"classmap": [
5152
"database/seeds",

config/filesystems.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
return [
44

5+
'bucket_name' => env('BUCKET_NAME', 'smdbstorageaccount'),
6+
57
/*
68
|--------------------------------------------------------------------------
79
| Default Filesystem Disk
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\Schema;
5+
6+
class CreateLegacyTables extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
* Drop all legacy tables in reverse dependency order to respect foreign key constraints.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('legacy_applications', function ($table) {
17+
$table->increments('id');
18+
$table->integer('tenant_id');
19+
$table->string('tenant_user_id');
20+
$table->string('name');
21+
$table->text('description')->nullable();
22+
$table->string('key')->unique('legacy_applications_key_unique');
23+
$table->timestamp('created_at')->nullable();
24+
$table->timestamp('updated_at')->nullable();
25+
$table->timestamp('deleted_at')->nullable();
26+
$table->bigInteger('estimated_users_count')->nullable();
27+
});
28+
Schema::table('legacy_applications', function ($table) {
29+
$table->index(['tenant_id', 'tenant_user_id'], 'legacy_applications_tenant_id_tenant_user_id_index');
30+
});
31+
32+
Schema::create('legacy_organisations', function ($table) {
33+
$table->increments('id');
34+
$table->string('country_code', 3);
35+
$table->string('org_name');
36+
$table->string('oid_code');
37+
$table->string('attribution_url')->nullable();
38+
$table->string('attribution_file_name')->nullable();
39+
});
40+
Schema::table('legacy_organisations', function ($table) {
41+
$table->index('country_code', 'legacy_organisations_country_code_index');
42+
});
43+
44+
Schema::create('legacy_organisation_details', function ($table) {
45+
$table->increments('id');
46+
$table->unsignedInteger('org_id');
47+
$table->string('language_code', 10)->nullable();
48+
$table->string('org_name');
49+
$table->text('attribution_message')->nullable();
50+
$table->tinyInteger('published');
51+
$table->unique(['org_id', 'language_code'], 'legacy_organisation_details_org_id_language_code_unique');
52+
$table->foreign('org_id', 'legacy_organisation_details_org_id_foreign')
53+
->references('id')->on('legacy_organisations')
54+
->onDelete('cascade');
55+
});
56+
57+
Schema::create('legacy_region_translations', function ($table) {
58+
$table->increments('id');
59+
$table->unsignedInteger('region_id');
60+
$table->string('language_code', 10)->nullable();
61+
$table->string('title');
62+
$table->text('description')->nullable();
63+
$table->timestamp('created_at')->nullable();
64+
$table->timestamp('updated_at')->nullable();
65+
$table->index('region_id', 'legacy_region_translations_region_id_index');
66+
});
67+
68+
Schema::create('legacy_regions', function ($table) {
69+
$table->increments('id');
70+
$table->unsignedInteger('organisation_id');
71+
$table->string('title');
72+
$table->string('slug');
73+
$table->timestamp('created_at')->nullable();
74+
$table->timestamp('updated_at')->nullable();
75+
$table->index('organisation_id', 'legacy_regions_organisation_id_index');
76+
$table->index('slug', 'legacy_regions_slug_index');
77+
});
78+
79+
Schema::create('legacy_whatnow_entities', function ($table) {
80+
$table->increments('id');
81+
$table->unsignedInteger('org_id');
82+
$table->integer('region_id')->nullable();
83+
$table->string('event_type');
84+
$table->timestamp('created_at')->nullable();
85+
$table->timestamp('updated_at')->nullable();
86+
$table->unique(['org_id', 'event_type', 'region_id'], 'legacy_whatnow_entities_org_id_event_type_region_id_unique');
87+
$table->index(['org_id', 'event_type'], 'legacy_whatnow_entities_org_id_event_type_index');
88+
$table->index('region_id', 'legacy_whatnow_entities_region_id_index');
89+
});
90+
91+
Schema::create('legacy_whatnow_entity_translations', function ($table) {
92+
$table->increments('id');
93+
$table->unsignedInteger('entity_id');
94+
$table->string('language_code', 10)->nullable();
95+
$table->string('title')->nullable();
96+
$table->text('description')->nullable();
97+
$table->string('web_url', 512)->nullable();
98+
$table->timestamp('created_at')->nullable();
99+
$table->timestamp('published_at')->nullable();
100+
$table->foreign('entity_id', 'legacy_whatnow_entity_translations_entity_id_foreign')
101+
->references('id')->on('legacy_whatnow_entities')
102+
->onDelete('cascade');
103+
});
104+
105+
Schema::create('legacy_whatnow_entity_stages', function ($table) {
106+
$table->increments('id');
107+
$table->unsignedInteger('translation_id');
108+
$table->string('language_code', 10)->nullable();
109+
$table->enum('stage', ['warning', 'watch', 'immediate', 'recover', 'mitigation', 'seasonalForecast']);
110+
$table->json('content')->nullable();
111+
$table->foreign('translation_id', 'legacy_whatnow_entity_stages_translation_id_foreign')
112+
->references('id')->on('legacy_whatnow_entity_translations')
113+
->onDelete('cascade');
114+
$table->index('translation_id', 'legacy_whatnow_entity_stages_translation_id_index');
115+
});
116+
}
117+
118+
/**
119+
* Reverse the migrations.
120+
* Drop all legacy tables in reverse dependency order to respect foreign key constraints.
121+
*
122+
* @return void
123+
*/
124+
public function down()
125+
{
126+
Schema::disableForeignKeyConstraints();
127+
128+
Schema::dropIfExists('legacy_whatnow_entity_stages');
129+
Schema::dropIfExists('legacy_whatnow_entity_translations');
130+
Schema::dropIfExists('legacy_whatnow_entities');
131+
Schema::dropIfExists('legacy_region_translations');
132+
Schema::dropIfExists('legacy_regions');
133+
Schema::dropIfExists('legacy_organisation_details');
134+
Schema::dropIfExists('legacy_organisations');
135+
Schema::dropIfExists('legacy_applications');
136+
137+
Schema::enableForeignKeyConstraints();
138+
}
139+
}
140+
141+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Legacy\Classes\Feeds;
4+
5+
interface JsonFeedInterface
6+
{
7+
/**
8+
* @return array
9+
*/
10+
public function getResponseData();
11+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
3+
namespace App\Legacy\Classes\Feeds;
4+
5+
use Illuminate\Database\Eloquent\Collection;
6+
use League\Fractal\Manager;
7+
use App\Legacy\Classes\Repositories\WhatNowRepositoryInterface;
8+
use App\Legacy\Classes\Repositories\WhatNowTranslationRepositoryInterface;
9+
use App\Legacy\Classes\Serializers\CustomDataSerializer;
10+
use App\Legacy\Classes\Transformers\WhatNowEntityTransformer;
11+
use App\Legacy\Models\Organisation;
12+
use App\Legacy\Models\WhatNowEntity;
13+
14+
class WhatNowFeed implements JsonFeedInterface
15+
{
16+
/**
17+
* @var string
18+
*/
19+
protected $language;
20+
21+
/**
22+
* @var Organisation
23+
*/
24+
protected $organisation;
25+
26+
/**
27+
* @var WhatNowRepositoryInterface
28+
*/
29+
protected $whatNowRepo;
30+
31+
/**
32+
* @var WhatNowTranslationRepositoryInterface
33+
*/
34+
protected $whatNowTransRepo;
35+
36+
/**
37+
* @var WhatNowEntityTransformer
38+
*/
39+
protected $transformer;
40+
41+
/**
42+
* @var array
43+
*/
44+
protected $filterEventTypes = [];
45+
46+
/**
47+
* @var Manager
48+
*/
49+
protected $responseManager;
50+
51+
/**
52+
* @var
53+
*/
54+
protected $collection = null;
55+
56+
/**
57+
* @param WhatNowRepositoryInterface $whatNowRepo
58+
* @param WhatNowTranslationRepositoryInterface $whatNowTransRepo
59+
* @param Manager $responseManager
60+
* @param WhatNowEntityTransformer $transformer
61+
*/
62+
public function __construct(
63+
WhatNowRepositoryInterface $whatNowRepo,
64+
WhatNowTranslationRepositoryInterface $whatNowTransRepo,
65+
Manager $responseManager,
66+
WhatNowEntityTransformer $transformer
67+
) {
68+
$this->whatNowRepo = $whatNowRepo;
69+
$this->whatNowTransRepo = $whatNowTransRepo;
70+
$this->responseManager = $responseManager;
71+
$this->transformer = $transformer;
72+
73+
$this->responseManager->setSerializer(new CustomDataSerializer());
74+
}
75+
76+
/**
77+
* @param Organisation $org
78+
* @return $this
79+
*/
80+
public function setOrganisation(Organisation $org)
81+
{
82+
$this->organisation = $org;
83+
84+
return $this;
85+
}
86+
87+
/**
88+
* @param string $lang
89+
* @return $this
90+
*/
91+
public function setLanguage($lang = 'en_US')
92+
{
93+
// @todo validate locale
94+
$this->language = $lang;
95+
96+
return $this;
97+
}
98+
99+
/**
100+
* @param null $types
101+
* @return $this
102+
*/
103+
public function setEventTypeFilter($types = null)
104+
{
105+
if (is_array($types)) {
106+
$this->filterEventTypes = $types;
107+
}
108+
109+
if (is_string($types)) {
110+
$this->filterEventTypes = explode(',', $types);
111+
}
112+
113+
return $this;
114+
}
115+
116+
public function loadData()
117+
{
118+
$data = $this->whatNowRepo->findItemsForOrgId(
119+
$this->organisation->id,
120+
$this->language,
121+
$this->filterEventTypes
122+
);
123+
124+
if ($data instanceof Collection) {
125+
126+
127+
$this->collection = $data->reject(function(WhatNowEntity $entity){
128+
129+
return ($this->whatNowTransRepo->getLatestPublishedTranslations($entity->id)->count() === 0);
130+
});
131+
}
132+
}
133+
134+
public function getCollection()
135+
{
136+
return $this->collection;
137+
}
138+
139+
public function getResponseData()
140+
{
141+
$resource = new \League\Fractal\Resource\Collection($this->collection, $this->transformer);
142+
$rootScope = $this->responseManager->createData($resource);
143+
return $rootScope->toArray();
144+
}
145+
}

0 commit comments

Comments
 (0)