Converting recorded wav calls to mp3 (Updated)

Recently started having issues with the script - latest version of CDR running on freepbx 15 would not playback mp3 converted files.

The required change was regarding updating the transient_cdr database as well as the cdr database.

Updated script below

#!/bin/bash
# ---
# Save script as /var/lib/asterisk/bin/wav2mp3.sh and then:
# chown asterisk:asterisk /var/lib/asterisk/bin/wav2mp3.sh
# chmod +x /var/lib/asterisk/bin/wav2mp3.sh
# ---
# Configure FreePBX postrecording script as: /var/lib/asterisk/bin/wav2mp3.sh ^{CALLFILENAME} ^{UNIQUEID}
# ---

# Wait 7 seconds before we start
sleep 7

# The default path for the recordings includes the current date
dy=$(date '+%Y')
dm=$(date '+%m')
dd=$(date '+%d')

# Path where recordings are stored, including trailing slash
dtpath=/var/spool/asterisk/monitor/$dy/$dm/$dd/

# Path where WAV are moved, including trailing slash
wavpath=/var/spool/asterisk/monitor/wav/$dy/$dm/$dd/

# If the WAV file is 44 bytes long, delete it and exit. These are empty audio files that are generated
# for example when a ring group or queue rings multiple extensions. This has been reported multiple
# times, most recent bug report is https://issues.freepbx.org/browse/FREEPBX-13370
if [ $(wc -c < "$dtpath$1.wav" | cut -d ' ' -f1) -eq 44 ]; 
then
	rm -f "$dtpath$1.wav"
	exit 0
fi

# Use LAME for the MP3 conversion, on a low priority process
nice lame -b 128 -h -m m --noreplaygain "$dtpath$1.wav" "$dtpath$1.mp3"

# If the conversion was successful, update CDR database and delete WAV file
if [ $? -eq 0 ]; 
then
	mysql -u root -s -D asteriskcdrdb -e "UPDATE cdr SET recordingfile = '$1.mp3' WHERE uniqueid = '$2'"
	mysql -u root -s -D asteriskcdrdb -e "UPDATE transient_cdr SET recordingfile = '$1.mp3' WHERE uniqueid = '$2'"
	

# Move to a wav folder instead of deleting the files, comment this when you decide to delete the WAV files.	
	# mkdir -p "$wavpath"
	# mv "$dtpath$1.wav" "$wavpath$1.wav"
	
# Uncomment	when you are confident and want to start deleting the files, comment the section above to stop moving the files.
rm -f "$dtpath$1.wav"
else
	exit 1
fi