-
Notifications
You must be signed in to change notification settings - Fork 0
/
NashvilleCarlXDeletePatronNotes.php
121 lines (108 loc) · 4.2 KB
/
NashvilleCarlXDeletePatronNotes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
// TO DO: set up github repository
// echo 'SYNTAX: $sudo php NashvilleCarlXDeletePatronNotes.php\n';
date_default_timezone_set('America/Chicago');
$configArray = parse_ini_file('../config.pwd.ini', true, INI_SCANNER_RAW);
$carlx_db_php = $configArray['Catalog']['carlx_db_php'];
$carlx_db_php_user = $configArray['Catalog']['carlx_db_php_user'];
$carlx_db_php_password = $configArray['Catalog']['carlx_db_php_password'];
$patronApiWsdl = $configArray['Catalog']['patronApiWsdl'];
$reportPath = '../data/';
function callAPI($wsdl, $requestName, $request) {
$connectionPassed = false;
$numTries = 0;
$result = new stdClass();
$result->response = "";
while (!$connectionPassed && $numTries < 3) {
try {
$client = new SOAPClient($wsdl, array('connection_timeout' => 3, 'features' => SOAP_WAIT_ONE_WAY_CALLS, 'trace' => 1));
$result->response = $client->$requestName($request);
$connectionPassed = true;
if (is_null($result->response)) {$result->response = $client->__getLastResponse();}
if (!empty($result->response)) {
if (gettype($result->response) == 'object') {
$ShortMessage[0] = $result->response->ResponseStatuses->ResponseStatus->ShortMessage;
$result->success = $ShortMessage[0] == 'Successful operation';
} else if (gettype($result->response) == 'string') {
$result->success = stripos($result->response, '<ns2:ShortMessage>Successful operation</ns2:ShortMessage>') !== false;
preg_match('/<ns2:LongMessage>(.+?)<\/ns2:LongMessage>/', $result->response, $longMessages);
preg_match('/<ns2:ShortMessage>(.+?)<\/ns2:ShortMessage>/', $result->response, $shortMessages);
}
if(!$result->success) {
$result->error = "$request->SearchID : Failed" . (isset($longMessages[1]) ? ' : ' . $longMessages[1] : (isset($shortMessages[0]) ? ' : ' . $shortMessages[0] : ''));
}
} else {
$result->error = "$request->SearchID : Failed : No SOAP response from API.";
}
} catch (SoapFault $e) {
if ($numTries == 2) { $result->error = "$request->SearchID : Exception : " . $e->getMessage(); }
}
$numTries++;
}
return $result;
}
// connect to carlx oracle db
$conn = oci_connect($carlx_db_php_user, $carlx_db_php_password, $carlx_db_php);
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$sql = <<<EOT
-- SQL FOR 13K+ NOTEIDs THAT SHOULD BE DELETED 2018 06 28
select n.noteid
from patronnotetext_v2 n
left join patron_v2 p on n.refid = p.patronid
where p.bty >= 21 and p.bty <= 37
and n.text like 'NPL: MNPS Guarantor effective%'
-- and n.text not like '%TESTY MCTESTERSON'
EOT;
$stid = oci_parse($conn, $sql);
oci_set_prefetch($stid, 10000);
oci_execute($stid);
// start a new file for the CarlX patron extract
$df;
$df = fopen($reportPath . "CARLX_MNPS_DELETE_PATRON_NOTES.CSV", 'w');
while (($row = oci_fetch_array ($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
// CSV OUTPUT
fputcsv($df, $row);
}
fclose($df);
echo "CARLX MNPS patron notes to be deleted retrieved and written\n";
oci_free_statement($stid);
oci_close($conn);
$records = array();
$fhnd = fopen($reportPath . "CARLX_MNPS_DELETE_PATRON_NOTES.CSV", "r");
if ($fhnd){
while (($data = fgetcsv($fhnd)) !== FALSE){
$records[] = $data;
}
}
$i = 0;
$errors = array();
foreach ($records as $patron) {
// CREATE PATRON DELETE REQUEST
$requestName = 'deletePatronNote';
$request = new stdClass();
$request->Modifiers = new stdClass();
$request->Modifiers->DebugMode = true;
$request->Modifiers->ReportMode = false;
$request->NoteID = $patron[0]; // Note ID
//var_dump($request);
$result = callAPI($patronApiWsdl, $requestName, $request);
//var_dump($result);
if (isset($result->error)) {
echo "$result->error\n";
$errors[] = $result->error;
} else {
echo "$request->NoteID : deleted\n";
}
//if(++$i==10) break;
}
$ferror = fopen($reportPath . "NashvilleCarlXDeletePatronNotes.log", "a");
fwrite($ferror, "-------------------------------------------------------------\n");
fwrite($ferror, date('c') . " BEGIN DELETE PATRON NOTES\n");
fwrite($ferror, $sql . "\n");
fwrite($ferror, implode(',',array_column($records,0)) . "\n");
fwrite($ferror, implode("\n",$errors) . "\n\n");
fclose($ferror);
?>