2024-05-15 23:37:42 +00:00
|
|
|
package migration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CategoryResult struct {
|
|
|
|
WordpressId int
|
|
|
|
SlowtwitchId int
|
|
|
|
OldUrl string
|
|
|
|
OldUrlStatus int
|
|
|
|
NewUrl string
|
|
|
|
IsSuccess bool
|
|
|
|
ErrorMessage string
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateCategoryResult(result CategoryResult, db *sql.DB) error {
|
2024-05-16 16:26:59 +00:00
|
|
|
_, err := db.Exec("insert into CategoryResults (SlowtwitchId, WordpressId, OldUrl, NewUrl, IsSuccess, ErrorMessage, OldUrlStatus) values (?, ?, ?, ?, ?, ?, ?);", result.SlowtwitchId, result.WordpressId, result.OldUrl, result.NewUrl, result.IsSuccess, result.ErrorMessage, result.OldUrlStatus)
|
2024-05-15 23:37:42 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-16 16:26:59 +00:00
|
|
|
func HasBeenMigrated(slowtwitchId int, db *sql.DB) bool {
|
|
|
|
_, err := GetSlowtwitchCategoryResult(slowtwitchId, db)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 23:37:42 +00:00
|
|
|
func GetSlowtwitchCategoryResult(slowtwitchId int, db *sql.DB) (CategoryResult, error) {
|
|
|
|
rows, err := db.Query("select WordpressId, SlowtwitchId, OldUrl, NewUrl, (IsSuccess = b'1'), ErrorMessage, OldUrlStatus from CategoryResults where SlowtwitchId = ?", slowtwitchId)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var slowtwitchCategoryResult CategoryResult
|
|
|
|
|
|
|
|
err = rows.Scan(&slowtwitchCategoryResult.WordpressId, &slowtwitchCategoryResult.SlowtwitchId, &slowtwitchCategoryResult.OldUrl, &slowtwitchCategoryResult.NewUrl, &slowtwitchCategoryResult.IsSuccess, &slowtwitchCategoryResult.ErrorMessage, &slowtwitchCategoryResult.OldUrlStatus)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
if slowtwitchCategoryResult.SlowtwitchId == slowtwitchId {
|
|
|
|
return slowtwitchCategoryResult, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CategoryResult{}, errors.New("Category Not Found")
|
|
|
|
}
|