Add (ui)
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
use App\Helpers\FirstParty\OpenAI\OpenAI;
|
||||
use App\Helpers\FirstParty\OSSUploader\OSSUploader;
|
||||
use App\Jobs\SchedulePublishPost;
|
||||
use App\Models\Entity;
|
||||
use App\Models\PostEntity;
|
||||
use App\Models\Category;
|
||||
use App\Models\Entity;
|
||||
use App\Models\Post;
|
||||
use App\Models\PostCategory;
|
||||
use App\Models\PostEntity;
|
||||
use App\Models\SerpUrlResearch;
|
||||
use App\Models\ServiceCostUsage;
|
||||
use Exception;
|
||||
@@ -78,100 +78,84 @@ public static function handle(int $post_id)
|
||||
$post = self::setPostImage($post);
|
||||
}
|
||||
|
||||
if (isset($post_meta_response->output->society_impact))
|
||||
{
|
||||
if (!is_empty($post_meta_response->output->society_impact))
|
||||
{
|
||||
$post->society_impact = $post_meta_response->output->society_impact;
|
||||
}
|
||||
if (isset($post_meta_response->output->society_impact)) {
|
||||
if (! is_empty($post_meta_response->output->society_impact)) {
|
||||
$post->society_impact = $post_meta_response->output->society_impact;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($post_meta_response->output->society_impact_level))
|
||||
{
|
||||
if (!is_empty($post_meta_response->output->society_impact_level))
|
||||
{
|
||||
$post->society_impact = $post_meta_response->output->society_impact_level;
|
||||
}
|
||||
if (isset($post_meta_response->output->society_impact_level)) {
|
||||
if (! is_empty($post_meta_response->output->society_impact_level)) {
|
||||
$post->society_impact = $post_meta_response->output->society_impact_level;
|
||||
}
|
||||
}
|
||||
|
||||
if ($post->save()) {
|
||||
|
||||
|
||||
// Set Category
|
||||
// Set Category
|
||||
|
||||
$category_name = 'Updates';
|
||||
$category_name = 'Updates';
|
||||
|
||||
if ((isset($post_meta_response->output->category)) && (!is_empty($post_meta_response->output->category)))
|
||||
{
|
||||
$category_name = $post_meta_response?->output?->category;
|
||||
}
|
||||
|
||||
$category = Category::where('name', $category_name)->first();
|
||||
|
||||
if (is_null($category))
|
||||
{
|
||||
$category = Category::where('name', 'Updates')->first();
|
||||
}
|
||||
|
||||
// Set Post Category
|
||||
$post_category = PostCategory::where('post_id', $post->id)->first();
|
||||
|
||||
if (is_null($post_category))
|
||||
{
|
||||
$post_category = new PostCategory;
|
||||
$post_category->post_id = $post->id;
|
||||
}
|
||||
$post_category->category_id = $category->id;
|
||||
|
||||
$post_category->save();
|
||||
|
||||
|
||||
// Set Post Entities
|
||||
if (isset($post_meta_response->output->entities))
|
||||
{
|
||||
$entity_names = [];
|
||||
|
||||
if (is_array($post_meta_response->output->entities))
|
||||
{
|
||||
$entity_names = $post_meta_response->output->entities;
|
||||
if ((isset($post_meta_response->output->category)) && (! is_empty($post_meta_response->output->category))) {
|
||||
$category_name = $post_meta_response?->output?->category;
|
||||
}
|
||||
|
||||
if (count($entity_names) > 0)
|
||||
{
|
||||
$previous_post_entities = PostEntity::where('post_id', $post->id)->delete();
|
||||
$category = Category::where('name', $category_name)->first();
|
||||
|
||||
foreach ($entity_names as $entity_name)
|
||||
{
|
||||
$entity_name = trim($entity_name);
|
||||
|
||||
$entity = Entity::where('name', $entity_name)->first();
|
||||
|
||||
if (is_null($entity))
|
||||
{
|
||||
$entity = new Entity;
|
||||
$entity->name = $entity_name;
|
||||
$entity->slug = str_slug($entity_name);
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
|
||||
$post_entity = PostEntity::where('post_id', $post->id)
|
||||
->where('entity_id', $entity->id)
|
||||
->first();
|
||||
|
||||
if (is_null($post_entity))
|
||||
{
|
||||
$post_entity = new PostEntity;
|
||||
$post_entity->post_id = $post->id;
|
||||
$post_entity->entity_id = $entity->id;
|
||||
$post_entity->save();
|
||||
}
|
||||
}
|
||||
if (is_null($category)) {
|
||||
$category = Category::where('name', 'Updates')->first();
|
||||
}
|
||||
}
|
||||
|
||||
// Set Schedule Publish
|
||||
SchedulePublishPost::dispatch($post->id, 'future')->onQueue('default')->onConnection('default');
|
||||
// Set Post Category
|
||||
$post_category = PostCategory::where('post_id', $post->id)->first();
|
||||
|
||||
if (is_null($post_category)) {
|
||||
$post_category = new PostCategory;
|
||||
$post_category->post_id = $post->id;
|
||||
}
|
||||
$post_category->category_id = $category->id;
|
||||
|
||||
$post_category->save();
|
||||
|
||||
// Set Post Entities
|
||||
if (isset($post_meta_response->output->entities)) {
|
||||
$entity_names = [];
|
||||
|
||||
if (is_array($post_meta_response->output->entities)) {
|
||||
$entity_names = $post_meta_response->output->entities;
|
||||
}
|
||||
|
||||
if (count($entity_names) > 0) {
|
||||
$previous_post_entities = PostEntity::where('post_id', $post->id)->delete();
|
||||
|
||||
foreach ($entity_names as $entity_name) {
|
||||
$entity_name = trim($entity_name);
|
||||
|
||||
$entity = Entity::where('name', $entity_name)->first();
|
||||
|
||||
if (is_null($entity)) {
|
||||
$entity = new Entity;
|
||||
$entity->name = $entity_name;
|
||||
$entity->slug = str_slug($entity_name);
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
$post_entity = PostEntity::where('post_id', $post->id)
|
||||
->where('entity_id', $entity->id)
|
||||
->first();
|
||||
|
||||
if (is_null($post_entity)) {
|
||||
$post_entity = new PostEntity;
|
||||
$post_entity->post_id = $post->id;
|
||||
$post_entity->entity_id = $entity->id;
|
||||
$post_entity->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set Schedule Publish
|
||||
SchedulePublishPost::dispatch($post->id, 'future')->onQueue('default')->onConnection('default');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ public static function handle(int $post_id)
|
||||
{
|
||||
$post = Post::find($post_id);
|
||||
|
||||
if (is_null($post))
|
||||
{
|
||||
return ;
|
||||
if (is_null($post)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post->status = 'publish';
|
||||
|
||||
Reference in New Issue
Block a user