Removed code referencing New, Good and Chosen columns
This commit is contained in:
parent
f4aa3cb804
commit
835e02c171
1 changed files with 14 additions and 83 deletions
|
@ -48,9 +48,7 @@ $opts=[
|
|||
'hostname'=>null,
|
||||
'timeout'=>10,
|
||||
'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
|
||||
'setnew'=>true,
|
||||
'dryrun'=>false,
|
||||
'jsonwrite'=>false,
|
||||
'fetchusers'=>false,
|
||||
|
@ -75,17 +73,10 @@ DESCRIPTION
|
|||
|
||||
OPTIONS
|
||||
|
||||
-N, --dontsetnew
|
||||
If this option is set, the script won’t mark a new instance as new. This can
|
||||
be useful for a first run.
|
||||
-D, --deadline <time>
|
||||
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.
|
||||
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>
|
||||
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
|
||||
|
@ -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);
|
||||
$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') {
|
||||
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);
|
||||
$i++;
|
||||
$opts['ldtoots']=$argv[$i]+0;
|
||||
} elseif ($argv[$i]=='-N' || $argv[$i]=='--dontsetnew') {
|
||||
$opts['setnew']=false;
|
||||
} elseif ($argv[$i]=='-d' || $argv[$i]=='--dryrun') {
|
||||
$opts['dryrun']=true;
|
||||
} 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';
|
||||
$iniarr=@parse_ini_file($inifp)
|
||||
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);
|
||||
mysqli_set_charset($link,'utf8mb4')
|
||||
or mexit('could not set «utf8mb4» charset fro MySQL: '.mysqli_error($link).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']); }
|
||||
catch (Exception $error) { mexit('could not connect to MySQL server: '.mysqli_connect_error().'.'.N,1,true); }
|
||||
// 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);
|
||||
//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__);
|
||||
$nrows=mysqli_num_rows($res);
|
||||
if ($nrows==1) {
|
||||
eecho(1,'«'.$opts['hostname'].'»: didn’t 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'].'»: didn’t respond, but it is present in the database; updating InstChecks, Instances.LastCheckOk and possibly Instances.Dead.'.N);
|
||||
$row=mysqli_fetch_assoc($res);
|
||||
$instid=$row['ID'];
|
||||
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
|
||||
$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
|
||||
|
@ -375,10 +359,9 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
|
|||
}
|
||||
} elseif ($nrows==0) {
|
||||
eecho(1,'«'.$opts['hostname'].'»: doesn’t 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
|
||||
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);
|
||||
myq($link,'INSERT INTO InstChecks SET InstID='.$instid.', Time='.$now.', Status=0',__LINE__);
|
||||
} else {
|
||||
|
@ -404,7 +387,7 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
|
|||
|
||||
if (!is_null($ismast))
|
||||
($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'];
|
||||
if (akeavinn('title',$info))
|
||||
$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 don’t know if it allows registrations';
|
||||
} elseif ($instrow['RegOpen']==0) {
|
||||
$whynot[]='it doesn’t allow registrations';
|
||||
}
|
||||
if (is_null($instrow['UserCount'])) {
|
||||
$whynot[]='we don’t 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 don’t 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__);
|
||||
|
||||
$nrows=mysqli_num_rows($res);
|
||||
|
@ -500,23 +452,7 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
|
|||
$oldinstrow=mysqli_fetch_assoc($res);
|
||||
$instid=$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'];
|
||||
if ($instrow['Good']==1 && $oldinstrow['Good']==0) {
|
||||
notify('Instance «<a href="viewinst.php?id='.$instrow['ID'].'">'.$instrow['URI'].'</a>» wasn’t 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 it’s no longer for these reasons: '.implode('; ',$whynot),1);
|
||||
}
|
||||
$instrow['Chosen']=$oldinstrow['Chosen'];
|
||||
$instrow['Priority']=$oldinstrow['Priority'];
|
||||
$instrow['Visible']=$oldinstrow['Visible'];
|
||||
$instrow['Noxious']=$oldinstrow['Noxious'];
|
||||
|
@ -573,9 +509,9 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
|
|||
|
||||
} elseif ($nrows==0) {
|
||||
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;
|
||||
if ($opts['setnew'])
|
||||
$instrow['New']=1;
|
||||
$instrow['InsertTS']=$now;
|
||||
$fields=[];
|
||||
$values='';
|
||||
foreach ($instrow as $field=>$value) {
|
||||
|
@ -594,8 +530,6 @@ if (willtrunc($opts['hostname'],'Instances','URI')) {
|
|||
} else {
|
||||
$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);
|
||||
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__);
|
||||
}
|
||||
|
||||
if ($instrow['Good']==1)
|
||||
notify('New instance «<a href="viewinst.php?id='.$instid.'">'.$instrow['URI'].'</a>» is suitable!',1);
|
||||
|
||||
} else {
|
||||
notify('Instance «'.$opts['hostname'].'» has '.$nrows.' entries in «Instances» table!',3);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue