Commit 0ab452ef authored by David Morley's avatar David Morley

Merge branch 'lesscrash' into 'develop'

Less crash of update.php

See merge request !224
parents a392b317 341cf8a3
Pipeline #835 passed with stage
in 2 minutes and 1 second
...@@ -83,8 +83,8 @@ EOF; ...@@ -83,8 +83,8 @@ EOF;
if (!$stop) { if (!$stop) {
$link = 'https://' . $_domain . '/nodeinfo/1.0'; $link = 'https://' . $_domain . '/nodeinfo/1.0';
if ($infos = file_get_contents('https://' . $_domain . '/.well-known/nodeinfo')) { $nodeinfo = curl('https://' . $_domain . '/.well-known/nodeinfo');
$info = json_decode($infos, true); if ($info = json_decode($nodeinfo['body'] ?: '', true)) {
$link = max($info['links'])['href']; $link = max($info['links'])['href'];
} }
......
...@@ -31,7 +31,9 @@ $existingpods = array_column($pods, 'domain'); ...@@ -31,7 +31,9 @@ $existingpods = array_column($pods, 'domain');
$foundpods = []; $foundpods = [];
//pulling all nodes for now //pulling all nodes for now
if ($pods = json_decode(file_get_contents('https://the-federation.info/graphql?query=%7Bnodes%7Bhost%20platform%7Bname%7Dprotocols%7Bname%7D%7D%7D&raw'), true)) { $federationpods = curl('https://the-federation.info/graphql?query=%7Bnodes%7Bhost%20platform%7Bname%7Dprotocols%7Bname%7D%7D%7D&raw');
if ($pods = json_decode($federationpods['body'] ?: '', true)) {
;
foreach ($pods['data']['nodes'] ?? [] as $poddata) { foreach ($pods['data']['nodes'] ?? [] as $poddata) {
$protocols = array_column($poddata['protocols'] ?? [], 'name'); $protocols = array_column($poddata['protocols'] ?? [], 'name');
...@@ -42,7 +44,8 @@ if ($pods = json_decode(file_get_contents('https://the-federation.info/graphql?q ...@@ -42,7 +44,8 @@ if ($pods = json_decode(file_get_contents('https://the-federation.info/graphql?q
} }
} }
if ($pods = json_decode(file_get_contents('https://diasp.org/pods.json'), true)) { $diasppods = curl('https://diasp.org/pods.json');
if ($pods = json_decode($diasppods['body'] ?: '', true)) {
foreach ($pods ?? [] as $poddata) { foreach ($pods ?? [] as $poddata) {
$foundpods[] = strtolower($poddata['host']); $foundpods[] = strtolower($poddata['host']);
} }
......
...@@ -22,10 +22,6 @@ use Longman\IPTools\Ip; ...@@ -22,10 +22,6 @@ use Longman\IPTools\Ip;
use Poduptime\PodStatus; use Poduptime\PodStatus;
use RedBeanPHP\R; use RedBeanPHP\R;
if (getMeta('pods_updating')) {
die('already running');
};
if (!is_connected()) { if (!is_connected()) {
die('no internet'); die('no internet');
} }
...@@ -59,14 +55,19 @@ try { ...@@ -59,14 +55,19 @@ try {
if ($_domain) { if ($_domain) {
$sql .= ' WHERE domain = ?'; $sql .= ' WHERE domain = ?';
$pods = R::getAll($sql, [$_domain]); $pods = R::getAll($sql, [$_domain]);
} elseif (is_cli() && (isset($argv) && in_array('Check_System_Deleted', $argv, true))) {
$sql .= ' WHERE status = ? ORDER BY id';
$pods = R::getAll($sql, [PodStatus::SYSTEM_DELETED]);
updateMeta('pods_updating', true);
} elseif (is_cli()) { } elseif (is_cli()) {
$sql .= ' WHERE status < ? ORDER BY id'; if (getMeta('pods_updating')) {
$pods = R::getAll($sql, [PodStatus::PAUSED]); die('already running');
}
updateMeta('pods_updating', true); updateMeta('pods_updating', true);
if (isset($argv) && in_array('Check_System_Deleted', $argv, true)) {
$sql .= ' WHERE status = ? ORDER BY id';
$pods = R::getAll($sql, [PodStatus::SYSTEM_DELETED]);
} else {
$sql .= ' WHERE status < ? ORDER BY id';
$pods = R::getAll($sql, [PodStatus::PAUSED]);
}
} }
} catch (\RedBeanPHP\RedException $e) { } catch (\RedBeanPHP\RedException $e) {
debug('Error in SQL query: ' . sprintf($e->getMessage())); debug('Error in SQL query: ' . sprintf($e->getMessage()));
...@@ -112,7 +113,11 @@ foreach ($pods as $pod) { ...@@ -112,7 +113,11 @@ foreach ($pods as $pod) {
$nodeinfo_url = "https://{$domain}/nodeinfo/1.0"; $nodeinfo_url = "https://{$domain}/nodeinfo/1.0";
if ($info = json_decode($nodeinfo_meta['body'] ?: '', true)) { if ($info = json_decode($nodeinfo_meta['body'] ?: '', true)) {
$nodeinfo_url = max($info['links'])['href']; if (count($info['links'], COUNT_RECURSIVE) === 2) {
$nodeinfo_url = $info['links']['href'];
} else {
$nodeinfo_url = max($info['links'])['href'];
}
} }
debug('Nodeinfo link', $nodeinfo_url); debug('Nodeinfo link', $nodeinfo_url);
...@@ -438,16 +443,16 @@ foreach ($pods as $pod) { ...@@ -438,16 +443,16 @@ foreach ($pods as $pod) {
debug('Success', $domain); debug('Success', $domain);
} }
updateMeta('pods_updated'); //if a full run
$time_end = microtime(true);
$execution_time = ($time_end - $time_start)/60;
updateMeta('pods_update_runtime', round($execution_time));
if ($languagesupdated) {
updateMeta('languages_updated');
}
//check daily updates
if (!$_domain) { if (!$_domain) {
updateMeta('pods_updated');
$time_end = microtime(true);
$execution_time = ($time_end - $time_start) / 60;
updateMeta('pods_update_runtime', round($execution_time));
if ($languagesupdated) {
updateMeta('languages_updated');
}
if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('masterversions_updated', 'date_created'))->diffInHours() > 12) { if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('masterversions_updated', 'date_created'))->diffInHours() > 12) {
require __DIR__ . '/update-masterversions.php'; require __DIR__ . '/update-masterversions.php';
} }
...@@ -458,13 +463,13 @@ if (!$_domain) { ...@@ -458,13 +463,13 @@ if (!$_domain) {
if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('cacert_updated', 'date_created'))->diffInHours() > 40) { if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('cacert_updated', 'date_created'))->diffInHours() > 40) {
$cacert = c('cafullpath'); $cacert = c('cafullpath');
file_put_contents($cacert, file_get_contents("https://curl.haxx.se/ca/cacert.pem")); copy('https://curl.haxx.se/ca/cacert.pem', $cacert);
updateMeta('cacert_updated'); updateMeta('cacert_updated');
} }
if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('geoip_updated', 'date_created'))->diffInHours() > 45) { if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('geoip_updated', 'date_created'))->diffInHours() > 45) {
$geo2ip = c('geoip2db'); $geo2ip = c('geoip2db');
file_put_contents($geo2ip, file_get_contents("compress.zlib://http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz")); copy('compress.zlib://http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz', $geo2ip);
updateMeta('geoip_updated'); updateMeta('geoip_updated');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment