admin.aprsto/htdocs/includes/utilities/fix_beacon_comment.php
Steve White ae9ece5266 *** Initial Commit of Files for APRS.TO Backend Administration Panel ***
This code is non-functional at this point.
2025-02-02 15:53:34 -05:00

49 lines
1.4 KiB
PHP

<?php
require dirname(dirname(__FILE__)) . "/bootstrap.php";
$config = parse_ini_file(ROOT . '/../config/backend.ini', true);
if (is_array($config) && isset($config['bootstrap']))
{
$databaseconfig = $config['bootstrap'];
if (!isset($databaseconfig['username']))
{
$databaseconfig['username'] = get_current_user();
}
$dbconn = pg_pconnect(
sprintf(
'dbname=%s host=%s port=%s user=%s password=%s',
$databaseconfig['database'],
$databaseconfig['host'],
$databaseconfig['port'],
$databaseconfig['username'],
$databaseconfig['password']
)
);
if ($dbconn === false) die('Could not connect DB!');
} else {
die('Invalid DB Config!');
}
$res = pg_query($dbconn,
"SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE'
AND table_name LIKE 'packet20______';");
while (($record = pg_fetch_assoc($res)) !== false)
{
echo "Fixing {$record['table_name']}...\r\n";
// Create a new index on the receiver_id
echo 'Populate empty comments on ' . $record['table_name'] . "... \r\n";
pg_query($dbconn, "UPDATE {$record['table_name']} SET comment = split_part(raw, ':', 2) WHERE packet_type_id = 11 AND receiver_id = 38 AND is_moving= 1 AND comment is null;");
}
echo "Nothing to do...\r\nProcessing complete!\r\n";