Skip to content

Commit

Permalink
[TM-1531] change metadata casted
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Dec 20, 2024
1 parent fdf627b commit 540344c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function clipOverlappingPolygonsBySite(string $uuid)
$delayedJob = DelayedJobProgress::create([
'processed_content' => 0,
'created_by' => $user->id,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $site->id,
'entity_type' => get_class($site),
'entity_name' => $site->name,
]),
],
'is_acknowledged' => false,
'name' => 'Polygon Fix',
]);
Expand Down Expand Up @@ -89,11 +89,11 @@ public function clipOverlappingPolygonsOfProjectBySite(string $uuid)

$delayedJob = DelayedJobProgress::create([
'processed_content' => 0,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $site->id,
'entity_type' => get_class($site),
'entity_name' => $site->name,
]),
],
'created_by' => $user->id,
'is_acknowledged' => false,
'name' => 'Polygon Fix',
Expand Down Expand Up @@ -152,11 +152,11 @@ public function clipOverlappingPolygons(Request $request)
$user = Auth::user();
$delayedJob = DelayedJobProgress::create([
'processed_content' => 0,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $entity->id,
'entity_type' => get_class($entity),
'entity_name' => $entity->name,
]),
],
'created_by' => $user->id,
'is_acknowledged' => false,
'name' => 'Polygon Fix',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ function ($attribute, $value, $fail) {
Redis::set($redis_key, $geojsonContent, 'EX', 7200);
$delayedJob = DelayedJob::create([
'created_by' => $user->id,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $entity->id,
'entity_type' => get_class($entity),
'entity_name' => $entity->name,
]),
],
'is_acknowledged' => false,
'name' => 'Polygon Upload',
]);
Expand Down Expand Up @@ -413,11 +413,11 @@ public function uploadShapefile(Request $request)
Redis::set($redis_key, $geojsonContent, 'EX', 7200);
$delayedJob = DelayedJob::create([
'created_by' => $user->id,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $entity->id,
'entity_type' => get_class($entity),
'entity_name' => $entity->name,
]),
],
'is_acknowledged' => false,
'name' => 'Polygon Upload',
]);
Expand Down Expand Up @@ -644,11 +644,11 @@ public function uploadGeoJSONFile(Request $request)
Redis::set($redis_key, $geojson_content, 'EX', 7200);
$delayedJob = DelayedJob::create([
'created_by' => $user->id,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $entity->id,
'entity_type' => get_class($entity),
'entity_name' => $entity->name,
]),
],
'is_acknowledged' => false,
'name' => 'Polygon Upload',
]);
Expand Down Expand Up @@ -1260,11 +1260,11 @@ public function runSiteValidationPolygon(Request $request)
'total_content' => count($sitePolygonsUuids),
'processed_content' => 0,
'created_by' => $user->id,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $entity->id,
'entity_type' => get_class($entity),
'entity_name' => $entity->name,
]),
],
'is_acknowledged' => false,
'name' => 'Polygon Validation',
]);
Expand Down Expand Up @@ -1293,11 +1293,11 @@ public function runPolygonsValidation(Request $request)
'total_content' => count($uuids),
'processed_content' => 0,
'created_by' => $user->id,
'metadata' => json_encode([
'metadata' => [
'entity_id' => $entity->id,
'entity_type' => get_class($entity),
'entity_name' => $entity->name,
]),
],
'is_acknowledged' => false,
'name' => 'Polygon Validation',
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FixPolygonOverlapJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function handle(): void
try {
$delayedJob = DelayedJobProgress::findOrFail($this->delayed_job_id);
$user = Auth::user();
$metadata = json_decode($delayedJob->metadata, true);
$metadata = $delayedJob->metadata;
$entityId = $metadata['entity_id'] ?? null;
$site = Site::findOrFail($entityId);
$userForMail = $delayedJob->creator;
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/InsertGeojsonToDBJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function handle(PolygonService $service)
{
$delayedJob = DelayedJob::findOrFail($this->delayed_job_id);
$user = $delayedJob->creator;
$metadata = json_decode($delayedJob->metadata, true);
$metadata = $delayedJob->metadata;
$entityId = $metadata['entity_id'] ?? null;

$site = Site::findOrFail($entityId);
Expand Down
9 changes: 7 additions & 2 deletions app/Jobs/RunSitePolygonsValidationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ public function handle(PolygonValidationService $validationService)
try {
$delayedJob = DelayedJobProgress::findOrFail($this->delayed_job_id);
$user = $delayedJob->creator;
$metadata = json_decode($delayedJob->metadata, true);
$metadata = $delayedJob->metadata;

$entityId = $metadata['entity_id'] ?? null;

$site = Site::findOrFail($entityId);
if ($entityId) {
$site = Site::findOrFail($entityId);
} else {
Log::error('entityId is null, unable to find site');
}

if (! $site) {
throw new Exception('Site not found for the given site UUID.');
Expand Down
1 change: 1 addition & 0 deletions app/Models/DelayedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DelayedJob extends Model

protected $casts = [
'uuid' => 'string',
'metadata' => 'array',
];

public function creator()
Expand Down

0 comments on commit 540344c

Please sign in to comment.