static function import($batch_code)
 {
     $batches = get_option('woocsv_batches');
     //check if the batch exists
     if (!isset($batches[$batch_code])) {
         return;
     }
     //it exists!!! lets continue;
     $batch = $batches[$batch_code];
     //see if we can influence the time limit
     //@TODO make an auto function to import as many rows as possible
     $max_execution_time_original = ini_get('max_execution_time');
     set_time_limit(0);
     $max_execution_time_new = ini_get('max_execution_time');
     $block_size = 1;
     //make sure if the row is set
     if (!isset($batch['row'])) {
         $batch['row'] = 0;
     }
     //start
     if ($batch['row'] == 0) {
         woocsv_batches::update($post_data, 'processing row');
     }
 }
 public function die_nicer($batch_code, $batch)
 {
     global $woocsv_product;
     //turn stuff back on again
     if (function_exists('wp_suspend_cache_invalidation')) {
         wp_suspend_cache_invalidation(false);
     }
     if (function_exists('wp_defer_term_counting ')) {
         wp_defer_term_counting(false);
     }
     //are we done?
     if ($batch['status'] == 'done') {
         $post_data['done'] = 1;
     } else {
         $post_data['batch_code'] = $batch_code;
         $post_data['status'] = 0;
     }
     woocsv_batches::update($batch_code, $batch);
     //=============================
     // Check if we need to debug
     //=============================
     if ($this->get_debug() == 0) {
         ob_get_clean();
     }
     $post_data['batch'] = $batch;
     echo json_encode($post_data);
     unset($post_data);
     wp_die();
 }
 public function import()
 {
     global $woocsv_import;
     //what page to load?
     /* ! HEADER */
     if (isset($_FILES['csvfile']) && $_FILES['csvfile']['error'] != 0) {
         echo '<div class="error"><p>';
         echo __('Something went wrong during the file upload, make sure the file is not to big!', 'woocommerce-csvimport');
         echo '</p></div>';
     }
     //save header
     if (isset($_POST['action']) && $_POST['action'] === 'save_header_preview' && check_admin_referer('save_header_preview', 'save_header_preview')) {
         $this->save_header();
         include dirname(__FILE__) . '/partials/woocsv-import-admin-header.php';
         return;
     }
     //preview the header
     if (isset($_POST['action']) && $_POST['action'] === 'start_header_preview' && @is_uploaded_file($_FILES['csvfile']['tmp_name']) && check_admin_referer('upload_header_file', 'upload_header_file')) {
         include dirname(__FILE__) . '/partials/woocsv-import-admin-header-preview.php';
         return;
     }
     //header page
     if (isset($_GET['page'], $_GET['tab']) && $_GET['page'] == 'woocsv_import' && $_GET['tab'] == 'headers' || empty($woocsv_import->headers)) {
         include dirname(__FILE__) . '/partials/woocsv-import-admin-header.php';
         return;
     }
     /* ! IMPORT */
     //preview the import
     if (isset($_POST['action']) && $_POST['action'] === 'start_import_preview' && @is_uploaded_file($_FILES['csvfile']['tmp_name']) && check_admin_referer('upload_import_file', 'upload_import_file')) {
         //			@since 3.1.0
         //@todo create batch allready!
         //set the active header
         $header = $woocsv_import->headers[$_POST['header_name']];
         $header_name = $_POST['header_name'];
         update_option('woocsv_header', $woocsv_import->headers[$_POST['header_name']]);
         $woocsv_import->header = $header;
         include dirname(__FILE__) . '/partials/woocsv-import-admin-import-preview.php';
         return;
     }
     //we are creating a batch
     if (isset($_POST['action']) && $_POST['action'] === 'create_batch' && check_admin_referer('create_batch', 'create_batch')) {
         //create a new batch
         $new_batch_code = woocsv_batches::create();
         if ($new_batch_code) {
             $data = array('filename' => $_POST['filename'], 'row' => 0, 'header_name' => $_POST['header_name'], 'speperator' => $_POST['seperator'], 'total_rows' => $_POST['total_rows']);
             woocsv_batches::update($new_batch_code, $data);
         }
     }
     //else just load the regular import screen
     include dirname(__FILE__) . '/partials/woocsv-import-admin-import.php';
 }