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;
if (!$stop) {
$link = 'https://' . $_domain . '/nodeinfo/1.0';
if ($infos = file_get_contents('https://' . $_domain . '/.well-known/nodeinfo')) {
$info = json_decode($infos, true);
$nodeinfo = curl('https://' . $_domain . '/.well-known/nodeinfo');
if ($info = json_decode($nodeinfo['body'] ?: '', true)) {
$link = max($info['links'])['href'];
}
......
......@@ -31,7 +31,9 @@ $existingpods = array_column($pods, 'domain');
$foundpods = [];
//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) {
$protocols = array_column($poddata['protocols'] ?? [], 'name');
......@@ -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) {
$foundpods[] = strtolower($poddata['host']);
}
......
......@@ -22,10 +22,6 @@ use Longman\IPTools\Ip;
use Poduptime\PodStatus;
use RedBeanPHP\R;
if (getMeta('pods_updating')) {
die('already running');
};
if (!is_connected()) {
die('no internet');
}
......@@ -59,14 +55,19 @@ try {
if ($_domain) {
$sql .= ' WHERE domain = ?';
$pods = R::getAll($sql, [$_domain]);
} elseif (is_cli() && (isset($argv) && in_array('Check_System_Deleted', $argv, true))) {
} elseif (is_cli()) {
if (getMeta('pods_updating')) {
die('already running');
}
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]);
updateMeta('pods_updating', true);
} elseif (is_cli()) {
} else {
$sql .= ' WHERE status < ? ORDER BY id';
$pods = R::getAll($sql, [PodStatus::PAUSED]);
updateMeta('pods_updating', true);
}
}
} catch (\RedBeanPHP\RedException $e) {
debug('Error in SQL query: ' . sprintf($e->getMessage()));
......@@ -112,8 +113,12 @@ foreach ($pods as $pod) {
$nodeinfo_url = "https://{$domain}/nodeinfo/1.0";
if ($info = json_decode($nodeinfo_meta['body'] ?: '', true)) {
if (count($info['links'], COUNT_RECURSIVE) === 2) {
$nodeinfo_url = $info['links']['href'];
} else {
$nodeinfo_url = max($info['links'])['href'];
}
}
debug('Nodeinfo link', $nodeinfo_url);
......@@ -438,16 +443,16 @@ foreach ($pods as $pod) {
debug('Success', $domain);
}
updateMeta('pods_updated');
$time_end = microtime(true);
$execution_time = ($time_end - $time_start)/60;
updateMeta('pods_update_runtime', round($execution_time));
if ($languagesupdated) {
//if a full run
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');
}
}
//check daily updates
if (!$_domain) {
if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('masterversions_updated', 'date_created'))->diffInHours() > 12) {
require __DIR__ . '/update-masterversions.php';
}
......@@ -458,13 +463,13 @@ if (!$_domain) {
if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('cacert_updated', 'date_created'))->diffInHours() > 40) {
$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');
}
if (Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('geoip_updated', 'date_created'))->diffInHours() > 45) {
$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');
}
......
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