fix: swap_vanity_urls()
works predictably with unset vanity URLs [DRAFT]
#361
+106
−101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Intent
When
swap_vanity_url()
was called on a piece of content without a vanity URL, the URL would be replaced with a randomized placeholder URL during the swap.Fixes #360
Approach
Instead of using a placeholder URL, delete the vanity URLs and re-assign them if vanity URLs are non-null.
Perhaps a better approach would be to call
set_vanity_url(content, url, force = TRUE)
, as this doesn't risk the (admittedly very unlikely) case that another piece of content snipes the URL before it's reassigned.I also renamed the function and its arguments, retaining the old name as a deprecated function that calls the new function for back compat. The old function was named
swap_vanity_url(from, to)
. This did not make clear that the operation is symmetrical and operates on two pieces of content, one or both of which can have vanity URLs that are swapped. The new function is calledswap_vanity_urls(content_a, content_b)
.Note
This is marked as a draft for now. I want to add proper error handling, so that in the case of a permissions error we correctly restore any changes that had been made.
Checklist
NEWS.md
(referencing the connected issue if necessary)? NOT YETdevtools::document()
?