Upgrade to Laravel 10
This commit is contained in:
parent
c4d7dc31d5
commit
16b120bc73
142 changed files with 1676 additions and 2019 deletions
|
@ -18,24 +18,22 @@ class AddClientToDatabase implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
protected $client_id;
|
||||
protected string $client_id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(string $client_id)
|
||||
public function __construct(string $clientId)
|
||||
{
|
||||
$this->client_id = $client_id;
|
||||
$this->client_id = $clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
if (MicropubClient::where('client_url', $this->client_id)->count() == 0) {
|
||||
if (MicropubClient::where('client_url', $this->client_id)->count() === 0) {
|
||||
MicropubClient::create([
|
||||
'client_url' => $this->client_id,
|
||||
'client_name' => $this->client_id, // default client name is the URL
|
||||
|
|
|
@ -19,34 +19,26 @@ class DownloadWebMention implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The webmention source URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(string $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
public function __construct(
|
||||
protected string $source
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
public function handle(Client $guzzle): void
|
||||
{
|
||||
$response = $guzzle->request('GET', $this->source);
|
||||
//4XX and 5XX responses should get Guzzle to throw an exception,
|
||||
//Laravel should catch and retry these automatically.
|
||||
if ($response->getStatusCode() == '200') {
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$filesystem = new FileSystem();
|
||||
$filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source);
|
||||
//backup file first
|
||||
|
@ -69,7 +61,7 @@ class DownloadWebMention implements ShouldQueue
|
|||
);
|
||||
//remove backup if the same
|
||||
if ($filesystem->exists($filenameBackup)) {
|
||||
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) {
|
||||
if ($filesystem->get($filename) === $filesystem->get($filenameBackup)) {
|
||||
$filesystem->delete($filenameBackup);
|
||||
}
|
||||
}
|
||||
|
@ -78,13 +70,11 @@ class DownloadWebMention implements ShouldQueue
|
|||
|
||||
/**
|
||||
* Create a file path from a URL. This is used when caching the HTML response.
|
||||
*
|
||||
* @return string The path name
|
||||
*/
|
||||
private function createFilenameFromURL(string $url)
|
||||
private function createFilenameFromURL(string $url): string
|
||||
{
|
||||
$filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
|
||||
if (substr($filepath, -1) == '/') {
|
||||
if (str_ends_with($filepath, '/')) {
|
||||
$filepath .= 'index.html';
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,12 @@ class ProcessBookmark implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
protected Bookmark $bookmark;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Bookmark $bookmark)
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
public function __construct(
|
||||
protected Bookmark $bookmark
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,21 +25,17 @@ class ProcessLike implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/** @var Like */
|
||||
protected $like;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Like $like)
|
||||
{
|
||||
$this->like = $like;
|
||||
public function __construct(
|
||||
protected Like $like
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(Client $client, Authorship $authorship): int
|
||||
|
|
|
@ -20,21 +20,18 @@ class ProcessMedia implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/** @var string */
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(string $filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
public function __construct(
|
||||
protected string $filename
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(ImageManager $manager)
|
||||
public function handle(ImageManager $manager): void
|
||||
{
|
||||
//open file
|
||||
try {
|
||||
|
|
|
@ -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 doesn’t 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 doesn’t so delete
|
||||
$webmention->delete();
|
||||
|
||||
return;
|
||||
} // note we don’t 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 doesn’t 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);
|
||||
}
|
||||
|
|
|
@ -20,25 +20,23 @@ class SaveProfileImage implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
protected array $microformats;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(array $microformats)
|
||||
{
|
||||
$this->microformats = $microformats;
|
||||
public function __construct(
|
||||
protected array $microformats
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(Authorship $authorship)
|
||||
public function handle(Authorship $authorship): void
|
||||
{
|
||||
try {
|
||||
$author = $authorship->findAuthor($this->microformats);
|
||||
} catch (AuthorshipParserException) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
$photo = Arr::get($author, 'properties.photo.0');
|
||||
|
@ -47,8 +45,8 @@ class SaveProfileImage implements ShouldQueue
|
|||
//dont save pbs.twimg.com links
|
||||
if (
|
||||
$photo
|
||||
&& parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com'
|
||||
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com'
|
||||
&& parse_url($photo, PHP_URL_HOST) !== 'pbs.twimg.com'
|
||||
&& parse_url($photo, PHP_URL_HOST) !== 'twitter.com'
|
||||
) {
|
||||
$client = resolve(Client::class);
|
||||
|
||||
|
@ -67,8 +65,8 @@ class SaveProfileImage implements ShouldQueue
|
|||
$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", $image);
|
||||
}
|
||||
|
|
|
@ -18,16 +18,12 @@ class SaveScreenshot implements ShouldQueue
|
|||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
private Bookmark $bookmark;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Bookmark $bookmark)
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
public function __construct(
|
||||
protected Bookmark $bookmark
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,20 +22,17 @@ class SendWebMentions implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
protected Note $note;
|
||||
|
||||
/**
|
||||
* Create the job instance, inject dependencies.
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Note $note)
|
||||
{
|
||||
$this->note = $note;
|
||||
public function __construct(
|
||||
protected Note $note
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(): void
|
||||
|
@ -60,7 +57,6 @@ class SendWebMentions implements ShouldQueue
|
|||
/**
|
||||
* Discover if a URL has a webmention endpoint.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function discoverWebmentionEndpoint(string $url): ?string
|
||||
|
@ -126,8 +122,6 @@ class SendWebMentions implements ShouldQueue
|
|||
|
||||
/**
|
||||
* Resolve a URI if necessary.
|
||||
*
|
||||
* @param string $base The base of the URL
|
||||
*/
|
||||
public function resolveUri(string $url, string $base): string
|
||||
{
|
||||
|
|
|
@ -20,24 +20,20 @@ class SyndicateBookmarkToTwitter implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/** @var Bookmark */
|
||||
protected $bookmark;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Bookmark $bookmark)
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
public function __construct(
|
||||
protected Bookmark $bookmark
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
public function handle(Client $guzzle): void
|
||||
{
|
||||
//send webmention
|
||||
$response = $guzzle->request(
|
||||
|
@ -52,7 +48,7 @@ class SyndicateBookmarkToTwitter implements ShouldQueue
|
|||
]
|
||||
);
|
||||
//parse for syndication URL
|
||||
if ($response->getStatusCode() == 201) {
|
||||
if ($response->getStatusCode() === 201) {
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$syndicates = $this->bookmark->syndicates;
|
||||
$syndicates['twitter'] = $json->url;
|
||||
|
|
|
@ -19,8 +19,6 @@ class SyndicateNoteToMastodon implements ShouldQueue
|
|||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
protected Note $note
|
||||
|
@ -30,7 +28,6 @@ class SyndicateNoteToMastodon implements ShouldQueue
|
|||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(Client $guzzle): void
|
||||
|
|
|
@ -18,15 +18,12 @@ class SyndicateNoteToTwitter implements ShouldQueue
|
|||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/** @var Note */
|
||||
protected $note;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Note $note)
|
||||
{
|
||||
$this->note = $note;
|
||||
public function __construct(
|
||||
protected Note $note
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue