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

# ---
# Save script as /var/lib/asterisk/bin/ and then:
# chown asterisk:asterisk /var/lib/asterisk/bin/
# chmod +x /var/lib/asterisk/bin/
# ---
# Configure FreePBX postrecording script as: /var/lib/asterisk/bin/ ^{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

# Path where WAV are moved, including trailing slash

# 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
if [ $(wc -c < "$dtpath$1.wav" | cut -d ' ' -f1) -eq 44 ]; 
	rm -f "$dtpath$1.wav"
	exit 0

# 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 ]; 
	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"
	exit 1