Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIS-231 Add notification to Koha exporter if offline mode is enabled #2202

Open
wants to merge 4 commits into
base: 25.02.00
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.turning_leaf_technologies.util;

import com.turning_leaf_technologies.indexing.IlsExtractLogEntry;
import com.turning_leaf_technologies.strings.AspenStringUtils;
import org.apache.logging.log4j.Logger;
import org.ini4j.Ini;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -54,4 +59,34 @@ public static void printMemoryStats(Logger logger) {
Runtime runtime = Runtime.getRuntime();
logger.debug("Max: " + AspenStringUtils.formatBytes(runtime.maxMemory()) + " | Total: " + AspenStringUtils.formatBytes(runtime.totalMemory()) + " | Used: " + (AspenStringUtils.formatBytes(runtime.totalMemory() - runtime.freeMemory())) + " | Free: " + AspenStringUtils.formatBytes(runtime.freeMemory()));
}

public static boolean isOffline(Connection dbConn, Logger logger) {
try {
PreparedStatement getOfflineStatusStmt = dbConn.prepareStatement("SELECT catalogStatus FROM system_variables", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet getOfflineStatusRS = getOfflineStatusStmt.executeQuery();
if (getOfflineStatusRS.next()) {
int catalogStatus = getOfflineStatusRS.getInt("catalogStatus");
getOfflineStatusStmt.close();
getOfflineStatusRS.close();
return (catalogStatus != 0);
}else{
getOfflineStatusStmt.close();
getOfflineStatusRS.close();
return false;
}
} catch (SQLException e) {
logger.error("Error determining if the catalog is offline, quitting to be safe", e);
System.exit(-9);
}
return true;
}

public static void QuitIfOffline(Connection dbConn, Logger logger, IlsExtractLogEntry logEntry)
{
if (isOffline(dbConn, logger)) {
logEntry.addNote("ILS is offline, won't index.");
logEntry.saveResults();
System.exit(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ public static void main(String[] args) {
}

//Check to see if the ILS connection is offline and don't index
if (isOffline()) {
System.exit(0);
}
SystemUtils.QuitIfOffline(dbConn, logger, logEntry);

//Connect to the Koha database
Connection kohaConn;
Expand Down
6 changes: 6 additions & 0 deletions code/web/release_notes/25.02.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@

//alexander

//imani
### Indexing Updates
- Created isOffline and QuitIfOffline in SystemUtils to share common behavior across exporters
- Changed existing offline checks in KohaExportMain to use SystemUtils instead.

//chloe
### WebBuilder Updates
- Fixed an issue preventing administrators from saving a 'URL to link image to' from the 'WebBuilder Portal Cells' page. (*CZ*)
Expand Down Expand Up @@ -114,6 +119,7 @@ Use mb_substr to presrve diacritics in lists (DIS-178) (*WNC*)
- Nick Clemens (WNC)
- Yanjun Li (YL)
- Leo Stoyanov (LS)
- Imani Thomas (IT)

### Grove For Libraries
- Mark Noble (MDN)
Expand Down