Little script to fix uris beginning with “https://”

This commit is contained in:
pezcurrel 2022-12-11 23:31:47 +01:00
parent d371a18af4
commit 853be9f0e0

View file

@ -0,0 +1,29 @@
#!/usr/bin/php
<?php
const N="\n";
use function mysqli_real_escape_string as myesc;
function mexit($msg,$code) {
echo($msg);
exit($code);
}
$iniarr=@parse_ini_file(__DIR__.'/../../conf/mustard.ini')
or mexit('Impossibile aprire il file di configurazione.'.N,1);
$link=mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
or mexit('Impossibile connettersi al database: '.mysqli_connect_error().' ['.mysqli_connect_errno().']'.N,1);
mysqli_set_charset($link,'utf8mb4');
$res=mysqli_query($link,'SELECT * FROM Instances WHERE URI REGEXP "^https?://"');
while ($row=mysqli_fetch_assoc($res)) {
$uri=preg_replace('#^https?://#','',$row['URI']);
mysqli_query($link,'UPDATE Instances SET URI=\''.myesc($link,$uri).'\' WHERE ID='.$row['ID']);
}
mysqli_close($link);
exit(0);
?>