1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-04 10:06:24 -07:00

Don't use gclog for gochan-migrate

This commit is contained in:
Eggbertx 2022-08-14 14:27:58 -07:00
parent 1b4c7ee389
commit 35a4dfc7b1
5 changed files with 40 additions and 38 deletions

View file

@ -1,7 +1,8 @@
package pre2021
import (
"github.com/gochan-org/gochan/pkg/gclog"
"log"
"github.com/gochan-org/gochan/pkg/gcsql"
)
@ -77,7 +78,7 @@ func (m *Pre2021Migrator) MigrateBoards() error {
m.oldBoards[id] = dir
}
if boards[b].Dir == dir {
gclog.Printf(gclog.LStdLog, "Board /%s/ already exists in new db, moving on\n", dir)
log.Printf("Board /%s/ already exists in new db, moving on\n", dir)
found = true
break
}
@ -113,7 +114,7 @@ func (m *Pre2021Migrator) MigrateBoards() error {
return err
}
m.newBoards[id] = dir
gclog.Printf(gclog.LStdLog, "/%s/ successfully migrated in the database", dir)
log.Printf("/%s/ successfully migrated in the database", dir)
// Automatic directory migration has the potential to go horribly wrong, so I'm leaving this
// commented out for now
// switch m.options.DirAction {
@ -122,15 +123,15 @@ func (m *Pre2021Migrator) MigrateBoards() error {
// case common.DirMove:
// // move the old directory (probably should copy instead) to the new one
// newDocumentRoot := config.GetSystemCriticalConfig().DocumentRoot
// gclog.Println(gclog.LStdLog, "Old board path:", path.Join(m.config.DocumentRoot, dir))
// gclog.Println(gclog.LStdLog, "Old board path:", path.Join(newDocumentRoot, dir))
// log.Println("Old board path:", path.Join(m.config.DocumentRoot, dir))
// log.Println("Old board path:", path.Join(newDocumentRoot, dir))
// if err = os.Rename(
// path.Join(m.config.DocumentRoot, dir),
// path.Join(newDocumentRoot, dir),
// ); err != nil {
// return err
// }
// gclog.Printf(gclog.LStdLog, "/%s/ directory/files successfully moved")
// log.Printf("/%s/ directory/files successfully moved")
// }
}
return nil

View file

@ -3,9 +3,9 @@ package pre2021
import (
"database/sql"
"fmt"
"log"
"time"
"github.com/gochan-org/gochan/pkg/gclog"
"github.com/gochan-org/gochan/pkg/gcsql"
)
@ -38,8 +38,8 @@ type postTable struct {
locked bool
reviewed bool
newBoardID int
oldParentID int
newBoardID int
// oldParentID int
}
func (m *Pre2021Migrator) MigratePosts() error {
@ -104,7 +104,7 @@ func (m *Pre2021Migrator) migrateThreads() error {
_, ok := m.oldBoards[post.boardid]
if !ok {
// board doesn't exist
gclog.Printf(gclog.LStdLog|gclog.LErrorLog,
log.Printf(
"Pre-migrated post #%d has an invalid boardid %d (board doesn't exist), skipping",
post.id, post.boardid)
continue

View file

@ -59,6 +59,8 @@ func (m *Pre2021Migrator) IsMigrated() (bool, error) {
case "postgres":
query = `SELECT COUNT(*) > 0 FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?`
default:
return false, gcsql.ErrUnsupportedDB
}
if err = m.db.QueryRowSQL(query,
[]interface{}{m.config.DBprefix + "migrated", m.config.DBname},
@ -81,18 +83,18 @@ func (m *Pre2021Migrator) MigrateDB() (bool, error) {
if err := m.MigrateBoards(); err != nil {
return false, err
}
if err = m.MigratePosts(); err != nil {
return false, err
}
if err = m.MigrateStaff("password"); err != nil {
return false, err
}
if err = m.MigrateBans(); err != nil {
return false, err
}
if err = m.MigrateAnnouncements(); err != nil {
return false, err
}
// if err = m.MigratePosts(); err != nil {
// return false, err
// }
// if err = m.MigrateStaff("password"); err != nil {
// return false, err
// }
// if err = m.MigrateBans(); err != nil {
// return false, err
// }
// if err = m.MigrateAnnouncements(); err != nil {
// return false, err
// }
return true, nil
}

View file

@ -2,11 +2,12 @@ package main
import (
"flag"
"log"
"github.com/gochan-org/gochan/cmd/gochan-migration/internal/common"
"github.com/gochan-org/gochan/cmd/gochan-migration/internal/pre2021"
"github.com/gochan-org/gochan/pkg/config"
"github.com/gochan-org/gochan/pkg/gclog"
"github.com/gochan-org/gochan/pkg/gcsql"
)
@ -23,7 +24,6 @@ Then copy the thumbnails to /path/to/gochan/documentroot/<boardname>/thumb/
Then start the gochan server and go to http://yoursite/manage?action=rebuildall to generate the html files
for the threads and board pages`
fatalLogFlags = gclog.LFatal | gclog.LErrorLog | gclog.LStdLog
allowedDirActions = "Valid values are noaction, copy, and move (defaults to noaction if unset)"
)
@ -33,9 +33,10 @@ var (
func main() {
var options common.MigrationOptions
config.InitConfig(versionStr)
var dirAction string
log.SetFlags(0)
config.InitConfig(versionStr)
flag.StringVar(&options.ChanType, "oldchan", "", "The imageboard we are migrating from (currently only pre2021 is supported, but more are coming")
flag.StringVar(&options.OldChanConfig, "oldconfig", "", "The path to the old chan's configuration file")
/* flag.StringVar(&dirAction, "diraction", "",
@ -45,7 +46,7 @@ func main() {
if options.ChanType == "" || options.OldChanConfig == "" {
flag.PrintDefaults()
gclog.Println(fatalLogFlags, "Missing required oldchan value")
log.Fatal("Missing required oldchan value")
return
}
switch dirAction {
@ -58,10 +59,10 @@ func main() {
case "move":
options.DirAction = common.DirMove
default:
gclog.Println(fatalLogFlags, "Invalid diraction value. "+allowedDirActions)
log.Fatalln("Invalid diraction value. " + allowedDirActions)
}
gclog.Printf(gclog.LAccessLog, banner, versionStr)
log.Printf(banner, versionStr)
var migrator common.DBMigrator
switch options.ChanType {
case "pre2021":
@ -71,7 +72,7 @@ func main() {
case "tinyboard":
fallthrough
default:
gclog.Printf(fatalLogFlags,
log.Fatalf(
"Unsupported chan type %q, Currently only pre2021 database migration is supported\n",
options.ChanType)
return
@ -87,20 +88,18 @@ func main() {
err := migrator.Init(&options)
if err != nil {
gclog.Printf(fatalLogFlags,
"Unable to initialize %s migrator: %s\n", options.ChanType, err.Error())
log.Fatalf("Unable to initialize %s migrator: %s\n",
options.ChanType, err.Error())
return
}
defer migrator.Close()
var migrated bool
if migrated, err = migrator.MigrateDB(); err != nil {
gclog.Println(fatalLogFlags, "Error migrating database:", err.Error())
return
log.Fatalln("Error migrating database:", err.Error())
}
if migrated {
gclog.Printf(gclog.LStdLog|gclog.LAccessLog, "Database is already migrated")
return
log.Fatalf("Database is already migrated")
}
gclog.Println(gclog.LStdLog, migrateCompleteTxt)
log.Println(migrateCompleteTxt)
}

View file

@ -83,7 +83,7 @@ sed -i 's/WantedBy=multi-user.target/WantedBy=vagrant.mount/' /lib/systemd/syste
openssl req -x509 -nodes -days 7305 -newkey rsa:2048 \
-keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt \
-subj "/CN=172.27.0.3"
-subj "/CN=192.168.56.3"
systemctl daemon-reload
systemctl enable nginx