mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Merge pull request #965 from int2001/limit_api
Adds an optional "limit" to the "get_contacts_adif"-API
This commit is contained in:
@@ -279,6 +279,10 @@ class API extends CI_Controller {
|
|||||||
$key = $obj['key'];
|
$key = $obj['key'];
|
||||||
$station_id = $obj['station_id'];
|
$station_id = $obj['station_id'];
|
||||||
$fetchfromid = $obj['fetchfromid'];
|
$fetchfromid = $obj['fetchfromid'];
|
||||||
|
$limit = 20000;
|
||||||
|
if ( (array_key_exists('limit',$obj)) && (is_numeric($obj['limit']*1)) ) {
|
||||||
|
$limit = $obj['limit'];
|
||||||
|
}
|
||||||
|
|
||||||
//check if goalpost is numeric as an additional layer of SQL injection prevention
|
//check if goalpost is numeric as an additional layer of SQL injection prevention
|
||||||
if(!is_numeric($fetchfromid))
|
if(!is_numeric($fetchfromid))
|
||||||
@@ -305,8 +309,7 @@ class API extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//return error if station not accessible for the API key
|
//return error if station not accessible for the API key
|
||||||
if(!in_array($station_id, $station_ids))
|
if(!in_array($station_id, $station_ids)) {
|
||||||
{
|
|
||||||
http_response_code(401);
|
http_response_code(401);
|
||||||
echo json_encode(['status' => 'failed', 'reason' => "Station ID not accessible for this API key"]);
|
echo json_encode(['status' => 'failed', 'reason' => "Station ID not accessible for this API key"]);
|
||||||
return;
|
return;
|
||||||
@@ -316,15 +319,14 @@ class API extends CI_Controller {
|
|||||||
$this->load->model('adif_data');
|
$this->load->model('adif_data');
|
||||||
|
|
||||||
//get qso data
|
//get qso data
|
||||||
$data['qsos'] = $this->adif_data->export_past_id($station_id, $fetchfromid);
|
$data['qsos'] = $this->adif_data->export_past_id($station_id, $fetchfromid, $limit);
|
||||||
|
|
||||||
//set internalonly attribute for adif creation
|
//set internalonly attribute for adif creation
|
||||||
$data['internalrender'] = true;
|
$data['internalrender'] = true;
|
||||||
|
|
||||||
//if no new QSOs are ready, return that
|
//if no new QSOs are ready, return that
|
||||||
$qso_count = count($data['qsos']->result());
|
$qso_count = count($data['qsos']->result());
|
||||||
if($qso_count <= 0)
|
if($qso_count <= 0) {
|
||||||
{
|
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
echo json_encode(['status' => 'successfull', 'message' => 'No new QSOs available.', 'lastfetchedid' => $fetchfromid, 'exported_qsos' => 0, 'adif' => null]);
|
echo json_encode(['status' => 'successfull', 'message' => 'No new QSOs available.', 'lastfetchedid' => $fetchfromid, 'exported_qsos' => 0, 'adif' => null]);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class adif_data extends CI_Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function export_past_id($station_id, $fetchfromid) {
|
function export_past_id($station_id, $fetchfromid, $limit) {
|
||||||
//create query
|
//create query
|
||||||
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
||||||
$this->db->from($this->config->item('table_name'));
|
$this->db->from($this->config->item('table_name'));
|
||||||
@@ -160,6 +160,11 @@ class adif_data extends CI_Model {
|
|||||||
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
||||||
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
||||||
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
||||||
|
$this->db->order_by("COL_PRIMARY_KEY", "ASC");
|
||||||
|
|
||||||
|
if ($limit > -1) {
|
||||||
|
$this->db->limit($limit);
|
||||||
|
}
|
||||||
|
|
||||||
//return result
|
//return result
|
||||||
return $this->db->get();
|
return $this->db->get();
|
||||||
|
|||||||
Reference in New Issue
Block a user