From bb99a22f59a49dd1bce7cc18c49a2868752abc87 Mon Sep 17 00:00:00 2001 From: objecttothis <17935339+objecttothis@users.noreply.github.com> Date: Thu, 17 Sep 2026 15:29:58 +0400 Subject: [PATCH] fix(job-throttle): return saved throttle id to prevent unintended deletion - JobThrottle::saveValue now returns int throttle_id instead of bool: new inserts return the DB-generated insertID, updates return the existing throttleId. - Jobs controller collects saved ids into $notToDelete using the returned value, so newly inserted throttles are correctly tracked. Fixes bug where newly inserted throttles had no id captured, causing them to be wrongly deleted in the post-save cleanup step. Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com> --- app/Controllers/Jobs.php | 3 ++- app/Models/JobThrottle.php | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Controllers/Jobs.php b/app/Controllers/Jobs.php index efa1a50b5..ae185a342 100644 --- a/app/Controllers/Jobs.php +++ b/app/Controllers/Jobs.php @@ -106,7 +106,8 @@ class Jobs extends Secure_Controller continue; } - $this->jobThrottle->saveValue($throttleData, $throttleId); + $savedThrottleId = $this->jobThrottle->saveValue($throttleData, $throttleId); + $notToDelete[] = (string)$savedThrottleId; } // All throttles not available in post will be deleted now diff --git a/app/Models/JobThrottle.php b/app/Models/JobThrottle.php index 032b3caa9..03d753b4a 100644 --- a/app/Models/JobThrottle.php +++ b/app/Models/JobThrottle.php @@ -35,9 +35,9 @@ class JobThrottle extends Model /** * @param array $throttleData * @param int $throttleId - * @return bool + * @return int Returns the throttle_id of the saved row (new id if inserted) */ - public function saveValue(array $throttleData, int $throttleId): bool + public function saveValue(array $throttleData, int $throttleId): int { $throttleDataToSave = [ 'max_count' => $throttleData['max_count'], @@ -47,13 +47,16 @@ class JobThrottle extends Model if (!$this->exists($throttleId)) { $builder = $this->db->table('job_throttles'); - return $builder->insert($throttleDataToSave); + $builder->insert($throttleDataToSave); + + return (int)$this->db->insertID(); } $builder = $this->db->table('job_throttles'); $builder->where('throttle_id', $throttleId); + $builder->update($throttleDataToSave); - return $builder->update($throttleDataToSave); + return $throttleId; } /**