- Implementation of a first version of a Wordpress plugin - Adding api service to nginx.conf
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
class EveAI_Bulk_Sync {
|
|
private $api;
|
|
private $post_handler;
|
|
|
|
public function __construct($api, $post_handler) {
|
|
$this->api = $api;
|
|
$this->post_handler = $post_handler;
|
|
}
|
|
|
|
public function init_bulk_sync() {
|
|
$posts = get_posts(array(
|
|
'post_type' => array('post', 'page'),
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => -1,
|
|
));
|
|
|
|
$sync_results = array();
|
|
|
|
foreach ($posts as $post) {
|
|
$evie_id = get_post_meta($post->ID, '_eveai_document_id', true);
|
|
$evie_version_id = get_post_meta($post->ID, '_eveai_document_version_id', true);
|
|
$is_update = ($evie_id && $evie_version_id);
|
|
|
|
$result = $this->post_handler->sync_post($post->ID, $is_update);
|
|
$sync_results[] = array(
|
|
'id' => $post->ID,
|
|
'title' => $post->post_title,
|
|
'type' => $post->post_type,
|
|
'status' => $result ? 'success' : 'failed'
|
|
);
|
|
}
|
|
|
|
return $sync_results;
|
|
}
|
|
} |