mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Use Chunking for Backup as well
This commit is contained in:
@@ -29,31 +29,43 @@ class Backup extends CI_Controller {
|
||||
$clean_key = $this->security->xss_clean($key);
|
||||
|
||||
$this->load->helper('file');
|
||||
$this->load->library('AdifHelper');
|
||||
// Set memory limit to unlimited to allow heavy usage
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$this->load->model('adif_data');
|
||||
$filename = 'backup/logbook'. date('_Y_m_d_H_i_s') .'.adi';
|
||||
|
||||
$data['qsos'] = $this->adif_data->export_all($clean_key);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
|
||||
$data['filename'] = 'backup/logbook'. date('_Y_m_d_H_i_s') .'.adi';
|
||||
|
||||
if ( ! write_file($data['filename'], $this->load->view('backup/exportall', $data, true)))
|
||||
{
|
||||
$data['status'] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['status'] = true;
|
||||
}
|
||||
// Output ADIF header // No chance to use exportall-view any longer, because of chunking logic
|
||||
echo "Wavelog ADIF export\n";
|
||||
echo "<ADIF_VER:5>3.1.6\n";
|
||||
echo "<PROGRAMID:".strlen($this->config->item('app_name')).">".$this->config->item('app_name')."\r\n";
|
||||
echo "<PROGRAMVERSION:".strlen($this->optionslib->get_option('version')).">".$this->optionslib->get_option('version')."\r\n";
|
||||
echo "<EOH>\n\n";
|
||||
|
||||
$data['page_title'] = __("ADIF - Backup");
|
||||
|
||||
// Stream QSOs in 5K chunks
|
||||
$offset = 0;
|
||||
$chunk_size = 5000;
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('backup/adif_view');
|
||||
$this->load->view('interface_assets/footer');
|
||||
do {
|
||||
$qsos = $this->adif_data->export_all_chunked($clean_key, null, null, false, null, $offset, $chunk_size);
|
||||
|
||||
if ($qsos->num_rows() > 0) {
|
||||
foreach ($qsos->result() as $qso) {
|
||||
echo $this->adifhelper->getAdifLine($qso);
|
||||
}
|
||||
|
||||
// Free memory
|
||||
$qsos->free_result();
|
||||
}
|
||||
|
||||
$offset += $chunk_size;
|
||||
} while ($qsos->num_rows() > 0);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Export the notes to XML */
|
||||
|
||||
@@ -2,6 +2,48 @@
|
||||
|
||||
class adif_data extends CI_Model {
|
||||
|
||||
function export_all_chunked($api_key = null, $from = null, $to = null, $exportLotw = false, $onlyop = null, $offset = 0, $limit = 5000) {
|
||||
$this->load->model('logbooks_model');
|
||||
if ($api_key != null) {
|
||||
$this->load->model('api_model');
|
||||
if (strpos($this->api_model->access($api_key), 'r') !== false) {
|
||||
$this->api_model->update_last_used($api_key);
|
||||
$user_id = $this->api_model->key_userid($api_key);
|
||||
$logbooks_locations_array = $this->list_station_locations($user_id);
|
||||
}
|
||||
} else {
|
||||
$this->load->model('stations');
|
||||
$logbooks_locations_array = $this->list_station_locations($this->session->userdata('user_id'));
|
||||
}
|
||||
|
||||
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
||||
$this->db->order_by("COL_TIME_ON", "ASC");
|
||||
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
||||
if ($from) {
|
||||
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= ", $from);
|
||||
}
|
||||
if ($to) {
|
||||
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= ",$to);
|
||||
}
|
||||
if ($onlyop) {
|
||||
$this->db->where("upper(".$this->config->item('table_name').".col_operator)",$onlyop);
|
||||
}
|
||||
if ($exportLotw) {
|
||||
$this->db->group_start();
|
||||
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
|
||||
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
|
||||
$this->db->group_end();
|
||||
}
|
||||
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
|
||||
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
|
||||
|
||||
// Add chunking
|
||||
$this->db->limit($limit, $offset);
|
||||
|
||||
$query = $this->db->get($this->config->item('table_name'));
|
||||
return $query;
|
||||
}
|
||||
|
||||
function export_all($api_key = null,$from = null, $to = null, $exportLotw = false, $onlyop = null) {
|
||||
$this->load->model('logbooks_model');
|
||||
if ($api_key != null) {
|
||||
@@ -239,47 +281,7 @@ class adif_data extends CI_Model {
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
function export_all_chunked($api_key = null, $from = null, $to = null, $exportLotw = false, $onlyop = null, $offset = 0, $limit = 5000) {
|
||||
$this->load->model('logbooks_model');
|
||||
if ($api_key != null) {
|
||||
$this->load->model('api_model');
|
||||
if (strpos($this->api_model->access($api_key), 'r') !== false) {
|
||||
$this->api_model->update_last_used($api_key);
|
||||
$user_id = $this->api_model->key_userid($api_key);
|
||||
$logbooks_locations_array = $this->list_station_locations($user_id);
|
||||
}
|
||||
} else {
|
||||
$this->load->model('stations');
|
||||
$logbooks_locations_array = $this->list_station_locations($this->session->userdata('user_id'));
|
||||
}
|
||||
|
||||
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
||||
$this->db->order_by("COL_TIME_ON", "ASC");
|
||||
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
||||
if ($from) {
|
||||
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= ", $from);
|
||||
}
|
||||
if ($to) {
|
||||
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= ",$to);
|
||||
}
|
||||
if ($onlyop) {
|
||||
$this->db->where("upper(".$this->config->item('table_name').".col_operator)",$onlyop);
|
||||
}
|
||||
if ($exportLotw) {
|
||||
$this->db->group_start();
|
||||
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
|
||||
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
|
||||
$this->db->group_end();
|
||||
}
|
||||
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
|
||||
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
|
||||
|
||||
// Add chunking
|
||||
$this->db->limit($limit, $offset);
|
||||
|
||||
$query = $this->db->get($this->config->item('table_name'));
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user