Skip to content

Commit

Permalink
Explicitly set the author ID to nil in the absence of a user ID + aut…
Browse files Browse the repository at this point in the history
…hor.
  • Loading branch information
twstokes committed Dec 3, 2022
1 parent bff014b commit 466c3f7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions WordPress/Classes/Models/Blog+Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ extension Blog {
post.postFormat = settings?.defaultPostFormat
post.postType = Post.typeDefaultIdentifier

if let userID = userID, let author = getAuthorWith(id: userID) {
if let userID, let author = getAuthorWith(id: userID) {
post.authorID = author.userID
post.author = author.displayName
} else {
/// Explicitly set the author ID to nil, otherwise it will default
/// to the Core Data value of 0 which is a logic error.
post.authorID = nil
post.author = nil
}

try? context.obtainPermanentIDs(for: [post])
Expand Down Expand Up @@ -85,9 +90,14 @@ extension Blog {
page.date_created_gmt = Date()
page.remoteStatus = .sync

if let userID = userID, let author = getAuthorWith(id: userID) {
if let userID, let author = getAuthorWith(id: userID) {
page.authorID = author.userID
page.author = author.displayName
} else {
/// Explicitly set the author ID to nil, otherwise it will default
/// to the Core Data value of 0 which is a logic error.
page.authorID = nil
page.author = nil
}

try? context.obtainPermanentIDs(for: [page])
Expand Down

0 comments on commit 466c3f7

Please sign in to comment.