Upgrade to Laravel 10

This commit is contained in:
Jonny Barnes 2023-02-18 09:34:57 +00:00
parent c4d7dc31d5
commit 16b120bc73
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
142 changed files with 1676 additions and 2019 deletions

View file

@ -24,30 +24,23 @@ class ProcessWebMention implements ShouldQueue
use Queueable;
use SerializesModels;
/** @var Note */
protected $note;
/** @var string */
protected $source;
/**
* Create a new job instance.
*/
public function __construct(Note $note, string $source)
{
$this->note = $note;
$this->source = $source;
public function __construct(
protected Note $note,
protected string $source
) {
}
/**
* Execute the job.
*
*
* @throws RemoteContentNotFoundException
* @throws GuzzleException
* @throws InvalidMentionException
*/
public function handle(Parser $parser, Client $guzzle)
public function handle(Parser $parser, Client $guzzle): void
{
try {
$response = $guzzle->request('GET', $this->source);
@ -60,8 +53,8 @@ class ProcessWebMention implements ShouldQueue
foreach ($webmentions as $webmention) {
// check webmention still references target
// we try each type of mention (reply/like/repost)
if ($webmention->type == 'in-reply-to') {
if ($parser->checkInReplyTo($microformats, $this->note->longurl) == false) {
if ($webmention->type === 'in-reply-to') {
if ($parser->checkInReplyTo($microformats, $this->note->longurl) === false) {
// it doesnt so delete
$webmention->delete();
@ -74,16 +67,16 @@ class ProcessWebMention implements ShouldQueue
return;
}
if ($webmention->type == 'like-of') {
if ($parser->checkLikeOf($microformats, $this->note->longurl) == false) {
if ($webmention->type === 'like-of') {
if ($parser->checkLikeOf($microformats, $this->note->longurl) === false) {
// it doesnt so delete
$webmention->delete();
return;
} // note we dont need to do anything if it still is a like
}
if ($webmention->type == 'repost-of') {
if ($parser->checkRepostOf($microformats, $this->note->longurl) == false) {
if ($webmention->type === 'repost-of') {
if ($parser->checkRepostOf($microformats, $this->note->longurl) === false) {
// it doesnt so delete
$webmention->delete();
@ -107,26 +100,23 @@ class ProcessWebMention implements ShouldQueue
/**
* Save the HTML of a webmention for future use.
*
* @param string $html
* @param string $url
*/
private function saveRemoteContent($html, $url)
private function saveRemoteContent(string $html, string $url): void
{
$filenameFromURL = str_replace(
['https://', 'http://'],
['https/', 'http/'],
$url
);
if (substr($url, -1) == '/') {
if (str_ends_with($url, '/')) {
$filenameFromURL .= 'index.html';
}
$path = storage_path() . '/HTML/' . $filenameFromURL;
$parts = explode('/', $path);
$name = array_pop($parts);
$dir = implode('/', $parts);
if (! is_dir($dir)) {
mkdir($dir, 0755, true);
if (! is_dir($dir) && ! mkdir($dir, 0755, true) && !is_dir($dir)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
}
file_put_contents("$dir/$name", $html);
}