@ -557,19 +557,28 @@ 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, privacy, owner_id, collection_id, updated, view_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)" )
created := time . Now ( )
if post . Created != nil {
created , err = time . Parse ( "2006-01-02T15:04:05Z" , * post . Created )
if err != nil {
log . Error ( "Unable to parse Created time '%s': %v" , * post . Created , err )
created = time . Now ( )
}
}
stmt , err := db . Prepare ( "INSERT INTO posts (id, slug, title, content, text_appearance, language, rtl, privacy, owner_id, collection_id, created, updated, view_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)" )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
defer stmt . Close ( )
defer stmt . Close ( )
_ , err = stmt . Exec ( friendlyID , slug , post . Title , post . Content , appearance , post . Language , post . IsRTL , 0 , ownerID , ownerCollID , 0 )
_ , err = stmt . Exec ( friendlyID , slug , post . Title , post . Content , appearance , post . Language , post . IsRTL , 0 , ownerID , ownerCollID , created , 0 )
if err != nil {
if err != nil {
if mysqlErr , ok := err . ( * mysql . MySQLError ) ; ok {
if mysqlErr , ok := err . ( * mysql . MySQLError ) ; ok {
if mysqlErr . Number == mySQLErrDuplicateKey {
if mysqlErr . Number == mySQLErrDuplicateKey {
// Duplicate entry error; try a new slug
// Duplicate entry error; try a new slug
// TODO: make this a little more robust
// TODO: make this a little more robust
slug = sql . NullString { id . GenSafeUniqueSlug ( slug . String ) , true }
slug = sql . NullString { id . GenSafeUniqueSlug ( slug . String ) , true }
_ , err = stmt . Exec ( friendlyID , slug , post . Title , post . Content , appearance , post . Language , post . IsRTL , 0 , ownerID , ownerCollID , 0 )
_ , err = stmt . Exec ( friendlyID , slug , post . Title , post . Content , appearance , post . Language , post . IsRTL , 0 , ownerID , ownerCollID , created , 0 )
if err != nil {
if err != nil {
return nil , handleFailedPostInsert ( fmt . Errorf ( "Retried slug generation, still failed: %v" , err ) )
return nil , handleFailedPostInsert ( fmt . Errorf ( "Retried slug generation, still failed: %v" , err ) )
}
}
@ -590,7 +599,7 @@ func (db *datastore) CreatePost(userID, collID int64, post *SubmittedPost) (*Pos
RTL : zero . NewBool ( post . IsRTL . Bool , post . IsRTL . Valid ) ,
RTL : zero . NewBool ( post . IsRTL . Bool , post . IsRTL . Valid ) ,
OwnerID : null . NewInt ( userID , true ) ,
OwnerID : null . NewInt ( userID , true ) ,
CollectionID : null . NewInt ( userID , true ) ,
CollectionID : null . NewInt ( userID , true ) ,
Created : time . Now ( ) . Truncate ( time . Second ) . UTC ( ) ,
Created : created . Truncate ( time . Second ) . UTC ( ) ,
Updated : time . Now ( ) . Truncate ( time . Second ) . UTC ( ) ,
Updated : time . Now ( ) . Truncate ( time . Second ) . UTC ( ) ,
Title : zero . NewString ( * ( post . Title ) , true ) ,
Title : zero . NewString ( * ( post . Title ) , true ) ,
Content : * ( post . Content ) ,
Content : * ( post . Content ) ,