Add autoindexing
This commit is contained in:
35
app/Jobs/PublishIndexPostJob.php
Normal file
35
app/Jobs/PublishIndexPostJob.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Jobs\Tasks\PublishIndexPostTask;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PublishIndexPostJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $ai_tool_id;
|
||||
|
||||
public $timeout = 10;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(int $ai_tool_id)
|
||||
{
|
||||
$this->ai_tool_id = $ai_tool_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
PublishIndexPostTask::handle($this->ai_tool_id);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Tasks;
|
||||
|
||||
use App\Helpers\FirstParty\OSSUploader\OSSUploader;
|
||||
use App\Jobs\PublishIndexPostJob;
|
||||
use App\Models\AiTool;
|
||||
use App\Models\UrlToCrawl;
|
||||
use Exception;
|
||||
@@ -72,7 +73,10 @@ public static function handle($url_to_crawl_id, $ai_tool_id)
|
||||
}
|
||||
|
||||
if ($ai_tool->isDirty()) {
|
||||
$ai_tool->save();
|
||||
if($ai_tool->save())
|
||||
{
|
||||
PublishIndexPostJob::dispatch($ai_tool->id)->onQueue('default')->onConnection('default');
|
||||
}
|
||||
}
|
||||
|
||||
return $ai_tool;
|
||||
|
||||
46
app/Jobs/Tasks/PublishIndexPostTask.php
Normal file
46
app/Jobs/Tasks/PublishIndexPostTask.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Tasks;
|
||||
|
||||
use App\Models\AiTool;
|
||||
use App\Notifications\PostWasPublished;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
|
||||
use LaravelGoogleIndexing;
|
||||
|
||||
class PublishIndexPostTask
|
||||
{
|
||||
public static function handle(int $ai_tool_id)
|
||||
{
|
||||
$ai_tool = AiTool::find($ai_tool_id);
|
||||
|
||||
if (is_null($ai_tool)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$ai_tool->is_ai_tool)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((app()->environment() == 'production') && (config('platform.general.indexing'))) {
|
||||
$ai_tool_url = route('front.aitool.show', ['ai_tool_slug' => $ai_tool->slug]);
|
||||
|
||||
try {
|
||||
IndexNow::submit($post_url);
|
||||
} catch (Exception) {
|
||||
}
|
||||
|
||||
try {
|
||||
LaravelGoogleIndexing::create()->update($post_url);
|
||||
} catch (Exception) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user