2024-05-16 18:50:53 +00:00
|
|
|
package migration
|
2024-05-16 19:48:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"federated.computer/wp-sync-slowtwitch/services/slowtwitch"
|
|
|
|
"federated.computer/wp-sync-slowtwitch/services/wordpress"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MigrateAuthors struct {
|
|
|
|
SlowtwitchDatabase *sql.DB
|
|
|
|
ResultsDatabase *sql.DB
|
|
|
|
WordpressBaseUrl string
|
|
|
|
WordpressUser string
|
|
|
|
WordpressPassword string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (migration *MigrateAuthors) Execute() []EditorResult {
|
|
|
|
editors := slowtwitch.GetUsers(migration.SlowtwitchDatabase)
|
|
|
|
var output []EditorResult
|
|
|
|
|
|
|
|
for _, editor := range editors {
|
|
|
|
hasBeenMigrated := EditorHasBeenMigrated(editor.Username, migration.ResultsDatabase)
|
|
|
|
|
|
|
|
if hasBeenMigrated == false {
|
|
|
|
createUser := wordpress.CreateUser{
|
|
|
|
Username: editor.Username,
|
|
|
|
Email: editor.Email,
|
|
|
|
Password: editor.Password,
|
|
|
|
Roles: "editor",
|
|
|
|
}
|
|
|
|
|
|
|
|
result := createUser.Execute(migration.WordpressBaseUrl, migration.WordpressUser, migration.WordpressPassword)
|
|
|
|
editorResult := EditorResult{
|
|
|
|
Username: result.Username,
|
|
|
|
Email: result.Username,
|
|
|
|
WordpressId: result.Id,
|
|
|
|
IsSuccess: true,
|
|
|
|
}
|
|
|
|
err := CreateEditorResult(editorResult, migration.ResultsDatabase)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
output = append(output, editorResult)
|
|
|
|
fmt.Println("Created user:", result.Username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|