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; } /**