diff --git a/pkg/api/external_references.go b/pkg/api/external_references.go index 955ee85c0..b0e14667c 100644 --- a/pkg/api/external_references.go +++ b/pkg/api/external_references.go @@ -2,6 +2,7 @@ package api import ( "net/http" + "time" restfulspec "github.com/emicklei/go-restful-openapi/v2" "github.com/emicklei/go-restful/v3" @@ -10,14 +11,15 @@ import ( // var RequestBody []byte type RequestEditExtRefLink struct { - ID uint `json:"id"` - ExternalReferenceID uint `json:"external_reference_id"` - ExternalSource string `json:"external_source"` - ExternalId string `json:"external_id"` - MatchType int `json:"match_type"` - InternalTable string `json:"internal_table"` - InternalDbId uint `json:"internal_db_id"` - InternalNameId string `json:"internal_name_id"` + ID uint `json:"id"` + ExternalReferenceID uint `json:"external_reference_id"` + ExternalSource string `json:"external_source"` + ExternalId string `json:"external_id"` + MatchType int `json:"match_type"` + InternalTable string `json:"internal_table"` + InternalDbId uint `json:"internal_db_id"` + InternalNameId string `json:"internal_name_id"` + DeleteDate time.Time `json:"delete_date"` } type ExternalReference struct{} @@ -152,7 +154,19 @@ func (i ExternalReference) deleteExtRefSourceLinksKeepManualMatches(req *restful db, _ := models.GetDB() defer db.Close() - db.Where("external_source like ? and match_type not in (99999, -1)", r.ExternalSource).Delete(models.ExternalReferenceLink{}) + if r.DeleteDate.IsZero() { + db.Where("external_source like ? and match_type not in (99999, -1)", r.ExternalSource).Delete(models.ExternalReferenceLink{}) + } else { + // Fetch records to delete + var recordsToDelete []models.ExternalReferenceLink + db.Debug().Joins("JOIN external_references ON external_reference_links.external_reference_id = external_references.id"). + Where("external_reference_links.external_source LIKE ? AND match_type NOT IN (99999, -1) AND external_references.external_date >= ?", r.ExternalSource, r.DeleteDate). + Find(&recordsToDelete) + for _, record := range recordsToDelete { + db.Debug().Delete(&record) + } + + } resp.WriteHeaderAndEntity(http.StatusOK, nil) } diff --git a/ui/src/views/options/overlays/SceneMatchParams.vue b/ui/src/views/options/overlays/SceneMatchParams.vue index 8d59b1f0f..2a718a057 100644 --- a/ui/src/views/options/overlays/SceneMatchParams.vue +++ b/ui/src/views/options/overlays/SceneMatchParams.vue @@ -240,8 +240,22 @@ export default { this.ignoreReleasedBefore = null }, saveSettings() { - this.params.ignore_released_before=this.ignoreReleasedBefore + this.params.ignore_released_before=this.ignoreReleasedBefore ky.post(`/api/options/site/save_match_params`, { json: { site: this.site.id, match_params: this.params } }) + if (this.ignoreReleasedBefore != null) { + const formattedDate = this.ignoreReleasedBefore.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric',}); + this.$buefy.dialog.confirm({ + title: 'Clear existing links', + message: `Do you also wish to clear links from ${formattedDate}`, + type: 'is-info is-wide', + hasIcon: true, + id: 'heh', + onConfirm: () => { + ky.delete(`/api/extref/delete_extref_source_links/keep_manual`, { json: {external_source: 'alternate scene ' + this.site.id, delete_date: this.ignoreReleasedBefore} }); + } + }) + + } }, prettyBytes }