Skip to content

Commit 2a0ac7a

Browse files
committed
DIS-65 chore: set up cron jobs
These aim to ensure that the aspen database contains up-to-date active ILL requests placed through the OCLC Resource Sharing For Groups integration by periodically fetching from the RS API and updating the user_oclc_resource_sharing_for_groups table in Aspen db.
1 parent 880c295 commit 2a0ac7a

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

code/web/Drivers/OCLCRSFGDriver.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class OCLCRSFGDriver {
1111
private $accessToken;
1212
private $_registryId;
1313

14-
public function __construct() {
14+
public function __construct($registryId = null) {
15+
if ($registryId) {
16+
$this->_registryId = $registryId;
17+
return;
18+
}
1519
$homeLocation = Location::getUserHomeLocation();
1620
$this->_registryId = $homeLocation ? $homeLocation->oclcRegistryId : "" ;
1721
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../bootstrap.php';
4+
require_once __DIR__ . '/../bootstrap_aspen.php';
5+
6+
require_once ROOT_DIR . '/sys/Account/User.php';
7+
require_once ROOT_DIR . '/sys/OCLCRSFG/OCLCRSFGRequest.php';
8+
9+
10+
$patron = new User();
11+
$oclcRSFGIllRequest = new OCLCRSFGRequest();
12+
$patron->selectAdd();
13+
$patron->selectAdd('DISTINCT user.id, user.homeLocationId');
14+
$patron->joinAdd($oclcRSFGIllRequest, 'INNER', 'patronWithIllRequests', 'id', 'userId');
15+
$patronWithIllRequestsList = $patron->fetchAll();
16+
17+
if (empty($patronWithIllRequestsList)) {
18+
die();
19+
}
20+
21+
require_once ROOT_DIR . '/sys/OCLCRSFG/OCLCRSFGSetting.php';
22+
require_once ROOT_DIR . '/Drivers/OCLCRSFGDriver.php';
23+
24+
foreach ($patronWithIllRequestsList as $patronWithIllRequests) {
25+
$oclcRegistryId = $patronWithIllRequests->getHomeLocation()->oclcRegistryId;
26+
if ($oclcRegistryId == -1) {
27+
continue;
28+
}
29+
$driver = new OCLCRSFGDriver($oclcRegistryId);
30+
$settings = new OCLCRSFGSetting();
31+
32+
$settings->id = $patronWithIllRequests->getHomeLibrary()->oclcRSFGSettingsId;
33+
if(!$settings->find(true)) {
34+
continue;
35+
};
36+
$driver->updateRequestsInAspenDbForPatron($settings, $patronWithIllRequests->id);
37+
}
38+
39+
die();

install/updateCron_25.02.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
if (count($_SERVER['argv']) > 1) {
4+
$serverName = $_SERVER['argv'][1];
5+
$fhnd = fopen("/usr/local/aspen-discovery/sites/$serverName/conf/crontab_settings.txt", 'a+');
6+
7+
if (!$fhnd) {
8+
echo("- Could not find cron settings file\n");
9+
exit();
10+
}
11+
12+
while (($line = fgets($fhnd)) !== false) {
13+
if (strpos($line, 'updateOCLCILLRequests') > 0) {
14+
echo("- No cron expression added: is already found in /sites/$serverName/conf/crontab_settings.txt \n");
15+
exit();
16+
}
17+
}
18+
19+
fwrite($fhnd, "\n#########################\n");
20+
fwrite($fhnd, "# fetch active OCLC ILL Requests and update them in Aspen DB #\n");
21+
fwrite($fhnd, "#########################\n");
22+
fwrite($fhnd, "0 0 * * * aspen php /usr/local/aspen-discovery/code/web/cron/updateOCLCILLRequests.php $serverName\n");
23+
exit();
24+
25+
} else {
26+
echo 'Must provide servername as first argument';
27+
exit();
28+
}

0 commit comments

Comments
 (0)