Skip to content

Commit

Permalink
Merge pull request #55 from AlexanderBlanchardAC/gdpr_cleanup_script
Browse files Browse the repository at this point in the history
Gdpr cleanup script
  • Loading branch information
AlexanderBlanchardAC authored May 24, 2024
2 parents 485e83b + eb58024 commit 89b8cf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Binary file modified code/cron/cron.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -452,16 +452,15 @@ private void removeOldLastListUsed(Connection dbConn, Logger logger, CronProcess
//Remove old last list used
try {
//Get list of libraries that want last used list cleared
PreparedStatement librariesListStmt = dbConn.prepareStatement("SELECT libraryId, deleteOldLastListUsedEntries from library where deleteOldLastListUsedEntries > 0");
PreparedStatement libraryLocationsStmt = dbConn.prepareStatement("SELECT locationId from location where libraryId = ?");
PreparedStatement deleteLastListUsedStmt = dbConn.prepareStatement("DELETE from user where lastListUsed = ?");
PreparedStatement librariesListStmt = dbConn.prepareStatement("SELECT libraryId FROM library WHERE deleteLastListUsedEntries = 1");
PreparedStatement libraryLocationsStmt = dbConn.prepareStatement("SELECT locationId FROM location where libraryId = ?");
PreparedStatement deleteLastListUsedStmt = dbConn.prepareStatement("UPDATE user SET lastListUsed = NULL WHERE lastListUsed = ?");

ResultSet librariesListRS = librariesListStmt.executeQuery();

long numDeletions = 0;
while (librariesListRS.next()) {
long libraryId = librariesListRS.getLong("libraryId");
long daysToPreserve = librariesListRS.getLong("deleteLastUsedListEntries");

libraryLocationsStmt.setLong(1, libraryId);

Expand All @@ -476,10 +475,10 @@ private void removeOldLastListUsed(Connection dbConn, Logger logger, CronProcess
}
if (libraryLocations.length() > 0) {
long now = new Date().getTime() /1000;
long daysToPreserve = 14;
long earliestDateToPreserve = now - (daysToPreserve * 24 * 60 * 60);

long earliestDateToPreserve = now - (14 * 24 * 60 * 60);

PreparedStatement lastListUsedEntriesToDeleteStmt = dbConn.prepareStatement("SELECT lastListUsed from user where user.homeLocationId IN (" + libraryLocations + ") and lastListused < ?");
PreparedStatement lastListUsedEntriesToDeleteStmt = dbConn.prepareStatement("SELECT lastListUsed FROM user WHERE user.homeLocationId IN (" + libraryLocations + ") AND lastListused < ?");
lastListUsedEntriesToDeleteStmt.setLong(1, earliestDateToPreserve);

ResultSet lastListUsedEntriesToDeleteRS = lastListUsedEntriesToDeleteStmt.executeQuery();
Expand All @@ -495,6 +494,8 @@ private void removeOldLastListUsed(Connection dbConn, Logger logger, CronProcess
}
librariesListRS.close();
librariesListStmt.close();
libraryLocationsStmt.close();
deleteLastListUsedStmt.close();
processLog.addNote("Removed " + numDeletions + " expired last list used entries");
} catch (SQLException e) {
processLog.incErrors("Unable to remove expired last used list entries.", e);
Expand Down

0 comments on commit 89b8cf0

Please sign in to comment.