mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-09-21 18:25:02 -04:00
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>
This commit is contained in:
1 parent
8e6032a285
commit
bb99a22f59
2 files changed
+9
-5
No files matched your search
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user