/**
  * Create new posts/pages
  * 
  * @author Ryan R. Bayne
  * @package CSV 2 POST
  * @since 8.1.33
  * @version 1.0.2
  * 
  * @param mixed $project_id
  * @param mixed $total - apply a limit for this import (global settings can offer a default limit suitable for server also)
  * @param mixed $row_ids - only use if creating posts using specific row ID's 
  */
 public function create_posts($project_id, $total = 1)
 {
     global $csv2post_settings;
     $autoblog = new CSV2POST_InsertPost();
     $autoblog->settings = $csv2post_settings;
     $autoblog->currentproject = $csv2post_settings['currentproject'];
     $autoblog->project = $this->get_project($project_id);
     // gets project row, includes sources and settings
     $autoblog->projectid = $project_id;
     $autoblog->maintable = self::get_project_main_table($project_id);
     // main table holds post_id and progress statistics
     $autoblog->projectsettings = maybe_unserialize($autoblog->project->projectsettings);
     // unserialize settings
     $autoblog->projectcolumns = $this->get_project_columns_from_db($project_id);
     $autoblog->requestmethod = 'manual';
     $sourceid_array = self::get_project_sourcesid($project_id);
     $autoblog->mainsourceid = $sourceid_array[0];
     // update the main source database table per post with new post ID
     unset($autoblog->project->projectsettings);
     // just simplifying the project object by removing the project settings
     $idcolumn = false;
     if (isset($autoblog->projectsettings['idcolumn'])) {
         $idcolumn = $autoblog->projectsettings['idcolumn'];
     }
     // get rows not used to create posts
     $unused_rows = $this->get_unused_rows($project_id, $total, $idcolumn);
     if (!$unused_rows) {
         $this->UI->create_notice(__('You have used all imported rows to create posts. Please ensure you have imported all of your data if you expected more posts than CSV 2 POST has already created.'), 'info', 'Small', 'No Rows Available');
         return;
     }
     // we will control how and when we end the operation
     $autoblog->finished = false;
     // when true, output will be complete and foreach below will discontinue, this can be happen if maximum execution time is reached
     $foreach_done = 0;
     foreach ($unused_rows as $key => $row) {
         ++$foreach_done;
         // to get the output at the end, tell the class we are on the final post, only required in "manual" requestmethod
         if ($foreach_done == $total) {
             $autoblog->finished = true;
             // not completely finished, indicates this is the last post
         }
         // pass row to $autob
         $autoblog->row = $row;
         // create a post - start method is the beginning of many nested functions
         $autoblog->start();
     }
     // log
     $atts = array('outcome' => 1, 'line' => __LINE__, 'function' => __FUNCTION__, 'file' => __FILE__, 'userid' => get_current_user_id(), 'type' => 'general', 'category' => 'postsevent', 'action' => __("Up to {$foreach_done} posts may have been created.", 'csv2post'), 'priority' => 'normal', 'triga' => 'manualrequest');
     self::newlog($atts);
 }
 /**
  * Locates imported records that have a post ID but the post no longer exists.
  * 
  * A count is done and optional re-creation of posts available.
  * 
  * @author Ryan R. Bayne
  * @package CSV 2 POST
  * @since 8.1.33
  * @version 1.1
  */
 public function recreatemissingposts()
 {
     global $csv2post_settings;
     $table_name = $this->CSV2POST->get_project_main_table($csv2post_settings['currentproject']);
     $select = 'c2p_rowid, c2p_postid';
     $missing_posts = 0;
     // count re-creations
     $recreated = 0;
     // get all rows that have a c2p_postid
     $result = $this->DB->selectwherearray($table_name, 'c2p_postid != ""', 'c2p_rowid', $select, ARRAY_A);
     if ($result) {
         $autoblog = new CSV2POST_InsertPost();
         $autoblog->settings = $csv2post_settings;
         $autoblog->currentproject = $csv2post_settings['currentproject'];
         $autoblog->project = $this->CSV2POST->get_project($csv2post_settings['currentproject']);
         // gets project row, includes sources and settings
         $autoblog->projectid = $csv2post_settings['currentproject'];
         $autoblog->maintable = $this->CSV2POST->get_project_main_table($csv2post_settings['currentproject']);
         // main table holds post_id and progress statistics
         $autoblog->projectsettings = maybe_unserialize($autoblog->project->projectsettings);
         // unserialize settings
         $autoblog->projectcolumns = $this->CSV2POST->get_project_columns_from_db($csv2post_settings['currentproject']);
         $autoblog->requestmethod = 'manual';
         $sourceid_array = $this->CSV2POST->get_project_sourcesid($csv2post_settings['currentproject']);
         $autoblog->mainsourceid = $sourceid_array[0];
         // update the main source database table per post with new post ID
         unset($autoblog->project->projectsettings);
         // just simplifying the project object by removing the project settings
         $idcolumn = false;
         if (isset($autoblog->projectsettings['idcolumn'])) {
             $idcolumn = $autoblog->projectsettings['idcolumn'];
         }
         // we will control how and when we end the operation
         $autoblog->finished = false;
         // when true, output will be complete and foreach below will discontinue, this can be happen if maximum execution time is reached
         foreach ($result as $key => $row) {
             $get_post_result = get_post($row['c2p_postid']);
             // create missing post
             if (!$get_post_result) {
                 ++$missing_posts;
                 if (isset($_POST['recreatemissingposts'])) {
                     // pass row to $autob
                     $autoblog->row = $row;
                     // create a post - start method is the beginning of many nested functions
                     $autoblog->start();
                     ++$recreated;
                 }
             }
         }
     }
     if ($missing_posts === 0) {
         $this->UI->create_notice(__('You do not have any missing posts, no changes were made to your blog. If you feel posts are missing, please ensure they are not in the WordPress trash.'), 'info', 'Small', __('No Missing Posts', 'csv2post'));
     } elseif ($recreated > 0) {
         $this->UI->create_notice(__("A total of {$recreated} posts were missing and have been re-created."), 'info', 'Small', __('No Rows Available', 'csv2post'));
     } elseif ($missing_posts > 0 && !isset($_POST['recreatemissingposts'])) {
         $this->UI->create_notice(__("A total of {$missing_posts} posts appear to be missing but do not worry if you still have your data WTG has made it easy to fix such problems."), 'info', 'Small', __('Posts Missing', 'csv2post'));
     }
 }