Skip to content

Commit

Permalink
2.8.1 Admin resources now force login first, completed Signals Update…
Browse files Browse the repository at this point in the history
… Lat / Lon from GSQ
  • Loading branch information
classaxe committed Apr 19, 2020
1 parent 830b56c commit 91e6bd0
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Controller/Web/Admin/Info.php
Expand Up @@ -30,7 +30,8 @@ public function controller(
$system
) {
if (!$this->parameters['isAdmin']) {
throw $this->createAccessDeniedException('You must be an Administrator to access this resource');
$this->session->set('route', 'admin/info');
return $this->redirectToRoute('logon', ['system' => $system]);
}
$entries = $this->getGitInfo();
$parameters = [
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Web/Admin/Logon.php
Expand Up @@ -65,6 +65,9 @@ public function logonController($_locale, $system, Request $request, LogonForm $
'_locale' => $_locale,
'system' => $system
];
if ($this->session->get('route')) {
return $this->redirectToRoute($this->session->get('route'), $parameters);
}
return $this->redirectToRoute('logon', $parameters);
}
} else {
Expand Down
14 changes: 11 additions & 3 deletions src/Controller/Web/Admin/Tools.php
Expand Up @@ -2,6 +2,7 @@
namespace App\Controller\Web\Admin;

use App\Controller\Web\Base;
use App\Repository\SignalRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -24,16 +25,21 @@ class Tools extends Base
* @param $_locale
* @param $system
* @param $tool
* @param SignalRepository $signalRepository
* @return Response
*/
public function controller(
$_locale,
$system,
$tool
$tool,
SignalRepository $signalRepository
) {
$this->signalRepository = $signalRepository;
if (!$this->parameters['isAdmin']) {
throw $this->createAccessDeniedException('You must be an Administrator to access this resource');
$this->session->set('route', 'admin/tools');
return $this->redirectToRoute('logon', ['system' => $system]);
}
$this->session->set('route', '');
switch ($tool) {
case 'icaoImport':
case 'listenersStats':
Expand Down Expand Up @@ -80,7 +86,9 @@ private function logsDaytime() {
}

private function signalsLatLon() {
$this->session->set('lastError', 'Not yet implemented');
$affected = $this->signalRepository->updateSignalLatLonFromGSQ();
$message = sprintf($this->translator->trans('Operation complete - %d record(s) were updated'), $affected);
$this->session->set('lastMessage', $message);
}

private function signalsStats() {
Expand Down
48 changes: 48 additions & 0 deletions src/Repository/SignalRepository.php
Expand Up @@ -1253,6 +1253,54 @@ private function getLogsStats($signalId = false)
return $out;
}

public function updateSignalLatLonFromGSQ($signalId = false)
{
$affected = 0;
$errors = [];
$WHERE = ($signalId ? "WHERE\n signalID = $signalId" : '');
$sql = <<< EOD
SELECT
`ID`,
`call`,
`GSQ`,
`khz`,
`lat`,
`lon`
FROM
`signals`
$WHERE
EOD;
$stmt = $this->connection->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $r) {
$latlon = Rxx::convertGsqToDegrees($r['GSQ']);
if (!$latlon) {
$errors[] = "{$r['call']}-{$r['khz']} has invalid GSQ {$r['GSQ']}";
continue;
}
if ((round($r['lat'], 3) === round($latlon['lat'], 3)) &&
(round($r['lon'], 3) === round($latlon['lon'], 3))
) {
continue;
}
$sql = <<< EOD
UPDATE
`signals`
SET
`GSQ` = '{$latlon['GSQ']}',
`lat` = {$latlon['lat']},
`lon` = {$latlon['lon']}
WHERE
`ID` = {$r['ID']}
EOD;
$stmt = $this->connection->prepare($sql);
$stmt->execute();
$affected += $stmt->rowCount();
}
return $affected;
}

public function updateSignalStats($signalId = false, $updateSpecs = false)
{
$all_regions = ['af', 'an', 'as', 'ca', 'eu', 'iw', 'na', 'oc', 'sa'];
Expand Down
2 changes: 2 additions & 0 deletions templates/i18n.html.twig
Expand Up @@ -33,6 +33,7 @@
{% trans %}Administrator Log On{% endtrans %}
{% trans %}Log On{% endtrans %}
{% trans %}You must Log On in order to perform administrative functions.{% endtrans %}
{% trans %}You have logged on as an Administrator.{% endtrans %}
{% trans %}You are now logged on as an Administrator and may perform administrative functions.{% endtrans %}
{% trans %}To Log Off, select <strong>Log Off</strong> from the main menu.{% endtrans %}
{% trans %}Username{% endtrans %}
Expand All @@ -45,6 +46,7 @@
{% if 'Admin Tools' %}
{% trans %}Administrator Management Tools{% endtrans %}
{% trans %}Update Lat and Lon values from GSQ (use after importing new signals using phpMyAdmin){% endtrans %}
{% trans %}Operation complete - %d record(s) were updated{% endtrans %}
{% trans %}Update listeners, logs and Heard In from latest log data (run if problems are seen){% endtrans %}
{% trans %}Recalculate all distances (use after adding GSQs for existing logging or function above){% endtrans %}
{% trans %}Mark daytime loggings (run periodically){% endtrans %}
Expand Down
4 changes: 2 additions & 2 deletions templates/status.html.twig
@@ -1,6 +1,6 @@
{% if lastError %}
<span id="lastError"><strong>{% trans %}Error:{% endtrans %}</strong> {{ lastError|raw|trans }} <a class="close">X</a></span>
<span id="lastError"><strong>{% trans %}Error:{% endtrans %}</strong> {{ lastError|raw }} <a class="close">X</a></span>
{% endif %}
{% if lastMessage %}
<span id="lastMessage"><strong>{% trans %}Message:{% endtrans %}</strong> {{ lastMessage|raw|trans }} <a class="close">X</a></span>
<span id="lastMessage"><strong>{% trans %}Message:{% endtrans %}</strong> {{ lastMessage|raw }} <a class="close">X</a></span>
{% endif %}
8 changes: 8 additions & 0 deletions translations/messages.de.xlf
Expand Up @@ -4167,6 +4167,14 @@
<source>Not yet implemented</source>
<target>__Not yet implemented</target>
</trans-unit>
<trans-unit id="CiOLtiu" resname="You have logged on as an Administrator.">
<source>You have logged on as an Administrator.</source>
<target>__You have logged on as an Administrator.</target>
</trans-unit>
<trans-unit id="7qWg2QA" resname="Operation complete - %d record(s) were updated">
<source>Operation complete - %d record(s) were updated</source>
<target>__Operation complete - %d record(s) were updated</target>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions translations/messages.en.xlf
Expand Up @@ -4167,6 +4167,14 @@
<source>Not yet implemented</source>
<target>Not yet implemented</target>
</trans-unit>
<trans-unit id="CiOLtiu" resname="You have logged on as an Administrator.">
<source>You have logged on as an Administrator.</source>
<target>You have logged on as an Administrator.</target>
</trans-unit>
<trans-unit id="7qWg2QA" resname="Operation complete - %d record(s) were updated">
<source>Operation complete - %d record(s) were updated</source>
<target>Operation complete - %d record(s) were updated</target>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions translations/messages.es.xlf
Expand Up @@ -4167,6 +4167,14 @@
<source>Not yet implemented</source>
<target>__Not yet implemented</target>
</trans-unit>
<trans-unit id="CiOLtiu" resname="You have logged on as an Administrator.">
<source>You have logged on as an Administrator.</source>
<target>__You have logged on as an Administrator.</target>
</trans-unit>
<trans-unit id="7qWg2QA" resname="Operation complete - %d record(s) were updated">
<source>Operation complete - %d record(s) were updated</source>
<target>__Operation complete - %d record(s) were updated</target>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions translations/messages.fr.xlf
Expand Up @@ -4167,6 +4167,14 @@
<source>Not yet implemented</source>
<target>__Not yet implemented</target>
</trans-unit>
<trans-unit id="CiOLtiu" resname="You have logged on as an Administrator.">
<source>You have logged on as an Administrator.</source>
<target>__You have logged on as an Administrator.</target>
</trans-unit>
<trans-unit id="7qWg2QA" resname="Operation complete - %d record(s) were updated">
<source>Operation complete - %d record(s) were updated</source>
<target>__Operation complete - %d record(s) were updated</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 91e6bd0

Please sign in to comment.