Eliminated some JS errors for guests on Cosora.

Fixed the build tags for the alt database engines.
Tweaked the quotes on the PgSQL adapter. Still not functional.
Removed the SQLite build tag as it's unlikely that it'll ever be implemented.
This commit is contained in:
Azareal 2018-08-15 17:02:57 +10:00
parent f2b210248a
commit 0305571cb3
49 changed files with 102 additions and 103 deletions

View File

@ -1,4 +1,4 @@
// +build !pgsql, !sqlite, !mssql
// +build !pgsql,!mssql
/* This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. */

View File

@ -33,56 +33,56 @@ func _gen_pgsql() (err error) {
common.DebugLog("Building the generated statements")
common.DebugLog("Preparing addForumPermsToForum statement.")
stmts.addForumPermsToForum, err = db.Prepare("INSERT INTO "forums_permissions"("gid","fid","preset","permissions") VALUES (?,?,?,?)")
stmts.addForumPermsToForum, err = db.Prepare("INSERT INTO \"forums_permissions\"(\"gid\",\"fid\",\"preset\",\"permissions\") VALUES (?,?,?,?)")
if err != nil {
log.Print("Error in addForumPermsToForum statement.")
return err
}
common.DebugLog("Preparing addTheme statement.")
stmts.addTheme, err = db.Prepare("INSERT INTO "themes"("uname","default") VALUES (?,?)")
stmts.addTheme, err = db.Prepare("INSERT INTO \"themes\"(\"uname\",\"default\") VALUES (?,?)")
if err != nil {
log.Print("Error in addTheme statement.")
return err
}
common.DebugLog("Preparing updateTheme statement.")
stmts.updateTheme, err = db.Prepare("UPDATE `themes` SET `default` = ? WHERE `uname` = ?")
stmts.updateTheme, err = db.Prepare("UPDATE \"themes\" SET `default` = ? WHERE `uname` = ?")
if err != nil {
log.Print("Error in updateTheme statement.")
return err
}
common.DebugLog("Preparing updateGroupPerms statement.")
stmts.updateGroupPerms, err = db.Prepare("UPDATE `users_groups` SET `permissions` = ? WHERE `gid` = ?")
stmts.updateGroupPerms, err = db.Prepare("UPDATE \"users_groups\" SET `permissions` = ? WHERE `gid` = ?")
if err != nil {
log.Print("Error in updateGroupPerms statement.")
return err
}
common.DebugLog("Preparing updateGroup statement.")
stmts.updateGroup, err = db.Prepare("UPDATE `users_groups` SET `name` = ?,`tag` = ? WHERE `gid` = ?")
stmts.updateGroup, err = db.Prepare("UPDATE \"users_groups\" SET `name` = ?,`tag` = ? WHERE `gid` = ?")
if err != nil {
log.Print("Error in updateGroup statement.")
return err
}
common.DebugLog("Preparing updateEmail statement.")
stmts.updateEmail, err = db.Prepare("UPDATE `emails` SET `email` = ?,`uid` = ?,`validated` = ?,`token` = ? WHERE `email` = ?")
stmts.updateEmail, err = db.Prepare("UPDATE \"emails\" SET `email` = ?,`uid` = ?,`validated` = ?,`token` = ? WHERE `email` = ?")
if err != nil {
log.Print("Error in updateEmail statement.")
return err
}
common.DebugLog("Preparing setTempGroup statement.")
stmts.setTempGroup, err = db.Prepare("UPDATE `users` SET `temp_group` = ? WHERE `uid` = ?")
stmts.setTempGroup, err = db.Prepare("UPDATE \"users\" SET `temp_group` = ? WHERE `uid` = ?")
if err != nil {
log.Print("Error in setTempGroup statement.")
return err
}
common.DebugLog("Preparing bumpSync statement.")
stmts.bumpSync, err = db.Prepare("UPDATE `sync` SET `last_update` = LOCALTIMESTAMP()")
stmts.bumpSync, err = db.Prepare("UPDATE \"sync\" SET `last_update` = LOCALTIMESTAMP()")
if err != nil {
log.Print("Error in bumpSync statement.")
return err

View File

@ -3,7 +3,7 @@
/*
*
* Gosora MSSQL Interface
* Copyright Azareal 2016 - 2018
* Copyright Azareal 2016 - 2019
*
*/
package main
@ -13,6 +13,7 @@ import (
"log"
"net/url"
"./common"
"./query_gen/lib"
_ "github.com/denisenkom/go-mssqldb"
)
@ -27,11 +28,11 @@ func init() {
func initMSSQL() (err error) {
// TODO: Move this bit to the query gen lib
query := url.Values{}
query.Add("database", dbConfig.Dbname)
query.Add("database", common.DbConfig.Dbname)
u := &url.URL{
Scheme: "sqlserver",
User: url.UserPassword(dbConfig.Username, dbConfig.Password),
Host: dbConfig.Host + ":" + dbConfig.Port,
User: url.UserPassword(common.DbConfig.Username, common.DbConfig.Password),
Host: common.DbConfig.Host + ":" + common.DbConfig.Port,
Path: dbInstance,
RawQuery: query.Encode(),
}
@ -72,42 +73,42 @@ func initMSSQL() (err error) {
}
// TODO: Is there a less noisy way of doing this for tests?
log.Print("Preparing getActivityFeedByWatcher statement.")
getActivityFeedByWatcherStmt, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM [activity_stream_matches] INNER JOIN [activity_stream] ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE [watcher] = ? ORDER BY activity_stream.asid DESC OFFSET 0 ROWS FETCH NEXT 8 ROWS ONLY")
/*log.Print("Preparing getActivityFeedByWatcher statement.")
stmts.getActivityFeedByWatcherStmt, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM [activity_stream_matches] INNER JOIN [activity_stream] ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE [watcher] = ? ORDER BY activity_stream.asid DESC OFFSET 0 ROWS FETCH NEXT 8 ROWS ONLY")
if err != nil {
return err
}
log.Print("Preparing getActivityCountByWatcher statement.")
getActivityCountByWatcherStmt, err = db.Prepare("SELECT count(*) FROM [activity_stream_matches] INNER JOIN [activity_stream] ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE [watcher] = ?")
stmts.getActivityCountByWatcherStmt, err = db.Prepare("SELECT count(*) FROM [activity_stream_matches] INNER JOIN [activity_stream] ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE [watcher] = ?")
if err != nil {
return err
}
log.Print("Preparing todaysPostCount statement.")
todaysPostCountStmt, err = db.Prepare("select count(*) from replies where createdAt >= DATEADD(DAY, -1, GETUTCDATE())")
stmts.todaysPostCountStmt, err = db.Prepare("select count(*) from replies where createdAt >= DATEADD(DAY, -1, GETUTCDATE())")
if err != nil {
return err
}
log.Print("Preparing todaysTopicCount statement.")
todaysTopicCountStmt, err = db.Prepare("select count(*) from topics where createdAt >= DATEADD(DAY, -1, GETUTCDATE())")
stmts.todaysTopicCountStmt, err = db.Prepare("select count(*) from topics where createdAt >= DATEADD(DAY, -1, GETUTCDATE())")
if err != nil {
return err
}
}*/
log.Print("Preparing todaysTopicCountByForum statement.")
// TODO: Stop hard-coding this query
todaysTopicCountByForum, err = db.Prepare("select count(*) from topics where createdAt >= DATEADD(DAY, -1, GETUTCDATE()) and parentID = ?")
stmts.todaysTopicCountByForum, err = db.Prepare("select count(*) from topics where createdAt >= DATEADD(DAY, -1, GETUTCDATE()) and parentID = ?")
if err != nil {
return err
}
log.Print("Preparing todaysNewUserCount statement.")
todaysNewUserCountStmt, err = db.Prepare("select count(*) from users where createdAt >= DATEADD(DAY, -1, GETUTCDATE())")
/*log.Print("Preparing todaysNewUserCount statement.")
stmts.todaysNewUserCountStmt, err = db.Prepare("select count(*) from users where createdAt >= DATEADD(DAY, -1, GETUTCDATE())")
if err != nil {
return err
}
}*/
return nil
}

View File

@ -1,4 +1,4 @@
// +build !pgsql, !sqlite, !mssql
// +build !pgsql,!mssql
/*
*

View File

@ -24,11 +24,11 @@ func init() {
func initPgsql() (err error) {
// TODO: Investigate connect_timeout to see what it does exactly and whether it's relevant to us
var _dbpassword string
if dbpassword != "" {
if common.DbConfig.Password != "" {
_dbpassword = " password='" + _escape_bit(common.DbConfig.Password) + "'"
}
// TODO: Move this bit to the query gen lib
db, err = sql.Open("postgres", "host='"+_escape_bit(common.DbConfig.Host)+"' port='"+_escape_bit(common.DbConfig.Port)+"' user='"+_escape_bit(common.DbConfig.Username)+"' dbname='"+_escape_bit(common.Config.Dbname)+"'"+_dbpassword+" sslmode='"+dbSslmode+"'")
db, err = sql.Open("postgres", "host='"+_escape_bit(common.DbConfig.Host)+"' port='"+_escape_bit(common.DbConfig.Port)+"' user='"+_escape_bit(common.DbConfig.Username)+"' dbname='"+_escape_bit(common.DbConfig.Dbname)+"'"+_dbpassword+" sslmode='"+dbSslmode+"'")
if err != nil {
return err
}

View File

@ -719,7 +719,7 @@ func (adapter *MysqlAdapter) Write() error {
}
// TODO: Move these custom queries out of this file
out := `// +build !pgsql, !sqlite, !mssql
out := `// +build !pgsql,!mssql
/* This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. */

View File

@ -67,7 +67,7 @@ func (adapter *PgsqlAdapter) CreateTable(name string, table string, charset stri
return "", errors.New("You can't have a table with no columns")
}
var querystr = "CREATE TABLE `" + table + "` ("
var querystr = "CREATE TABLE \"" + table + "\" ("
for _, column := range columns {
if column.AutoIncrement {
column.Type = "serial"
@ -222,7 +222,8 @@ func (adapter *PgsqlAdapter) SimpleUpdate(name string, table string, set string,
if set == "" {
return "", errors.New("You need to set data in this update statement")
}
var querystr = "UPDATE `" + table + "` SET "
var querystr = "UPDATE \"" + table + "\" SET "
for _, item := range processSet(set) {
querystr += "`" + item.Column + "` ="
for _, token := range item.Expr {
@ -243,7 +244,6 @@ func (adapter *PgsqlAdapter) SimpleUpdate(name string, table string, set string,
}
querystr += ","
}
// Remove the trailing comma
querystr = querystr[0 : len(querystr)-1]
@ -414,7 +414,7 @@ func (adapter *PgsqlAdapter) Write() error {
stmts += "\t" + name + " *sql.Stmt\n"
body += `
common.DebugLog("Preparing ` + name + ` statement.")
stmts.` + name + `, err = db.Prepare("` + stmt.Contents + `")
stmts.` + name + `, err = db.Prepare("` + strings.Replace(stmt.Contents, "\"", "\\\"", -1) + `")
if err != nil {
log.Print("Error in ` + name + ` statement.")
return err

View File

@ -1,4 +1,4 @@
CREATE TABLE `activity_stream` (
CREATE TABLE "activity_stream" (
`asid` serial not null,
`actor` int not null,
`targetUser` int not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `activity_stream_matches` (
CREATE TABLE "activity_stream_matches" (
`watcher` int not null,
`asid` int not null
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `activity_subscriptions` (
CREATE TABLE "activity_subscriptions" (
`user` int not null,
`targetID` int not null,
`targetType` varchar (50) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `administration_logs` (
CREATE TABLE "administration_logs" (
`action` varchar (100) not null,
`elementID` int not null,
`elementType` varchar (100) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `attachments` (
CREATE TABLE "attachments" (
`attachID` serial not null,
`sectionID` int DEFAULT 0 not null,
`sectionTable` varchar (200) DEFAULT 'forums' not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `emails` (
CREATE TABLE "emails" (
`email` varchar (200) not null,
`uid` int not null,
`validated` boolean DEFAULT 0 not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `forums` (
CREATE TABLE "forums" (
`fid` serial not null,
`name` varchar (100) not null,
`desc` varchar (200) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `forums_permissions` (
CREATE TABLE "forums_permissions" (
`fid` int not null,
`gid` int not null,
`preset` varchar (100) DEFAULT '' not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `likes` (
CREATE TABLE "likes" (
`weight` tinyint DEFAULT 1 not null,
`targetItem` int not null,
`targetType` varchar (50) DEFAULT 'replies' not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `menu_items` (
CREATE TABLE "menu_items" (
`miid` serial not null,
`mid` int not null,
`name` varchar (200) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `menus` (
CREATE TABLE "menus" (
`mid` serial not null,
primary key(`mid`)
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `moderation_logs` (
CREATE TABLE "moderation_logs" (
`action` varchar (100) not null,
`elementID` int not null,
`elementType` varchar (100) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `pages` (
CREATE TABLE "pages" (
`pid` serial not null,
`name` varchar (200) not null,
`title` varchar (200) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `plugins` (
CREATE TABLE "plugins" (
`uname` varchar (180) not null,
`active` boolean DEFAULT 0 not null,
`installed` boolean DEFAULT 0 not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `polls` (
CREATE TABLE "polls" (
`pollID` serial not null,
`parentID` int DEFAULT 0 not null,
`parentTable` varchar (100) DEFAULT 'topics' not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `polls_options` (
CREATE TABLE "polls_options" (
`pollID` int not null,
`option` int DEFAULT 0 not null,
`votes` int DEFAULT 0 not null

View File

@ -1,5 +0,0 @@
CREATE TABLE `polls_voters` (
`pollID` int not null,
`uid` int not null,
`option` int DEFAULT 0 not null
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `polls_votes` (
CREATE TABLE "polls_votes" (
`pollID` int not null,
`uid` int not null,
`option` int DEFAULT 0 not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `postchunks` (
CREATE TABLE "postchunks" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `registration_logs` (
CREATE TABLE "registration_logs" (
`rlid` serial not null,
`username` varchar (100) not null,
`email` varchar (100) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `replies` (
CREATE TABLE "replies" (
`rid` serial not null,
`tid` int not null,
`content` text not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `revisions` (
CREATE TABLE "revisions" (
`reviseID` serial not null,
`content` text not null,
`contentID` int not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `settings` (
CREATE TABLE "settings" (
`name` varchar (180) not null,
`content` varchar (250) not null,
`type` varchar (50) not null,

View File

@ -1,3 +1,3 @@
CREATE TABLE `sync` (
CREATE TABLE "sync" (
`last_update` timestamp not null
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `themes` (
CREATE TABLE "themes" (
`uname` varchar (180) not null,
`default` boolean DEFAULT 0 not null,
unique(`uname`)

View File

@ -1,4 +1,4 @@
CREATE TABLE `topicchunks` (
CREATE TABLE "topicchunks" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `topics` (
CREATE TABLE "topics" (
`tid` serial not null,
`title` varchar (100) not null,
`content` text not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `users` (
CREATE TABLE "users" (
`uid` serial not null,
`name` varchar (100) not null,
`password` varchar (100) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `users_2fa_keys` (
CREATE TABLE "users_2fa_keys" (
`uid` int not null,
`secret` varchar (100) not null,
`scratch1` varchar (50) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `users_avatar_queue` (
CREATE TABLE "users_avatar_queue" (
`uid` int not null,
primary key(`uid`)
);

View File

@ -1,4 +1,4 @@
CREATE TABLE `users_groups` (
CREATE TABLE "users_groups" (
`gid` serial not null,
`name` varchar (100) not null,
`permissions` text not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `users_groups_scheduler` (
CREATE TABLE "users_groups_scheduler" (
`uid` int not null,
`set_group` int not null,
`issued_by` int not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `users_replies` (
CREATE TABLE "users_replies" (
`rid` serial not null,
`uid` int not null,
`content` text not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `viewchunks` (
CREATE TABLE "viewchunks" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null,
`route` varchar (200) not null

View File

@ -1,4 +1,4 @@
CREATE TABLE `viewchunks_agents` (
CREATE TABLE "viewchunks_agents" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null,
`browser` varchar (200) not null

View File

@ -1,4 +1,4 @@
CREATE TABLE `viewchunks_forums` (
CREATE TABLE "viewchunks_forums" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null,
`forum` int not null

View File

@ -1,4 +1,4 @@
CREATE TABLE `viewchunks_langs` (
CREATE TABLE "viewchunks_langs" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null,
`lang` varchar (200) not null

View File

@ -1,4 +1,4 @@
CREATE TABLE `viewchunks_referrers` (
CREATE TABLE "viewchunks_referrers" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null,
`domain` varchar (200) not null

View File

@ -1,4 +1,4 @@
CREATE TABLE `viewchunks_systems` (
CREATE TABLE "viewchunks_systems" (
`count` int DEFAULT 0 not null,
`createdAt` timestamp not null,
`system` varchar (200) not null

View File

@ -1,4 +1,4 @@
CREATE TABLE `widgets` (
CREATE TABLE "widgets" (
`position` int not null,
`side` varchar (100) not null,
`type` varchar (100) not null,

View File

@ -1,4 +1,4 @@
CREATE TABLE `word_filters` (
CREATE TABLE "word_filters" (
`wfid` serial not null,
`find` varchar (200) not null,
`replacement` varchar (200) not null,

View File

@ -1,6 +1,8 @@
"use strict"
$(document).ready(function(){
let loggedIn = document.head.querySelector("[property='x-loggedin']").content;
if(loggedIn) {
// Is there we way we can append instead? Maybe, an editor plugin?
attachItemCallback = function(attachItem) {
let currentContent = $('#input_content').trumbowyg('html');
@ -31,6 +33,7 @@ $(document).ready(function(){
btns: [['viewHTML'],['strong','em','del'],['link'],['insertImage'],['removeformat']],
autogrow: true,
});
}
// TODO: Refactor this to use `each` less
$('.button_menu').click(function(){