2024-05-16 19:48:39 +00:00
|
|
|
package migration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EditorResult struct {
|
|
|
|
WordpressId int
|
|
|
|
Username string
|
|
|
|
Email string
|
|
|
|
IsSuccess bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateEditorResult(result EditorResult, db *sql.DB) error {
|
|
|
|
_, err := db.Exec("insert into EditorsResults(WordpressId, Username, Email, IsSuccess) values (?, ?, ?, ?)", result.WordpressId, result.Username, result.Email, result.IsSuccess)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-03 22:28:17 +00:00
|
|
|
func GetEditor(username, email string, db *sql.DB) (EditorResult, error) {
|
|
|
|
rows, err := db.Query("select WordpressId, Username, Email, (IsSuccess = b'1') from EditorsResults where Username = ? OR Email = ?", username, email)
|
2024-05-16 19:48:39 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
editor := EditorResult{}
|
|
|
|
|
|
|
|
err := rows.Scan(&editor.WordpressId, &editor.Username, &editor.Email, &editor.IsSuccess)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
2024-06-03 22:28:17 +00:00
|
|
|
if editor.Username == username || editor.Email == email {
|
2024-05-16 19:48:39 +00:00
|
|
|
return editor, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EditorResult{}, errors.New("Could not find editor.")
|
|
|
|
}
|
|
|
|
|
2024-06-03 22:28:17 +00:00
|
|
|
func EditorHasBeenMigrated(username, email string, db *sql.DB) bool {
|
|
|
|
_, err := GetEditor(username, email, db)
|
2024-05-16 19:48:39 +00:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|