+
+sub PurgeImportTables {
+ #First purge import_records
+ #Delete cascades to import_biblios, import_items and import_record_matches
+ $sth = $dbh->prepare("DELETE FROM import_records WHERE upload_timestamp < date_sub(curdate(), interval ? DAY)");
+ $sth->execute($pImport) or die $dbh->errstr;
+
+ # Now purge import_batches
+ # Timestamp cannot be used here without care, because records are added
+ # continuously to batches without updating timestamp (z3950 search).
+ # So we only delete older empty batches.
+ # This delete will therefore not have a cascading effect.
+ $sth = $dbh->prepare("DELETE ba
+ FROM import_batches ba
+ LEFT JOIN import_records re ON re.import_batch_id=ba.import_batch_id
+ WHERE re.import_record_id IS NULL AND
+ ba.upload_timestamp < date_sub(curdate(), interval ? DAY)");
+ $sth->execute($pImport) or die $dbh->errstr;
+}