2016-09-15 15:54:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2016-09-15 15:54:57 +01:00
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
2019-10-27 19:31:33 +00:00
|
|
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
2016-09-15 15:54:57 +01:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\FileSystem\FileSystem;
|
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.
The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.
Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00
|
|
|
use Illuminate\Http\Client\RequestException;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.
The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.
Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2016-09-15 15:54:57 +01:00
|
|
|
|
|
|
|
|
class DownloadWebMention implements ShouldQueue
|
|
|
|
|
{
|
2019-10-27 19:31:33 +00:00
|
|
|
use InteractsWithQueue;
|
|
|
|
|
use Queueable;
|
|
|
|
|
use SerializesModels;
|
2016-09-15 15:54:57 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
public function __construct(
|
|
|
|
|
protected string $source
|
2024-07-13 10:55:19 +01:00
|
|
|
) {}
|
2016-09-15 15:54:57 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the job.
|
|
|
|
|
*
|
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.
The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.
Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00
|
|
|
* @throws RequestException
|
2019-10-27 19:31:33 +00:00
|
|
|
* @throws FileNotFoundException
|
2016-09-15 15:54:57 +01:00
|
|
|
*/
|
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.
The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.
Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00
|
|
|
public function handle(): void
|
2016-09-15 15:54:57 +01:00
|
|
|
{
|
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.
The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.
Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00
|
|
|
// 4XX and 5XX responses should throw so Laravel can catch and
|
|
|
|
|
// retry these automatically.
|
|
|
|
|
$response = Http::throw()->get($this->source);
|
|
|
|
|
if ($response->status() === 200) {
|
2024-10-25 20:40:52 +01:00
|
|
|
$filesystem = new FileSystem;
|
2026-04-07 09:01:19 +01:00
|
|
|
$filename = storage_path('HTML').'/'.$this->createFilenameFromURL($this->source);
|
2025-03-01 15:00:41 +00:00
|
|
|
// backup file first
|
2026-04-07 09:01:19 +01:00
|
|
|
$filenameBackup = $filename.'.'.date('Y-m-d').'.backup';
|
2016-09-19 17:18:24 +01:00
|
|
|
if ($filesystem->exists($filename)) {
|
2016-09-19 17:25:01 +01:00
|
|
|
$filesystem->copy($filename, $filenameBackup);
|
2016-09-19 17:18:24 +01:00
|
|
|
}
|
2025-03-01 15:00:41 +00:00
|
|
|
// check if base directory exists
|
2016-09-21 14:25:12 +01:00
|
|
|
if (! $filesystem->exists($filesystem->dirname($filename))) {
|
2016-09-21 14:18:58 +01:00
|
|
|
$filesystem->makeDirectory(
|
|
|
|
|
$filesystem->dirname($filename),
|
2025-03-01 15:00:41 +00:00
|
|
|
0755, // mode
|
|
|
|
|
true // recursive
|
2016-09-21 14:18:58 +01:00
|
|
|
);
|
|
|
|
|
}
|
2025-03-01 15:00:41 +00:00
|
|
|
// save new HTML
|
2016-09-15 15:54:57 +01:00
|
|
|
$filesystem->put(
|
2016-09-19 17:18:24 +01:00
|
|
|
$filename,
|
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.
The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.
Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00
|
|
|
$response->body()
|
2016-09-17 21:29:32 +01:00
|
|
|
);
|
2025-03-01 15:00:41 +00:00
|
|
|
// remove backup if the same
|
2016-09-21 14:18:58 +01:00
|
|
|
if ($filesystem->exists($filenameBackup)) {
|
2023-02-18 09:34:57 +00:00
|
|
|
if ($filesystem->get($filename) === $filesystem->get($filenameBackup)) {
|
2016-09-21 14:18:58 +01:00
|
|
|
$filesystem->delete($filenameBackup);
|
|
|
|
|
}
|
2016-09-19 17:25:01 +01:00
|
|
|
}
|
2016-09-15 15:54:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-27 19:31:33 +00:00
|
|
|
* Create a file path from a URL. This is used when caching the HTML response.
|
2016-09-15 15:54:57 +01:00
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
private function createFilenameFromURL(string $url): string
|
2016-09-15 15:54:57 +01:00
|
|
|
{
|
2016-09-21 14:18:58 +01:00
|
|
|
$filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
|
2023-02-18 09:34:57 +00:00
|
|
|
if (str_ends_with($filepath, '/')) {
|
2016-09-21 14:18:58 +01:00
|
|
|
$filepath .= 'index.html';
|
2016-09-15 15:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 14:18:58 +01:00
|
|
|
return $filepath;
|
2016-09-15 15:54:57 +01:00
|
|
|
}
|
|
|
|
|
}
|