1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00
documize/domain/meta/mysql/store.go
2018-09-18 20:55:40 +01:00

73 lines
2.3 KiB
Go

// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package mysql
import (
"database/sql"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/model/page"
"github.com/pkg/errors"
)
// Scope provides data access to MySQL.
type Scope struct {
Runtime *env.Runtime
}
// GetDocumentsID returns every document ID value stored.
// The query runs at the instance level across all tenants.
func (s Scope) GetDocumentsID(ctx domain.RequestContext) (documents []string, err error) {
err = s.Runtime.Db.Select(&documents, `SELECT c_refid FROM dmz_doc WHERE c_lifecycle=1`)
if err == sql.ErrNoRows {
err = nil
documents = []string{}
}
if err != nil {
err = errors.Wrap(err, "failed to get instance document ID values")
}
return
}
// GetDocumentPages returns a slice containing all published page records for a given documentID, in presentation sequence.
func (s Scope) GetDocumentPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
err = s.Runtime.Db.Select(&p, `
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid,
c_userid AS userid, c_contenttype AS contenttype,
c_type AS type, c_level AS level, c_sequence AS sequence, c_name AS name,
c_body AS body, c_revisions AS revisions, c_blockid AS templateid,
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
FROM dmz_section
WHERE c_docid=? AND (c_status=0 OR ((c_status=4 OR c_status=2) AND c_relativeid=''))`,
documentID)
if err != nil {
err = errors.Wrap(err, "failed to get instance document pages")
}
return
}
// SearchIndexCount returns the numnber of index entries.
func (s Scope) SearchIndexCount(ctx domain.RequestContext) (c int, err error) {
row := s.Runtime.Db.QueryRow("SELECT count(*) FROM dmz_search")
err = row.Scan(&c)
if err != nil {
err = errors.Wrap(err, "count search index entries")
c = 0
}
return
}