Optimized “dryrun” behavior, fixed some flaws
This commit is contained in:
parent
f31aeaf1db
commit
8e5cc30412
1 changed files with 30 additions and 21 deletions
|
@ -260,7 +260,8 @@ if ($buf['cont']!==false) {
|
|||
(preg_match('/^'.$mastodons.'/',$idata['Software'])===1) ? $idata['IsMastodon']=true : $idata['IsMastodon']=false;
|
||||
$res=myq($link,'SELECT Name FROM Platforms WHERE Name=\''.myesc($link,$idata['Software']).'\'',__LINE__);
|
||||
if (mysqli_num_rows($res)<1) {
|
||||
if (!$opts['dryrun']) myq($link,'INSERT INTO Platforms (Name) VALUES (\''.myesc($link,truncs($idata['Software'], 'Platforms', 'Name', '«'.$opts['hostname'].'»')).'\')',__LINE__);
|
||||
if (!$opts['dryrun'])
|
||||
myq($link,'INSERT INTO Platforms (Name) VALUES (\''.myesc($link,truncs($idata['Software'], 'Platforms', 'Name', '«'.$opts['hostname'].'»')).'\')',__LINE__);
|
||||
notify('«'.$opts['hostname'].'» runs on «'.$idata['Software'].'», which was not present in the «Platforms» table, so it was added there. It would be good to check whether it is a Mastodon derivate and how compatible it is, to decide whether to consider instances using it as Mastodon instances by setting the «Consider» field of its record to «1».',2);
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +293,7 @@ if ($buf['cont']!==false) {
|
|||
} else {
|
||||
eecho(2,'«'.$opts['hostname'].'»: could not fetch nodeinfo specs: '.$buf['emsg'].'.'.N);
|
||||
}
|
||||
if ($idata['IsMastodon'] && $idata['Version']>='4.0.0') {
|
||||
if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4.0.0') {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance info from API v2...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v2/instance',$opts['timeout']);
|
||||
if ($buf['cont']!==false) {
|
||||
|
@ -635,9 +636,10 @@ if (!$opts['dryrun']) myq($link,'INSERT INTO InstChecks (InstID, Time, Status) V
|
|||
|
||||
if ($instanswered && isset($idata['languages']) && is_array($idata['languages']) && count($idata['languages'])>0) {
|
||||
eecho(1,'«'.$opts['hostname'].'»: declared languages: '.implode(', ',$idata['languages']).N);
|
||||
if (!$opts['dryrun']) {
|
||||
if (!$opts['dryrun'])
|
||||
myq($link,'DELETE FROM InstLangs WHERE InstID='.$instid,__LINE__);
|
||||
$langids=getlangsidsarr($idata['languages'],$supplangs,$link,$opts['hostname'],$opts['dryrun'],__LINE__);
|
||||
$langids=getlangsidsarr($idata['languages'],$supplangs,$link,$opts['hostname'],$opts['dryrun'],__LINE__);
|
||||
if (!$opts['dryrun']) {
|
||||
$pos=0;
|
||||
foreach ($langids as $langid) {
|
||||
$pos++;
|
||||
|
@ -663,9 +665,10 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages'])
|
|||
$idata['ourlanguages']=$idata['languages'];
|
||||
eecho(1,'«'.$opts['hostname'].'»: copied declared languages to detected languages.'.N);
|
||||
}
|
||||
if (!$opts['dryrun']) {
|
||||
if (!$opts['dryrun'])
|
||||
myq($link,'DELETE FROM InstOurLangs WHERE InstID='.$instid,__LINE__);
|
||||
$langids=getlangsidsarr($idata['ourlanguages'],$supplangs,$link,$opts['hostname'],$opts['dryrun'],__LINE__);
|
||||
$langids=getlangsidsarr($idata['ourlanguages'],$supplangs,$link,$opts['hostname'],$opts['dryrun'],__LINE__);
|
||||
if (!$opts['dryrun']) {
|
||||
$pos=0;
|
||||
foreach ($langids as $langid) {
|
||||
$pos++;
|
||||
|
@ -675,20 +678,22 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages'])
|
|||
}
|
||||
}
|
||||
|
||||
if ($instanswered && !$opts['dryrun'])
|
||||
myq($link,'DELETE FROM InstActivity WHERE InstID='.$instid,__LINE__);
|
||||
if (isset($idata['activity']) && is_array($idata['activity'])) {
|
||||
if (!$opts['dryrun']) {
|
||||
myq($link,'DELETE FROM InstActivity WHERE InstID='.$instid,__LINE__);
|
||||
$pos=0;
|
||||
foreach ($idata['activity'] as $buf) {
|
||||
// these should all be int, but mastodon represents them as strings
|
||||
if (isset($buf['week']) && is_string($buf['week']) && preg_match('/^\d+$/',$buf['week'])===1 && isset($buf['statuses']) && is_string($buf['statuses']) && preg_match('/^\d+$/',$buf['statuses'])===1 && isset($buf['logins']) && is_string($buf['logins']) && preg_match('/^\d+$/',$buf['logins'])===1 && isset($buf['registrations']) && is_string($buf['registrations']) && preg_match('/^\d+$/',$buf['registrations'])===1) {
|
||||
$pos++;
|
||||
$pos=0;
|
||||
foreach ($idata['activity'] as $buf) {
|
||||
// these should all be int, but mastodon represents them as strings
|
||||
if (isset($buf['week']) && is_string($buf['week']) && preg_match('/^\d+$/',$buf['week'])===1 && isset($buf['statuses']) && is_string($buf['statuses']) && preg_match('/^\d+$/',$buf['statuses'])===1 && isset($buf['logins']) && is_string($buf['logins']) && preg_match('/^\d+$/',$buf['logins'])===1 && isset($buf['registrations']) && is_string($buf['registrations']) && preg_match('/^\d+$/',$buf['registrations'])===1) {
|
||||
$pos++;
|
||||
if (!$opts['dryrun'])
|
||||
myq($link,'INSERT INTO InstActivity (InstID, Week, Statuses, Logins, Registrations, Pos) VALUES ('.$instid.', '.$buf['week'].', '.$buf['statuses'].', '.$buf['logins'].', '.$buf['registrations'].', '.$pos.')',__LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($instanswered && !$opts['dryrun'])
|
||||
myq($link,'DELETE FROM InstTrends WHERE InstID='.$instid,__LINE__);
|
||||
if (isset($idata['trends']) && is_array($idata['trends'])) {
|
||||
$trends=[];
|
||||
foreach ($idata['trends'] as $buf) {
|
||||
|
@ -715,25 +720,27 @@ if (isset($idata['trends']) && is_array($idata['trends'])) {
|
|||
}
|
||||
//print_r($trends);
|
||||
mdasortbykey($trends,'trend',true);
|
||||
if (!$opts['dryrun']) myq($link,'DELETE FROM InstTrends WHERE InstID='.$instid,__LINE__);
|
||||
$pos=0;
|
||||
foreach ($trends as $trend) {
|
||||
$pos++;
|
||||
$query='INSERT INTO InstTrends (InstID, LastDay, Name, URL, Pos) VALUES ('.$trend['InstID'].', \''.$trend['LastDay'].'\', \''.myesc($link, truncs($trend['Name'], 'InstTrends', 'Name', '«'.$opts['hostname'].'»')).'\', \''.myesc($link, truncs($trend['URL'], 'InstTrends', 'URL', '«'.$opts['hostname'].'»')).'\', '.$pos.')';
|
||||
if (!$opts['dryrun']) myq($link,$query,__LINE__);
|
||||
if (!$opts['dryrun'])
|
||||
myq($link,$query,__LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($idata['rules']) && is_array($idata['rules'])) {
|
||||
if (!$opts['dryrun']) myq($link,'DELETE FROM InstRules WHERE InstID='.$instid,__LINE__);
|
||||
ksort($idata['rules']);
|
||||
foreach ($idata['rules'] as $rule)
|
||||
if (!$opts['dryrun'])
|
||||
if (!$opts['dryrun']) {
|
||||
myq($link,'DELETE FROM InstRules WHERE InstID='.$instid,__LINE__);
|
||||
foreach ($idata['rules'] as $rule)
|
||||
myq($link,'INSERT INTO InstRules SET InstID='.$instid.', Text=\''.myesc($link, truncs($rule, 'InstRules', 'Text', '«'.$opts['hostname'].'»')).'\'',__LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
if ($instanswered && !$opts['dryrun'])
|
||||
myq($link,'DELETE FROM InstBlocks WHERE InstID='.$instid,__LINE__);
|
||||
if (isset($idata['blocks']) && is_array($idata['blocks'])) {
|
||||
if (!$opts['dryrun']) myq($link,'DELETE FROM InstBlocks WHERE InstID='.$instid,__LINE__);
|
||||
foreach ($idata['blocks'] as $block) {
|
||||
(is_null($block['comm'])) ? $block['comm']='NULL' : $block['comm']="'".myesc($link, truncs($block['comm'], 'InstBlocks', 'Comment', '«'.$opts['hostname'].'»'))."'";
|
||||
if (!$opts['dryrun'])
|
||||
|
@ -741,7 +748,7 @@ if (isset($idata['blocks']) && is_array($idata['blocks'])) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($opts['fetchusers'] && $idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4.0.0') {
|
||||
if ($instanswered && $opts['fetchusers'] && $idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4.0.0') {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch users info from directory API...'.N);
|
||||
$users=[];// array of users in this instance's directory
|
||||
$chunk=0;
|
||||
|
@ -852,6 +859,8 @@ if ($opts['fetchusers'] && $idata['IsMastodon'] && !is_null($idata['Version']) &
|
|||
if (!$opts['dryrun']) {
|
||||
myq($link,$query,__LINE__);
|
||||
$uid=mysqli_insert_id($link);
|
||||
} else {
|
||||
$uid=0;
|
||||
}
|
||||
} else {
|
||||
eecho(0,'«'.$opts['hostname'].'»: NOT inserting user «'.$user['username'].'» because they don’t want to be indexed...'.N);
|
||||
|
|
Loading…
Reference in a new issue