-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from Kovah/dev
Release
- Loading branch information
Showing
67 changed files
with
508 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Helper\HtmlMeta; | ||
use App\Models\Link; | ||
use Illuminate\Console\Command; | ||
|
||
class UpdateLinkThumbnails extends Command | ||
{ | ||
protected $signature = 'links:update-thumbnails'; | ||
|
||
protected $description = 'Updates the thumbnails for all existing links, done in batches.'; | ||
|
||
public function handle() | ||
{ | ||
$this->confirm('This command updates the thumbnail for all links with the status "ok". This can take a long time, depending on the amount of links you have saved. Do you want to proceed?'); | ||
|
||
$totalCount = Link::where('status', Link::STATUS_OK)->count(); | ||
$processedLinks = 0; | ||
|
||
if ($totalCount === 0) { | ||
$this->warn('No links with status "ok" found. Aborting'); | ||
} | ||
|
||
$this->comment("Started processing of $totalCount links..."); | ||
|
||
Link::where('status', Link::STATUS_OK)->latest() | ||
->chunk(100, function ($links) use ($processedLinks, $totalCount) { | ||
foreach ($links as $link) { | ||
$this->updateThumbnailForLink($link); | ||
sleep(1); // Rate limiting of outgoing traffic | ||
} | ||
|
||
$processedLinks += count($links); | ||
$this->comment("Processed $processedLinks of $totalCount links."); | ||
}); | ||
|
||
$this->info('Finished processing all links.'); | ||
} | ||
|
||
protected function updateThumbnailForLink(Link $link): void | ||
{ | ||
$meta = (new HtmlMeta)->getFromUrl($link->url); | ||
|
||
if ($meta['thumbnail'] !== null) { | ||
$link->thumbnail = $meta['thumbnail']; | ||
$link->save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.