@@ -134,18 +134,20 @@ class TerritoryReferenceSeeder extends Seeder
|
|||||||
}
|
}
|
||||||
|
|
||||||
$type = $record['location_type'];
|
$type = $record['location_type'];
|
||||||
$expectedParent = [
|
$parentTypes = [
|
||||||
'country' => null,
|
'country' => null,
|
||||||
'province' => 'country',
|
'province' => 'country',
|
||||||
'district' => 'province',
|
'district' => 'province',
|
||||||
'admin_post' => 'district',
|
'admin_post' => 'district',
|
||||||
'locality' => 'admin_post',
|
'locality' => 'admin_post',
|
||||||
][$type] ?? false;
|
];
|
||||||
|
|
||||||
if ($expectedParent === false || isset($seen[$record['id']])) {
|
if (! array_key_exists($type, $parentTypes) || isset($seen[$record['id']])) {
|
||||||
throw new RuntimeException('Territory reference has an invalid type or duplicate ID.');
|
throw new RuntimeException('Territory reference has an invalid type or duplicate ID.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$expectedParent = $parentTypes[$type];
|
||||||
|
|
||||||
if ($expectedParent === null) {
|
if ($expectedParent === null) {
|
||||||
if ($record['parent_id'] !== null) {
|
if ($record['parent_id'] !== null) {
|
||||||
throw new RuntimeException('Country reference cannot have a parent.');
|
throw new RuntimeException('Country reference cannot have a parent.');
|
||||||
|
|||||||
Reference in New Issue
Block a user