From 65e066b756bbfe0a704d232ba2f33783a3650156 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 1 Jul 2021 17:59:54 +0200 Subject: add mintouched argument to delete_untouched to prevent deletes on importer problems --- it_dbi.class | 9 +++++++-- 1 file 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; -- cgit v1.2.3