@@ -32,31 +32,36 @@ public function handle()
32
32
33
33
$ isFlarum = false ;
34
34
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 );
37
41
38
- if ($ response ->getStatusCode () === 200 ) {
39
- $ page = new Crawler ($ response ->getBody ()->getContents ());
42
+ if ($ response ->getStatusCode () === 200 ) {
43
+ $ page = new Crawler ($ response ->getBody ()->getContents ());
40
44
41
- $ meta = $ page ->filter ('meta[name=migratetoflarum-lab-opt-out] ' )->first ();
45
+ $ meta = $ page ->filter ('meta[name=migratetoflarum-lab-opt-out] ' )->first ();
42
46
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
+ }
48
52
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 ' );
51
55
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
56
64
}
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
60
65
}
61
66
62
67
$ this ->website ->updateIsFlarumStatus ($ isFlarum );
0 commit comments