[eQSL] Made CRON job for download, renamed to sync

pull/2112/head
Andreas 2023-05-06 08:17:23 +02:00
rodzic 50e3b2bd5e
commit 678a33d452
3 zmienionych plików z 52 dodań i 17 usunięć

Wyświetl plik

@ -13,8 +13,8 @@ class eqsl extends CI_Controller {
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
// Check if eQSL Nicknames have been defined
$this->load->model('stations');
$eqsl_locations = $this->stations->all_of_user_with_eqsl_nick_defined();
$this->load->model('eqslmethods_model');
$eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined();
if($eqsl_locations->num_rows() == 0) {
show_error("eQSL Nicknames in Station Profiles aren't defined");
exit;
@ -28,8 +28,6 @@ class eqsl extends CI_Controller {
$this->load->library('upload', $config);
$this->load->model('eqslmethods_model');
$eqsl_results = array();
if ($this->input->post('eqslimport') == 'fetch')
{
@ -564,9 +562,41 @@ class eqsl extends CI_Controller {
}
}
function uploadUser($userid, $username, $password) {
/*
* Used for CRON job
*/
public function sync() {
ini_set('memory_limit', '-1');
set_time_limit(0);
$this->load->model('eqslmethods_model');
$users = $this->eqslmethods_model->get_eqsl_users();
foreach ($users as $user) {
$this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
$this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
}
}
public function downloadUser($userid, $username, $password) {
$this->load->library('EqslImporter');
$this->load->model('eqslmethods_model');
$config['upload_path'] = './uploads/';
$eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined();
foreach ($eqsl_locations->result_array() as $eqsl_location) {
$this->eqslimporter->from_callsign_and_QTH(
$eqsl_location['station_callsign'],
$eqsl_location['eqslqthnickname'],
$config['upload_path']
);
$eqsl_results[] = $this->eqslimporter->fetch($eqsl_password);
}
}
function uploadUser($userid, $username, $password) {
$data['user_eqsl_name'] = $this->security->xss_clean($username);
$data['user_eqsl_password'] = $this->security->xss_clean($password);
$clean_userid = $this->security->xss_clean($userid);

Wyświetl plik

@ -81,6 +81,23 @@ class Eqslmethods_model extends CI_Model {
return "eQSL Sent";
}
// Returns all the distinct callsign, eqsl nick pair for the current user/supplied user
function all_of_user_with_eqsl_nick_defined($userid = null) {
if ($userid == null) {
$this->db->where('user_id', $this->session->userdata('user_id'));
} else {
$this->db->where('user_id', $userid);
}
$this->db->where('eqslqthnickname IS NOT NULL');
$this->db->where('eqslqthnickname !=', '');
$this->db->from('station_profile');
$this->db->select('station_callsign, eqslqthnickname');
$this->db->distinct(TRUE);
return $this->db->get();
}
}
?>

Wyświetl plik

@ -397,18 +397,6 @@ class Stations extends CI_Model {
return $query->num_rows();
}
// Returns all the distinct callsing, eqsl nick pair for the current user
function all_of_user_with_eqsl_nick_defined() {
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('eqslqthnickname IS NOT NULL');
$this->db->where('eqslqthnickname !=', '');
$this->db->from('station_profile');
$this->db->select('station_callsign, eqslqthnickname');
$this->db->distinct(TRUE);
return $this->db->get();
}
public function check_station_is_accessible($id) {
// check if station belongs to user
$this->db->select('station_id');