2017-06-05 11:57:27 +00:00
/* WIP Under Construction */
package main
2017-10-16 07:32:58 +00:00
import (
"fmt"
"log"
"os"
"runtime/debug"
2017-06-05 11:57:27 +00:00
2017-10-16 07:32:58 +00:00
"./lib"
)
// TODO: Make sure all the errors in this file propagate upwards properly
2017-06-05 11:57:27 +00:00
func main ( ) {
2017-10-16 07:32:58 +00:00
// Capture panics instead of closing the window at a superhuman speed before the user can read the message on Windows
defer func ( ) {
r := recover ( )
if r != nil {
fmt . Println ( r )
debug . PrintStack ( )
return
}
} ( )
2017-06-05 11:57:27 +00:00
log . Println ( "Running the query generator" )
2017-11-12 05:25:04 +00:00
for _ , adapter := range qgen . Registry {
log . Printf ( "Building the queries for the %s adapter" , adapter . GetName ( ) )
2017-07-12 11:05:18 +00:00
qgen . Install . SetAdapterInstance ( adapter )
2017-11-23 05:37:08 +00:00
qgen . Install . AddPlugins ( NewPrimaryKeySpitter ( ) ) // TODO: Do we really need to fill the spitter for every adapter?
2017-10-16 07:32:58 +00:00
err := writeStatements ( adapter )
if err != nil {
log . Print ( err )
}
err = qgen . Install . Write ( )
if err != nil {
log . Print ( err )
}
err = adapter . Write ( )
if err != nil {
log . Print ( err )
}
2017-06-05 11:57:27 +00:00
}
}
2017-09-10 16:57:22 +00:00
// nolint
2017-11-12 05:25:04 +00:00
func writeStatements ( adapter qgen . Adapter ) error {
2017-10-16 07:32:58 +00:00
err := createTables ( adapter )
2017-07-12 11:05:18 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = seedTables ( adapter )
2017-07-12 11:05:18 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeSelects ( adapter )
2017-06-10 07:58:15 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeLeftJoins ( adapter )
2017-06-12 09:03:14 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeInnerJoins ( adapter )
2017-06-10 07:58:15 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeInserts ( adapter )
2017-06-10 07:58:15 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeUpdates ( adapter )
2017-06-12 09:03:14 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeDeletes ( adapter )
2017-06-14 07:09:44 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeSimpleCounts ( adapter )
2017-06-19 08:06:54 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeInsertSelects ( adapter )
2017-06-19 08:06:54 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeInsertLeftJoins ( adapter )
2017-06-19 08:06:54 +00:00
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-10-16 07:32:58 +00:00
err = writeInsertInnerJoins ( adapter )
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-07-12 11:05:18 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func seedTables ( adapter qgen . Adapter ) error {
2017-10-14 07:39:22 +00:00
qgen . Install . SimpleInsert ( "sync" , "last_update" , "UTC_TIMESTAMP()" )
qgen . Install . SimpleInsert ( "settings" , "name, content, type" , "'url_tags','1','bool'" )
qgen . Install . SimpleInsert ( "settings" , "name, content, type, constraints" , "'activation_type','1','list','1-3'" )
qgen . Install . SimpleInsert ( "settings" , "name, content, type" , "'bigpost_min_words','250','int'" )
qgen . Install . SimpleInsert ( "settings" , "name, content, type" , "'megapost_min_words','1000','int'" )
2017-12-25 06:12:19 +00:00
qgen . Install . SimpleInsert ( "settings" , "name, content, type" , "'meta_desc','','html-attribute'" )
2017-10-14 07:39:22 +00:00
qgen . Install . SimpleInsert ( "themes" , "uname, default" , "'tempra-simple',1" )
qgen . Install . SimpleInsert ( "emails" , "email, uid, validated" , "'admin@localhost',1,1" ) // ? - Use a different default email or let the admin input it during installation?
/ *
The Permissions :
Global Permissions :
BanUsers
ActivateUsers
EditUser
EditUserEmail
EditUserPassword
EditUserGroup
EditUserGroupSuperMod
EditUserGroupAdmin
EditGroup
EditGroupLocalPerms
EditGroupGlobalPerms
EditGroupSuperMod
EditGroupAdmin
ManageForums
EditSettings
ManageThemes
ManagePlugins
ViewAdminLogs
ViewIPs
Non - staff Global Permissions :
UploadFiles
Forum Permissions :
ViewTopic
LikeItem
CreateTopic
EditTopic
DeleteTopic
CreateReply
EditReply
DeleteReply
PinTopic
CloseTopic
2018-01-15 08:24:18 +00:00
MoveTopic
2017-10-14 07:39:22 +00:00
* /
2017-11-23 05:37:08 +00:00
// TODO: Set the permissions on a struct and then serialize the struct and insert that instead of writing raw JSON
2018-01-15 08:24:18 +00:00
qgen . Install . SimpleInsert ( "users_groups" , "name, permissions, plugin_perms, is_mod, is_admin, tag" , ` 'Administrator',' { "BanUsers":true,"ActivateUsers":true,"EditUser":true,"EditUserEmail":true,"EditUserPassword":true,"EditUserGroup":true,"EditUserGroupSuperMod":true,"EditUserGroupAdmin":false,"EditGroup":true,"EditGroupLocalPerms":true,"EditGroupGlobalPerms":true,"EditGroupSuperMod":true,"EditGroupAdmin":false,"ManageForums":true,"EditSettings":true,"ManageThemes":true,"ManagePlugins":true,"ViewAdminLogs":true,"ViewIPs":true,"UploadFiles":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}',' { }',1,1,"Admin" ` )
2017-10-14 07:39:22 +00:00
2018-01-15 08:24:18 +00:00
qgen . Install . SimpleInsert ( "users_groups" , "name, permissions, plugin_perms, is_mod, tag" , ` 'Moderator',' { "BanUsers":true,"ActivateUsers":false,"EditUser":true,"EditUserEmail":false,"EditUserGroup":true,"ViewIPs":true,"UploadFiles":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}',' { }',1,"Mod" ` )
2017-10-14 07:39:22 +00:00
qgen . Install . SimpleInsert ( "users_groups" , "name, permissions, plugin_perms" , ` 'Member',' { "UploadFiles":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"CreateReply":true}',' { }' ` )
qgen . Install . SimpleInsert ( "users_groups" , "name, permissions, plugin_perms, is_banned" , ` 'Banned',' { "ViewTopic":true}',' { }',1 ` )
qgen . Install . SimpleInsert ( "users_groups" , "name, permissions, plugin_perms" , ` 'Awaiting Activation',' { "ViewTopic":true}',' { }' ` )
qgen . Install . SimpleInsert ( "users_groups" , "name, permissions, plugin_perms, tag" , ` 'Not Loggedin',' { "ViewTopic":true}',' { }','Guest' ` )
//
// TODO: Stop processFields() from stripping the spaces in the descriptions in the next commit
qgen . Install . SimpleInsert ( "forums" , "name, active, desc" , "'Reports',0,'All the reports go here'" )
qgen . Install . SimpleInsert ( "forums" , "name, lastTopicID, lastReplyerID, desc" , "'General',1,1,'A place for general discussions which don't fit elsewhere'" )
//
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 1,1,' { "ViewTopic":true,"CreateReply":true,"CreateTopic":true,"PinTopic":true,"CloseTopic":true}' ` )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 2,1,' { "ViewTopic":true,"CreateReply":true,"CloseTopic":true}' ` )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , "3,1,'{}'" )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , "4,1,'{}'" )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , "5,1,'{}'" )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , "6,1,'{}'" )
//
2018-01-15 08:24:18 +00:00
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 1,2,' { "ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true,"EditTopic":true,"DeleteTopic":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}' ` )
2017-10-14 07:39:22 +00:00
2018-01-15 08:24:18 +00:00
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 2,2,' { "ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true,"EditTopic":true,"DeleteTopic":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}' ` )
2017-10-14 07:39:22 +00:00
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 3,2,' { "ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true}' ` )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 4,2,' { "ViewTopic":true}' ` )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 5,2,' { "ViewTopic":true}' ` )
qgen . Install . SimpleInsert ( "forums_permissions" , "gid, fid, permissions" , ` 6,2,' { "ViewTopic":true}' ` )
//
2017-11-06 16:24:45 +00:00
qgen . Install . SimpleInsert ( "topics" , "title, content, parsed_content, createdAt, lastReplyAt, lastReplyBy, createdBy, parentID, ipaddress" , "'Test Topic','A topic automatically generated by the software.','A topic automatically generated by the software.',UTC_TIMESTAMP(),UTC_TIMESTAMP(),1,1,2,'::1'" )
2017-10-14 07:39:22 +00:00
2017-11-06 16:24:45 +00:00
qgen . Install . SimpleInsert ( "replies" , "tid, content, parsed_content, createdAt, createdBy, lastUpdated, lastEdit, lastEditBy, ipaddress" , "1,'A reply!','A reply!',UTC_TIMESTAMP(),1,UTC_TIMESTAMP(),0,0,'::1'" )
2017-10-14 07:39:22 +00:00
2017-07-12 11:05:18 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeSelects ( adapter qgen . Adapter ) error {
2017-11-13 00:31:46 +00:00
build := adapter . Builder ( )
2017-09-18 17:03:52 +00:00
// Looking for getTopic? Your statement is in another castle
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getPassword" ) . Table ( "users" ) . Columns ( "password, salt" ) . Where ( "uid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "isPluginActive" ) . Table ( "plugins" ) . Columns ( "active" ) . Where ( "uname = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
//build.Select("isPluginInstalled").Table("plugins").Columns("installed").Where("uname = ?").Parse()
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getUsersOffset" ) . Table ( "users" ) . Columns ( "uid, name, group, active, is_super_admin, avatar" ) . Orderby ( "uid ASC" ) . Limit ( "?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "isThemeDefault" ) . Table ( "themes" ) . Columns ( "default" ) . Where ( "uname = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getModlogs" ) . Table ( "moderation_logs" ) . Columns ( "action, elementID, elementType, ipaddress, actorID, doneAt" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getModlogsOffset" ) . Table ( "moderation_logs" ) . Columns ( "action, elementID, elementType, ipaddress, actorID, doneAt" ) . Orderby ( "doneAt DESC" ) . Limit ( "?,?" ) . Parse ( )
2018-01-11 08:03:17 +00:00
build . Select ( "getAdminlogsOffset" ) . Table ( "administration_logs" ) . Columns ( "action, elementID, elementType, ipaddress, actorID, doneAt" ) . Orderby ( "doneAt DESC" ) . Limit ( "?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getTopicFID" ) . Table ( "topics" ) . Columns ( "parentID" ) . Where ( "tid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getUserName" ) . Table ( "users" ) . Columns ( "name" ) . Where ( "uid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getEmailsByUser" ) . Table ( "emails" ) . Columns ( "email, validated, token" ) . Where ( "uid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getTopicBasic" ) . Table ( "topics" ) . Columns ( "title, content" ) . Where ( "tid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getActivityEntry" ) . Table ( "activity_stream" ) . Columns ( "actor, targetUser, event, elementType, elementID" ) . Where ( "asid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "forumEntryExists" ) . Table ( "forums" ) . Columns ( "fid" ) . Where ( "name = ''" ) . Orderby ( "fid ASC" ) . Limit ( "0,1" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "groupEntryExists" ) . Table ( "users_groups" ) . Columns ( "gid" ) . Where ( "name = ''" ) . Orderby ( "gid ASC" ) . Limit ( "0,1" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Select ( "getAttachment" ) . Table ( "attachments" ) . Columns ( "sectionID, sectionTable, originID, originTable, uploadedBy, path" ) . Where ( "path = ? AND sectionID = ? AND sectionTable = ?" ) . Parse ( )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
2017-06-10 07:58:15 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeLeftJoins ( adapter qgen . Adapter ) error {
2017-09-18 17:03:52 +00:00
adapter . SimpleLeftJoin ( "getForumTopics" , "topics" , "users" , "topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, users.name, users.avatar" , "topics.createdBy = users.uid" , "topics.parentID = ?" , "topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy desc" , "" )
2017-09-10 16:57:22 +00:00
2017-09-18 17:03:52 +00:00
adapter . SimpleLeftJoin ( "getProfileReplies" , "users_replies" , "users" , "users_replies.rid, users_replies.content, users_replies.createdBy, users_replies.createdAt, users_replies.lastEdit, users_replies.lastEditBy, users.avatar, users.name, users.group" , "users_replies.createdBy = users.uid" , "users_replies.uid = ?" , "" , "" )
2017-09-10 16:57:22 +00:00
2017-06-12 09:03:14 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeInnerJoins ( adapter qgen . Adapter ) ( err error ) {
2017-10-16 07:32:58 +00:00
_ , err = adapter . SimpleInnerJoin ( "getWatchers" , "activity_stream" , "activity_subscriptions" , "activity_subscriptions.user" , "activity_subscriptions.targetType = activity_stream.elementType AND activity_subscriptions.targetID = activity_stream.elementID AND activity_subscriptions.user != activity_stream.actor" , "asid = ?" , "" , "" )
if err != nil {
return err
}
2017-09-10 16:57:22 +00:00
2017-06-10 07:58:15 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeInserts ( adapter qgen . Adapter ) error {
2017-11-13 00:31:46 +00:00
build := adapter . Builder ( )
build . Insert ( "createReport" ) . Table ( "topics" ) . Columns ( "title, content, parsed_content, createdAt, lastReplyAt, createdBy, lastReplyBy, data, parentID, css_class" ) . Fields ( "?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,1,'report'" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Insert ( "addActivity" ) . Table ( "activity_stream" ) . Columns ( "actor, targetUser, event, elementType, elementID" ) . Fields ( "?,?,?,?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Insert ( "notifyOne" ) . Table ( "activity_stream_matches" ) . Columns ( "watcher, asid" ) . Fields ( "?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Insert ( "addForumPermsToForum" ) . Table ( "forums_permissions" ) . Columns ( "gid,fid,preset,permissions" ) . Fields ( "?,?,?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Insert ( "addPlugin" ) . Table ( "plugins" ) . Columns ( "uname, active, installed" ) . Fields ( "?,?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Insert ( "addTheme" ) . Table ( "themes" ) . Columns ( "uname, default" ) . Fields ( "?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Insert ( "createWordFilter" ) . Table ( "word_filters" ) . Columns ( "find, replacement" ) . Fields ( "?,?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-06-10 07:58:15 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeUpdates ( adapter qgen . Adapter ) error {
2017-11-13 00:31:46 +00:00
build := adapter . Builder ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "editReply" ) . Table ( "replies" ) . Set ( "content = ?, parsed_content = ?" ) . Where ( "rid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updatePlugin" ) . Table ( "plugins" ) . Set ( "active = ?" ) . Where ( "uname = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updatePluginInstall" ) . Table ( "plugins" ) . Set ( "installed = ?" ) . Where ( "uname = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updateTheme" ) . Table ( "themes" ) . Set ( "default = ?" ) . Where ( "uname = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2018-02-10 15:07:21 +00:00
build . Update ( "updateUser" ) . Table ( "users" ) . Set ( "name = ?, email = ?, group = ?" ) . Where ( "uid = ?" ) . Parse ( ) // TODO: Implement user_count for users_groups on things which use this
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updateGroupPerms" ) . Table ( "users_groups" ) . Set ( "permissions = ?" ) . Where ( "gid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updateGroup" ) . Table ( "users_groups" ) . Set ( "name = ?, tag = ?" ) . Where ( "gid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updateEmail" ) . Table ( "emails" ) . Set ( "email = ?, uid = ?, validated = ?, token = ?" ) . Where ( "email = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "verifyEmail" ) . Table ( "emails" ) . Set ( "validated = 1, token = ''" ) . Where ( "email = ?" ) . Parse ( ) // Need to fix this: Empty string isn't working, it gets set to 1 instead x.x -- Has this been fixed?
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "setTempGroup" ) . Table ( "users" ) . Set ( "temp_group = ?" ) . Where ( "uid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Update ( "updateWordFilter" ) . Table ( "word_filters" ) . Set ( "find = ?, replacement = ?" ) . Where ( "wfid = ?" ) . Parse ( )
build . Update ( "bumpSync" ) . Table ( "sync" ) . Set ( "last_update = UTC_TIMESTAMP()" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-06-05 11:57:27 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeDeletes ( adapter qgen . Adapter ) error {
2017-11-13 00:31:46 +00:00
build := adapter . Builder ( )
//build.Delete("deleteForumPermsByForum").Table("forums_permissions").Where("fid = ?").Parse()
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Delete ( "deleteActivityStreamMatch" ) . Table ( "activity_stream_matches" ) . Where ( "watcher = ? AND asid = ?" ) . Parse ( )
//build.Delete("deleteActivityStreamMatchesByWatcher").Table("activity_stream_matches").Where("watcher = ?").Parse()
2017-09-10 16:57:22 +00:00
2017-11-13 00:31:46 +00:00
build . Delete ( "deleteWordFilter" ) . Table ( "word_filters" ) . Where ( "wfid = ?" ) . Parse ( )
2017-09-10 16:57:22 +00:00
2017-06-12 09:03:14 +00:00
return nil
2017-06-14 07:09:44 +00:00
}
2017-11-12 05:25:04 +00:00
func writeSimpleCounts ( adapter qgen . Adapter ) error {
2017-09-18 17:03:52 +00:00
adapter . SimpleCount ( "reportExists" , "topics" , "data = ? AND data != '' AND parentID = 1" , "" )
2017-09-10 16:57:22 +00:00
2017-06-19 08:06:54 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeInsertSelects ( adapter qgen . Adapter ) error {
2017-10-21 00:27:47 +00:00
/ * adapter . SimpleInsertSelect ( "addForumPermsToForumAdmins" ,
2017-10-14 07:39:22 +00:00
qgen . DB_Insert { "forums_permissions" , "gid, fid, preset, permissions" , "" } ,
2017-09-10 16:57:22 +00:00
qgen . DB_Select { "users_groups" , "gid, ? AS fid, ? AS preset, ? AS permissions" , "is_admin = 1" , "" , "" } ,
2017-10-21 00:27:47 +00:00
) * /
2017-09-10 16:57:22 +00:00
2017-10-21 00:27:47 +00:00
/ * adapter . SimpleInsertSelect ( "addForumPermsToForumStaff" ,
2017-10-14 07:39:22 +00:00
qgen . DB_Insert { "forums_permissions" , "gid, fid, preset, permissions" , "" } ,
2017-09-10 16:57:22 +00:00
qgen . DB_Select { "users_groups" , "gid, ? AS fid, ? AS preset, ? AS permissions" , "is_admin = 0 AND is_mod = 1" , "" , "" } ,
2017-10-21 00:27:47 +00:00
) * /
2017-09-10 16:57:22 +00:00
2017-10-21 00:27:47 +00:00
/ * adapter . SimpleInsertSelect ( "addForumPermsToForumMembers" ,
2017-10-14 07:39:22 +00:00
qgen . DB_Insert { "forums_permissions" , "gid, fid, preset, permissions" , "" } ,
2017-09-10 16:57:22 +00:00
qgen . DB_Select { "users_groups" , "gid, ? AS fid, ? AS preset, ? AS permissions" , "is_admin = 0 AND is_mod = 0 AND is_banned = 0" , "" , "" } ,
2017-10-21 00:27:47 +00:00
) * /
2017-09-10 16:57:22 +00:00
2017-06-19 08:06:54 +00:00
return nil
}
2017-09-10 16:57:22 +00:00
// nolint
2017-11-12 05:25:04 +00:00
func writeInsertLeftJoins ( adapter qgen . Adapter ) error {
2017-06-19 08:06:54 +00:00
return nil
}
2017-11-12 05:25:04 +00:00
func writeInsertInnerJoins ( adapter qgen . Adapter ) error {
2017-09-18 17:03:52 +00:00
adapter . SimpleInsertInnerJoin ( "notifyWatchers" ,
2017-11-12 05:25:04 +00:00
qgen . DBInsert { "activity_stream_matches" , "watcher, asid" , "" } ,
qgen . DBJoin { "activity_stream" , "activity_subscriptions" , "activity_subscriptions.user, activity_stream.asid" , "activity_subscriptions.targetType = activity_stream.elementType AND activity_subscriptions.targetID = activity_stream.elementID AND activity_subscriptions.user != activity_stream.actor" , "asid = ?" , "" , "" } ,
2017-06-19 08:06:54 +00:00
)
2017-09-10 16:57:22 +00:00
2017-06-14 07:09:44 +00:00
return nil
}
2017-10-16 07:32:58 +00:00
func writeFile ( name string , content string ) ( err error ) {
f , err := os . Create ( name )
if err != nil {
return err
}
_ , err = f . WriteString ( content )
if err != nil {
return err
}
err = f . Sync ( )
if err != nil {
return err
}
return f . Close ( )
}