+ POOL_MEM query(PM_MESSAGE);
+
+ Mmsg(query, "DELETE FROM File WHERE JobId IN (%s)", jobs);
+ db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+ Dmsg1(050, "Delete File sql=%s\n", query.c_str());
+
+ /*
+ * Now mark Job as having files purged. This is necessary to
+ * avoid having too many Jobs to process in future prunings. If
+ * we don't do this, the number of JobId's in our in memory list
+ * could grow very large.
+ */
+ Mmsg(query, "UPDATE Job SET PurgedFiles=1 WHERE JobId IN (%s)", jobs);
+ db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+ Dmsg1(050, "Mark purged sql=%s\n", query.c_str());
+}
+
+/*
+ * Delete jobs (all records) from the catalog in groups of 1000
+ * at a time.
+ */
+void purge_job_list_from_catalog(UAContext *ua, del_ctx &del)
+{
+ POOL_MEM jobids(PM_MESSAGE);
+ char ed1[50];
+
+ for (int i=0; del.num_ids; ) {
+ Dmsg1(150, "num_ids=%d\n", del.num_ids);
+ pm_strcat(jobids, "");
+ for (int j=0; j<1000 && del.num_ids>0; j++) {
+ del.num_ids--;
+ if (del.JobId[i] == 0 || ua->jcr->JobId == del.JobId[i]) {
+ Dmsg2(150, "skip JobId[%d]=%d\n", i, (int)del.JobId[i]);
+ i++;
+ continue;
+ }
+ if (*jobids.c_str() != 0) {
+ pm_strcat(jobids, ",");
+ }
+ pm_strcat(jobids, edit_int64(del.JobId[i++], ed1));
+ Dmsg1(150, "Add id=%s\n", ed1);
+ del.num_del++;
+ }
+ Dmsg1(150, "num_ids=%d\n", del.num_ids);
+ purge_jobs_from_catalog(ua, jobids.c_str());
+ }
+}
+
+/*
+ * Delete files from a list of jobs in groups of 1000
+ * at a time.
+ */
+void purge_files_from_job_list(UAContext *ua, del_ctx &del)
+{
+ POOL_MEM jobids(PM_MESSAGE);
+ char ed1[50];
+ /*
+ * OK, now we have the list of JobId's to be pruned, send them
+ * off to be deleted batched 1000 at a time.
+ */
+ for (int i=0; del.num_ids; ) {
+ pm_strcat(jobids, "");
+ for (int j=0; j<1000 && del.num_ids>0; j++) {
+ del.num_ids--;
+ if (del.JobId[i] == 0 || ua->jcr->JobId == del.JobId[i]) {
+ Dmsg2(150, "skip JobId[%d]=%d\n", i, (int)del.JobId[i]);
+ i++;
+ continue;
+ }
+ if (*jobids.c_str() != 0) {
+ pm_strcat(jobids, ",");
+ }
+ pm_strcat(jobids, edit_int64(del.JobId[i++], ed1));
+ Dmsg1(150, "Add id=%s\n", ed1);
+ del.num_del++;
+ }
+ purge_files_from_jobs(ua, jobids.c_str());
+ }
+}
+
+/*
+ * Remove all records from catalog for a list of JobIds
+ */
+void purge_jobs_from_catalog(UAContext *ua, char *jobs)
+{
+ POOL_MEM query(PM_MESSAGE);
+
+ /* Delete (or purge) records associated with the job */
+ purge_files_from_jobs(ua, jobs);
+
+ Mmsg(query, "DELETE FROM JobMedia WHERE JobId IN (%s)", jobs);
+ db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+ Dmsg1(050, "Delete JobMedia sql=%s\n", query.c_str());