mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
completed red-line links
This commit is contained in:
parent
16b7fd45d7
commit
7c2051cc7a
8 changed files with 70 additions and 16 deletions
|
@ -102,5 +102,10 @@ func (p *Persister) GetAttachmentsWithData(docID string) (attachments []entity.A
|
|||
|
||||
// DeleteAttachment deletes the id record from the database attachment table.
|
||||
func (p *Persister) DeleteAttachment(id string) (rows int64, err error) {
|
||||
return p.Base.DeleteConstrained(p.Context.Transaction, "attachment", p.Context.OrgID, id)
|
||||
rows, err = p.Base.DeleteConstrained(p.Context.Transaction, "attachment", p.Context.OrgID, id)
|
||||
|
||||
// Mark references to this document as orphaned
|
||||
err = p.MarkOrphanAttachmentLink(id)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
|||
l.Created = time.Now().UTC()
|
||||
l.Revised = time.Now().UTC()
|
||||
|
||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO link (refid, orgid, folderid, userid, sourcedocumentid, sourcepageid, targetdocumentid, targetpageid, linktype, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO link (refid, orgid, folderid, userid, sourcedocumentid, sourcepageid, targetdocumentid, targetid, linktype, orphan, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
@ -35,7 +35,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourcePageID, l.TargetDocumentID, l.TargetPageID, l.LinkType, l.Created, l.Revised)
|
||||
_, err = stmt.Exec(l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourcePageID, l.TargetDocumentID, l.TargetID, l.LinkType, l.Orphan, l.Created, l.Revised)
|
||||
|
||||
if err != nil {
|
||||
log.Error("Unable to execute insert for link", err)
|
||||
|
@ -185,7 +185,7 @@ func (p *Persister) GetDocumentOutboundLinks(documentID string) (links []entity.
|
|||
err = nil
|
||||
|
||||
err = Db.Select(&links,
|
||||
`select l.refid, l.orgid, l.folderid, l.userid, l.sourcedocumentid, l.sourcepageid, l.targetdocumentid, l.targetpageid, l.linktype, l.orphan, l.created, l.revised
|
||||
`select l.refid, l.orgid, l.folderid, l.userid, l.sourcedocumentid, l.sourcepageid, l.targetdocumentid, l.targetid, l.linktype, l.orphan, l.created, l.revised
|
||||
FROM link l
|
||||
WHERE l.orgid=? AND l.sourcedocumentid=?`,
|
||||
p.Context.OrgID,
|
||||
|
@ -202,6 +202,29 @@ func (p *Persister) GetDocumentOutboundLinks(documentID string) (links []entity.
|
|||
return
|
||||
}
|
||||
|
||||
// GetPageLinks returns outbound links for specified page in document.
|
||||
func (p *Persister) GetPageLinks(documentID, pageID string) (links []entity.Link, err error) {
|
||||
err = nil
|
||||
|
||||
err = Db.Select(&links,
|
||||
`select l.refid, l.orgid, l.folderid, l.userid, l.sourcedocumentid, l.sourcepageid, l.targetdocumentid, l.targetid, l.linktype, l.orphan, l.created, l.revised
|
||||
FROM link l
|
||||
WHERE l.orgid=? AND l.sourcedocumentid=? AND l.sourcepageid=?`,
|
||||
p.Context.OrgID,
|
||||
documentID,
|
||||
pageID)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(links) == 0 {
|
||||
links = []entity.Link{}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// MarkOrphanDocumentLink marks all link records referencing specified document.
|
||||
func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
||||
revised := time.Now().UTC()
|
||||
|
@ -216,10 +239,6 @@ func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
|||
|
||||
_, err = stmt.Exec(revised, p.Context.OrgID, documentID)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -227,7 +246,7 @@ func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
|||
func (p *Persister) MarkOrphanPageLink(pageID string) (err error) {
|
||||
revised := time.Now().UTC()
|
||||
|
||||
stmt, err := p.Context.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='section' AND orgid=? AND targetpageid=?")
|
||||
stmt, err := p.Context.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='section' AND orgid=? AND targetid=?")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -237,10 +256,23 @@ func (p *Persister) MarkOrphanPageLink(pageID string) (err error) {
|
|||
|
||||
_, err = stmt.Exec(revised, p.Context.OrgID, pageID)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// MarkOrphanAttachmentLink marks all link records referencing specified attachment.
|
||||
func (p *Persister) MarkOrphanAttachmentLink(attachmentID string) (err error) {
|
||||
revised := time.Now().UTC()
|
||||
|
||||
stmt, err := p.Context.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='file' AND orgid=? AND targetid=?")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer utility.Close(stmt)
|
||||
|
||||
_, err = stmt.Exec(revised, p.Context.OrgID, attachmentID)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -290,6 +290,10 @@ func (p *Persister) UpdatePage(page entity.Page, refID, userID string, skipRevis
|
|||
// find any content links in the HTML
|
||||
links := util.GetContentLinks(page.Body)
|
||||
|
||||
// get a copy of previously saved links
|
||||
previousLinks, _ := p.GetPageLinks(page.DocumentID, page.RefID)
|
||||
fmt.Println(len(previousLinks))
|
||||
|
||||
// delete previous content links for this page
|
||||
_, _ = p.DeleteSourcePageLinks(page.RefID)
|
||||
|
||||
|
@ -299,11 +303,22 @@ func (p *Persister) UpdatePage(page entity.Page, refID, userID string, skipRevis
|
|||
link.OrgID = p.Context.OrgID
|
||||
link.UserID = p.Context.UserID
|
||||
link.SourceDocumentID = page.DocumentID
|
||||
link.SourcePageID = page.RefID
|
||||
|
||||
if link.LinkType == "section" {
|
||||
link.SourcePageID = page.RefID
|
||||
if link.LinkType == "document" {
|
||||
link.TargetID = ""
|
||||
}
|
||||
|
||||
// We check if there was a previously saved version of this link.
|
||||
// If we find one, we carry forward the orphan flag.
|
||||
for _, p := range previousLinks {
|
||||
if link.TargetID == p.TargetID && link.LinkType == p.LinkType {
|
||||
link.Orphan = p.Orphan
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// save
|
||||
err := p.AddContentLink(link)
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue