ready to roll

This commit is contained in:
Ross Trottier 2024-05-28 17:45:47 -06:00
parent 90b725bb8a
commit ffde450209
2 changed files with 33 additions and 14 deletions

View File

@ -40,12 +40,13 @@ func (migration MigratePosts) Execute() []PostResult {
batchSize := 5 batchSize := 5
var postBatch []int var postBatch []int
for _, postId := range slowtwitchPostIdsForMigration { for i, postId := range slowtwitchPostIdsForMigration {
//anonymous func will take in post IDs: the rest it can access from scope //anonymous func will take in post IDs: the rest it can access from scope
postBatch = append(postBatch, postId) postBatch = append(postBatch, postId)
if len(postBatch) == batchSize {
if len(postBatch) == batchSize || i == len(slowtwitchPostIdsForMigration)-1 {
postResultsChannel := make(chan PostResult) postResultsChannel := make(chan PostResult)
for _, batchId := range postBatch { for _, batchId := range postBatch {
go func(id int) { go func(id int) {
errorMessage := "" errorMessage := ""
@ -157,7 +158,13 @@ func (migration MigratePosts) Execute() []PostResult {
if wordpressImageErr != nil { if wordpressImageErr != nil {
errorMessage = errorMessage + wordpressImageErr.Error() errorMessage = errorMessage + wordpressImageErr.Error()
createImageFailureResult(imageUrl, migration.ResultsDatabase) imageFailureResult := ImageResult{
OldUrl: imageUrl,
NewUrl: "",
WordpressId: 0,
IsSuccess: false,
}
imageResults = append(imageResults, imageFailureResult)
continue continue
} }
//first photo is the featured photo //first photo is the featured photo
@ -271,7 +278,9 @@ func (migration MigratePosts) Execute() []PostResult {
} }
func updatePostRelationships(postResults []PostResult, migration MigratePosts) { func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
for _, postResult := range postResults { fmt.Println("Updating post relationships")
for i, postResult := range postResults {
fmt.Println("Updating post", i+1, "/", len(postResults))
if postResult.IsSuccess { if postResult.IsSuccess {
var relatedWordpressIds []int var relatedWordpressIds []int
@ -357,8 +366,10 @@ func getSuccessfulWordpressImageIds(imageResults []ImageResult) []int {
var output []int var output []int
for _, imageResult := range imageResults { for _, imageResult := range imageResults {
if imageResult.IsSuccess {
output = append(output, imageResult.WordpressId) output = append(output, imageResult.WordpressId)
} }
}
return output return output
} }
@ -366,6 +377,8 @@ func getSuccessfulWordpressImageIds(imageResults []ImageResult) []int {
func updateAcfImages(imageResults []ImageResult, postId int, baseUrl, user, pass string) { func updateAcfImages(imageResults []ImageResult, postId int, baseUrl, user, pass string) {
if len(imageResults) > 0 { if len(imageResults) > 0 {
wordpressImageIds := getSuccessfulWordpressImageIds(imageResults) wordpressImageIds := getSuccessfulWordpressImageIds(imageResults)
if len(wordpressImageIds) > 0 {
updateAcfImages := wordpress.UpdateAcfImages{ updateAcfImages := wordpress.UpdateAcfImages{
Acf: wordpress.AcfImages{ Acf: wordpress.AcfImages{
PostImages: wordpressImageIds, PostImages: wordpressImageIds,
@ -377,4 +390,5 @@ func updateAcfImages(imageResults []ImageResult, postId int, baseUrl, user, pass
fmt.Println("Error updating acf images for post", postId, ":", acfImagesErr.Error()) fmt.Println("Error updating acf images for post", postId, ":", acfImagesErr.Error())
} }
} }
}
} }

View File

@ -33,6 +33,11 @@ func GetImagesAndPostHtml(url string) (imagePaths []string, htmlBody string, err
}) })
// Get blog html, remove first image because wordpress will handle that as a featured image // Get blog html, remove first image because wordpress will handle that as a featured image
blog := doc.Find(".detail_text") blog := doc.Find(".detail_text")
blog.Find("a").Each(func(i int, a *goquery.Selection) {
if a.Text() == "Slideshow" {
a.Remove()
}
})
htmlBody, err = blog.Html() htmlBody, err = blog.Html()
return return
} }