Fix several PHP messages
- Add logging for exceptions
This commit is contained in:
parent
230f17ef36
commit
f854d7d5f7
|
@ -66,7 +66,7 @@ class Servers extends BaseController
|
||||||
$sql_where = '';
|
$sql_where = '';
|
||||||
$values = [];
|
$values = [];
|
||||||
|
|
||||||
if ($args['language']) {
|
if (!empty($args['language'])) {
|
||||||
$sql_where .= '
|
$sql_where .= '
|
||||||
AND LEFT(`language`, 2) = LEFT(:language, 2)';
|
AND LEFT(`language`, 2) = LEFT(:language, 2)';
|
||||||
$values['language'] = $args['language'];
|
$values['language'] = $args['language'];
|
||||||
|
@ -104,7 +104,7 @@ AND NOT `hidden`
|
||||||
$vars = [
|
$vars = [
|
||||||
'title' => $this->l10n->gettext('Public Servers'),
|
'title' => $this->l10n->gettext('Public Servers'),
|
||||||
'total' => $count,
|
'total' => $count,
|
||||||
'language' => $args['language'],
|
'language' => $args['language'] ?? null,
|
||||||
'servers' => $servers,
|
'servers' => $servers,
|
||||||
'pager' => $pager->renderFull($count),
|
'pager' => $pager->renderFull($count),
|
||||||
'stable_version' => $stable_version,
|
'stable_version' => $stable_version,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Friendica\Directory\Pollers;
|
namespace Friendica\Directory\Pollers;
|
||||||
|
|
||||||
use Friendica\Directory\Utils\Network;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
||||||
|
@ -136,13 +136,28 @@ class Profile
|
||||||
//Skip the profile scrape?
|
//Skip the profile scrape?
|
||||||
if ($server['noscrape_url']) {
|
if ($server['noscrape_url']) {
|
||||||
$this->logger->debug('Calling ' . $server['noscrape_url'] . '/' . $username);
|
$this->logger->debug('Calling ' . $server['noscrape_url'] . '/' . $username);
|
||||||
$params = \Friendica\Directory\Utils\Scrape::retrieveNoScrapeData($this->http, $server['noscrape_url'] . '/' . $username);
|
try {
|
||||||
|
$params = \Friendica\Directory\Utils\Scrape::retrieveNoScrapeData($this->http, $server['noscrape_url'] . '/' . $username);
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$this->logger->info('Request failed with error code ' . $e->getCode());
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->logger->warning('Request failed with exception ' . get_class($e));
|
||||||
|
$this->logger->warning(var_export($e, true));
|
||||||
|
}
|
||||||
|
|
||||||
$available = !!$params; //If the result was false, do a scrape after all.
|
$available = !!$params; //If the result was false, do a scrape after all.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$available) {
|
if (!$available) {
|
||||||
$this->logger->notice('Parsing profile page ' . $profile_uri);
|
$this->logger->info('Parsing profile page ' . $profile_uri);
|
||||||
$params = \Friendica\Directory\Utils\Scrape::retrieveProfileData($this->http, $profile_uri);
|
try {
|
||||||
|
$params = \Friendica\Directory\Utils\Scrape::retrieveProfileData($this->http, $profile_uri);
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$this->logger->info('Request failed with error code ' . $e->getCode());
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->logger->warning('Request failed with exception ' . get_class($e));
|
||||||
|
$this->logger->warning(var_export($e, true));
|
||||||
|
}
|
||||||
$params['language'] = $server['language'];
|
$params['language'] = $server['language'];
|
||||||
|
|
||||||
$available = !empty($params['fn']);
|
$available = !empty($params['fn']);
|
||||||
|
@ -306,23 +321,27 @@ class Profile
|
||||||
$status = false;
|
$status = false;
|
||||||
|
|
||||||
if ($profile_id) {
|
if ($profile_id) {
|
||||||
$img_str = $this->http->get($params['photo'])->getBody()->getContents();
|
try {
|
||||||
$img = new \Friendica\Directory\Utils\Photo($img_str);
|
$img_str = $this->http->get($params['photo'])->getBody()->getContents();
|
||||||
if ($img->getImage()) {
|
$img = new \Friendica\Directory\Utils\Photo($img_str);
|
||||||
$img->scaleImageSquare(80);
|
if ($img->getImage()) {
|
||||||
|
$img->scaleImageSquare(80);
|
||||||
|
|
||||||
$this->atlas->perform('INSERT INTO `photo` SET
|
$this->atlas->perform('INSERT INTO `photo` SET
|
||||||
`profile_id` = :profile_id,
|
`profile_id` = :profile_id,
|
||||||
`data` = :data
|
`data` = :data
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
`data` = :data',
|
`data` = :data',
|
||||||
[
|
[
|
||||||
'profile_id' => $profile_id,
|
'profile_id' => $profile_id,
|
||||||
'data' => $img->imageString()
|
'data' => $img->imageString()
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
$status = true;
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$this->logger->info('Photo retrieval unsuccessful', ['url' => $params['photo'], 'code' => $e->getCode()]);
|
||||||
}
|
}
|
||||||
$status = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$submit_end = microtime(true);
|
$submit_end = microtime(true);
|
||||||
|
|
|
@ -154,7 +154,7 @@ class Server
|
||||||
$addons = $probe_result['data']['plugins'];
|
$addons = $probe_result['data']['plugins'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($probe_result['data']['admin']['profile']) {
|
if (!empty($probe_result['data']['admin']['profile'])) {
|
||||||
$subscribe = $this->getSubscribeUrl($probe_result['data']['url'], $probe_result['data']['admin']['profile']);
|
$subscribe = $this->getSubscribeUrl($probe_result['data']['url'], $probe_result['data']['admin']['profile']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,14 +178,14 @@ class Server
|
||||||
[
|
[
|
||||||
'server_id' => $server['id'],
|
'server_id' => $server['id'],
|
||||||
'base_url' => strtolower($probe_result['data']['url']),
|
'base_url' => strtolower($probe_result['data']['url']),
|
||||||
'name' => $probe_result['data']['site_name'],
|
'name' => substr($probe_result['data']['site_name'], 0, 255),
|
||||||
'language' => $probe_result['data']['language'] ?? null,
|
'language' => $probe_result['data']['language'] ?? null,
|
||||||
'version' => $probe_result['data']['version'],
|
'version' => $probe_result['data']['version'],
|
||||||
'addons' => implode(',', $addons),
|
'addons' => implode(',', $addons),
|
||||||
'reg_policy' => $probe_result['data']['register_policy'],
|
'reg_policy' => $probe_result['data']['register_policy'],
|
||||||
'info' => $probe_result['data']['info'],
|
'info' => $probe_result['data']['info'],
|
||||||
'admin_name' => $probe_result['data']['admin']['name'],
|
'admin_name' => $probe_result['data']['admin']['name'] ?? null,
|
||||||
'admin_profile' => $probe_result['data']['admin']['profile'],
|
'admin_profile' => $probe_result['data']['admin']['profile'] ?? null,
|
||||||
'noscrape_url' => $probe_result['data']['no_scrape_url'] ?? null,
|
'noscrape_url' => $probe_result['data']['no_scrape_url'] ?? null,
|
||||||
'subscribe_url' => $subscribe ?? null,
|
'subscribe_url' => $subscribe ?? null,
|
||||||
'ssl_state' => $probe_result['ssl_state']
|
'ssl_state' => $probe_result['ssl_state']
|
||||||
|
@ -265,29 +265,35 @@ class Server
|
||||||
|
|
||||||
$sslcert_issues = false;
|
$sslcert_issues = false;
|
||||||
|
|
||||||
|
$probe_start = microtime(true);
|
||||||
|
$probe_data = null;
|
||||||
try {
|
try {
|
||||||
//Probe the site.
|
//Probe the site.
|
||||||
$probe_start = microtime(true);
|
|
||||||
$probe_data = $this->http->get($base_url . '/friendica/json', $options)->getBody()->getContents();
|
$probe_data = $this->http->get($base_url . '/friendica/json', $options)->getBody()->getContents();
|
||||||
$probe_end = microtime(true);
|
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
if (!in_array($e->getHandlerContext()['errno'], [
|
if (in_array($e->getHandlerContext()['errno'] ?? 0, [
|
||||||
60, //Could not authenticate certificate with known CA's
|
60, //Could not authenticate certificate with known CA's
|
||||||
83 //Issuer check failed
|
83 //Issuer check failed
|
||||||
])) {
|
])) {
|
||||||
throw $e;
|
$sslcert_issues = true;
|
||||||
|
|
||||||
|
//When it's the certificate that doesn't work, we probe again without strict SSL.
|
||||||
|
$options['verify'] = false;
|
||||||
|
|
||||||
|
$probe_start = microtime(true);
|
||||||
|
try {
|
||||||
|
$probe_data = $this->http->get($base_url . '/friendica/json', $options)->getBody()->getContents();
|
||||||
|
} catch(RequestException $e) {
|
||||||
|
// Collects 404, 500 errors
|
||||||
|
$this->logger->info('SSL-non-verified URL probe failed with error code: ' . $e->getCode());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->logger->info('SSL-verified URL probe failed with error code: ' . $e->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
$sslcert_issues = true;
|
|
||||||
|
|
||||||
//When it's the certificate that doesn't work, we probe again without strict SSL.
|
|
||||||
$options['verify'] = false;
|
|
||||||
|
|
||||||
$probe_start = microtime(true);
|
|
||||||
$probe_data = $this->http->get($base_url . '/friendica/json', $options)->getBody()->getContents();
|
|
||||||
$probe_end = microtime(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$probe_end = microtime(true);
|
||||||
|
|
||||||
$time = round(($probe_end - $probe_start) * 1000);
|
$time = round(($probe_end - $probe_start) * 1000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -404,11 +410,9 @@ class Server
|
||||||
{
|
{
|
||||||
$uri = Uri::withQueryValues(new Uri($base_url . '/poco'), ['fields' => 'urls', 'count' => 1000]);
|
$uri = Uri::withQueryValues(new Uri($base_url . '/poco'), ['fields' => 'urls', 'count' => 1000]);
|
||||||
|
|
||||||
$response = $this->http->request('GET', $uri);
|
try {
|
||||||
|
$response = $this->http->request('GET', $uri);
|
||||||
$this->logger->debug('WebRequest: ' . $uri . ' Status: ' . $response->getStatusCode());
|
} catch (RequestException $e) {
|
||||||
|
|
||||||
if ($response->getStatusCode() != 200) {
|
|
||||||
$this->logger->info('Unsuccessful poco request: ' . $uri);
|
$this->logger->info('Unsuccessful poco request: ' . $uri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -445,7 +449,12 @@ class Server
|
||||||
{
|
{
|
||||||
$uri = Uri::withQueryValues(new Uri($base_url . '/xrd'), ['uri' => $profile]);
|
$uri = Uri::withQueryValues(new Uri($base_url . '/xrd'), ['uri' => $profile]);
|
||||||
|
|
||||||
$response = $this->http->request('GET', $uri, ['headers' => ['Accept' => 'application/jrd+json']]);
|
try {
|
||||||
|
$response = $this->http->request('GET', $uri, ['headers' => ['Accept' => 'application/jrd+json']]);
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$this->logger->info('Unsuccessful xrd request: ' . $uri);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$xrdJsonData = $response->getBody()->getContents();
|
$xrdJsonData = $response->getBody()->getContents();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue