fixed broken images issue
This commit is contained in:
parent
ffde450209
commit
ee3ae47d4f
8
main.go
8
main.go
@ -7,15 +7,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// WP Config
|
// WP Config
|
||||||
const baseUrl = "http://go-api-playground.local/"
|
const baseUrl = "https://slowtwitch.cloud/"
|
||||||
const wordpressKey = "admin"
|
const wordpressKey = "admin@slowtwitch.cloud"
|
||||||
const wordpressSecret = "KStj VH7E 9UZf FV8C ptGQ F4Tl"
|
const wordpressSecret = "rcI0 7qAM Q1CR xi6n sGcB 4XFN"
|
||||||
|
|
||||||
// DB Config
|
// DB Config
|
||||||
const slowtwitchAdminUser = "admin"
|
const slowtwitchAdminUser = "admin"
|
||||||
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
|
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
|
||||||
const slowtwitchDbName = "slowtwitch"
|
const slowtwitchDbName = "slowtwitch"
|
||||||
const migrationDbName = "slowtwitch_transfer_threaded_test"
|
const migrationDbName = "slowtwitch_transfer"
|
||||||
const federatedDbUrl = "slowtwitch.northend.network"
|
const federatedDbUrl = "slowtwitch.northend.network"
|
||||||
const federatedDbPort = "3306"
|
const federatedDbPort = "3306"
|
||||||
|
|
||||||
|
BIN
results.txt
BIN
results.txt
Binary file not shown.
@ -44,6 +44,8 @@ func (migration *MigrateAuthors) Execute() []EditorResult {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
wordpressId = result.Id
|
wordpressId = result.Id
|
||||||
isSuccess = true
|
isSuccess = true
|
||||||
|
} else {
|
||||||
|
fmt.Println("error creating user:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
editorResult := EditorResult{
|
editorResult := EditorResult{
|
||||||
|
@ -180,7 +180,9 @@ func (migration MigratePosts) Execute() []PostResult {
|
|||||||
}
|
}
|
||||||
imageResults = append(imageResults, imageResult)
|
imageResults = append(imageResults, imageResult)
|
||||||
//replace old links with new in post html
|
//replace old links with new in post html
|
||||||
strings.ReplaceAll(html, imageUrl, wordpressImage.Link)
|
//TODO Wordpress path vs link? If path works I prefer that
|
||||||
|
newImagePath := "/wp-content/uploads/" + wordpressImage.MediaDetails.File
|
||||||
|
html = strings.ReplaceAll(html, imagePath, newImagePath)
|
||||||
//create redirect
|
//create redirect
|
||||||
imageRedirect := wordpress.CreateRedirect{
|
imageRedirect := wordpress.CreateRedirect{
|
||||||
Title: postBase.Title + "image-" + string((i + 1)),
|
Title: postBase.Title + "image-" + string((i + 1)),
|
||||||
@ -271,7 +273,7 @@ func (migration MigratePosts) Execute() []PostResult {
|
|||||||
postResults = append(postResults, batchResults...)
|
postResults = append(postResults, batchResults...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Update related posts once work is done
|
// Update related posts once work is done -- Why are there duplicates?
|
||||||
updatePostRelationships(postResults, migration)
|
updatePostRelationships(postResults, migration)
|
||||||
|
|
||||||
return postResults
|
return postResults
|
||||||
@ -366,7 +368,7 @@ func getSuccessfulWordpressImageIds(imageResults []ImageResult) []int {
|
|||||||
var output []int
|
var output []int
|
||||||
|
|
||||||
for _, imageResult := range imageResults {
|
for _, imageResult := range imageResults {
|
||||||
if imageResult.IsSuccess {
|
if imageResult.WordpressId > 0 && imageResult.IsSuccess {
|
||||||
output = append(output, imageResult.WordpressId)
|
output = append(output, imageResult.WordpressId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,3 +394,12 @@ func updateAcfImages(imageResults []ImageResult, postId int, baseUrl, user, pass
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getContentType(filename string) string {
|
||||||
|
if strings.Contains(filename, "png") {
|
||||||
|
return ".png"
|
||||||
|
} else if strings.Contains(filename, "gif") {
|
||||||
|
return ".gif"
|
||||||
|
}
|
||||||
|
return ".jpeg"
|
||||||
|
}
|
||||||
|
@ -17,6 +17,11 @@ type CreateImageResponse struct {
|
|||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
|
MediaDetails MediaDetails `json:"media_details"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaDetails struct {
|
||||||
|
File string `json:"file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (parameters *CreateImage) Execute(baseUrl, user, pass string) (CreateImageResponse, error) {
|
func (parameters *CreateImage) Execute(baseUrl, user, pass string) (CreateImageResponse, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user