Skip to content

Commit

Permalink
Merge pull request #95 from AlexanderBlanchardAC/cookie_management_db…
Browse files Browse the repository at this point in the history
…_cleanup

Cookie management db cleanup
  • Loading branch information
AlexanderBlanchardAC authored Jul 26, 2024
2 parents 0720b1c + 4c3d5b0 commit c8fe69c
Show file tree
Hide file tree
Showing 35 changed files with 1,009 additions and 298 deletions.
Binary file modified code/cron/cron.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void doCronProcess(String servername, Ini configIni, Section processSetti
removeOldIndexingDiagnostics(dbConn, logger, processLog);

removeOldObjectHistory(dbConn, logger, processLog);
removeExternalSearchTracking(dbConn, logger, processLog);

processLog.setFinished();
processLog.saveResults();
Expand Down Expand Up @@ -467,4 +468,91 @@ private void removeOldSearches(Connection dbConn, Logger logger, CronProcessLogE
}
}

private void removeExternalSearchTracking(Connection dbConn, Logger logger, CronProcessLogEntry processLog) {
try {
//Get userIDs that have cookie consent for external search sources set to 0
PreparedStatement getNoExternalTrackingUserIdsStmt = dbConn.prepareStatement("SELECT id FROM user WHERE userCookiePreferenceExternalSearchServices = 0");
ResultSet userIdsRS = getNoExternalTrackingUserIdsStmt.executeQuery();

PreparedStatement removeAxis360UsageStmt = dbConn.prepareStatement("DELETE FROM user_axis360_usage WHERE userId = ?");
PreparedStatement removeCloudLibraryUsageStmt = dbConn.prepareStatement("DELETE FROM user_cloud_library_usage WHERE userId = ?");
PreparedStatement removeEbscoHostUsageStmt = dbConn.prepareStatement("DELETE FROM user_ebscohost_usage WHERE userId = ?");
PreparedStatement removeEbscoEdsUsageStmt = dbConn.prepareStatement("DELETE FROM user_ebsco_eds_usage WHERE userId = ?");
PreparedStatement removeHooplaUsageStmt = dbConn.prepareStatement("DELETE FROM user_hoopla_usage WHERE userId = ?");
PreparedStatement removeOverdriveUsageStmt = dbConn.prepareStatement("DELETE FROM user_overdrive_usage WHERE userId = ?");
PreparedStatement removePalaceProjectUsageStmt = dbConn.prepareStatement("DELETE FROM user_palace_project_usage WHERE userId = ?");
PreparedStatement removeSideloadUsageStmt = dbConn.prepareStatement("DELETE FROM user_sideload_usage WHERE userId = ?");
PreparedStatement removeSummonUsageStmt = dbConn.prepareStatement("DELETE FROM user_summon_usage WHERE userId = ?");

int totalRowsRemovedAXIS360 = 0;
int totalRowsRemovedCloudLibrary = 0;
int totalRowsRemovedEbscoHost = 0;
int totalRowsRemovedEbscoEds = 0;
int totalRowsRemovedHoopla = 0;
int totalRowsRemovedOverdrive = 0;
int totalRowsRemovedPalaceProject = 0;
int totalRowsRemovedSideload = 0;
int totalRowsRemovedSummon = 0;

while (userIdsRS.next()) {
int userId = userIdsRS.getInt("id");

removeAxis360UsageStmt.setInt(1, userId);
totalRowsRemovedAXIS360 += removeAxis360UsageStmt.executeUpdate();

removeCloudLibraryUsageStmt.setInt(1, userId);
totalRowsRemovedCloudLibrary += removeCloudLibraryUsageStmt.executeUpdate();

removeEbscoHostUsageStmt.setInt(1, userId);
totalRowsRemovedEbscoHost += removeEbscoHostUsageStmt.executeUpdate();

removeEbscoEdsUsageStmt.setInt(1, userId);
totalRowsRemovedEbscoEds += removeEbscoEdsUsageStmt.executeUpdate();

removeHooplaUsageStmt.setInt(1, userId);
totalRowsRemovedHoopla += removeHooplaUsageStmt.executeUpdate();

removeOverdriveUsageStmt.setInt(1, userId);
totalRowsRemovedOverdrive += removeOverdriveUsageStmt.executeUpdate();

removePalaceProjectUsageStmt.setInt(1, userId);
totalRowsRemovedPalaceProject += removePalaceProjectUsageStmt.executeUpdate();

removeSideloadUsageStmt.setInt(1, userId);
totalRowsRemovedSideload += removeSideloadUsageStmt.executeUpdate();

removeSummonUsageStmt.setInt(1, userId);
totalRowsRemovedSummon += removeSummonUsageStmt.executeUpdate();
}


//Log results
processLog.addNote("Removed " + totalRowsRemovedAXIS360 + " AXIS 360 usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedCloudLibrary + " Cloud Library usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedEbscoHost + " Ebsco Host usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedEbscoEds + " Ebsco EDS usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedHoopla + " Hoopla usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedOverdrive + " Overdrive usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedPalaceProject + " Palace Project usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedSideload + " Sideload usage records for users with externalSearchSources set to 0");
processLog.addNote("Removed " + totalRowsRemovedSummon + " Summon usage records for users with externalSearchSources set to 0");
processLog.incUpdated();
processLog.saveResults();

//Close statements and results sets
getNoExternalTrackingUserIdsStmt.close();
userIdsRS.close();
removeAxis360UsageStmt.close();
removeCloudLibraryUsageStmt.close();
removeEbscoHostUsageStmt.close();
removeEbscoEdsUsageStmt.close();
removeHooplaUsageStmt.close();
removeOverdriveUsageStmt.close();
removePalaceProjectUsageStmt.close();
removeSideloadUsageStmt.close();
removeSummonUsageStmt.close();
} catch (SQLException e) {
processLog.incErrors("Unable to remove external search tracking. ", e);
}
}
}
19 changes: 12 additions & 7 deletions code/web/Drivers/Axis360Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,14 +703,19 @@ public function trackUserUsageOfAxis360($user): void {
$userUsage->year = date('Y');
$userUsage->month = date('n');
global $aspenUsage;
$userUsage->instance = $aspenUsage->getInstance();
global $library;

if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
$userUsage->instance = $aspenUsage->getInstance();
$userObj = UserAccount::getActiveUserObj();
$userAxis360Tracking = $userObj->userCookiePreferenceExternalSearchServices;
if ($userAxis360Tracking && $library->cookieStorageConsent){
if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
}
}
}

Expand Down
17 changes: 11 additions & 6 deletions code/web/Drivers/CloudLibraryDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,17 +777,22 @@ private function callCloudLibraryUrl(CloudLibrarySetting $settings, string $apiP
*/
public function trackUserUsageOfCloudLibrary($user): void {
require_once ROOT_DIR . '/sys/CloudLibrary/UserCloudLibraryUsage.php';
global $library;
$userObj = UserAccount::getActiveUserObj();
$userCloudLibraryTracking = $userObj->userCookiePreferenceExternalSearchServices;
$userUsage = new UserCloudLibraryUsage();
$userUsage->userId = $user->id;
$userUsage->year = date('Y');
$userUsage->month = date('n');

if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
if ($userCloudLibraryTracking && $library->cookieStorageConsent) {
if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
}
}
}

Expand Down
17 changes: 11 additions & 6 deletions code/web/Drivers/HooplaDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,19 +681,24 @@ function cancelHold($patron, $recordId, $cancelId = null, $isIll = false): array
*/
public function trackUserUsageOfHoopla($user): void {
require_once ROOT_DIR . '/sys/Hoopla/UserHooplaUsage.php';
global $library;
$userUsage = new UserHooplaUsage();
$userObj = UserAccount::getActiveUserObj();
$userHooplaTracking = $userObj->userCookiePreferenceExternalSearchServices;
global $aspenUsage;
$userUsage->instance = $aspenUsage->getInstance();
$userUsage->userId = $user->id;
$userUsage->year = date('Y');
$userUsage->month = date('n');

if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
if ($userHooplaTracking && $library->cookieStorageConsent) {
if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions code/web/Drivers/OverDriveDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1618,18 +1618,22 @@ function renewCheckout($patron, $recordId, $itemId = null, $itemIndex = null) {
public function trackUserUsageOfOverDrive($user): void {
require_once ROOT_DIR . '/sys/OverDrive/UserOverDriveUsage.php';
$userUsage = new UserOverDriveUsage();
$userObj = UserAccount::getActiveUserObj();
$userOverDriveTracking = $userObj->userCookiePreferenceExternalSearchServices;
global $aspenUsage;
global $library;
$userUsage->instance = $aspenUsage->getInstance();
$userUsage->userId = $user->id;
$userUsage->year = date('Y');
$userUsage->month = date('n');

if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
if ($userOverDriveTracking && $library->cookieStorageConsent) {
if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions code/web/Drivers/PalaceProjectDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,18 +722,22 @@ private function getSettings(User $user = null) {
public function trackUserUsageOfPalaceProject($user): void {
require_once ROOT_DIR . '/sys/PalaceProject/UserPalaceProjectUsage.php';
$userUsage = new UserPalaceProjectUsage();
$userObj = UserAccount::getActiveUserObj();
$userPalaceProjectTracking = $userObj->userCookiePreferenceExternalSearchServices;
$userUsage->userId = $user->id;
$userUsage->year = date('Y');
$userUsage->month = date('n');
global $aspenUsage;
global $library;
$userUsage->instance = $aspenUsage->getInstance();

if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
if ($userPalaceProjectTracking && $library->cookieStorageConsent) {
if ($userUsage->find(true)) {
$userUsage->usageCount++;
$userUsage->update();
} else {
$userUsage->usageCount = 1;
$userUsage->insert();
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions code/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,32 @@
$cookie = json_decode(urldecode($_COOKIE["cookieConsent"]), true);
if (!empty($cookie)) {
$analyticsPref = $cookie['Analytics'];
$userAxis360Pref = $cookie['UserAxis360'];
$userEbscoEdsPref = $cookie['UserEbscoEds'];
$userEbscoHostPref = $cookie['UserEbscoHost'];
$userSummonPref = $cookie['UserSummon'];
$userEventsPref = $cookie['UserEvents'];
$userHooplaPref = $cookie['UserHoopla'];
$userOpenArchivesPref = $cookie['UserOpenArchives'];
$userOverdrivePref = $cookie['UserOverdrive'];
$userPalaceProjectPref = $cookie['UserPalaceProject'];
$userSideLoadPref = $cookie['UserSideLoad'];
$userWebsitePref = $cookie['UserWebsite'];
$userObj->userCookiePreferenceEssential = 1;
$userObj->userCookiePreferenceAnalytics = $analyticsPref;
$userObj->userCookiePreferenceAxis360 = $userAxis360Pref;
$userObj->userCookiePreferenceEbscoEds = $userEbscoEdsPref;
$userObj->userCookiePreferenceEbscoHost = $userEbscoHostPref;
$userObj->userCookiePreferenceSummon = $userSummonPref;
$userObj->userCookiePreferenceEvents = $userEventsPref;
$userObj->userCookiePreferenceHoopla = $userHooplaPref;
$userObj->userCookiePreferenceOpenArchives = $userOpenArchivesPref;
$userObj->userCookiePreferenceOverdrive = $userOverdrivePref;
$userObj->userCookiePreferencePalaceProject = $userPalaceProjectPref;
$userObj->userCookiePreferenceSideLoad = $userSideLoadPref;
$userObj->userCookiePreferenceCloudLibrary = $userCloudLibraryPref;
$userObj->userCookiePreferenceWebsite = $userWebsitePref;
$userObj->userCookiePreferenceExternalSearchServices = $userExternalSearchServicesPref;
$userObj->update();
}
}
Expand Down
105 changes: 105 additions & 0 deletions code/web/interface/themes/responsive/AJAX/cookieManagement.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{if $loggedIn}
<script>
cookieValues = {
Essential: {$profile->userCookiePreferenceEssential},
Analytics: {$profile->userCookiePreferenceAnalytics},
UserEvents: {$profile->userCookiePreferenceEvents},
UserOpenArchives: {$profile->userCookiePreferenceOpenArchives},
UserWebsite: {$profile->userCookiePreferenceWebsite},
UserExternalSearchServices: {$profile->userCookiePreferenceExternalSearchServices},
};
</script>
<div>
<form method="post" name="cookieManagementPreferencesForm" id="cookieManagementPreferencesForm" class="form">
<div>
<label>
<input type="checkbox" name="cookieEssential" id="cookieEssential" checked disabled> Essential Cookies
</label>
</div>
<div>
<label>
<input type="checkbox" name="cookieAnalytics" id="cookieAnalytics"> Analytics Cookies
</label>
</div>
{if array_key_exists('Axis 360', $enabledModules) || array_key_exists('EBSCO EDS', $enabledModules) || array_key_exists('EBSCOhost', $enabledModules) || array_key_exists('Summon', $enabledModules) || array_key_exists('OverDrive', $enabledModules)
|| array_key_exists('Palace Project', $enabledModules) || array_key_exists('Hoopla', $enabledModules) || array_key_exists('Side Loads', $enabledModules) || array_key_exists('Cloud Library', $enabledModules) || array_key_exists('Web Indexer', $enabledModules)}
<div>
<label>
<input type="checkbox" name="cookieUserExternalSearchServices" id="cookieUserExternalSearchServices"> External Search Services&nbsp;<i class="fas fa-question-circle" onclick="return displayCookieExplanation()"></i>
</label>
</div>
<div id="cookieExplanation" style="display:none; margin-top:10px;">
By checking this box you are giving consent to the tracking of your usage of:
<ul>
{if array_key_exists('Axis 360', $enabledModules)}
<li>Axis 360</li>
{/if}
{if array_key_exists('Cloud Library', $enabledModules)}
<li>Cloud Library</li>
{/if}
{if array_key_exists('EBSCO EDS', $enabledModules)}
<li>Ebsco Eds</li>
{/if}
{if array_key_exists('EBSCOhost', $enabledModules)}
<li>Ebsco Host</li>
{/if}
{if array_key_exists('Hoopla', $enabledModules)}
<li>Hoopla</li>
{/if}
{if array_key_exists('OverDrive', $enabledModules)}
<li>Overdrive</li>
{/if}
{if array_key_exists('Palace Project', $enabledModules)}
<li>Palace Project</li>
{/if}
{if array_key_exists('Side Loads', $enabledModules)}
<li>Side Loaded eContent</li>
{/if}
{if array_key_exists('Summon', $enabledModules)}
<li>Summon</li>
{/if}
</ul>
</div>
{/if}
{if array_key_exists('Events', $enabledModules)}
<div>
<label>
<input type="checkbox" name="cookieUserEvents" id="cookieUserEvents"> Events
</label>
</div>
{/if}
{if array_key_exists('Open Archives', $enabledModules)}
<div>
<label>
<input type="checkbox" name="cookieUserOpenArchives" id="cookieUserOpenArchives"> Open Archives
</label>
</div>
{/if}
{if array_key_exists('Web Indexer', $enabledModules)}
<div>
<label>
<input type="checkbox" name="cookieUserWebsite" id="cookieUserWebsite"> Website
</label>
</div>
{/if}
</div>
{/if}

<script type="text/javascript">
{literal}
function displayCookieExplanation() {
var explanationDiv = document.getElementById("cookieExplanation");
if (explanationDiv.style.display === "none") {
explanationDiv.style.display = "block";
} else {
explanationDiv.style.display = "none";
}
return false;
}
$("#cookieManagementPreferencesForm").validate({
submitHandler: function(){
AspenDiscovery.CookieConsent.cookieManagementPreferences();
}
});
{/literal}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
<div class="panel-body">
{if empty($offline)}
{if !empty($showUserPreferences)}<div class="myAccountLink"><a href="/MyAccount/MyPreferences">{translate text='Your Preferences' isPublicFacing=true}</a></div>{/if}
{if $cookieConsentEnabled} <div class="header-menu-option"><a href="/MyAccount/MyCookiePreferences">{translate text="Your Cookie Preferences" isPublicFacing=true}</a></div>{/if}

{if !empty($showUserContactInformation)}<div class="myAccountLink"><a href="/MyAccount/ContactInformation">{translate text='Contact Information' isPublicFacing=true}</a></div>{/if}
{if $user->showHoldNotificationPreferences()}
<div class="myAccountLink"><a href="/MyAccount/HoldNotificationPreferences">{translate text='Hold Notification Preferences' isPublicFacing=true}</a></div>
Expand Down
Loading

0 comments on commit c8fe69c

Please sign in to comment.