Skip to content

Commit

Permalink
Address #832 and #833.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Oct 20, 2024
1 parent 44a873d commit 4358d41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions workbench
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,13 @@ def create_redirects():
logging.warning(message)
continue

if row["redirect_target"].lower().startswith("http") is False:
# It's an internal redirect.
redirect_target = f'internal:/{row["redirect_target"]}'
else:
# It's an external redirect.
redirect_target = row["redirect_target"]

# Check to see if the redirect source value is already a redirect. We don't use issue_request()
# since we don't want to override config["allow_redirects"] for this one request.
is_redirect_url = config["host"].rstrip("/") + "/" + row["redirect_source"]
Expand All @@ -3377,7 +3384,7 @@ def create_redirects():
redirect = {
"type": [{"value": "redirect"}],
"redirect_source": [{"path": row["redirect_source"].lstrip("/").strip()}],
"redirect_redirect": [{"uri": row["redirect_target"].strip()}],
"redirect_redirect": [{"uri": redirect_target.strip()}],
"status_code": [{"value": int(config["redirect_status_code"])}],
}
redirect_endpoint = config["host"] + "/entity/redirect?_format=json"
Expand All @@ -3404,7 +3411,7 @@ def create_redirects():
+ '" not created.'
)
print("Error: " + message + " See log for more info.")
logging.error(message + "HTTP status code: " + str(response.status_code))
logging.error(message + " HTTP status code: " + str(response.status_code))

if config["progress_bar"] is True:
redirect_row_position = get_percentage(redirect_row_count, num_csv_records)
Expand Down
4 changes: 2 additions & 2 deletions workbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3119,12 +3119,12 @@ def check_input(config, args):
)
if path_exists_response.status_code == 404:
message = (
'Redirect path "'
'Redirect source path "'
+ row["redirect_source"].strip()
+ '" (row '
+ str(count)
+ ") does not exist (HTTP response code is "
+ str(is_redirect_response.status_code)
+ str(path_exists_response.status_code)
+ "). This may be intentional."
)
logging.warning(message)
Expand Down

0 comments on commit 4358d41

Please sign in to comment.