Avoid copy fields duplicates
@@ -18,23 +18,38 @@ sendCommand() {
fi
}
+deleteCopyFields() {
+ # test if command is empty
+ if [[ -z "${1// }" ]]; then
+ return;
+ fi
+ source=$(echo $1 | jq '.source')
+ for row in $(echo $1 | jq '.dest[]'); do
+ delete_item="{ \"source\":$source, \"dest\":$row }"
+ resp=$(echo '{ "delete-'$2'": '$delete_item' }' | curl -s -X POST -H 'Content-type:application/json' --data-binary @- $server)
+ echo $resp
+ done
+}
+
processFile() {
value=''
while IFS='' read -r line || [[ -n "$line" ]]; do
# read file and find && separtor
if [ "$line" = "&&" ]; then
- sendCommand "${value}" $2
+ $2 "${value}" $3
value=''
else
value=${value}${line}
fi
done < $1
-sendCommand "${value}" $2
+$2 "${value}" $3
}
-processFile custom_fieldTypes.incl field-type
-processFile custom_fields.incl field
-processFile custom_dynamicFields.incl dynamic-field
-processFile custom_copyFields.incl copy-field
+processFile custom_fieldTypes.incl sendCommand field-type
+processFile custom_fields.incl sendCommand field
+processFile custom_dynamicFields.incl sendCommand dynamic-field
+#Try to delete the copy fields to avoid duplicates
+processFile custom_copyFields.incl deleteCopyFields copy-field
+processFile custom_copyFields.incl sendCommand copy-field
echo done
\ No newline at end of file
