diff --git a/app/Jobs/BrowseSingleRSSJob.php b/app/Jobs/BrowseSingleRSSJob.php index b18007f..5ca4050 100644 --- a/app/Jobs/BrowseSingleRSSJob.php +++ b/app/Jobs/BrowseSingleRSSJob.php @@ -43,6 +43,7 @@ public function handle(): void if (is_null($rss_post)) { $rss_post = new RssPost; $rss_post->post_url = $raw_post->link; + $rss_post->post_domain = get_domain_from_url($raw_post->link); $rss_post->source = $raw_post->source; $rss_post->source_url = $raw_post->source_url; $rss_post->title = remove_newline($raw_post->title); diff --git a/app/Models/RssPost.php b/app/Models/RssPost.php index e828769..48ce65d 100644 --- a/app/Models/RssPost.php +++ b/app/Models/RssPost.php @@ -54,6 +54,7 @@ class RssPost extends Model implements Feedable 'source', 'source_url', 'post_url', + 'post_domain', 'title', 'slug', 'body', diff --git a/database/migrations/2023_11_23_132623_add_domain_to_rss_posts_table.php b/database/migrations/2023_11_23_132623_add_domain_to_rss_posts_table.php new file mode 100644 index 0000000..ea626d1 --- /dev/null +++ b/database/migrations/2023_11_23_132623_add_domain_to_rss_posts_table.php @@ -0,0 +1,28 @@ +string('post_domain')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('rss_posts', function (Blueprint $table) { + $table->dropColumn('post_domain'); + }); + } +}; diff --git a/routes/tests.php b/routes/tests.php index 175d982..e0fb71c 100644 --- a/routes/tests.php +++ b/routes/tests.php @@ -53,6 +53,23 @@ Route::get('/crawlTask', [App\Http\Controllers\Tests\TestController::class, 'crawlTask']); +Route::get('/set_domain', function (Request $request) { + + $last_record = RssPost::whereNull('post_domain')->orderBy('id', 'DESC')->first(); + + for ($i = 1; $i <= $last_record->id; $i++) { + $rss_post = RssPost::find($i); + + if (!is_null($rss_post)) + { + $rss_post->post_domain = get_domain_from_url($rss_post->post_url); + $rss_post->save(); + } + } + + return 'ok'; +}); + Route::get('/set_keywords', function (Request $request) { $last_record = RssPost::where('keyword_saved', false)->orderBy('id', 'DESC')->first();