summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2021-07-01 17:59:54 +0200
committerUrban Müller2021-07-01 17:59:54 +0200
commit65e066b756bbfe0a704d232ba2f33783a3650156 (patch)
tree95958a939e922b3d686eec8f1a0927ff9e3824cd
parentc58d0dd54e9dc0ea6c85d825b03ac8148ef8e41a (diff)
downloaditools-65e066b756bbfe0a704d232ba2f33783a3650156.tar.gz
itools-65e066b756bbfe0a704d232ba2f33783a3650156.tar.bz2
itools-65e066b756bbfe0a704d232ba2f33783a3650156.zip
add mintouched argument to delete_untouched to prevent deletes on importer problems
-rw-r--r--it_dbi.class9
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;