Skip to content

Commit

Permalink
Update installUpgradeFunctions.sh: add update_array_field()
Browse files Browse the repository at this point in the history
It updates a value in an array, or deletes the array entry the value is at.
  • Loading branch information
EricClaeys authored Aug 31, 2024
1 parent 64e6b16 commit e86c025
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/installUpgradeFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,31 @@ function update_json_file() # [-d] field, new value, file, [type]
}


####
# Update a field in an array or delete the array index the field is at.
function update_array_field()
{
local FILE="${1}"
local ARRAY="${2}"
local FIELD="${3}" # may be ""
local VALUE="${4}"
local NEW_VALUE="${5}" # a value or "--delete"

local I="$( getJSONarrayIndex "${FILE}" "${ARRAY}" "${VALUE}" )"
[[ ${I} -eq -1 ]] && return

if [[ ${NEW_VALUE} == "--delete" ]]; then
update_json_file -d ".${ARRAY}[${I}]" "" "${FILE}"
else
local URL=".${ARRAY}[${I}].${FIELD}"
local V="$( settings "${URL}" "${FILE}" )"
if [[ ${V} != ${NEW_VALUE} ]]; then
update_json_file "${URL}" "${NEW_VALUE}" "${FILE}"
fi
fi
}


# Replace all the ${NEED_TO_UPDATE} placeholders.
function replace_website_placeholders()
{
Expand Down

0 comments on commit e86c025

Please sign in to comment.