Skip to content

Commit

Permalink
fix: project import
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 27, 2023
1 parent 1a4abe5 commit e32da44
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions app/Console/Commands/Import/ImportProjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ protected function importProjects(): void
'MainImageId' => $this->db
->table('dbo.ProjectImages')
->select('ImageId')
->whereColumn('dbo.ProjectImages.ProjectId', 'dbo.ONGProjects.Id')
->whereColumn('dbo.ProjectImages.ProjectId', 'dbo.Projects.Id')
->where('dbo.ProjectImages.IsMainImage', 1),
'GalleryImageIds' => $this->db
->table('dbo.ProjectImages')
->selectRaw("STRING_AGG(ImageId,',')")
->whereColumn('dbo.ProjectImages.ProjectId', 'dbo.ONGProjects.Id')
->whereColumn('dbo.ProjectImages.ProjectId', 'dbo.Projects.Id')
->where('dbo.ProjectImages.IsMainImage', 0),
'Counties' => $this->db
->table('dbo.ProjectCounties')
->selectRaw("STRING_AGG(CountyId,',')")
->whereColumn('dbo.ProjectCounties.ProjectId', 'dbo.ONGProjects.Id'),
->whereColumn('dbo.ProjectCounties.ProjectId', 'dbo.Projects.Id'),
])
->rightJoin('dbo.Projects', 'dbo.Projects.Id', 'dbo.ONGProjects.Id')
->orderBy('dbo.ONGProjects.Id');
Expand Down Expand Up @@ -184,30 +184,27 @@ private function createBcrProject(object $row, Carbon $created_at): Model|BCRPro

$countyID = $mappedCounties?->first() ?? null;

return BCRProject::forceCreate([
'id' => (int) $row->Id,
'name' => Sanitize::text($row->Name),
'slug' => Sanitize::text($row->DynamicUrl),
'description' => Sanitize::text($row->Description),
'project_category_id' => $row->ProjectCategoryId,
'county_id' => $countyID,
'start_date' => $this->parseDate($row->StartDate),
'end_date' => $this->parseDate($row->EndDate),
'is_national' => (bool) $row->AllCounties,
'facebook_link' => $row->FacebookPageLink,
'created_at' => $created_at,
'updated_at' => $created_at,

return BCRProject::forceCreate(
[
'id' => (int) $row->Id,
'name' => Sanitize::text($row->Name),
'slug' => Sanitize::text($row->DynamicUrl),
'description' => Sanitize::text($row->Description),
'project_category_id' => $row->ProjectCategoryId,
'county_id' => $countyID,
'start_date' => $this->parseDate($row->StartDate),
'end_date' => $this->parseDate($row->EndDate),
'is_national' => (bool) $row->AllCounties,
'facebook_link' => $row->FacebookPageLink,
'created_at' => $created_at,
'updated_at' => $created_at,

'status' => match ($row->ProjectStatusTypeId) {
1 => ProjectStatus::pending,
2 => ProjectStatus::approved,
3 => ProjectStatus::approved,//set arhivat
4 => ProjectStatus::approved,
default => ProjectStatus::draft,
},
]
);
'status' => match ($row->ProjectStatusTypeId) {
1 => ProjectStatus::pending,
2 => ProjectStatus::approved,
3 => ProjectStatus::approved,//set arhivat
4 => ProjectStatus::approved,
default => ProjectStatus::draft,
},
]);
}
}

0 comments on commit e32da44

Please sign in to comment.