Added “revive” action; minor changes

This commit is contained in:
pezcurrel 2023-10-02 16:28:47 +02:00
parent 89d40c71ef
commit c453ba6e3f

View file

@ -21,6 +21,7 @@ require(__DIR__.'/lib/delinstbyid.php');
$levs=['Debug', 'Info', 'Warning', 'Error'];
$opts=array(
'revive'=>false,
'shuffle'=>false,
'updstats'=>false,
'clean'=>false,
@ -41,6 +42,9 @@ $help='mustool.php
you choose whether you want to delete them and all records referencing them
in other tables.
Example: mustool.php deleteinstswhere "IsMastodon!=1"
revive
Set a new, succesful check with current time for every instance that
succesfully responded to last check.
shuffle
Randomize instances list (values in «RPos» column).
updstats
@ -74,6 +78,9 @@ for ($i=1; $i<$argc; $i++) {
} elseif ($argv[$i]=='shuffle') {
$dosome=true;
$opts['shuffle']=true;
} elseif ($argv[$i]=='revive') {
$dosome=true;
$opts['revive']=true;
} elseif ($argv[$i]=='updstats') {
$dosome=true;
$opts['updstats']=true;
@ -109,7 +116,7 @@ if ($opts['deleteinstswhere']) {
$buf=[];
while ($row=mysqli_fetch_assoc($res)) $buf[]=$row;
$cbuf=count($buf);
if ($cbuf) {
if ($cbuf>0) {
foreach ($buf as $row) echo($row['URI'].' (ID='.$row['ID'].')'.N);
echo('Do you really want to delete those '.$cbuf.' record(s)? Enter «YES» to do it, anything else to not do it: ');
$inp=rtrim(fgets(STDIN));
@ -123,10 +130,33 @@ if ($opts['deleteinstswhere']) {
}
}
} else {
eecho('no Instances records match expression «'.$opts['deleteinstswhereconds'].'».'.N);
eecho('no Instances records match expression «'.$opts['deleteinstswhereconds'].'».'.N,2);
}
}
if ($opts['revive']) {
$now=time();
$res=myq($link,'SELECT * FROM Instances WHERE WasLastCheckOk IS TRUE;');
$buf=[];
while ($row=mysqli_fetch_assoc($res)) $buf[]=$row;
$cbuf=count($buf);
$i=0;
foreach ($buf as $row) {
$i++;
$res=myq($link,'INSERT INTO InstChecks (InstID, Time, Status) VALUES ('.$row['ID'].', '.$now.', 1);');
if ($res!==false) {
$res=myq($link,'UPDATE Instances SET TotChecks='.($row['TotChecks']+1).', OkChecks='.($row['OkChecks']+1).', WasLastCheckOk=1, LastOkCheckTS='.$now.' WHERE ID='.$row['ID'].';');
if ($res===false)
mexit('could not update instance record with ID='.$row['ID'].'; shutting down.'.N,3);
else
eecho("{$i}/{$cbuf}\n",1);
} else {
mexit('could not insert new check record into InstChecks for instance with ID='.$row['ID'].'; shutting down.'.N,3);
}
}
eecho('done! Affected rows: '.$cbuf.'.'.N,1);
}
if ($opts['shuffle']) {
eecho('randomizing values in «RPos» column...'.N,1);
$res=myq($link,'SELECT ID FROM Instances');
@ -239,7 +269,7 @@ if ($opts['clean']) {
}
if ($opts['optimize']) {
eecho('optimizing all the tables in the database...'.N);
eecho('optimizing all the tables in the database...'.N,1);
$res=myq($link,'SHOW TABLES');
while ($row=mysqli_fetch_row($res)) {
$rres=myq($link,'OPTIMIZE TABLE '.$row[0]);