err=Db.Select(&pages,"SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.revisions, a.blockid, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? ORDER BY a.sequence",p.Context.OrgID,documentID)
sql:="SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.blockid, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? AND a.refid IN (?"+strings.Repeat(",?",len(tempValues)-1)+") ORDER BY sequence"
err=Db.Select(&pages,"SELECT id, refid, orgid, documentid, userid, contenttype, pagetype, sequence, level, title, revisions, blockid, created, revised FROM page WHERE orgid=? AND documentid=? ORDER BY sequence",p.Context.OrgID,documentID)
stmt,err=p.Context.Transaction.Preparex("INSERT INTO revision (refid, orgid, documentid, ownerid, pageid, userid, contenttype, pagetype, title, body, rawbody, config, created, revised) SELECT ? as refid, a.orgid, a.documentid, a.userid as ownerid, a.refid as pageid, ? as userid, a.contenttype, a.pagetype, a.title, a.body, b.rawbody, b.config, ? as created, ? as revised FROM page a, pagemeta b WHERE a.refid=? AND a.refid=b.pageid")
log.Error(fmt.Sprintf("Unable to execute insert for page revision %s",page.RefID),err)
returnerr
}
}
// Update page
varstmt2*sqlx.NamedStmt
stmt2,err=p.Context.Transaction.PrepareNamed("UPDATE page SET documentid=:documentid, level=:level, title=:title, body=:body, revisions=:revisions, sequence=:sequence, revised=:revised WHERE orgid=:orgid AND refid=:refid")
deferutility.Close(stmt2)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to prepare update for page %s",page.RefID),err)
return
}
_,err=stmt2.Exec(&page)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to execute update for page %s",page.RefID),err)
stmt,err=p.Context.Transaction.PrepareNamed("UPDATE pagemeta SET userid=:userid, documentid=:documentid, rawbody=:rawbody, config=:config, externalsource=:externalsource, revised=:revised WHERE orgid=:orgid AND pageid=:pageid")
deferutility.Close(stmt)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to prepare update for page meta %s",meta.PageID),err)
return
}
_,err=stmt.Exec(&meta)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to execute update for page meta %s",meta.PageID),err)
return
}
return
}
// UpdatePageSequence changes the presentation sequence of the pageID page in the document.
// It then propagates that change into the search table and audits that it has occurred.
stmt,err:=Db.Preparex("SELECT id, pageid, orgid, userid, documentid, rawbody, coalesce(config,JSON_UNQUOTE('{}')) as config, externalsource, created, revised FROM pagemeta WHERE orgid=? AND pageid=?")
deferutility.Close(stmt)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to prepare select for pagemeta %s",pageID),err)
return
}
err=stmt.Get(&meta,p.Context.OrgID,pageID)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to execute select for pagemeta %s",pageID),err)
return
}
return
}
// GetDocumentPageMeta returns the meta information associated with a document.
err=Db.Select(&meta,"SELECT id, pageid, orgid, userid, documentid, rawbody, coalesce(config,JSON_UNQUOTE('{}')) as config, externalsource, created, revised FROM pagemeta WHERE orgid=? AND documentid=?"+filter,p.Context.OrgID,documentID)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to execute select document page meta for org %s and document %s",p.Context.OrgID,documentID),err)
err=Db.Select(&revisions,"SELECT a.id, a.refid, a.orgid, a.documentid, a.ownerid, a.pageid, a.userid, a.contenttype, a.pagetype, a.title, /*a.body, a.rawbody, a.config,*/ a.created, a.revised, coalesce(b.email,'') as email, coalesce(b.firstname,'') as firstname, coalesce(b.lastname,'') as lastname, coalesce(b.initials,'') as initials, coalesce(p.revisions, 0) as revisions FROM revision a LEFT JOIN user b ON a.userid=b.refid LEFT JOIN page p ON a.pageid=p.refid WHERE a.orgid=? AND a.documentid=? AND a.pagetype='section' ORDER BY a.id DESC",p.Context.OrgID,documentID)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to execute select revisions for org %s and document %s",p.Context.OrgID,documentID),err)
return
}
iflen(revisions)==0{
revisions=[]entity.Revision{}
}
return
}
// GetPageRevisions returns a slice of page revision records for a given pageID, in the order they were created.
// Then audits that the get-page-revisions action has occurred.
err=Db.Select(&revisions,"SELECT a.id, a.refid, a.orgid, a.documentid, a.ownerid, a.pageid, a.userid, a.contenttype, a.pagetype, a.title, /*a.body, a.rawbody, a.config,*/ a.created, a.revised, coalesce(b.email,'') as email, coalesce(b.firstname,'') as firstname, coalesce(b.lastname,'') as lastname, coalesce(b.initials,'') as initials FROM revision a LEFT JOIN user b ON a.userid=b.refid WHERE a.orgid=? AND a.pageid=? AND a.pagetype='section' ORDER BY a.id DESC",p.Context.OrgID,pageID)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to execute select revisions for org %s and page %s",p.Context.OrgID,pageID),err)
return
}
return
}
// DeletePageRevisions deletes all of the page revision records for a given pageID.