Fixes abortion of lotw_download loop caused by returns
这个提交包含在:
父节点
007488f7a7
当前提交
6303d90c1c
共有 1 个文件被更改,包括 146 次插入 和 145 次删除
|
|
@ -216,152 +216,152 @@ class Lotw extends CI_Controller {
|
|||
$qso_id_array = array();
|
||||
|
||||
// Build TQ8 Outputs
|
||||
if ($station_profiles->num_rows() >= 1) {
|
||||
if ($station_profiles->num_rows() >= 1) {
|
||||
|
||||
foreach ($station_profiles->result() as $station_profile) {
|
||||
foreach ($station_profiles->result() as $station_profile) {
|
||||
|
||||
// Get Certificate Data
|
||||
$this->load->model('LotwCert');
|
||||
$data['station_profile'] = $station_profile;
|
||||
$data['lotw_cert_info'] = $this->LotwCert->lotw_cert_details($station_profile->station_callsign, $station_profile->station_dxcc);
|
||||
// Get Certificate Data
|
||||
$this->load->model('LotwCert');
|
||||
$data['station_profile'] = $station_profile;
|
||||
$data['lotw_cert_info'] = $this->LotwCert->lotw_cert_details($station_profile->station_callsign, $station_profile->station_dxcc);
|
||||
|
||||
// If Station Profile has no LOTW Cert continue on.
|
||||
if(!isset($data['lotw_cert_info']->cert_dxcc_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if LoTW certificate itself is valid
|
||||
// Validty of QSO dates will be checked later
|
||||
$current_date = date('Y-m-d H:i:s');
|
||||
if ($current_date <= $data['lotw_cert_info']->date_created) {
|
||||
echo $data['lotw_cert_info']->callsign.": LoTW certificate not valid yet!";
|
||||
continue;
|
||||
}
|
||||
if ($current_date >= $data['lotw_cert_info']->date_expires) {
|
||||
echo $data['lotw_cert_info']->callsign.": LoTW certificate expired!";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get QSOs
|
||||
|
||||
$this->load->model('Logbook_model');
|
||||
|
||||
$data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id, $data['lotw_cert_info']->qso_start_date, $data['lotw_cert_info']->qso_end_date);
|
||||
|
||||
// Nothing to upload
|
||||
if(empty($data['qsos']->result())){
|
||||
if ($this->user_model->authorize(2)) { // Only be verbose if we have a session
|
||||
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") No QSOs to Upload <br>";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($data['qsos']->result() as $temp_qso) {
|
||||
array_push($qso_id_array, $temp_qso->COL_PRIMARY_KEY);
|
||||
}
|
||||
|
||||
// Build File to save
|
||||
$adif_to_save = $this->load->view('lotw_views/adif_views/adif_export', $data, TRUE);
|
||||
|
||||
// create folder to store upload file
|
||||
if (!file_exists('./uploads/lotw')) {
|
||||
mkdir('./uploads/lotw', 0775, true);
|
||||
}
|
||||
|
||||
// Build Filename
|
||||
$filename_for_saving = './uploads/lotw/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($data['lotw_cert_info']->callsign))."-".date("Y-m-d-H-i-s")."-cloudlog.tq8";
|
||||
|
||||
$gzdata = gzencode($adif_to_save, 9);
|
||||
$fp = fopen($filename_for_saving, "w");
|
||||
fwrite($fp, $gzdata);
|
||||
fclose($fp);
|
||||
|
||||
//The URL that accepts the file upload.
|
||||
$url = 'https://lotw.arrl.org/lotw/upload';
|
||||
|
||||
//The name of the field for the uploaded file.
|
||||
$uploadFieldName = 'upfile';
|
||||
|
||||
//The full path to the file that you want to upload
|
||||
$filePath = realpath($filename_for_saving);
|
||||
|
||||
//Initiate cURL
|
||||
$ch = curl_init();
|
||||
|
||||
//Set the URL
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
//Set the HTTP request to POST
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
//Tell cURL to return the output as a string.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
//If the function curl_file_create exists
|
||||
if(function_exists('curl_file_create')){
|
||||
//Use the recommended way, creating a CURLFile object.
|
||||
$filePath = curl_file_create($filePath);
|
||||
} else{
|
||||
//Otherwise, do it the old way.
|
||||
//Get the canonicalized pathname of our file and prepend
|
||||
//the @ character.
|
||||
$filePath = '@' . realpath($filePath);
|
||||
//Turn off SAFE UPLOAD so that it accepts files
|
||||
//starting with an @
|
||||
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
|
||||
}
|
||||
|
||||
//Setup our POST fields
|
||||
$postFields = array(
|
||||
$uploadFieldName => $filePath
|
||||
);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
|
||||
//Execute the request
|
||||
$result = curl_exec($ch);
|
||||
|
||||
//If an error occured, throw an exception
|
||||
//with the error message.
|
||||
if(curl_errno($ch)){
|
||||
throw new Exception(curl_error($ch));
|
||||
}
|
||||
|
||||
$pos = strpos($result, "<!-- .UPL. accepted -->");
|
||||
|
||||
if ($pos === false) {
|
||||
// Upload of TQ8 Failed for unknown reason
|
||||
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") Upload Failed"."<br>";
|
||||
} else {
|
||||
// Upload of TQ8 was successfull
|
||||
|
||||
echo "Upload Successful - ".$filename_for_saving."<br>";
|
||||
|
||||
$this->LotwCert->last_upload($data['lotw_cert_info']->lotw_cert_id);
|
||||
|
||||
// Mark QSOs as Sent
|
||||
foreach ($qso_id_array as $qso_number) {
|
||||
$this->Logbook_model->mark_lotw_sent($qso_number);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete TQ8 File - This is done regardless of whether upload was succcessful
|
||||
unlink(realpath($filename_for_saving));
|
||||
// If Station Profile has no LOTW Cert continue on.
|
||||
if(!isset($data['lotw_cert_info']->cert_dxcc_id)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
echo "No Station Profiles found to upload to LOTW";
|
||||
|
||||
// Check if LoTW certificate itself is valid
|
||||
// Validty of QSO dates will be checked later
|
||||
$current_date = date('Y-m-d H:i:s');
|
||||
if ($current_date <= $data['lotw_cert_info']->date_created) {
|
||||
echo $data['lotw_cert_info']->callsign.": LoTW certificate not valid yet!";
|
||||
continue;
|
||||
}
|
||||
if ($current_date >= $data['lotw_cert_info']->date_expires) {
|
||||
echo $data['lotw_cert_info']->callsign.": LoTW certificate expired!";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get QSOs
|
||||
|
||||
$this->load->model('Logbook_model');
|
||||
|
||||
$data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id, $data['lotw_cert_info']->qso_start_date, $data['lotw_cert_info']->qso_end_date);
|
||||
|
||||
// Nothing to upload
|
||||
if(empty($data['qsos']->result())){
|
||||
if ($this->user_model->authorize(2)) { // Only be verbose if we have a session
|
||||
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") No QSOs to Upload <br>";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($data['qsos']->result() as $temp_qso) {
|
||||
array_push($qso_id_array, $temp_qso->COL_PRIMARY_KEY);
|
||||
}
|
||||
|
||||
// Build File to save
|
||||
$adif_to_save = $this->load->view('lotw_views/adif_views/adif_export', $data, TRUE);
|
||||
|
||||
// create folder to store upload file
|
||||
if (!file_exists('./uploads/lotw')) {
|
||||
mkdir('./uploads/lotw', 0775, true);
|
||||
}
|
||||
|
||||
// Build Filename
|
||||
$filename_for_saving = './uploads/lotw/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($data['lotw_cert_info']->callsign))."-".date("Y-m-d-H-i-s")."-cloudlog.tq8";
|
||||
|
||||
$gzdata = gzencode($adif_to_save, 9);
|
||||
$fp = fopen($filename_for_saving, "w");
|
||||
fwrite($fp, $gzdata);
|
||||
fclose($fp);
|
||||
|
||||
//The URL that accepts the file upload.
|
||||
$url = 'https://lotw.arrl.org/lotw/upload';
|
||||
|
||||
//The name of the field for the uploaded file.
|
||||
$uploadFieldName = 'upfile';
|
||||
|
||||
//The full path to the file that you want to upload
|
||||
$filePath = realpath($filename_for_saving);
|
||||
|
||||
//Initiate cURL
|
||||
$ch = curl_init();
|
||||
|
||||
//Set the URL
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
//Set the HTTP request to POST
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
//Tell cURL to return the output as a string.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
//If the function curl_file_create exists
|
||||
if(function_exists('curl_file_create')){
|
||||
//Use the recommended way, creating a CURLFile object.
|
||||
$filePath = curl_file_create($filePath);
|
||||
} else{
|
||||
//Otherwise, do it the old way.
|
||||
//Get the canonicalized pathname of our file and prepend
|
||||
//the @ character.
|
||||
$filePath = '@' . realpath($filePath);
|
||||
//Turn off SAFE UPLOAD so that it accepts files
|
||||
//starting with an @
|
||||
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
|
||||
}
|
||||
|
||||
//Setup our POST fields
|
||||
$postFields = array(
|
||||
$uploadFieldName => $filePath
|
||||
);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
|
||||
//Execute the request
|
||||
$result = curl_exec($ch);
|
||||
|
||||
//If an error occured, throw an exception
|
||||
//with the error message.
|
||||
if(curl_errno($ch)){
|
||||
throw new Exception(curl_error($ch));
|
||||
}
|
||||
|
||||
$pos = strpos($result, "<!-- .UPL. accepted -->");
|
||||
|
||||
if ($pos === false) {
|
||||
// Upload of TQ8 Failed for unknown reason
|
||||
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") Upload Failed"."<br>";
|
||||
} else {
|
||||
// Upload of TQ8 was successfull
|
||||
|
||||
echo "Upload Successful - ".$filename_for_saving."<br>";
|
||||
|
||||
$this->LotwCert->last_upload($data['lotw_cert_info']->lotw_cert_id);
|
||||
|
||||
// Mark QSOs as Sent
|
||||
foreach ($qso_id_array as $qso_number) {
|
||||
$this->Logbook_model->mark_lotw_sent($qso_number);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete TQ8 File - This is done regardless of whether upload was succcessful
|
||||
unlink(realpath($filename_for_saving));
|
||||
}
|
||||
} else {
|
||||
echo "No Station Profiles found to upload to LOTW";
|
||||
}
|
||||
|
||||
/*
|
||||
| Download QSO Matches from LoTW
|
||||
*/
|
||||
if ($this->user_model->authorize(2)) {
|
||||
echo "<br><br>";
|
||||
$sync_user_id=$this->session->userdata('user_id');
|
||||
} else {
|
||||
$sync_user_id=null;
|
||||
}
|
||||
echo $this->lotw_download($sync_user_id);
|
||||
*/
|
||||
if ($this->user_model->authorize(2)) {
|
||||
echo "<br><br>";
|
||||
$sync_user_id=$this->session->userdata('user_id');
|
||||
} else {
|
||||
$sync_user_id=null;
|
||||
}
|
||||
echo $this->lotw_download($sync_user_id);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -624,14 +624,14 @@ class Lotw extends CI_Controller {
|
|||
$query = $this->user_model->get_all_lotw_users();
|
||||
|
||||
if ($query->num_rows() >= 1) {
|
||||
|
||||
$results='';
|
||||
foreach ($query->result() as $user) {
|
||||
if ( ($sync_user_id != null) && ($sync_user_id != $user->user_id) ) { continue; }
|
||||
|
||||
$config['upload_path'] = './uploads/';
|
||||
$file = $config['upload_path'] . 'lotwreport_download.adi';
|
||||
if (file_exists($file) && ! is_writable($file)) {
|
||||
return "Temporary download file ".$file." is not writable. Aborting!";
|
||||
$result.= "Temporary download file ".$file." is not writable. Aborting!";
|
||||
}
|
||||
|
||||
// Get credentials for LoTW
|
||||
|
|
@ -662,18 +662,19 @@ class Lotw extends CI_Controller {
|
|||
$lotw_url .= "$lotw_last_qsl_date";
|
||||
|
||||
if (! is_writable(dirname($file))) {
|
||||
return "Temporary download directory ".dirname($file)." is not writable. Aborting!";
|
||||
$results.= "Temporary download directory ".dirname($file)." is not writable. Aborting!";
|
||||
continue;
|
||||
}
|
||||
file_put_contents($file, file_get_contents($lotw_url));
|
||||
if (file_get_contents($file, false, null, 0, 39) != "ARRL Logbook of the World Status Report") {
|
||||
return "LoTW downloading failed either due to it being down or incorrect logins.";
|
||||
$results.= "LoTW downloading failed for User ".$data['user_lotw_name']." either due to it being down or incorrect logins.";
|
||||
continue;
|
||||
}
|
||||
|
||||
ini_set('memory_limit', '-1');
|
||||
$results = $this->loadFromFile($file, false);
|
||||
|
||||
return $results;
|
||||
$results.= $this->loadFromFile($file, false);
|
||||
}
|
||||
return $results;
|
||||
} else {
|
||||
return "No LOTW User details found to carry out matches.";
|
||||
}
|
||||
|
|
|
|||
正在加载…
在新工单中引用