mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-04 10:06:24 -07:00
Fix board deletion and partially fix modification
This commit is contained in:
parent
9e82333c47
commit
656c2a3046
6 changed files with 28 additions and 12 deletions
|
@ -18,9 +18,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
dirIsAFileStr = `unable to create "%s", path exists and is a file`
|
||||
genericErrStr = `unable to create "%s": %s`
|
||||
pathExistsStr = `unable to create "%s", path already exists`
|
||||
dirIsAFileStr = `unable to create %q, path exists and is a file`
|
||||
genericErrStr = `unable to create %q: %s`
|
||||
pathExistsStr = `unable to create %q, path already exists`
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -133,7 +133,7 @@ func BuildBoardPages(board *gcsql.Board) error {
|
|||
boardPageFile, err = os.OpenFile(path.Join(criticalCfg.DocumentRoot, board.Dir, "1.html"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
|
||||
if err != nil {
|
||||
return errors.New(gclog.Printf(gclog.LErrorLog,
|
||||
"Failed opening /%s/board.html: %s",
|
||||
"failed opening /%s/board.html: %s",
|
||||
board.Dir, err.Error()))
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ func BuildBoardPages(board *gcsql.Board) error {
|
|||
catalogJSONFile, err := os.OpenFile(path.Join(criticalCfg.DocumentRoot, board.Dir, "catalog.json"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
|
||||
if err != nil {
|
||||
return errors.New(gclog.Printf(gclog.LErrorLog,
|
||||
"Failed opening /%s/catalog.json: %s", board.Dir, err.Error()))
|
||||
"failed opening /%s/catalog.json: %s", board.Dir, err.Error()))
|
||||
}
|
||||
defer catalogJSONFile.Close()
|
||||
|
||||
|
@ -177,7 +177,7 @@ func BuildBoardPages(board *gcsql.Board) error {
|
|||
currentPageFile, err = os.OpenFile(currentPageFilepath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
|
||||
if err != nil {
|
||||
err = errors.New(gclog.Printf(gclog.LErrorLog,
|
||||
"Failed opening /%s/%s: %s", board.Dir, pageFilename, err.Error()))
|
||||
"failed opening /%s/%s: %s", board.Dir, pageFilename, err.Error()))
|
||||
continue
|
||||
}
|
||||
defer currentPageFile.Close()
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
const (
|
||||
UnsupportedSQLVersionMsg = `Received syntax error while preparing a SQL string.
|
||||
This means that either there is a bug in gochan's code (hopefully not) or that you are using an unsupported My/Postgre version.
|
||||
This means that either there is a bug in gochan's code (hopefully not) or that you are using an unsupported MySQL/PostgreSQL version.
|
||||
Before reporting an error, make sure that you are using the up to date version of your selected SQL server.
|
||||
Error text: %s`
|
||||
mysqlConnStr = "%s:%s@tcp(%s)/%s?parseTime=true&collation=utf8mb4_unicode_ci"
|
||||
|
@ -68,7 +68,7 @@ func (db *GCDB) PrepareSQL(query string) (*sql.Stmt, error) {
|
|||
}
|
||||
stmt, err := db.db.Prepare(db.replacer.Replace((preparedStr)))
|
||||
if err != nil {
|
||||
return stmt, fmt.Errorf("Error preparing sql query:\n%s\n%s", query, err.Error())
|
||||
return stmt, fmt.Errorf("error preparing sql query:\n%s\n%s", query, err.Error())
|
||||
}
|
||||
return stmt, sqlVersionError(err, db.driver, &preparedStr)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ const (
|
|||
var (
|
||||
// ErrInvalidVersion is used when the db contains a database_version table
|
||||
// but zero or more than one versions were found
|
||||
ErrInvalidVersion = errors.New("Database contains database_version table but zero or more than one versions were found")
|
||||
ErrInvalidVersion = errors.New("database contains database_version table but zero or more than one versions were found")
|
||||
)
|
||||
|
||||
// GetCompleteDatabaseVersion checks the database for any versions and errors that may exist.
|
||||
|
|
|
@ -958,7 +958,10 @@ func (board *Board) PopulateData(id int) error {
|
|||
func (board *Board) Delete() error {
|
||||
exists := DoesBoardExistByID(board.ID)
|
||||
if !exists {
|
||||
return errors.New("board does not exist")
|
||||
return ErrBoardDoesNotExist
|
||||
}
|
||||
if board.ID == 0 {
|
||||
return ErrNilBoard
|
||||
}
|
||||
const delSql = `DELETE FROM DBPREFIXboards WHERE id = ?`
|
||||
_, err := ExecSQL(delSql, board.ID)
|
||||
|
|
|
@ -237,7 +237,10 @@ func (board *Board) SetDefaults(title string, subtitle string, description strin
|
|||
|
||||
// ChangeFromRequest takes values from a HTTP request
|
||||
func (board *Board) ChangeFromRequest(request *http.Request) {
|
||||
board.Dir = request.FormValue("dir")
|
||||
if request.FormValue("docreate") != "" {
|
||||
// prevent directory changes if the board already exists
|
||||
board.Dir = request.FormValue("dir")
|
||||
}
|
||||
board.Title = request.FormValue("title")
|
||||
board.Subtitle = request.FormValue("subtitle")
|
||||
board.Description = request.FormValue("description")
|
||||
|
|
|
@ -413,7 +413,17 @@ var actions = []Action{
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if requestType == "create" || requestType == "modify" && err != nil {
|
||||
if err = building.BuildBoardListJSON(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err = building.BuildBoards(false, board.ID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err = building.BuildBoardPages(&board); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageBoards,
|
||||
map[string]interface{}{
|
||||
"webroot": config.GetSystemCriticalConfig().WebRoot,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue