|
|
|
@ -557,19 +557,19 @@ func (db *datastore) CreatePost(userID, collID int64, post *SubmittedPost) (*Pos |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stmt, err := db.Prepare("INSERT INTO posts (id, slug, title, content, text_appearance, language, rtl, owner_id, collection_id, updated, view_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)") |
|
|
|
|
stmt, err := db.Prepare("INSERT INTO posts (id, slug, title, content, text_appearance, language, rtl, privacy, owner_id, collection_id, updated, view_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)") |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
defer stmt.Close() |
|
|
|
|
_, err = stmt.Exec(friendlyID, slug, post.Title, post.Content, appearance, post.Language, post.IsRTL, ownerID, ownerCollID, 0) |
|
|
|
|
_, err = stmt.Exec(friendlyID, slug, post.Title, post.Content, appearance, post.Language, post.IsRTL, 0, ownerID, ownerCollID, 0) |
|
|
|
|
if err != nil { |
|
|
|
|
if mysqlErr, ok := err.(*mysql.MySQLError); ok { |
|
|
|
|
if mysqlErr.Number == mySQLErrDuplicateKey { |
|
|
|
|
// Duplicate entry error; try a new slug
|
|
|
|
|
// TODO: make this a little more robust
|
|
|
|
|
slug = sql.NullString{id.GenSafeUniqueSlug(slug.String), true} |
|
|
|
|
_, err = stmt.Exec(friendlyID, slug, post.Title, post.Content, appearance, post.Language, post.IsRTL, ownerID, ownerCollID, 0) |
|
|
|
|
_, err = stmt.Exec(friendlyID, slug, post.Title, post.Content, appearance, post.Language, post.IsRTL, 0, ownerID, ownerCollID, 0) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, handleFailedPostInsert(fmt.Errorf("Retried slug generation, still failed: %v", err)) |
|
|
|
|
} |
|
|
|
|