Skip to content

Commit 5ca2dc2

Browse files
added hour-restrictions for updater and improved frontendlanguage-handling in updater
1 parent 986e439 commit 5ca2dc2

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

l10n/custom-data-type-gnd.csv

100644100755
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ custom.data.type.gnd.config.parameter.schema.add_subjects.value.checkbox,Sachbeg
6767
custom.data.type.gnd.config.parameter.schema.add_works.value.checkbox,Werke,Works
6868
custom.data.type.gnd.config.parameter.schema.add_conferenceorevent.value.checkbox,Konferenzen und Veranstaltungen,Conference and events
6969
custom.data.type.gnd.url.tooltip,zu **%(name)s** bei der Deutschen Nationalbibliothek springen,jump to **%(name)s** at German National Library (DNB)
70-
server.config.name.system.update_interval_gnd,GND-Update-Einstellungen,GND-Update-Settings
71-
server.config.parameter.system.update_interval_gnd.days.label,Tage zwischen Updates,Days between updates
70+
server.config.name.system.update_gnd,GND-Update-Einstellungen,GND-Update-Settings
71+
server.config.parameter.system.update_gnd.restrict_time.label,Beschränke Updates auf bestimmte Stunden?,Restrict updates to specific hours?
72+
server.config.parameter.system.update_gnd.restrict_time.checkbox,Ja - beschränken,Yes - restrict
73+
server.config.parameter.system.update_gnd.from_time.label,Stunde von (Zahl 0-24),Hour from (Int 0-24)
74+
server.config.parameter.system.update_gnd.to_time.label,Stunde bis (Zahl 0-24),Hour to (Int 0-24)
75+
server.config.parameter.system.update_gnd.default_language.label,Standard-Datensprache als Fallback für Update (ISO 639-1),Default-data-language (as fallback) for update (ISO 639-1)
7276
custom.data.type.gnd.config.parameter.mask.editor_display.value.label,Editor-Ansicht,Editor-Display
7377
custom.data.type.gnd.config.option.mask.editor_display.value.default,Standard,Default
7478
custom.data.type.gnd.config.option.mask.editor_display.value.condensed,1 Zeile,One-liner

manifest.master.yml

100644100755
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,29 @@ custom_types:
9090
value: "%info.json%"
9191
timeout: 60
9292
batch_size: 1
93-
expires_days: 1
94-
interval_base_config: update_interval_gnd.days
95-
93+
expires_days: 1
9694

9795
base_config:
98-
- name: update_interval_gnd
96+
- name: update_gnd
9997
group: update_custom_data_type
10098
parameters:
101-
days:
99+
restrict_time:
100+
type: bool
101+
default: false
102+
position: 0
103+
from_time:
102104
type: int
105+
default: 19
103106
min: 0
104-
default: 0
105-
position: 0
107+
max: 24
108+
position: 1
109+
to_time:
110+
type: int
111+
default: 4
112+
min: 0
113+
max: 24
114+
position: 2
106115
default_language:
107116
type: text
108117
default: 'de'
109-
position: 1
118+
position: 3

src/updater/gndUpdater.js

100644100755
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ main = (payload) => {
150150
newCdata.conceptURI = data.id;
151151
newCdata.conceptName = data.preferredName;
152152

153+
// if no frontendLanguage exists in originalData: add
154+
if (! originalCdata?.frontendLanguage?.length == 2) {
155+
originalCdata.frontendLanguage = defaultLanguage;
156+
}
157+
// save frontend language (same as given or default)
153158
newCdata.frontendLanguage = originalCdata.frontendLanguage;
154159

155160
newCdata.facetTerm = GNDUtil.getFacetTerm(newCdata, databaseLanguages);
@@ -219,6 +224,29 @@ outputErr = (err2) => {
219224

220225
process.stdin.setEncoding('utf8');
221226

227+
////////////////////////////////////////////////////////////////////////////
228+
// check if hour-restriction is set
229+
////////////////////////////////////////////////////////////////////////////
230+
231+
if(info?.config?.plugin?.['custom-data-type-gnd']?.config?.update_gnd?.restrict_time === true) {
232+
let plugin_config = info.config.plugin['custom-data-type-gnd'].config.update_gnd;
233+
// check if hours are configured
234+
if(plugin_config?.from_time !== false && plugin_config?.to_time !== false) {
235+
const now = new Date();
236+
const hour = now.getHours();
237+
// check if hours do not match
238+
if(hour < plugin_config.from_time && hour >= plugin_config.to_time) {
239+
// exit if hours do not match
240+
outputData({
241+
"state": {
242+
"theend": 2,
243+
"log": ["hours do not match, cancel update"]
244+
}
245+
});
246+
}
247+
}
248+
}
249+
222250
access_token = info && info.plugin_user_access_token;
223251

224252
if (access_token) {
@@ -235,7 +263,7 @@ outputErr = (err2) => {
235263

236264
frontendLanguages = config.system.config.languages.frontend;
237265

238-
const testDefaultLanguageConfig = config.plugin['custom-data-type-gnd'].config.update_interval_gnd.default_language;
266+
const testDefaultLanguageConfig = config.plugin['custom-data-type-gnd'].config.update_gnd.default_language;
239267
if (testDefaultLanguageConfig) {
240268
if (testDefaultLanguageConfig.length == 2) {
241269
defaultLanguage = testDefaultLanguageConfig;

0 commit comments

Comments
 (0)