[Welcome] Claim Notes, API Keys

pull/1653/head
Peter Goodhall 2022-10-10 15:06:01 +01:00
rodzic d7efc67f99
commit cd44097d66
4 zmienionych plików z 102 dodań i 4 usunięć

Wyświetl plik

@ -21,6 +21,14 @@ class Welcome extends CI_Controller {
$this->load->model('logbooks_model');
$data['NumberOfStationLogbooks'] = $this->logbooks_model->CountAllStationLogbooks();
// load api model
$this->load->model('api_model');
$data['NumberOfAPIKeys'] = $this->api_model->CountKeysWithNoUserID();
// load note model
$this->load->model('note');
$data['NumberOfNotes'] = $this->note->CountAllNotes();
// load views
$this->load->view('interface_assets/mini_header', $data);
$this->load->view('welcome/index');
@ -52,4 +60,30 @@ class Welcome extends CI_Controller {
echo "Error Creating Default Logbook during Migration. See Logs for further information";
}
}
public function claimnotes() {
try {
// load model Stations and call function ClaimAllStationLocations
$this->load->model('note');
$this->note->ClaimAllNotes();
echo "Notes all claimed";
} catch (Exception $e) {
log_message('error', 'Error claiming notes during Migration. '.$e->getMessage());
echo "Error claiming notes during Migration. See Logs for further information";
}
}
public function claimapikeys() {
try {
// load model Stations and call function ClaimAllStationLocations
$this->load->model('api_model');
$this->api_model->ClaimAllAPIKeys();
echo "All API Keys claimed";
} catch (Exception $e) {
log_message('error', 'Error claiming API Keys during Migration. '.$e->getMessage());
echo "Error claiming API Keys during Migration. See Logs for further information";
}
}
}

Wyświetl plik

@ -14,6 +14,25 @@ class API_Model extends CI_Model {
return $this->db->get('api');
}
function CountKeysWithNoUserID() {
$this->db->where('user_id !=', NULL);
return $this->db->count_all('api');
}
function ClaimAllAPIKeys($id = NULL) {
// if $id is empty then use session user_id
if (empty($id)) {
// Get the first USER ID from user table in the database
$id = $this->db->get("users")->row()->user_id;
}
$data = array(
'user_id' => $id,
);
$this->db->update('api', $data);
}
function key_description($key) {
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('key', $key);

Wyświetl plik

@ -41,6 +41,27 @@ class Note extends CI_Model {
return $this->db->get('notes');
}
function ClaimAllNotes($id = NULL) {
// if $id is empty then use session user_id
if (empty($id)) {
// Get the first USER ID from user table in the database
$id = $this->db->get("users")->row()->user_id;
}
$data = array(
'user_id' => $id,
);
$this->db->update('notes', $data);
}
function CountAllNotes() {
// count all notes
// where user_id is not NULL
$this->db->where('user_id !=', NULL);
return $this->db->count_all('notes');
}
}
?>

Wyświetl plik

@ -59,10 +59,10 @@
<code>
# Update the Cloudlog installation every day at midnight <br>
0 0 * * * /bin/bash -c "<Full-Path-To-Bash-Script>/cloudlog.sh" <br>
0 0 * * * /bin/bash -c "Full-Path-To-Bash-Script/cloudlog.sh" <br>
<br>
# Upload QSOs to Club Log (ignore cron job if this integration is not required) <br>
0 */6 * * * curl --silent <?php echo site_url();?>/clublog/upload/<username-with-clublog-login> &>/dev/null <br>
0 */6 * * * curl --silent <?php echo site_url();?>/clublog/upload/username-with-clublog-login &>/dev/null <br>
<br>
# Upload QSOs to LoTW if certs have been provided every hour. <br>
0 */1 * * * curl --silent <?php echo site_url();?>/lotw/lotw_upload &>/dev/null <br>
@ -90,7 +90,7 @@
<br>
<?php if($CountAllStationLocations == 0) { ?>
<?php if(!$CountAllStationLocations) { ?>
<div class="card">
<div class="card-header">Assign ALL Station Locations to this username</div>
<div class="card-body">
@ -102,7 +102,7 @@
<br>
<?php } ?>
<?php if($NumberOfStationLogbooks == 0) { ?>
<?php if(!$NumberOfStationLogbooks) { ?>
<div class="card">
<div class="card-header">Create Station Logbooks</div>
<div class="card-body">
@ -115,6 +115,30 @@
<br>
<?php } ?>
<?php if(!$NumberOfNotes) { ?>
<div class="card">
<div class="card-header">Claim Notes <?php echo $NumberOfNotes; ?></div>
<div class="card-body">
<p class="card-text">Looks like you have some notes saved, we need to assign them to your username.</p>
<button type="button" class="btn btn-primary" hx-post="<?php echo site_url('welcome/claimnotes'); ?>">Claim Notes</button>
</div>
</div>
<br>
<?php } ?>
<?php if(!$NumberOfAPIKeys) { ?>
<div class="card">
<div class="card-header">Claim API Keys</div>
<div class="card-body">
<p class="card-text">Looks like you have some API Keys, we need to assign them to your username else they will stop working.</p>
<button type="button" class="btn btn-primary" hx-post="<?php echo site_url('welcome/claimapikeys'); ?>">Claim API Keys</button>
</div>
</div>
<br>
<?php } ?>
<div class="card">
<div class="card-header">Update Country Files</div>
<div class="card-body">