From fdaf90b89f3716f7d05a246916efe1a1f2ebe4f7 Mon Sep 17 00:00:00 2001 From: ro Date: Fri, 9 Feb 2024 21:05:33 -0600 Subject: [PATCH] added total actions count to DB, action count fix Added a new field to the locations table for total actions which will be used to set the active state of location. this will result in data being parsed and sorted easier instead of doing those calculations on the back end, so DB queries will be simpler also fixed actions counts for csv imports --- app/Http/Controllers/LocationController.php | 21 +++++++++++++++++---- app/Models/Location.php | 3 ++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index ea28d5a..c6df1e9 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -112,9 +112,9 @@ class LocationController extends Controller $silence = 0; $suspend = 0; if ($item[1] == "suspend" || $item[1] == "defederate") { - ++$silence; - } else { ++$suspend; + } else { + ++$silence; } array_push($unified, [ 'name' => $item[0], @@ -164,6 +164,12 @@ class LocationController extends Controller $location->block_count = $item['block_count']; $location->silence_count = $item['silence_count']; + $location->actions_count = $item['block_count'] + $item['silence_count']; + + if (($item['block_count'] + $item['silence_count']) < 2) { + $location->active = false; + } + //replace null with empty array if ($location->images == null) { $location->images = []; @@ -174,18 +180,25 @@ class LocationController extends Controller ++$fresh; $images = []; $rating = ($item['rating'] == 'defederate') ? 'suspend' : $item['rating']; - $new = Location::create([ + + $status = true; + if (($item['block_count'] + $item['silence_count']) < 2) { + $status = false; + } + + $new = Location::create([ 'uuid' => Uuid::uuid4(), 'name' => $item['url'], 'url' => $item['url'], 'description' => ($item['comment'] != null) ? $item['comment'] : "no description", - 'active' => true, + 'active' => $status, 'rating' => $rating, 'added_by' => 1, 'tags' => 'poor moderation, hate speech', 'images' => json_encode($images), 'block_count' => $item['block_count'], 'silence_count' => $item['silence_count'], + 'actions_cont' => $item['block_count'] + $item['silence_count'] ]); } } diff --git a/app/Models/Location.php b/app/Models/Location.php index 7ae2c95..e5a6b93 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -33,6 +33,7 @@ class Location extends Model "block_count", "silence_count", "created_at", - "updated_at" + "updated_at", + "actions_count" ]; }