Skip to content

Commit e97e66c

Browse files
Fix InvalidArgumentException in ping job
Sentry MIGRATETOFLARUM-LAB-3A
1 parent 06e5e7e commit e97e66c

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

app/Jobs/WebsitePing.php

+24-19
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,36 @@ public function handle()
3232

3333
$isFlarum = false;
3434

35-
try {
36-
$response = $client->get($this->website->canonical_url);
35+
// It's very unlikely to run this method for a website without a canonical URL
36+
// But it can happen if all requests fail in ScanAlternateUrlsAndHeaders while the scan still succeeds
37+
// If we don't handle this we encounter an InvalidArgumentException when trying to call Guzzle with null
38+
if ($this->website->canonical_url) {
39+
try {
40+
$response = $client->get($this->website->canonical_url);
3741

38-
if ($response->getStatusCode() === 200) {
39-
$page = new Crawler($response->getBody()->getContents());
42+
if ($response->getStatusCode() === 200) {
43+
$page = new Crawler($response->getBody()->getContents());
4044

41-
$meta = $page->filter('meta[name=migratetoflarum-lab-opt-out]')->first();
45+
$meta = $page->filter('meta[name=migratetoflarum-lab-opt-out]')->first();
4246

43-
// If the website wasn't ignored but we notice it should be, add ignore flag
44-
// Let the opt out check take care of removing websites from the opt out
45-
if (!$this->website->ignore && $meta->count() > 0) {
46-
$this->website->ignore = true;
47-
}
47+
// If the website wasn't ignored but we notice it should be, add ignore flag
48+
// Let the opt out check take care of removing websites from the opt out
49+
if (!$this->website->ignore && $meta->count() > 0) {
50+
$this->website->ignore = true;
51+
}
4852

49-
$page->filter('head link[rel="stylesheet"]')->each(function (Crawler $link) use (&$isFlarum) {
50-
$href = $link->attr('href');
53+
$page->filter('head link[rel="stylesheet"]')->each(function (Crawler $link) use (&$isFlarum) {
54+
$href = $link->attr('href');
5155

52-
if (str_contains($href, '/assets/forum-')) {
53-
$isFlarum = true;
54-
}
55-
});
56+
if (str_contains($href, '/assets/forum-')) {
57+
$isFlarum = true;
58+
}
59+
});
60+
}
61+
} catch (RequestException $exception) {
62+
// Ignore connect exceptions, they will be considered as non-flarum
63+
// We also need to catch RequestException for certificate issues and such
5664
}
57-
} catch (RequestException $exception) {
58-
// Ignore connect exceptions, they will be considered as non-flarum
59-
// We also need to catch RequestException for certificate issues and such
6065
}
6166

6267
$this->website->updateIsFlarumStatus($isFlarum);

0 commit comments

Comments
 (0)