Removed code referencing New, Good and Chosen columns

This commit is contained in:
pezcurrel 2022-12-18 18:26:03 +01:00
parent f4aa3cb804
commit 835e02c171

View file

@ -48,9 +48,7 @@ $opts=[
'hostname'=>null, 'hostname'=>null,
'timeout'=>10, 'timeout'=>10,
'deadline'=>60*24*60*60,// if an instance has not been responding for more than this value of seconds, declare it dead 'deadline'=>60*24*60*60,// if an instance has not been responding for more than this value of seconds, declare it dead
'oldline'=>30*24*60*60,// if an instance has been new for a period longer than this amount, it's no longer new
'ldtoots'=>40,// number of toots to check with the automatic language detection function 'ldtoots'=>40,// number of toots to check with the automatic language detection function
'setnew'=>true,
'dryrun'=>false, 'dryrun'=>false,
'jsonwrite'=>false, 'jsonwrite'=>false,
'fetchusers'=>false, 'fetchusers'=>false,
@ -75,17 +73,10 @@ DESCRIPTION
OPTIONS OPTIONS
-N, --dontsetnew
If this option is set, the script wont mark a new instance as new. This can
be useful for a first run.
-D, --deadline <time> -D, --deadline <time>
If an instance has not been responding for longer than this time, declare If an instance has not been responding for longer than this time, declare
it dead. See section «TIME SPECIFICATION» below to see how to specify time. it dead. See section «TIME SPECIFICATION» below to see how to specify time.
DEFAULT: '.ght($opts['deadline'],$ghtsa).' DEFAULT: '.ght($opts['deadline'],$ghtsa).'
-o, --oldline <time>
If an instance has been marked as new for longer than this time, mark it as
not new. See section «TIME SPECIFICATION» below to see how to specify time.
DEFAULT: '.ght($opts['oldline'],$ghtsa).'
-l, --ldtoots <number> -l, --ldtoots <number>
This option defines the number of toots the script will try to fetch from This option defines the number of toots the script will try to fetch from
the local public timelines, to try and guess the most used languages of each the local public timelines, to try and guess the most used languages of each
@ -163,18 +154,11 @@ for ($i=1; $i<$argc; $i++) {
mexit('option «'.$argv[$i].'» requires a time specification as an argument (use «-h» to read help).'.N,1); mexit('option «'.$argv[$i].'» requires a time specification as an argument (use «-h» to read help).'.N,1);
$i++; $i++;
$opts['deadline']=parsetime($argv[$i]); $opts['deadline']=parsetime($argv[$i]);
} elseif ($argv[$i]=='-o' || $argv[$i]=='--oldline') {
if ($i+1>=$argc || parsetime($argv[$i+1])===false)
mexit('option «'.$argv[$i].'» requires a time specification as an argument (use «-h» to read help).'.N,1);
$i++;
$opts['oldline']=parsetime($argv[$i]);
} elseif ($argv[$i]=='-l' || $argv[$i]=='--ldtoots') { } elseif ($argv[$i]=='-l' || $argv[$i]=='--ldtoots') {
if ($i+1>=$argc || preg_match('/^\d+$/',$argv[$i+1])!==1 || $argv[$i+1]+0>40 || $argv[$i+1]+0<10) if ($i+1>=$argc || preg_match('/^\d+$/',$argv[$i+1])!==1 || $argv[$i+1]+0>40 || $argv[$i+1]+0<10)
mexit('option «'.$argv[$i].'» requires a number >= 10 and <= 40 as an argument (use «-h» to read help).'.N,1); mexit('option «'.$argv[$i].'» requires a number >= 10 and <= 40 as an argument (use «-h» to read help).'.N,1);
$i++; $i++;
$opts['ldtoots']=$argv[$i]+0; $opts['ldtoots']=$argv[$i]+0;
} elseif ($argv[$i]=='-N' || $argv[$i]=='--dontsetnew') {
$opts['setnew']=false;
} elseif ($argv[$i]=='-d' || $argv[$i]=='--dryrun') { } elseif ($argv[$i]=='-d' || $argv[$i]=='--dryrun') {
$opts['dryrun']=true; $opts['dryrun']=true;
} elseif ($argv[$i]=='-j' || $argv[$i]=='--jsonwrite') { } elseif ($argv[$i]=='-j' || $argv[$i]=='--jsonwrite') {
@ -206,10 +190,15 @@ foreach ($msglevs as $key=>$val) $msglevs[$key]=ucfirst($val);
$inifp=__DIR__.'/../conf/mustard.ini'; $inifp=__DIR__.'/../conf/mustard.ini';
$iniarr=@parse_ini_file($inifp) $iniarr=@parse_ini_file($inifp)
or mexit('could not open config file «'.$inifp.'»'.N,1); or mexit('could not open config file «'.$inifp.'»'.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('could not connect to MySQL server: '.mysqli_connect_error().N,1); try { $link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket']); }
mysqli_set_charset($link,'utf8mb4') catch (Exception $error) { mexit('could not connect to MySQL server: '.mysqli_connect_error().'.'.N,1,true); }
or mexit('could not set «utf8mb4» charset fro MySQL: '.mysqli_error($link).N,1); // for php versions < 8
if ($link===false) mexit('could not connect to MySQL server: '.mysqli_connect_error().'.'.N,1,true);
try { $res=mysqli_set_charset($link,'utf8mb4'); }
catch (Exception $error) { mexit('could not set «utf8mb4» charset for MySQL: '.mysqli_error($link).'.'.N,1,true); }
// for php versions < 8
if ($res===false) mexit('could not set MySQL charset: '.mysqli_errno($link).': '.mysqli_error($link).'.'.N,1,true);
$tables=tables($link); $tables=tables($link);
//print_r($tables); //print_r($tables);
@ -350,15 +339,10 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
$res=myq($link,'SELECT * FROM Instances WHERE URI=\''.myesc($link,$opts['hostname']).'\'',__LINE__); $res=myq($link,'SELECT * FROM Instances WHERE URI=\''.myesc($link,$opts['hostname']).'\'',__LINE__);
$nrows=mysqli_num_rows($res); $nrows=mysqli_num_rows($res);
if ($nrows==1) { if ($nrows==1) {
eecho(1,'«'.$opts['hostname'].'»: didnt respond, but it is present in the database; updating InstChecks, Instances.LastCheckOk and possibly Instances.New=0 and Instances.Dead=1.'.N); eecho(1,'«'.$opts['hostname'].'»: didnt respond, but it is present in the database; updating InstChecks, Instances.LastCheckOk and possibly Instances.Dead.'.N);
$row=mysqli_fetch_assoc($res); $row=mysqli_fetch_assoc($res);
$instid=$row['ID']; $instid=$row['ID'];
if (!$opts['dryrun']) myq($link,'UPDATE Instances SET LastCheckOk=0 WHERE ID='.$instid,__LINE__); if (!$opts['dryrun']) myq($link,'UPDATE Instances SET LastCheckOk=0 WHERE ID='.$instid,__LINE__);
if ($row['New']==1 && !is_null($row['FirstSeen']) && $now-$row['FirstSeen']>$opts['oldline']) {
notify('Instance «<a href="viewinst.php?id='.$instid.'">'.$row['URI'].'</a>» is no longer new.',2);
if (!$opts['dryrun']) myq($link,'UPDATE Instances SET New=0 WHERE ID='.$instid,__LINE__);
}
// we check the last time instance responded, if ever // we check the last time instance responded, if ever
$rres=myq($link,'SELECT Time FROM InstChecks WHERE InstID='.$instid.' AND Status=1 ORDER BY Time DESC LIMIT 1',__LINE__); $rres=myq($link,'SELECT Time FROM InstChecks WHERE InstID='.$instid.' AND Status=1 ORDER BY Time DESC LIMIT 1',__LINE__);
// if instance never responded we consider the time of first check // if instance never responded we consider the time of first check
@ -375,10 +359,9 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
} }
} elseif ($nrows==0) { } elseif ($nrows==0) {
eecho(1,'«'.$opts['hostname'].'»: doesnt respond and is not in the database, adding it.'.N); eecho(1,'«'.$opts['hostname'].'»: doesnt respond and is not in the database, adding it.'.N);
($opts['setnew']) ? $new=1 : $new=0;
// "FirstSeen=NULL" because it's not seen until it responds for the first time // "FirstSeen=NULL" because it's not seen until it responds for the first time
if (!$opts['dryrun']) { if (!$opts['dryrun']) {
myq($link,'INSERT INTO Instances SET FirstSeen=NULL, New='.$new.', Good=0, Chosen=0, Visible=0, Noxious=0, URI=\''.myesc($link,$opts['hostname']).'\', LastCheckOk=0, InsertTS='.$now,__LINE__); myq($link,'INSERT INTO Instances SET FirstSeen=NULL, Visible=1, Noxious=0, URI=\''.myesc($link,$opts['hostname']).'\', LastCheckOk=0, InsertTS='.$now,__LINE__);
$instid=mysqli_insert_id($link); $instid=mysqli_insert_id($link);
myq($link,'INSERT INTO InstChecks SET InstID='.$instid.', Time='.$now.', Status=0',__LINE__); myq($link,'INSERT INTO InstChecks SET InstID='.$instid.', Time='.$now.', Status=0',__LINE__);
} else { } else {
@ -404,7 +387,7 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
if (!is_null($ismast)) if (!is_null($ismast))
($ismast) ? $ismast=1 : $ismast=0; ($ismast) ? $ismast=1 : $ismast=0;
$instrow=['ID'=>null, 'FirstSeen'=>null, 'IsMastodon'=>$ismast, 'Dead'=>0, 'New'=>0, 'Good'=>0, 'Chosen'=>0, 'Priority'=>null, 'Visible'=>0, 'Noxious'=>0, 'NoxReason'=>null, 'NoxLastModTS'=>null, 'URI'=>null, 'Title'=>null, 'ShortDesc'=>null, 'LongDesc'=>null, 'OurDesc'=>null, 'OurDescEN'=> null, 'LocalityID'=>null, 'OurLangsLock'=>0, 'Email'=>null, 'Software'=>null, 'Version'=>null, 'UserCount'=>null, 'StatusCount'=>null, 'DomainCount'=>null, 'ActiveUsersMonth'=>null, 'ActiveUsersHalfYear'=>null, 'Thumb'=>null, 'RegOpen'=>null, 'RegReqApproval'=>null, 'MaxTootChars'=>null, 'AdmAccount'=>null, 'AdmDisplayName'=>null, 'AdmCreatedAt'=>null, 'AdmNote'=>null, 'AdmURL'=>null, 'AdmAvatar'=>null, 'AdmHeader'=>null, 'LastCheckOk'=>1, 'GuestID'=>null, 'LastGuestEdit'=>null]; $instrow=['ID'=>null, 'FirstSeen'=>null, 'IsMastodon'=>$ismast, 'Dead'=>0, 'Priority'=>null, 'Visible'=>1, 'Noxious'=>0, 'NoxReason'=>null, 'NoxLastModTS'=>null, 'URI'=>null, 'Title'=>null, 'ShortDesc'=>null, 'LongDesc'=>null, 'OurDesc'=>null, 'OurDescEN'=> null, 'LocalityID'=>null, 'OurLangsLock'=>0, 'Email'=>null, 'Software'=>null, 'Version'=>null, 'UserCount'=>null, 'StatusCount'=>null, 'DomainCount'=>null, 'ActiveUsersMonth'=>null, 'ActiveUsersHalfYear'=>null, 'Thumb'=>null, 'RegOpen'=>null, 'RegReqApproval'=>null, 'MaxTootChars'=>null, 'AdmAccount'=>null, 'AdmDisplayName'=>null, 'AdmCreatedAt'=>null, 'AdmNote'=>null, 'AdmURL'=>null, 'AdmAvatar'=>null, 'AdmHeader'=>null, 'LastCheckOk'=>1, 'GuestID'=>null, 'LastGuestEdit'=>null];
$instrow['URI']=$opts['hostname']; $instrow['URI']=$opts['hostname'];
if (akeavinn('title',$info)) if (akeavinn('title',$info))
$instrow['Title']=nempty(truncs($info['title'],'Instances','Title','«'.$instrow['URI'].'»')); $instrow['Title']=nempty(truncs($info['title'],'Instances','Title','«'.$instrow['URI'].'»'));
@ -461,37 +444,6 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
} }
} }
$whynot=[];
if (is_null($instrow['RegOpen'])) {
$whynot[]='we dont know if it allows registrations';
} elseif ($instrow['RegOpen']==0) {
$whynot[]='it doesnt allow registrations';
}
if (is_null($instrow['UserCount'])) {
$whynot[]='we dont know its total users number';
} elseif ($instrow['UserCount']<10 || $instrow['UserCount']>30000) {
$whynot[]='total users number is not greater than 10 and less than 30000';
}
if (is_null($instrow['DomainCount'])) {
$whynot[]='we dont know the number of other instances it knows';
} elseif ($instrow['DomainCount']<500) {
$whynot[]='the number of other instances it knows is less than 500';
}
if (!is_null($instrow['ActiveUsersMonth'])) {
if ($instrow['ActiveUsersMonth']<10)
$whynot[]='the number of active users for the last month is less than 10';
} elseif (!is_null($instrow['StatusCount']) && $instrow['UserCount']>0 && $instrow['StatusCount']/$instrow['UserCount']<10) {
$whynot[]='the average number of toots for user is less than 10';
} else {
$whynot[]='it was impossible to detect the number of active users for the last month or the average number of toots for user';
}
if (count($whynot)==0) {
$instrow['Good']=1;
eecho(1,'«'.$opts['hostname'].'»: this is a suitable instance! :-)'.N);
} else {
eecho(1,'«'.$opts['hostname'].'»: this is not a suitable instance: '.implode('; ',$whynot).' :-('.N);
}
$res=myq($link,'SELECT * FROM Instances WHERE URI=\''.myesc($link,$instrow['URI']).'\'',__LINE__); $res=myq($link,'SELECT * FROM Instances WHERE URI=\''.myesc($link,$instrow['URI']).'\'',__LINE__);
$nrows=mysqli_num_rows($res); $nrows=mysqli_num_rows($res);
@ -500,23 +452,7 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
$oldinstrow=mysqli_fetch_assoc($res); $oldinstrow=mysqli_fetch_assoc($res);
$instid=$oldinstrow['ID']; $instid=$oldinstrow['ID'];
$instrow['ID']=$oldinstrow['ID']; $instrow['ID']=$oldinstrow['ID'];
if ($oldinstrow['New']==1) {
if (!is_null($oldinstrow['FirstSeen']) && $now-$oldinstrow['FirstSeen']>$opts['oldline']) {
$instrow['New']=0;
notify('Instance «<a href="viewinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» is no longer new.',2);
} else {
$instrow['New']=1;
}
} else {
$instrow['New']=0;
}
(is_null($oldinstrow['FirstSeen'])) ? $instrow['FirstSeen']=$now : $instrow['FirstSeen']=$oldinstrow['FirstSeen']; (is_null($oldinstrow['FirstSeen'])) ? $instrow['FirstSeen']=$now : $instrow['FirstSeen']=$oldinstrow['FirstSeen'];
if ($instrow['Good']==1 && $oldinstrow['Good']==0) {
notify('Instance «<a href="viewinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» wasnt suitable, but it is now!',1);
} elseif ($instrow['Good']==0 && $oldinstrow['Good']==1) {
notify('Instance «<a href="viewinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» was suitable, but its no longer for these reasons: '.implode('; ',$whynot),1);
}
$instrow['Chosen']=$oldinstrow['Chosen'];
$instrow['Priority']=$oldinstrow['Priority']; $instrow['Priority']=$oldinstrow['Priority'];
$instrow['Visible']=$oldinstrow['Visible']; $instrow['Visible']=$oldinstrow['Visible'];
$instrow['Noxious']=$oldinstrow['Noxious']; $instrow['Noxious']=$oldinstrow['Noxious'];
@ -573,9 +509,9 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
} elseif ($nrows==0) { } elseif ($nrows==0) {
eecho(1,'«'.$opts['hostname'].'» is not present in the database, adding it...'.N); eecho(1,'«'.$opts['hostname'].'» is not present in the database, adding it...'.N);
if (!$opts['dryrun']) notify('New instance found: «<a href="viewinst.php?id='.$instid.'">'.$instrow['URI'].'</a>».',1);
$instrow['FirstSeen']=$now; $instrow['FirstSeen']=$now;
if ($opts['setnew']) $instrow['InsertTS']=$now;
$instrow['New']=1;
$fields=[]; $fields=[];
$values=''; $values='';
foreach ($instrow as $field=>$value) { foreach ($instrow as $field=>$value) {
@ -594,8 +530,6 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
} else { } else {
$instid=0; $instid=0;
} }
if ($opts['setnew'] && !$opts['dryrun'])
notify('New instance found: «<a href="viewinst.php?id='.$instid.'">'.$instrow['URI'].'</a>».',1);
$instlangs=langs($instid, $instrow['URI'], false); $instlangs=langs($instid, $instrow['URI'], false);
if (!$opts['dryrun']) { if (!$opts['dryrun']) {
@ -612,9 +546,6 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
myq($link,'INSERT INTO InstOurLangs (InstID, OurLangID, Pos) VALUES ('.$row['InstID'].', '.$row['LangID'].', '.$row['Pos'].')',__LINE__); myq($link,'INSERT INTO InstOurLangs (InstID, OurLangID, Pos) VALUES ('.$row['InstID'].', '.$row['LangID'].', '.$row['Pos'].')',__LINE__);
} }
if ($instrow['Good']==1)
notify('New instance «<a href="viewinst.php?id='.$instid.'">'.$instrow['URI'].'</a>» is suitable!',1);
} else { } else {
notify('Instance «'.$opts['hostname'].'» has '.$nrows.' entries in «Instances» table!',3); notify('Instance «'.$opts['hostname'].'» has '.$nrows.' entries in «Instances» table!',3);
} }