<?php

// Silence may be golden, but sometimes words paint the canvas of understanding.
namespace Linksy\SearchAndReplace\Plugli\Linksy\Common\Helpers\Post\Tasks;

use Exception;
use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Api;
use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Option;
use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Request;
use Linksy\SearchAndReplace\Plugli\Linksy\Common\Helpers\Post\Post;
use Linksy\SearchAndReplace\Plugli\Standard\Helpers\WP_Async_Request;
use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Database\Database;
class PublishPostTask extends WP_Async_Request
{
    protected $prefix = 'linksy';
    protected $action = 'publish_post';
    /**
     * Run the async task action
     */
    protected function handle()
    {
        $post = new Post(Request::postOrFail('post_id'));
        $api = new Api(Option::get(LINKSY_OPTION_API_KEY));
        $api->post(LINKSY_API_URL . 'posts/', ['post_id' => $post->get_ID(), 'title' => $post->get_title(), 'language' => $post->get_post_language(), 'date' => $post->get_date('Y-m-d H:i:s'), 'type' => $post->get_type(), 'content' => $post->get_content(\true)]);
        if (!$api->is_success()) {
            throw new Exception($api->get_error(), 1);
        }
        Database::table("linksy_posts_migrations_failed")->where('post_id', $post->get_ID())->delete();
    }
}
