Skip to content

Commit 39d16d6

Browse files
authored
Merge pull request wavelog#2665 from iu2frl/dev-log-fallback
Implementing callbook failover logic
2 parents 94eba32 + eb8b845 commit 39d16d6

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

application/libraries/Callbook.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,40 @@ public function __construct() {
1818
// Implement the following:
1919
// - Implement callsign reduced logic
2020
public function getCallbookData($callsign) {
21-
switch ($this->ci->config->item('callbook')) {
21+
// Load callbook configuration from config.php
22+
$source_callbooks = $this->ci->config->item('callbook');
23+
24+
// Check if the source callbook is a single element or an array
25+
if (is_array($source_callbooks)) {
26+
// Parse each callbook in the array until we get a valid result
27+
foreach ($source_callbooks as $source) {
28+
$callbook = $this->queryCallbook($callsign, $source);
29+
if (!isset($callbook['error']) || $callbook['error'] == '') {
30+
break;
31+
}
32+
}
33+
}
34+
else {
35+
// Single callbook lookup (default behavior)
36+
$callbook = $this->queryCallbook($callsign, $source_callbooks);
37+
}
38+
39+
// Handle callbook specific fields
40+
if (! array_key_exists('geoloc', $callbook)) {
41+
$callbook['geoloc'] = '';
42+
}
43+
44+
// qrz.com gives AA00aa if the user deleted his grid from the profile
45+
$this->ci->load->library('qra');
46+
if (!array_key_exists('gridsquare', $callbook) || !$this->ci->qra->validate_grid($callbook['gridsquare'])) {
47+
$callbook['gridsquare'] = '';
48+
}
49+
50+
return $callbook;
51+
}
52+
53+
function queryCallbook($callsign, $source) {
54+
switch ($source) {
2255
case 'qrz':
2356
if ($this->ci->config->item('qrz_username') == null || $this->ci->config->item('qrz_password') == null) {
2457
$callbook['error'] = 'Lookup not configured. Please review configuration.';
@@ -46,15 +79,8 @@ public function getCallbookData($callsign) {
4679
default:
4780
$callbook['error'] = 'No callbook defined. Please review configuration.';
4881
}
49-
// Handle callbook specific fields
50-
if (! array_key_exists('geoloc', $callbook)) {
51-
$callbook['geoloc'] = '';
52-
}
53-
// qrz.com gives AA00aa if the user deleted his grid from the profile
54-
$this->ci->load->library('qra');
55-
if (!array_key_exists('gridsquare', $callbook) || !$this->ci->qra->validate_grid($callbook['gridsquare'])) {
56-
$callbook['gridsquare'] = '';
57-
}
82+
83+
log_message('debug', 'Callbook lookup for '.$callsign.' using '.$source.': '.((($callbook['error'] ?? '' ) != '') ? $callbook['error'] : 'Success'));
5884
return $callbook;
5985
}
6086

0 commit comments

Comments
 (0)