diff --git a/core/database/check.go b/core/database/check.go index 78331294..62aa72da 100644 --- a/core/database/check.go +++ b/core/database/check.go @@ -73,36 +73,20 @@ func Check(runtime *env.Runtime) bool { return false } - { // if there are no rows in the database, enter set-up mode - var flds []string - if err := runtime.Db.Select(&flds, runtime.StoreProvider.QueryTableList()); err != nil { - msg := fmt.Sprintf("Database: unable to get database table list ") - runtime.Log.Error(msg, err) - web.SiteInfo.Issue = msg + err.Error() - runtime.Flags.SiteMode = env.SiteModeBadDB - return false - } - - if strings.TrimSpace(flds[0]) == "0" { - runtime.Log.Info("Database: starting setup mode for empty database") - runtime.Flags.SiteMode = env.SiteModeSetup - return false - } + // if there are no rows in the database, enter set-up mode + var flds []string + if err := runtime.Db.Select(&flds, runtime.StoreProvider.QueryTableList()); err != nil { + msg := fmt.Sprintf("Database: unable to get database table list ") + runtime.Log.Error(msg, err) + web.SiteInfo.Issue = msg + err.Error() + runtime.Flags.SiteMode = env.SiteModeBadDB + return false } - // Ensure no missing tables. - var tables = []string{"account", "attachment", "document", - "label", "organization", "page", "revision", "search", "user"} - - for _, table := range tables { - var result []string - if err := runtime.Db.Select(&result, fmt.Sprintf("SELECT COUNT(*) FROM %s ;", table)); err != nil { - msg := fmt.Sprintf("Database: missing table %s", table) - runtime.Log.Error(msg, err) - web.SiteInfo.Issue = msg - runtime.Flags.SiteMode = env.SiteModeBadDB - return false - } + if strings.TrimSpace(flds[0]) == "0" { + runtime.Log.Info("Database: starting setup mode for empty database") + runtime.Flags.SiteMode = env.SiteModeSetup + return false } // We have good database, so proceed with app boot process. diff --git a/core/database/installer.go b/core/database/installer.go index 2ea89ad8..fd40acec 100644 --- a/core/database/installer.go +++ b/core/database/installer.go @@ -16,7 +16,7 @@ import ( "regexp" "strconv" "strings" - "time" + // "time" "github.com/documize/community/core/env" "github.com/jmoiron/sqlx" @@ -24,7 +24,7 @@ import ( // InstallUpgrade creates new database or upgrades existing database. func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) { - amLeader := false + // amLeader := false // Get all SQL scripts. scripts, err := LoadScripts() @@ -40,7 +40,7 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) { return } - runtime.Log.Info(fmt.Sprintf("Database: loaded %d SQL scripts for provider %s", len(dbTypeScripts), runtime.StoreProvider.Type())) + runtime.Log.Info(fmt.Sprintf("Database: loaded %d SQL scripts for provider %s", len(dbTypeScripts), runtime.StoreProvider.Type())) // Get current database version. currentVersion := 0 @@ -62,51 +62,77 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) { } } - if existingDB { - var err error - amLeader, err = Lock(runtime, len(toProcess)) - if err != nil { - runtime.Log.Error("Database: failed to lock existing database for processing", err) - } - } else { - // New installation hopes that you are only spinning up one instance of Documize. - // Assumption: nobody will perform the intial setup in a clustered environment. - amLeader = true + // For MySQL type there was major new schema introduced in v24. + // We check for this release and bypass usual locking code + // because tables have changed. + legacyMigration := runtime.StoreProvider.Type() == env.StoreTypeMySQL && + currentVersion > 0 && currentVersion < 25 && len(toProcess) >= 26 && toProcess[len(toProcess)-1].Version == 25 + + if legacyMigration { + // Bypass all DB locking/checking processes as these look for new schema + // which we are about to install. + toProcess = toProcess[len(toProcess)-1:] } tx, err := runtime.Db.Beginx() if err != nil { - return Unlock(runtime, tx, err, amLeader) + return err } - - // If currently running process is database leader then we perform upgrade. - if amLeader { - runtime.Log.Info(fmt.Sprintf("Database: %d SQL scripts to process", len(toProcess))) - - err = runScripts(runtime, tx, toProcess) - if err != nil { - runtime.Log.Error("Database: error processing SQL script", err) - } - - return Unlock(runtime, tx, err, amLeader) - } - - // If currently running process is a slave instance then we wait for migration to complete. - targetVersion := toProcess[len(toProcess)-1].Version - - for targetVersion != currentVersion { - time.Sleep(time.Second) - runtime.Log.Info("Database: slave instance polling for upgrade process completion") + err = runScripts(runtime, tx, toProcess) + if err != nil { + runtime.Log.Error("Database: error processing SQL scripts", err) tx.Rollback() - - // Get database version and check again. - currentVersion, err = CurrentVersion(runtime) - if err != nil { - return Unlock(runtime, tx, err, amLeader) - } } - return Unlock(runtime, tx, nil, amLeader) + tx.Commit() + + return nil + + // New style schema + // if existingDB { + // amLeader, err = Lock(runtime, len(toProcess)) + // if err != nil { + // runtime.Log.Error("Database: failed to lock existing database for processing", err) + // } + // } else { + // // New installation hopes that you are only spinning up one instance of Documize. + // // Assumption: nobody will perform the intial setup in a clustered environment. + // amLeader = true + // } + + // tx, err := runtime.Db.Beginx() + // if err != nil { + // return Unlock(runtime, tx, err, amLeader) + // } + + // // If currently running process is database leader then we perform upgrade. + // if amLeader { + // runtime.Log.Info(fmt.Sprintf("Database: %d SQL scripts to process", len(toProcess))) + + // err = runScripts(runtime, tx, toProcess) + // if err != nil { + // runtime.Log.Error("Database: error processing SQL script", err) + // } + + // return Unlock(runtime, tx, err, amLeader) + // } + + // // If currently running process is a slave instance then we wait for migration to complete. + // targetVersion := toProcess[len(toProcess)-1].Version + + // for targetVersion != currentVersion { + // time.Sleep(time.Second) + // runtime.Log.Info("Database: slave instance polling for upgrade process completion") + // tx.Rollback() + + // // Get database version and check again. + // currentVersion, err = CurrentVersion(runtime) + // if err != nil { + // return Unlock(runtime, tx, err, amLeader) + // } + // } + + // return Unlock(runtime, tx, nil, amLeader) } // Run SQL scripts to instal or upgrade this database. @@ -117,12 +143,23 @@ func runScripts(runtime *env.Runtime, tx *sqlx.Tx, scripts []Script) (err error) err = executeSQL(tx, runtime.StoreProvider.Type(), runtime.StoreProvider.TypeVariant(), script.Script) if err != nil { + runtime.Log.Error(fmt.Sprintf("error executing script version %d", script.Version), err) return err } // Record the fact we have processed this database script version. _, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version)) if err != nil { + // For MySQL we try the legacy DB checks. + if runtime.StoreProvider.Type() == env.StoreTypeMySQL { + runtime.Log.Error(fmt.Sprintf("Database: attempting legacy fallback for script version %d", script.Version), err) + + _, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgradeLegacy(script.Version)) + if err != nil { + return err + } + } + return err } } @@ -143,6 +180,7 @@ func executeSQL(tx *sqlx.Tx, st env.StoreType, variant string, SQLfile []byte) e _, err := tx.Exec(stmt) if err != nil { + fmt.Println("sql statement error:", stmt) return err } } @@ -175,12 +213,16 @@ func getStatements(bytes []byte) (stmts []string) { // CurrentVersion returns number that represents the current database version number. // For example 23 represents the 23rd iteration of the database. func CurrentVersion(runtime *env.Runtime) (version int, err error) { - row := runtime.Db.QueryRow(runtime.StoreProvider.QueryGetDatabaseVersion()) + currentVersion := "0" - var currentVersion string + row := runtime.Db.QueryRow(runtime.StoreProvider.QueryGetDatabaseVersion()) err = row.Scan(¤tVersion) if err != nil { - currentVersion = "0" + // For MySQL we try the legacy DB checks. + if runtime.StoreProvider.Type() == env.StoreTypeMySQL { + row := runtime.Db.QueryRow(runtime.StoreProvider.QueryGetDatabaseVersionLegacy()) + err = row.Scan(¤tVersion) + } } return extractVersionNumber(currentVersion), nil diff --git a/core/database/scripts/mysql/db_00025.sql b/core/database/scripts/mysql/db_00025.sql index 3c8c3202..042e0814 100644 --- a/core/database/scripts/mysql/db_00025.sql +++ b/core/database/scripts/mysql/db_00025.sql @@ -29,10 +29,11 @@ RENAME TABLE `userevent` TO dmz_audit_log, `useraction` TO dmz_action; + -- field renaming -ALTER TABLE `dmz_org` +ALTER TABLE dmz_org CHANGE `refid` `c_refid` CHAR(16) NOT NULL, - CHANGE `company` `c_refid` VARCHAR(500) NOT NULL, + CHANGE `company` `c_company` VARCHAR(500) NOT NULL, CHANGE `title` `c_title` VARCHAR(500) NOT NULL, CHANGE `message` `c_message` VARCHAR(500) NOT NULL, CHANGE `domain` `c_domain` VARCHAR(200) NOT NULL DEFAULT '', @@ -48,7 +49,7 @@ ALTER TABLE `dmz_org` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_space` +ALTER TABLE dmz_space CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL DEFAULT '', @@ -59,7 +60,7 @@ ALTER TABLE `dmz_space` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_category` +ALTER TABLE dmz_category CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL, @@ -67,7 +68,7 @@ ALTER TABLE `dmz_category` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_category_member` +ALTER TABLE dmz_category_member CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL, @@ -76,7 +77,7 @@ ALTER TABLE `dmz_category_member` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_group` +ALTER TABLE dmz_group CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `role` `c_name` VARCHAR(50) NOT NULL DEFAULT '', @@ -84,12 +85,13 @@ ALTER TABLE `dmz_group` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_group_member` +ALTER TABLE dmz_group_member CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `roleid` `c_groupid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL; -ALTER TABLE `dmz_permission` + +ALTER TABLE dmz_permission CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `who` `c_who` VARCHAR(30) NOT NULL, CHANGE `whoid` `c_whoid` CHAR(16) NOT NULL DEFAULT '', @@ -99,7 +101,8 @@ ALTER TABLE `dmz_permission` CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_doc` + +ALTER TABLE dmz_doc CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL, @@ -121,7 +124,7 @@ ALTER TABLE `dmz_doc` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_doc_share` +ALTER TABLE dmz_doc_share CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) DEFAULT '', @@ -133,7 +136,7 @@ ALTER TABLE `dmz_doc_share` CHANGE `active` `c_active` BOOL NOT NULL DEFAULT 1, CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_doc_vote` +ALTER TABLE dmz_doc_vote CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, @@ -142,7 +145,7 @@ ALTER TABLE `dmz_doc_vote` CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_doc_comment` +ALTER TABLE dmz_doc_comment CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, @@ -151,7 +154,7 @@ ALTER TABLE `dmz_doc_comment` CHANGE `feedback` `c_feedback` LONGTEXT, CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_doc_attachment` +ALTER TABLE dmz_doc_attachment CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, @@ -163,7 +166,7 @@ ALTER TABLE `dmz_doc_attachment` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_doc_link` +ALTER TABLE dmz_doc_link CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `folderid` `c_spaceid` CHAR(16) NOT NULL, @@ -178,7 +181,7 @@ ALTER TABLE `dmz_doc_link` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_section` +ALTER TABLE dmz_section CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, @@ -196,7 +199,7 @@ ALTER TABLE `dmz_section` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_section_meta` +ALTER TABLE dmz_section_meta CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL DEFAULT '', @@ -207,7 +210,7 @@ ALTER TABLE `dmz_section_meta` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_section_template` +ALTER TABLE dmz_section_template CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `labelid` `c_spaceid` CHAR(16) DEFAULT '', @@ -224,7 +227,7 @@ ALTER TABLE `dmz_section_template` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_section_revision` +ALTER TABLE dmz_section_revision CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, @@ -240,7 +243,7 @@ ALTER TABLE `dmz_section_revision` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_user` +ALTER TABLE dmz_user CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `firstname` `c_firstname` VARCHAR(500) NOT NULL DEFAULT '', CHANGE `lastname` `c_lastname` VARCHAR(500) NOT NULL DEFAULT '', @@ -255,7 +258,7 @@ ALTER TABLE `dmz_user` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_user_account` +ALTER TABLE dmz_user_account CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL, @@ -267,7 +270,7 @@ ALTER TABLE `dmz_user_account` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_user_activity` +ALTER TABLE dmz_user_activity CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL, CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL, @@ -278,17 +281,17 @@ ALTER TABLE `dmz_user_activity` CHANGE `metadata` `c_metadata` VARCHAR(1000) NOT NULL DEFAULT '', CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_user_config` +ALTER TABLE dmz_user_config CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL, CHANGE `key` `c_key` CHAR(200) NOT NULL, CHANGE `config` `c_config` JSON; -ALTER TABLE `dmz_config` +ALTER TABLE dmz_config CHANGE `key` `c_key` CHAR(200) NOT NULL, CHANGE `config` `c_config` JSON; -ALTER TABLE `dmz_pin` +ALTER TABLE dmz_pin CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) DEFAULT '', @@ -299,7 +302,7 @@ ALTER TABLE `dmz_pin` CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_search` +ALTER TABLE dmz_search CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, CHANGE `itemid` `c_itemid` CHAR(16) NOT NULL DEFAULT '', @@ -307,14 +310,14 @@ ALTER TABLE `dmz_search` CHANGE `content` `c_content` LONGTEXT, CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_audit_log` +ALTER TABLE dmz_audit_log CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `userid` `c_userid` CHAR(16) NOT NULL, CHANGE `eventtype` `c_eventtype` VARCHAR(100) NOT NULL DEFAULT '', CHANGE `ip` `c_ip` VARCHAR(39) NOT NULL DEFAULT '', CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP; -ALTER TABLE `dmz_action` +ALTER TABLE dmz_action CHANGE `refid` `c_refid` CHAR(16) NOT NULL, CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL, CHANGE `documentid` `c_docid` CHAR(16) NOT NULL, diff --git a/core/env/runtime.go b/core/env/runtime.go index 789426d5..27207610 100644 --- a/core/env/runtime.go +++ b/core/env/runtime.go @@ -107,9 +107,17 @@ type StoreProvider interface { // that records the database version number. QueryRecordVersionUpgrade(version int) string + // QueryRecordVersionUpgrade returns database specific insert statement + // that records the database version number. + // For use on databases before The Great Schema Migration (v25, MySQL). + QueryRecordVersionUpgradeLegacy(version int) string + // QueryGetDatabaseVersion returns the schema version number. QueryGetDatabaseVersion() string + // QueryGetDatabaseVersionLegacy returns the schema version number before The Great Schema Migration (v25, MySQL). + QueryGetDatabaseVersionLegacy() string + // QueryTableList returns a list tables in Documize database. QueryTableList() string diff --git a/domain/activity/mysql/store.go b/domain/activity/mysql/store.go index 2d0c79d3..ccf1941a 100644 --- a/domain/activity/mysql/store.go +++ b/domain/activity/mysql/store.go @@ -34,7 +34,7 @@ func (s Scope) RecordUserActivity(ctx domain.RequestContext, activity activity.U activity.UserID = ctx.UserID activity.Created = time.Now().UTC() - _, err = ctx.Transaction.Exec("INSERT INTO dmz_user_activity (c_orgid, c_userid, c_spaceid, c_docid, c_pageid, c_sourcetype, c_activitytype, c_metadata, c_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", + _, err = ctx.Transaction.Exec("INSERT INTO dmz_user_activity (c_orgid, c_userid, c_spaceid, c_docid, c_sectionid, c_sourcetype, c_activitytype, c_metadata, c_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", activity.OrgID, activity.UserID, activity.SpaceID, activity.DocumentID, activity.SectionID, activity.SourceType, activity.ActivityType, activity.Metadata, activity.Created) if err != nil { @@ -46,15 +46,15 @@ func (s Scope) RecordUserActivity(ctx domain.RequestContext, activity activity.U // GetDocumentActivity returns the metadata for a specified document. func (s Scope) GetDocumentActivity(ctx domain.RequestContext, id string) (a []activity.DocumentActivity, err error) { - qry := `SELECT a.id, DATE(a.c_created) as created, a.c_orgid as orgid, + qry := `SELECT a.id, DATE(a.c_created) AS created, a.c_orgid AS orgid, IFNULL(a.c_userid, '') AS userid, a.c_spaceid AS spaceid, a.docid AS documentid, a.sectionid AS sectionid, a.c_activitytype AS activitytype, a.c_metadata AS metadata, IFNULL(u.c_firstname, 'Anonymous') AS firstname, IFNULL(u.c_lastname, 'Viewer') AS lastname, - IFNULL(p.c_name, '') as sectionname + IFNULL(p.c_name, '') AS sectionname FROM dmz_user_activity a - LEFT JOIN user u ON a.c_userid=u.c_refid - LEFT JOIN page p ON a.c_pageid=p.c_refid + LEFT JOIN dmz_user u ON a.c_userid=u.c_refid + LEFT JOIN dmz_section p ON a.c_sectionid=p.c_refid WHERE a.c_orgid=? AND a.c_docid=? AND a.c_userid != '0' AND a.c_userid != '' ORDER BY a.c_created DESC` diff --git a/domain/auth/endpoint.go b/domain/auth/endpoint.go index d91e84f0..d2866761 100644 --- a/domain/auth/endpoint.go +++ b/domain/auth/endpoint.go @@ -190,7 +190,7 @@ func (h *Handler) ValidateToken(w http.ResponseWriter, r *http.Request) { rc.OrgName = org.Title rc.Administrator = false rc.Editor = false - rc.Global = false + rc.GlobalAdmin = false rc.AppURL = r.Host rc.Subdomain = organization.GetSubdomainFromHost(r) rc.SSL = r.TLS != nil @@ -210,7 +210,7 @@ func (h *Handler) ValidateToken(w http.ResponseWriter, r *http.Request) { rc.Administrator = u.Admin rc.Editor = u.Editor - rc.Global = u.Global + rc.GlobalAdmin = u.GlobalAdmin response.WriteJSON(w, u) } diff --git a/domain/auth/ldap/ldap.go b/domain/auth/ldap/ldap.go index 7c8d4297..11c53c1e 100644 --- a/domain/auth/ldap/ldap.go +++ b/domain/auth/ldap/ldap.go @@ -250,7 +250,7 @@ func convertUser(c lm.LDAPConfig, lu lm.LDAPUser) (du user.User) { du.ViewUsers = false du.Analytics = false du.Admin = false - du.Global = false + du.GlobalAdmin = false du.Editor = c.DefaultPermissionAddSpace du.Email = lu.Email du.Firstname = lu.Firstname diff --git a/domain/block/endpoint.go b/domain/block/endpoint.go index 02034ba2..b075fb5e 100644 --- a/domain/block/endpoint.go +++ b/domain/block/endpoint.go @@ -54,10 +54,11 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { err = json.Unmarshal(body, &b) if err != nil { response.WriteBadRequestError(w, method, err.Error()) + h.Runtime.Log.Error(method, err) return } - if !permission.CanUploadDocument(ctx, *h.Store, b.LabelID) { + if !permission.CanUploadDocument(ctx, *h.Store, b.SpaceID) { response.WriteForbiddenError(w) return } @@ -67,6 +68,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { ctx.Transaction, err = h.Runtime.Db.Beginx() if err != nil { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -74,6 +76,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -84,6 +87,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { b, err = h.Store.Block.Get(ctx, b.RefID) if err != nil { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -104,6 +108,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) { b, err := h.Store.Block.Get(ctx, blockID) if err != nil { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -132,6 +137,7 @@ func (h *Handler) GetBySpace(w http.ResponseWriter, r *http.Request) { if err != nil { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -165,7 +171,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { b.RefID = blockID - if !permission.CanUploadDocument(ctx, *h.Store, b.LabelID) { + if !permission.CanUploadDocument(ctx, *h.Store, b.SpaceID) { response.WriteForbiddenError(w) return } @@ -173,6 +179,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { ctx.Transaction, err = h.Runtime.Db.Beginx() if err != nil { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -180,6 +187,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -212,6 +220,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) { if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } @@ -219,6 +228,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) { if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } diff --git a/domain/block/mysql/store.go b/domain/block/mysql/store.go index 47d3cdd1..49c85ba4 100644 --- a/domain/block/mysql/store.go +++ b/domain/block/mysql/store.go @@ -35,7 +35,7 @@ func (s Scope) Add(ctx domain.RequestContext, b block.Block) (err error) { b.Revised = time.Now().UTC() _, err = ctx.Transaction.Exec("INSERT INTO dmz_section_template (c_refid, c_orgid, c_spaceid, c_userid, c_contenttype, c_type, c_name, c_body, c_desc, c_rawbody, c_config, c_external, used, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - b.RefID, b.OrgID, b.SpaceID, b.UserID, b.ContentType, b.PageType, b.Name, b.Body, b.Excerpt, b.RawBody, b.Config, b.ExternalSource, b.Used, b.Created, b.Revised) + b.RefID, b.OrgID, b.SpaceID, b.UserID, b.ContentType, b.Type, b.Name, b.Body, b.Excerpt, b.RawBody, b.Config, b.ExternalSource, b.Used, b.Created, b.Revised) if err != nil { err = errors.Wrap(err, "execute insert block") @@ -53,7 +53,7 @@ func (s Scope) Get(ctx domain.RequestContext, id string) (b block.Block, err err a.c_name AS name, a.c_body AS body, a.c_desc AS excerpt, a.c_rawbody AS rawbody, a.c_config AS config, a.c_external AS externalsource, a.c_used AS used, a.c_created AS created, a.c_revised AS revised, - b.c_firstname a firstname, b.c_lastname AS lastname + b.c_firstname AS firstname, b.c_lastname AS lastname FROM dmz_section_template a LEFT JOIN dmz_user b ON a.c_userid = b.c_refid WHERE a.c_orgid=? AND a.c_refid=?`, ctx.OrgID, id) @@ -74,7 +74,7 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (b []block. a.c_name AS name, a.c_body AS body, a.c_desc AS excerpt, a.c_rawbody AS rawbody, a.c_config AS config, a.c_external AS externalsource, a.c_used AS used, a.c_created AS created, a.c_revised AS revised, - b.c_firstname a firstname, b.c_lastname AS lastname + b.c_firstname AS firstname, b.c_lastname AS lastname FROM dmz_section_template a LEFT JOIN dmz_user b ON a.c_userid = b.c_refid WHERE a.c_orgid=? AND a.c_spaceid=? ORDER BY a.c_name`, diff --git a/domain/category/endpoint.go b/domain/category/endpoint.go index 717fe85b..4d9a7d4e 100644 --- a/domain/category/endpoint.go +++ b/domain/category/endpoint.go @@ -74,9 +74,9 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { } // Category max length 30. - cat.Category = strings.TrimSpace(cat.Category) - if len(cat.Category) > 30 { - cat.Category = cat.Category[:30] + cat.Name = strings.TrimSpace(cat.Name) + if len(cat.Name) > 30 { + cat.Name = cat.Name[:30] } err = h.Store.Category.Add(ctx, cat) @@ -200,7 +200,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { cat.OrgID = ctx.OrgID cat.RefID = categoryID - ok := permission.HasPermission(ctx, *h.Store, cat.LabelID, pm.SpaceManage, pm.SpaceOwner) + ok := permission.HasPermission(ctx, *h.Store, cat.SpaceID, pm.SpaceManage, pm.SpaceOwner) if !ok || !ctx.Authenticated { response.WriteForbiddenError(w) return @@ -252,7 +252,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) { return } - ok := permission.HasPermission(ctx, *h.Store, cat.LabelID, pm.SpaceManage, pm.SpaceOwner) + ok := permission.HasPermission(ctx, *h.Store, cat.SpaceID, pm.SpaceManage, pm.SpaceOwner) if !ok || !ctx.Authenticated { response.WriteForbiddenError(w) return @@ -358,7 +358,7 @@ func (h *Handler) SetDocumentCategoryMembership(w http.ResponseWriter, r *http.R return } - if !permission.HasPermission(ctx, *h.Store, cats[0].LabelID, pm.DocumentAdd, pm.DocumentEdit) { + if !permission.HasPermission(ctx, *h.Store, cats[0].SpaceID, pm.DocumentAdd, pm.DocumentEdit) { response.WriteForbiddenError(w) return } @@ -413,7 +413,7 @@ func (h *Handler) GetDocumentCategoryMembership(w http.ResponseWriter, r *http.R return } - if !permission.HasPermission(ctx, *h.Store, doc.LabelID, pm.SpaceView, pm.DocumentAdd, pm.DocumentEdit) { + if !permission.HasPermission(ctx, *h.Store, doc.SpaceID, pm.SpaceView, pm.DocumentAdd, pm.DocumentEdit) { response.WriteForbiddenError(w) return } diff --git a/domain/category/mysql/store.go b/domain/category/mysql/store.go index 14669318..50753c71 100644 --- a/domain/category/mysql/store.go +++ b/domain/category/mysql/store.go @@ -225,7 +225,7 @@ func (s Scope) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string c = []category.SummaryModel{} err = s.Runtime.Db.Select(&c, ` - SELECT 'documents' AS type, c_categoryid, COUNT(*) AS count + SELECT 'documents' AS type, c_categoryid AS categoryid, COUNT(*) AS count FROM dmz_category_member WHERE c_orgid=? AND c_spaceid=? AND c_docid IN ( @@ -241,13 +241,13 @@ func (s Scope) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string GROUP BY c_groupid ) AS x INNER JOIN dmz_doc AS d ON d.c_groupid=x.c_groupid AND d.c_versionorder=x.latestversion ) - GROUP BY c_categoryid, c_type + GROUP BY c_categoryid, type UNION ALL SELECT 'users' AS type, c_refid AS categoryid, count(*) AS count FROM dmz_permission WHERE c_orgid=? AND c_location='category' AND c_refid IN (SELECT c_refid FROM dmz_category WHERE c_orgid=? AND c_spaceid=?) - GROUP BY c_refid, c_type`, + GROUP BY c_refid, type`, ctx.OrgID, spaceID, ctx.OrgID, spaceID, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, spaceID) @@ -286,7 +286,7 @@ func (s Scope) GetSpaceCategoryMembership(ctx domain.RequestContext, spaceID str err = s.Runtime.Db.Select(&c, ` SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_categoryid AS categoryid, c_docid AS documentid, c_created AS created, c_revised AS revised FROM dmz_category_member - WHERE c_orgid=? AND c_spaceid=? AND spaceid IN + WHERE c_orgid=? AND c_spaceid=? AND c_spaceid IN (SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN (SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view' UNION ALL @@ -311,7 +311,7 @@ func (s Scope) GetOrgCategoryMembership(ctx domain.RequestContext, userID string err = s.Runtime.Db.Select(&c, ` SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_categoryid AS categoryid, c_docid AS documentid, c_created AS created, c_revised AS revised FROM dmz_category_member - WHERE c_orgid=? AND c_spaceid IN + WHERE c_orgid=? AND c_spaceid IN (SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN (SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view' UNION ALL diff --git a/domain/context.go b/domain/context.go index 42c40722..0ed8660f 100644 --- a/domain/context.go +++ b/domain/context.go @@ -42,7 +42,7 @@ type RequestContext struct { Analytics bool Active bool Editor bool - Global bool + GlobalAdmin bool ViewUsers bool } diff --git a/domain/conversion/conversion.go b/domain/conversion/conversion.go index 6564e197..a097c13c 100644 --- a/domain/conversion/conversion.go +++ b/domain/conversion/conversion.go @@ -171,7 +171,7 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St document := convertFileResult(filename, fileResult) document.Job = job document.OrgID = ctx.OrgID - document.LabelID = sp.RefID + document.SpaceID = sp.RefID document.UserID = ctx.UserID documentID := uniqueid.Generate() document.RefID = documentID @@ -193,16 +193,16 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St p.OrgID = ctx.OrgID p.DocumentID = documentID p.Level = v.Level - p.Title = v.Title + p.Name = v.Title p.Body = string(v.Body) p.Sequence = float64(k+1) * 1024.0 // need to start above 0 to allow insertion before the first item pageID := uniqueid.Generate() p.RefID = pageID p.ContentType = "wysiwyg" - p.PageType = "section" + p.Type = "section" meta := page.Meta{} - meta.PageID = pageID + meta.SectionID = pageID meta.RawBody = p.Body meta.Config = "{}" @@ -245,7 +245,7 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St } store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: newDocument.LabelID, + SpaceID: newDocument.SpaceID, DocumentID: newDocument.RefID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypeCreated}) @@ -278,13 +278,13 @@ func convertFileResult(filename string, fileResult *api.DocumentConversionRespon document = doc.Document{} document.RefID = "" document.OrgID = "" - document.LabelID = "" + document.SpaceID = "" document.Job = "" document.Location = filename if fileResult != nil { if len(fileResult.Pages) > 0 { - document.Title = fileResult.Pages[0].Title + document.Name = fileResult.Pages[0].Title document.Slug = stringutil.MakeSlug(fileResult.Pages[0].Title) } document.Excerpt = fileResult.Excerpt diff --git a/domain/document/document.go b/domain/document/document.go index 73a9308e..22cdf663 100644 --- a/domain/document/document.go +++ b/domain/document/document.go @@ -100,7 +100,7 @@ func CopyDocument(ctx domain.RequestContext, s domain.Store, documentID string) pageID := uniqueid.Generate() p.RefID = pageID - meta.PageID = pageID + meta.SectionID = pageID meta.DocumentID = newDocumentID m := page.NewPage{} diff --git a/domain/document/endpoint.go b/domain/document/endpoint.go index 50d165d9..fe251356 100644 --- a/domain/document/endpoint.go +++ b/domain/document/endpoint.go @@ -70,7 +70,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) { return } - if !permission.CanViewSpaceDocument(ctx, *h.Store, document.LabelID) { + if !permission.CanViewSpaceDocument(ctx, *h.Store, document.SpaceID) { response.WriteForbiddenError(w) return } @@ -85,7 +85,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) { } err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: document.LabelID, + SpaceID: document.SpaceID, DocumentID: document.RefID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypeRead}) @@ -166,7 +166,7 @@ func (h *Handler) BySpace(w http.ResponseWriter, r *http.Request) { } // Sort by title. - sort.Sort(doc.ByTitle(documents)) + sort.Sort(doc.ByName(documents)) // Remove documents that cannot be seen due to lack of // category view/access permission. @@ -231,9 +231,9 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { return } - if oldDoc.LabelID != d.LabelID { + if oldDoc.SpaceID != d.SpaceID { h.Store.Category.RemoveDocumentCategories(ctx, d.RefID) - err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.LabelID, d.LabelID) + err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.SpaceID, d.SpaceID) if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) @@ -268,7 +268,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { // Record document being marked as archived. if d.Lifecycle == workflow.LifecycleArchived { h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: d.LabelID, + SpaceID: d.SpaceID, DocumentID: documentID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypeArchived}) @@ -277,7 +277,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { // Record document being marked as draft. if d.Lifecycle == workflow.LifecycleDraft { h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: d.LabelID, + SpaceID: d.SpaceID, DocumentID: documentID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypeDraft}) @@ -286,7 +286,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) { // Record document being marked as live. if d.Lifecycle == workflow.LifecycleLive { h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: d.LabelID, + SpaceID: d.SpaceID, DocumentID: documentID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypePublished}) @@ -340,7 +340,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) { // If approval workflow then only approvers can delete page if doc.Protection == workflow.ProtectionReview { - approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.LabelID, doc.RefID, pm.DocumentApprove) + approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.SpaceID, doc.RefID, pm.DocumentApprove) if err != nil { response.WriteForbiddenError(w) h.Runtime.Log.Error(method, err) @@ -389,7 +389,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) { // Draft actions are not logged if doc.Lifecycle == workflow.LifecycleLive { h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: doc.LabelID, + SpaceID: doc.SpaceID, DocumentID: documentID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypeDeleted}) @@ -458,7 +458,7 @@ func (h *Handler) SearchDocuments(w http.ResponseWriter, r *http.Request) { } err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: "", + SpaceID: "", DocumentID: "", Metadata: options.Keywords, SourceType: activity.SourceTypeSearch, @@ -504,7 +504,7 @@ func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.Que if _, isExisting := prev[q[i].DocumentID]; !isExisting { err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: q[i].SpaceID, + SpaceID: q[i].SpaceID, DocumentID: q[i].DocumentID, Metadata: keywords, SourceType: activity.SourceTypeSearch, @@ -545,7 +545,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) { return } - if !permission.CanViewSpaceDocument(ctx, *h.Store, document.LabelID) { + if !permission.CanViewSpaceDocument(ctx, *h.Store, document.SpaceID) { response.WriteForbiddenError(w) return } @@ -557,9 +557,10 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) { } // permissions - perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.LabelID) + perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.SpaceID) if err != nil && err != sql.ErrNoRows { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } if len(perms) == 0 { @@ -570,6 +571,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) { roles, err := h.Store.Permission.GetUserDocumentPermissions(ctx, document.RefID) if err != nil && err != sql.ErrNoRows { response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) return } if len(roles) == 0 { @@ -629,7 +631,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) { if document.Lifecycle == workflow.LifecycleLive { err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{ - LabelID: document.LabelID, + SpaceID: document.SpaceID, DocumentID: document.RefID, SourceType: activity.SourceTypeDocument, ActivityType: activity.TypeRead}) diff --git a/domain/document/export.go b/domain/document/export.go index 0196c24f..a8d05a2e 100644 --- a/domain/document/export.go +++ b/domain/document/export.go @@ -153,7 +153,7 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc for _, d := range docs { docHTML, e := processDocument(ctx, s, d.RefID) if e == nil && len(docHTML) > 0 { - toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title}) + toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name}) b.WriteString(docHTML) } else { return toc, b.String(), err @@ -221,7 +221,7 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c for _, d := range exportDocs { docHTML, e := processDocument(ctx, s, d.RefID) if e == nil && len(docHTML) > 0 { - toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title}) + toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name}) b.WriteString(docHTML) } else { return toc, b.String(), err @@ -274,7 +274,7 @@ func exportDocument(ctx domain.RequestContext, s domain.Store, spaceID string, d if permission.CanViewDocument(ctx, s, d.RefID) { docHTML, e := processDocument(ctx, s, d.RefID) if e == nil && len(docHTML) > 0 { - toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title}) + toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name}) b.WriteString(docHTML) } else { return toc, b.String(), err @@ -325,7 +325,7 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin // Put out document name. b.WriteString(fmt.Sprintf("