コード例 #1
0
function wiziapp_batch_process_pages()
{
    $GLOBALS['WiziappLog']->write('info', "Got a request to process pages as a batch: " . print_r($_POST, TRUE), "post_install.wiziapp_batch_process_pages");
    global $wpdb;
    $status = TRUE;
    $message = '';
    if (!isset($_POST['pages'])) {
        $status = FALSE;
        $message = 'incorrect usage';
    } else {
        ob_start();
        ini_set('display_errors', 0);
        register_shutdown_function('wiziappBatchShutdown');
        $pagesIds = explode(',', $_POST['pages']);
        foreach ($pagesIds as $id) {
            $GLOBALS['WiziappLog']->write('info', "Processing page: {$id} inside the batch", "post_install.wiziapp_batch_process_pages");
            $GLOBALS['wiziapp_page'] = $id;
            wiziapp_save_page($id);
            $GLOBALS['WiziappLog']->write('info', "Finished processing page: {$id} inside the batch", "post_install.wiziapp_batch_process_pages");
        }
    }
    $header = array('action' => 'batch_process_posts', 'status' => $status, 'code' => $status ? 200 : 500, 'message' => $message);
    $GLOBALS['WiziappLog']->write('debug', "Finished processing the requested page batch:" . print_r($_POST['pages'], TRUE) . ", going to return: " . print_r($header, TRUE), "post_install.wiziapp_batch_process_pages");
    echo json_encode(array('header' => $header));
    exit;
}
コード例 #2
0
/**
* Called from the install method, to install the base content
* that will be used at first for the simulator and for building the cms
* profile
* 
* After the initial processing the user will be able to trigger the processing
* via his plugin control panel or when a post is requested for the first time
*/
function wiziapp_generate_latest_content()
{
    global $wpdb;
    $done = false;
    $GLOBALS['WiziappLog']->write('info', "Parsing the latest content", "content");
    // Parse the latest posts
    $number_recents_posts = WiziappConfig::getInstance()->post_processing_batch_size;
    $recent_posts = wp_get_recent_posts($number_recents_posts);
    $last_post = -1;
    foreach ($recent_posts as $post) {
        $post_id = $post['ID'];
        $GLOBALS['WiziappLog']->write('info', "Processing post: {$post_id}", 'content.wiziapp_generate_latest_content');
        wiziapp_save_post($post_id);
        $last_post = $post_id;
    }
    $GLOBALS['WiziappLog']->write('info', "Processing all pages", 'content');
    $pages = get_all_page_ids();
    for ($p = 0, $total = count($pages); $p < $total; ++$p) {
        wiziapp_save_page($pages[$p]);
    }
    // Save the fact that we processed  $number_recents_posts and if the number of posts
    // in the blog is bigger, we need to continue
    $numposts = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'publish'");
    if ($numposts <= $number_recents_posts) {
        $last_post = -1;
    }
    add_option("wiziapp_last_processed", $last_post);
    $GLOBALS['WiziappLog']->write('info', "Finished parsing initial content", 'content');
    return $done;
}