Skip to content

Commit

Permalink
Option to delete links from the ignore before date
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski committed Nov 29, 2023
1 parent 26517f1 commit 2a3292b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
32 changes: 23 additions & 9 deletions pkg/api/external_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"net/http"
"time"

restfulspec "github.com/emicklei/go-restful-openapi/v2"
"github.com/emicklei/go-restful/v3"
Expand All @@ -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{}
Expand Down Expand Up @@ -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)
}
16 changes: 15 additions & 1 deletion ui/src/views/options/overlays/SceneMatchParams.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong>${formattedDate}</strong>`,
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
}
Expand Down

0 comments on commit 2a3292b

Please sign in to comment.