diff options
-rw-r--r-- | it_dbi.class | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/it_dbi.class b/it_dbi.class index e371101..ce2e8c0 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -886,10 +886,15 @@ function delete($query = null) /** * Delete records matching query which were not touched since creation of this object or last call of this func + * @param $query Query for entries to be checked + * @param $p['mintouched'] Minimum records that have to be touched, error otherwise + * @param $p['it_error'] Parameters for too few records error message */ -function delete_untouched($query = null) +function delete_untouched($query = null, $p = []) { - if ($this->select(['SELECT' => $this->escape_name($this->_p['keyfield'])] + (array)$query)) + if (count((array)$this->_touchedids) < $p['mintouched']) + it::error((array)$p['it_error'] + ['title' => "skipping delete, only " . count((array)$this->_touchedids) . " records were touched"]); + else if ($this->select(['SELECT' => $this->escape_name($this->_p['keyfield'])] + (array)$query)) while ($this->iterate()) if (($id = $this->_key) && !$this->_touchedids[$id] && $this->delete()) $result[] = $id; |