-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1457 from younginnovations/1407-check-use-of-upda…
…ted-iati-codelists Review:1407-check-use-of-updated-iati-codelists
- Loading branch information
Showing
268 changed files
with
44,434 additions
and
33,264 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
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
126 changes: 126 additions & 0 deletions
126
app/Console/Commands/Issue1407CheckUseOfUpdatedIatiCodelists.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,126 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\IATI\Models\Activity\Activity; | ||
use App\IATI\Models\Activity\Indicator; | ||
use App\IATI\Models\Activity\Period; | ||
use App\IATI\Models\Activity\Result; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class Issue1407CheckUseOfUpdatedIatiCodelists extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'command:Issue1407CheckUseOfUpdatedIatiCodelists'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Refresh deprecation list for data prior to this change.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$dataModelMappedToHelperMidfix = [ | ||
'activity' => Activity::class, | ||
'result' => Result::class, | ||
'indicator' => Indicator::class, | ||
'period' => Period::class, | ||
]; | ||
|
||
$AttributesMappedToHelperMidfix = [ | ||
'activity' => [ | ||
'id', | ||
'iati_identifier', | ||
'other_identifier', | ||
'title', | ||
'description', | ||
'activity_status', | ||
'status', | ||
'activity_date', | ||
'contact_info', | ||
'activity_scope', | ||
'participating_org', | ||
'recipient_country', | ||
'recipient_region', | ||
'location', | ||
'sector', | ||
'country_budget_items', | ||
'humanitarian_scope', | ||
'policy_marker', | ||
'collaboration_type', | ||
'default_flow_type', | ||
'default_finance_type', | ||
'default_aid_type', | ||
'default_tied_status', | ||
'budget', | ||
'planned_disbursement', | ||
'capital_spend', | ||
'document_link', | ||
'related_activity', | ||
'legacy_data', | ||
'conditions', | ||
'org_id', | ||
'default_field_values', | ||
'tag', | ||
'reporting_org', | ||
], | ||
'result' => ['id', 'result'], | ||
'indicator' => ['id', 'indicator'], | ||
'period' => ['id', 'period'], | ||
'transaction' => ['id', 'transaction'], | ||
]; | ||
|
||
try { | ||
DB::beginTransaction(); | ||
|
||
foreach ($dataModelMappedToHelperMidfix as $key => $model) { | ||
$columns = $AttributesMappedToHelperMidfix[$key]; | ||
|
||
$model::select($columns)->chunkById(10, function ($chunkedRecords) use ($model, $key) { | ||
foreach ($chunkedRecords as $record) { | ||
$this->info("Processing {$model} ID: {$record->id}"); | ||
|
||
$record->timestamps = false; | ||
|
||
if ($key === 'activity') { | ||
$element = $record->toArray(); | ||
} else { | ||
$element = Arr::get($record->toArray(), $key, []); | ||
} | ||
|
||
/** Call helper here */ | ||
$helperFunctionName = 'refresh' . ucfirst($key) . 'DeprecationStatusMap'; | ||
|
||
if (is_callable($helperFunctionName)) { | ||
$record->updateQuietly( | ||
['deprecation_status_map' => call_user_func($helperFunctionName, $element)], | ||
['touch' => false] | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
DB::commit(); | ||
} catch (\Exception $e) { | ||
DB::rollBack(); | ||
|
||
logger()->error($e); | ||
} | ||
} | ||
} |
Oops, something went wrong.