2017-09-19 16:07:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-09-19 16:07:32 +01:00
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
use App\Models\Like;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
2017-09-19 16:07:32 +01:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
use Illuminate\Support\Arr;
|
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;
|
2017-09-19 16:07:32 +01:00
|
|
|
use Jonnybarnes\WebmentionsParser\Authorship;
|
|
|
|
|
use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
|
|
|
|
|
|
|
|
|
|
class ProcessLike implements ShouldQueue
|
|
|
|
|
{
|
2019-10-27 16:15:14 +00:00
|
|
|
use Dispatchable;
|
|
|
|
|
use InteractsWithQueue;
|
|
|
|
|
use Queueable;
|
|
|
|
|
use SerializesModels;
|
2017-09-19 16:07:32 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
public function __construct(
|
|
|
|
|
protected Like $like
|
2024-07-13 10:55:19 +01:00
|
|
|
) {}
|
2017-09-19 16:07:32 +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
|
|
|
public function handle(Authorship $authorship): int
|
2017-09-19 16:07:32 +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
|
|
|
$response = Http::throw()->get($this->like->url);
|
|
|
|
|
$mf2 = \Mf2\parse($response->body(), $this->like->url);
|
2019-02-01 18:49:35 +00:00
|
|
|
if (Arr::has($mf2, 'items.0.properties.content')) {
|
2017-09-19 16:07:32 +01:00
|
|
|
$this->like->content = $mf2['items'][0]['properties']['content'][0]['html'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$author = $authorship->findAuthor($mf2);
|
|
|
|
|
if (is_array($author)) {
|
2019-02-01 18:49:35 +00:00
|
|
|
$this->like->author_name = Arr::get($author, 'properties.name.0');
|
|
|
|
|
$this->like->author_url = Arr::get($author, 'properties.url.0');
|
2017-09-19 16:07:32 +01:00
|
|
|
}
|
|
|
|
|
if (is_string($author) && $author !== '') {
|
|
|
|
|
$this->like->author_name = $author;
|
|
|
|
|
}
|
|
|
|
|
} catch (AuthorshipParserException $exception) {
|
2018-01-12 21:19:42 +00:00
|
|
|
return 1;
|
2017-09-19 16:07:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->like->save();
|
2018-01-15 14:02:13 +00:00
|
|
|
|
|
|
|
|
return 0;
|
2017-09-19 16:07:32 +01:00
|
|
|
}
|
|
|
|
|
}
|