Timestamp changed, Add Undo to new code

1.  To increase portability,  changed the ':' in timestamo to '.' (MacOS problems)
2.  Completed adding WriteLog and logic to support UNDO for importing Viewstate
This commit is contained in:
ChuckPa 2022-11-09 21:33:07 -05:00
parent 580ec27986
commit 303cde633d
No known key found for this signature in database
GPG Key ID: 3CE28A0F6BC31B5B

View File

@ -548,7 +548,7 @@ do
[ "$Choice" -eq 0 ] && echo " " && echo "'$Input' - Is invalid. Try again" [ "$Choice" -eq 0 ] && echo " " && echo "'$Input' - Is invalid. Try again"
# Update timestamp # Update timestamp
TimeStamp="$(date "+%Y-%m-%d_%H:%M:%S")" TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")"
done done
# Spacing for legibility # Spacing for legibility
@ -1068,18 +1068,34 @@ do
continue continue
fi fi
WriteLog "Import - Attempting to import watch history from '$Input' "
# Confirm our databases are intact # Confirm our databases are intact
if ! CheckDatabases; then if ! CheckDatabases; then
Output "Error: PMS databases are damaged. Repair needed. Refusing to import." Output "Error: PMS databases are damaged. Repair needed. Refusing to import."
WriteLog "Import - Verify main database - FAIL"
continue continue
fi fi
# Check the given database # Check the given database
if ! CheckDB "$Input"; then if ! CheckDB "$Input"; then
Output "Error: Given database is damaged. Repair needed. Database not trusted. Refusing to import." Output "Error: Given database is damaged. Repair needed. Database not trusted. Refusing to import."
WriteLog "Import - Verify '$Input' - FAIL"
continue continue
fi fi
# Make a backup
Output "Backing up databases"
if ! MakeBackups "Import "; then
Output "Error making backups. Cannot continue."
WriteLog "Import - MakeBackups - FAIL"
Fail=1
continue
else
WriteLog "Import - MakeBackups - PASS"
fi
# Export viewstate from DB # Export viewstate from DB
Output "Exporting Viewstate / Watch history" Output "Exporting Viewstate / Watch history"
echo ".dump metadata_item_settings" | "$PLEX_SQLITE" "$Input" | grep -v TABLE | grep -v INDEX > "$TMPDIR/Viewstate.sql-$TimeStamp" echo ".dump metadata_item_settings" | "$PLEX_SQLITE" "$Input" | grep -v TABLE | grep -v INDEX > "$TMPDIR/Viewstate.sql-$TimeStamp"
@ -1101,17 +1117,24 @@ do
# Make certain the resultant DB is OK # Make certain the resultant DB is OK
Output "Checking database following import" Output "Checking database following import"
if CheckDB $CPPL.db ; then if ! CheckDB $CPPL.db ; then
Output "Viewstate import successful."
WriteLog " Import - Import: $Input - PASS" Output "Error $Result during import. Import corrupted database."
else Output " Undoing viewstate import."
Output "Error $Result during import. Reverting to previous state."
Output " Viewstate history not imported." RestoreSaved "$LastTimestamp"
mv -f "$TMPDIR/Viewstate.db-$TimeStamp" $CPPL.db
WriteLog "Import - Import: $Input - FAIL" WriteLog "Import - Import: $Input - FAIL"
continue continue
fi fi
# We were successful
Output "Viewstate import successful."
WriteLog "Import - Import: $Input - PASS"
# We were successful
SetLast "Import" "$TimeStamp"
# 8. - Show Logfile # 8. - Show Logfile
elif [ $Choice -eq 8 ]; then elif [ $Choice -eq 8 ]; then