Merge pull request #571 from AndreasK79/qrz_upload_error_logging

Added a bit better error handling. Writing errors to logfile now, if …
pull/576/head
Peter Goodhall 2020-08-08 17:50:22 +01:00 zatwierdzone przez GitHub
commit 7485b9d3b4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 52 dodań i 10 usunięć

Wyświetl plik

@ -36,7 +36,7 @@ class Qrz extends CI_Controller {
}
} else {
echo "No station_id's with a QRZ API Key found";
log_message('info', "No station_id's with a QRZ API Key found");
log_message('error', "No station_id's with a QRZ API Key found");
}
}
@ -56,6 +56,7 @@ class Qrz extends CI_Controller {
function mass_upload_qsos($station_id, $qrz_api_key) {
$i = 0;
$data['qsos'] = $this->logbook_model->get_qrz_qsos($station_id);
$errormessages=array();
if ($data['qsos']) {
foreach ($data['qsos'] as $qso) {
@ -67,14 +68,24 @@ class Qrz extends CI_Controller {
$result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif);
}
if ($result) {
if ($result['status'] == 'OK') {
$this->markqso($qso['COL_PRIMARY_KEY']);
$i++;
} else {
log_message('error', 'QRZ upload failed for qso: Call: ' . $qso['COL_CALL'] . ' Band: ' . $qso['COL_BAND'] . ' Mode: ' . $qso['COL_MODE'] . ' Time: ' . $qso['COL_TIME_ON']);
log_message('error', 'QRZ upload failed with the following message: ' .$result['message']);
$errormessages[] = $result['message'] . ' Call: ' . $qso['COL_CALL'] . ' Band: ' . $qso['COL_BAND'] . ' Mode: ' . $qso['COL_MODE'] . ' Time: ' . $qso['COL_TIME_ON'];
}
}
return $i;
$result['status'] = 'OK';
$result['count'] = $i;
$result['errormessages'] = $errormessages;
return $result;
} else {
return $i;
$result['status'] = 'Error';
$result['count'] = $i;
$result['errormessages'] = $errormessages;
return $result;
}
}
@ -116,17 +127,20 @@ class Qrz extends CI_Controller {
$qrz_api_key = $this->logbook_model->exists_qrz_api_key($postData['station_id']);
header('Content-type: application/json');
if ($i = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key)) {
$result = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key);
if ($result['status'] == 'OK') {
$stationinfo = $this->stations->stations_with_qrz_api_key();
$info = $stationinfo->result();
$data['status'] = 'OK';
$data['info'] = $info;
$data['infomessage'] = $i . " QSOs are now uploaded to QRZ.com";
$data['infomessage'] = $result['count'] . " QSOs are now uploaded to QRZ.com";
$data['errormessages'] = $result['errormessages'];
echo json_encode($data);
} else {
$data['status'] = 'Error';
$data['info'] = 'Error, no QSOs to upload found';
$data['errormessages'] = $result['errormessages'];
echo json_encode($data);
}
}

Wyświetl plik

@ -328,7 +328,8 @@ class Logbook_model extends CI_Model {
// Push qso to qrz if apikey is set
if ($apikey = $this->exists_qrz_api_key($data['station_id'])) {
$adif = $this->create_adif_from_data($data);
IF ($this->push_qso_to_qrz($apikey, $adif)) {
$result = $this->push_qso_to_qrz($apikey, $adif);
IF ($result['status'] == 'OK') {
$data['COL_QRZCOM_QSO_UPLOAD_STATUS'] = 'Y';
$data['COL_QRZCOM_QSO_UPLOAD_DATE'] = date("Y-m-d H:i:s", strtotime("now"));
}
@ -382,14 +383,19 @@ class Logbook_model extends CI_Model {
$content = curl_exec($ch);
if ($content){
if (stristr($content,'RESULT=OK') || stristr($content,'RESULT=REPLACE')) {
return true;
$result['status'] = 'OK';
return $result;
}
else {
return false;
$result['status'] = 'error';
$result['message'] = $content;
return $result;
}
}
if(curl_errno($ch)){
return false;
$result['status'] = 'error';
$result['message'] = 'Curl error: '. curl_errno($ch);
return $result;
}
curl_close($ch);
}

Wyświetl plik

@ -1383,6 +1383,12 @@ $(document).ready(function(){
<?php if ($this->uri->segment(1) == "qrz") { ?>
<script>
function ExportQrz(station_id) {
if ($(".alert").length > 0) {
$(".alert").remove();
}
if ($(".errormessages").length > 0) {
$(".errormessages").remove();
}
$(".ld-ext-right").addClass('running');
$(".ld-ext-right").prop('disabled', true);
var baseURL= "<?php echo base_url();?>";
@ -1404,6 +1410,22 @@ $(document).ready(function(){
else {
$(".card-body").append('<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' + data.info + '</div>');
}
if (data.errormessages.length > 0) {
$(".card-body").append('' +
'<div class="errormessages"><p>\n' +
' <button class="btn btn-danger" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">\n' +
' Show error messages\n' +
' </button>\n' +
' </p>\n' +
' <div class="collapse" id="collapseExample">\n' +
' <div class="card card-body"><div class="errors"></div>\n' +
' </div>\n' +
' </div></div>');
$.each(data.errormessages, function(index, value) {
$(".errors").append('<li>' + value);
});
}
}
});
}