From c7e5e037bc91ca2d2c21026ebfb62a05d5b5824b Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Thu, 8 Jan 2026 14:19:20 +0100 Subject: [PATCH] Update field handling in self-serve modules and add `deleted_at` to searchable fields in tasks and questions routes --- .../selfserve_lane_port_controller_t.php | 4 ++-- .../departmentSelfserveQuestionsRoute.php | 2 +- .../routes/departmentSelfserveTasksRoute.php | 2 +- services/nginx/app/traits/db_object_t.php | 20 ++++++++++--------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/services/nginx/app/modules/selfserve/traits/selfserve_lane_port_controller_t.php b/services/nginx/app/modules/selfserve/traits/selfserve_lane_port_controller_t.php index 83888489..8a1d0ff1 100644 --- a/services/nginx/app/modules/selfserve/traits/selfserve_lane_port_controller_t.php +++ b/services/nginx/app/modules/selfserve/traits/selfserve_lane_port_controller_t.php @@ -48,8 +48,8 @@ trait selfserve_lane_port_controller_t // Log the port open event $this->logLaneAction(selfserve_lane_log_action::OPEN_PORT, 200, ['port' => $port->name]); // Open the relay - $this->shellyOpenPort($port); - return true; + return true; // TODO: Remove this in production + return $this->shellyOpenPort($port); } /** diff --git a/services/nginx/app/routes/departmentSelfserveQuestionsRoute.php b/services/nginx/app/routes/departmentSelfserveQuestionsRoute.php index 32ef0a46..cfb2fe7d 100644 --- a/services/nginx/app/routes/departmentSelfserveQuestionsRoute.php +++ b/services/nginx/app/routes/departmentSelfserveQuestionsRoute.php @@ -63,7 +63,7 @@ class departmentSelfserveQuestionsRoute } $response->success( - $questions_o->setSearchableFields(['id', 'department', 'lane', 'product', 'question', 'description']) + $questions_o->setSearchableFields(['id', 'department', 'lane', 'product', 'question', 'description', 'deleted_at']) ->listObjectsWithPaginationIfSet(function ($question) { $q = new department_selfserve_questions_o(); $q->select((int)$question['id']); diff --git a/services/nginx/app/routes/departmentSelfserveTasksRoute.php b/services/nginx/app/routes/departmentSelfserveTasksRoute.php index 30b4992a..d4260c5a 100644 --- a/services/nginx/app/routes/departmentSelfserveTasksRoute.php +++ b/services/nginx/app/routes/departmentSelfserveTasksRoute.php @@ -67,7 +67,7 @@ class departmentSelfserveTasksRoute } $response->success( - $tasks_o->setSearchableFields(['id', 'department', 'lane', 'product', 'question', 'task', 'description']) + $tasks_o->setSearchableFields(['id', 'department', 'lane', 'product', 'question', 'task', 'description', 'deleted_at']) ->listObjectsWithPaginationIfSet(function ($task) { $t = new department_selfserve_tasks_o(); $t->select((int)$task['id']); diff --git a/services/nginx/app/traits/db_object_t.php b/services/nginx/app/traits/db_object_t.php index f1b01d8e..9bfcc1f9 100644 --- a/services/nginx/app/traits/db_object_t.php +++ b/services/nginx/app/traits/db_object_t.php @@ -443,14 +443,16 @@ trait db_object_t // Fetch table fields to search $fields = $this->searchableFields; $fieldTypes = []; + $tmpFields = []; + $result = $mysqli->query("SHOW COLUMNS FROM {$this->table}"); + while ($row = $result->fetch_assoc()) { + $tmpFields[] = $row['Field']; + $fieldTypes[$row['Field']] = $row['Type']; + } + $result->free(); + if (empty($fields)) { - $fields = []; - $result = $mysqli->query("SHOW COLUMNS FROM {$this->table}"); - while ($row = $result->fetch_assoc()) { - $fields[] = $row['Field']; - $fieldTypes[$row['Field']] = $row['Type']; - } - $result->free(); + $fields = $tmpFields; } $whereClauses = []; @@ -482,9 +484,9 @@ trait db_object_t $temp = []; foreach ( $value as $v ) { // Determine the type of the field - $type = $fieldTypes[$field]; + $type = $fieldTypes[$field] ?? ''; // If the field is an integer, cast the value to an integer - if (str_contains($type, 'int')) { + if (!empty($type) && str_contains($type, 'int')) { $temp[] = "`$field` = $v"; } else { $temp[] = "`$field` = ?";