Skip to content

Commit

Permalink
Merge branch 'code4romania:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanRauta authored Oct 28, 2024
2 parents b119949 + d7817f5 commit 4823614
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 121 deletions.
2 changes: 1 addition & 1 deletion app/Concerns/Enums/HasLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait HasLabel
{
protected function labelKeyPrefix(): ?string
{
return 'vulnerability.label';
return null;
}

public function label(): string
Expand Down
2 changes: 1 addition & 1 deletion app/Imports/VulnerabilitiesImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class VulnerabilitiesImport implements ToCollection, WithHeadingRow
{
public function collection(Collection $rows): void
{
if ($rows->first()->count() === 2) {
if ($rows->first()?->count() === 2) {
VulnerabilityCategory::upsert($rows->toArray(), 'id');
} else {
Vulnerability::upsert(
Expand Down
4 changes: 2 additions & 2 deletions app/Reports/Queries/Pregnant/P03.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class P03 extends ReportQuery
{
/**
* Sum beneficiari with Gravidă adultă (VGR_04) OR Minoră gravidă (VGR_01); Femeie însărcinată care a efectuat consultaţii prenatale (VGR_98).
* Sum beneficiari with Gravidă adultă (VGR_04) OR Minoră gravidă (VGR_01); Femeie însărcinată care a efectuat consultaţii prenatale (VGR_96).
*/
public static function query(): Builder
{
Expand All @@ -22,7 +22,7 @@ public static function query(): Builder
$query->whereJsonOverlaps('properties', ['VGR_04', 'VGR_01']);
})
->whereHasCatagraphyRelation(Catagraphy::class, function (QueryBuilder $query) {
$query->whereJsonContains('properties->attributes->cat_preg', 'VGR_98');
$query->whereJsonContains('properties->attributes->cat_preg', 'VGR_96');
});
}
}
Binary file added database/data/241028-vulnerabilities.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('vulnerabilities', function (Blueprint $table) {
$table->boolean('is_valid')
->virtualAs(<<<'SQL'
CASE
WHEN id LIKE '%\\_9_' THEN 0
ELSE 1
END
SQL)
->change();
});
}
};
60 changes: 60 additions & 0 deletions database/migrations/2024_10_28_132539_update_vulnerabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

use App\Imports\VulnerabilitiesImport;
use App\Models\Activity;
use App\Models\Catagraphy;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Maatwebsite\Excel\Facades\Excel;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Excel::import(new VulnerabilitiesImport, database_path('data/241028-vulnerabilities.xlsx'));

$cutoffDate = Carbon::parse('2024-10-24 00:00:00');

$callback = fn (string $preg) => $preg === 'VGR_98' ? 'VGR_96' : $preg;

// Catagraphy
// updated_at >= 2024-10-24 00:00:00
// cat_preg VGR_98 => VGR_96
Catagraphy::query()
->whereDate('updated_at', '>=', $cutoffDate)
->whereJsonContains('cat_preg', 'VGR_98')
->get()
->each(function (Catagraphy $catagraphy) use ($callback) {
$catagraphy->timestamps = false;

$catagraphy->updateQuietly([
'cat_preg' => collect($catagraphy->cat_preg)
->map($callback)
->all(),
]);
});

// Activity log `vulnerabilities`
// created_at >= 2024-10-24 00:00:00
// VGR_98 => VGR_96
Activity::query()
->where('created_at', '>=', $cutoffDate)
->where('log_name', 'vulnerabilities')
->whereJsonContains('properties', 'VGR_98')
->get()
->each(function (Activity $activity) use ($callback) {
$activity->timestamps = false;

$activity->updateQuietly([
'properties' => $activity->properties
->map($callback)
->all(),
]);
});
}
};
117 changes: 0 additions & 117 deletions lang/ro/vulnerability.php

This file was deleted.

0 comments on commit 4823614

Please sign in to comment.