Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
twstokes committed Dec 3, 2022
1 parent bff014b commit cb9c1bd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion WordPress/Classes/Models/Blog+Post.swift
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit cb9c1bd

Please sign in to comment.