mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Merge pull request #2694 from AndreasK79/dbtools_fix
[DBTools] Some fixes
This commit is contained in:
@@ -66,11 +66,17 @@ class Geojson {
|
||||
];
|
||||
|
||||
private $qra;
|
||||
private $geojsonFile = null;
|
||||
private $geojsonData = null;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct($dxcc = null) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->library('qra');
|
||||
$this->qra = $CI->qra;
|
||||
if ($dxcc !== null) {
|
||||
$this->geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson";
|
||||
$this->geojsonData = $this->loadGeoJsonFile($geojsonFile);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -114,14 +120,16 @@ class Geojson {
|
||||
return null;
|
||||
}
|
||||
|
||||
$geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson";
|
||||
$geojsonData = $this->loadGeoJsonFile($geojsonFile);
|
||||
if ($this->geojsonFile === null) {
|
||||
$this->geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson";
|
||||
$this->geojsonData = $this->loadGeoJsonFile($this->geojsonFile);
|
||||
}
|
||||
|
||||
if ($geojsonData === null) {
|
||||
if ($this->geojsonData === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->findFeatureContainingPoint($lat, $lng, $geojsonData);
|
||||
return $this->findFeatureContainingPoint($lat, $lng, $this->geojsonData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1583,7 +1583,7 @@ class Logbookadvanced_model extends CI_Model {
|
||||
* @return array Result array with success, dxcc_name, dxcc_number, state_code, skipped
|
||||
*/
|
||||
function fixStateBatch($dxcc) {
|
||||
$this->load->library('Geojson');
|
||||
$this->load->library('Geojson', $dxcc);
|
||||
|
||||
// Get QSO data
|
||||
$sql = "SELECT COL_PRIMARY_KEY, COL_CALL, COL_GRIDSQUARE, COL_DXCC, COL_STATE, d.name as dxcc_name, station_profile.station_profile_name
|
||||
@@ -1605,13 +1605,17 @@ class Logbookadvanced_model extends CI_Model {
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
$count = 0;
|
||||
$batch_updates = [];
|
||||
|
||||
foreach ($query->result() as $qso) {
|
||||
$result = $this->fixStateSingle($qso->COL_PRIMARY_KEY);
|
||||
$result = $this->fixStateDxcc($qso);
|
||||
|
||||
if ($result['success']) {
|
||||
$count++;
|
||||
// Prepare data for batch update
|
||||
$batch_updates[] = [
|
||||
'COL_PRIMARY_KEY' => $qso->COL_PRIMARY_KEY,
|
||||
'COL_STATE' => $result['state_code']
|
||||
];
|
||||
} else {
|
||||
$result['station_profile_name'] = $qso->station_profile_name;
|
||||
$result['id'] = $qso->COL_PRIMARY_KEY;
|
||||
@@ -1620,11 +1624,59 @@ class Logbookadvanced_model extends CI_Model {
|
||||
}
|
||||
}
|
||||
|
||||
// Perform batch update if there are any updates
|
||||
$count = 0;
|
||||
if (!empty($batch_updates)) {
|
||||
$this->db->update_batch($this->config->item('table_name'), $batch_updates, 'COL_PRIMARY_KEY');
|
||||
$count = count($batch_updates);
|
||||
}
|
||||
|
||||
$results['count'] = $count;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix state for a batch of QSOs, based on the DXCC
|
||||
* Note: This now only validates and prepares data
|
||||
*
|
||||
* @param object $qso QSO object
|
||||
* @return array Result array with success, dxcc_name, dxcc_number, state_code, skipped
|
||||
*/
|
||||
function fixStateDxcc($qso) {
|
||||
$callsign = $qso->COL_CALL ?? 'Unknown';
|
||||
$dxcc = (int)$qso->COL_DXCC;
|
||||
$gridsquare = $qso->COL_GRIDSQUARE;
|
||||
$state = $qso->COL_STATE ?? '';
|
||||
$dxcc_name = $qso->dxcc_name ?? 'Unknown';
|
||||
|
||||
// Find state from gridsquare
|
||||
$state = $this->geojson->findStateFromGridsquare($gridsquare, $dxcc);
|
||||
|
||||
if ($state === null || !isset($state['code'])) {
|
||||
return [
|
||||
'success' => false,
|
||||
'skipped' => false,
|
||||
'callsign' => $callsign,
|
||||
'dxcc_number' => $dxcc,
|
||||
'dxcc_name' => $dxcc_name,
|
||||
'gridsquare' => $gridsquare,
|
||||
'reason' => 'State not found in GeoJSON'
|
||||
];
|
||||
}
|
||||
|
||||
// Return success with state info
|
||||
return [
|
||||
'success' => true,
|
||||
'skipped' => false,
|
||||
'callsign' => $callsign,
|
||||
'dxcc_number' => $dxcc,
|
||||
'dxcc_name' => $dxcc_name,
|
||||
'state_code' => $state['code'],
|
||||
'state_name' => $state['name'] ?? null
|
||||
];
|
||||
}
|
||||
|
||||
function getStateListQsos($dxcc) {
|
||||
$sql = "SELECT col_primary_key, col_call, col_time_on, col_mode, col_submode, col_band, col_state, col_gridsquare, d.name as dxcc_name, station_profile.station_profile_name FROM " . $this->config->item('table_name') . " qsos
|
||||
JOIN station_profile ON qsos.station_id = station_profile.station_id
|
||||
@@ -1724,29 +1776,41 @@ class Logbookadvanced_model extends CI_Model {
|
||||
$result = $this->getMissingGridQsos();
|
||||
|
||||
$count = 0;
|
||||
$batch_updates = [];
|
||||
|
||||
$this->db->trans_start();
|
||||
|
||||
if (count($result) > 0) {
|
||||
if (!$this->load->is_loaded('callbook')) {
|
||||
$this->load->library('callbook');
|
||||
}
|
||||
|
||||
foreach ($result as $row) {
|
||||
$callsign = $row->col_call;
|
||||
if (!$this->load->is_loaded('callbook')) {
|
||||
$this->load->library('callbook');
|
||||
}
|
||||
|
||||
$callbook = $this->callbook->getCallbookData($callsign);
|
||||
|
||||
if (isset($callbook)) {
|
||||
if (isset($callbook['error'])) {
|
||||
log_message('error', "Error: " . $callbook['error']);
|
||||
} else {
|
||||
if ($callbook['gridsquare'] != '') {
|
||||
$sql = "update " . $this->config->item('table_name') . " set COL_GRIDSQUARE = ? where COL_PRIMARY_KEY = ?";
|
||||
$this->db->query($sql, array($callbook['gridsquare'], $row->col_primary_key));
|
||||
$count++;
|
||||
if (isset($callbook['gridsquare']) && $callbook['gridsquare'] != '') {
|
||||
// Prepare data for batch update
|
||||
$batch_updates[] = [
|
||||
'COL_PRIMARY_KEY' => $row->col_primary_key,
|
||||
'COL_GRIDSQUARE' => $callbook['gridsquare']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform batch update if there are any updates
|
||||
if (!empty($batch_updates)) {
|
||||
$this->db->update_batch($this->config->item('table_name'), $batch_updates, 'COL_PRIMARY_KEY');
|
||||
$count = count($batch_updates);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $count;
|
||||
@@ -1758,7 +1822,7 @@ class Logbookadvanced_model extends CI_Model {
|
||||
WHERE station_profile.user_id = ?
|
||||
AND (qsos.COL_GRIDSQUARE IS NULL OR qsos.COL_GRIDSQUARE = '')
|
||||
AND (qsos.COL_VUCC_GRIDS IS NULL OR qsos.COL_VUCC_GRIDS = '')
|
||||
ORDER BY COL_TIME_ON DESC limit 250";
|
||||
ORDER BY COL_TIME_ON DESC limit 150";
|
||||
|
||||
$query = $this->db->query($sql, [$this->session->userdata('user_id')]);
|
||||
|
||||
|
||||
@@ -90,12 +90,12 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($this->config->item('callbook_batch_lookup')): ?>
|
||||
<?php if ($this->config->item('callbook_batch_lookup') ?? true): ?>
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="mb-1"><?= __("Lookup QSOs with missing grid in callbook") ?></h6>
|
||||
<p class="mb-1 small text-muted"><?= __("Use callbook lookup to set gridsquare") ?></p>
|
||||
<p class="mb-1 small alert-danger"><?= __("This is limited to 250 callsigns for each run!") ?></p>
|
||||
<p class="mb-1 small alert-danger"><?= __("This is limited to 150 callsigns for each run!") ?></p>
|
||||
</div>
|
||||
<div class="d-flex nowrap">
|
||||
<button type="button" class="btn btn-sm btn-success me-1 ld-ext-right" id="checkGridsBtn" onclick="checkGrids()">
|
||||
|
||||
@@ -787,14 +787,6 @@ $options = json_decode($options);
|
||||
<button type="button" class="btn btn-sm btn-success dropdown-action" id="fixState"><?= __("Fix State"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="card-header p-2">
|
||||
<span class="h6 w-100 mt-0 mb-0"><?= __("With ALL QSOs: "); ?></span>
|
||||
</div>
|
||||
<div class="card-body p-2">
|
||||
<div class="d-grid gap-2">
|
||||
<button type="button" class="btn btn-sm btn-success dropdown-action" id="dbtools2"><?= __("Database Tools"); ?></button>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
<?php
|
||||
if($this->session->userdata('user_date_format')) {
|
||||
// If Logged in and session exists
|
||||
$custom_date_format = $this->session->userdata('user_date_format');
|
||||
} else {
|
||||
// Get Default date format from /config/wavelog.php
|
||||
$custom_date_format = $this->config->item('qso_date_format');
|
||||
}
|
||||
?>
|
||||
<div class="container-fluid">
|
||||
<?php if (!empty($qsos) && count($qsos) > 0): ?>
|
||||
<div class="table-responsive" style="max-height:50vh; overflow:auto;">
|
||||
@@ -14,14 +23,14 @@
|
||||
<th><?= __("State") ?></th>
|
||||
<th><?= __("Gridsquare") ?></th>
|
||||
<th><?= __("DXCC") ?></th>
|
||||
<th><?= __("Station") ?></th>
|
||||
<th><?= __("Station Location") ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($qsos as $qso): ?>
|
||||
<tr>
|
||||
<td><?php echo '<a id="edit_qso" href="javascript:displayQso(' . $qso->col_primary_key . ')">' . htmlspecialchars($qso->col_call) . '</a>'; ?></td>
|
||||
<td><?php echo date('Y-m-d H:i', strtotime($qso->col_time_on)); ?></td>
|
||||
<td><?php echo date($custom_date_format . ' H:i', strtotime($qso->col_time_on)); ?></td>
|
||||
<td><?php echo $qso->col_mode; ?></td>
|
||||
<td><?php echo $qso->col_band; ?></td>
|
||||
<td><?php echo $qso->col_state; ?></td>
|
||||
|
||||
Reference in New Issue
Block a user