Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: VGR_98 vulnerabilities issue #332

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
}
};
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.