| 1 |
<?php |
| 2 |
/** |
| 3 |
* Batch Processing |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! class_exists( 'CartFlows_Batch_Process' ) ) : |
| 10 |
|
| 11 |
/** |
| 12 |
* CartFlows_Batch_Process |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class CartFlows_Batch_Process { |
| 17 |
|
| 18 |
/** |
| 19 |
* Instance |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
* @var object Class object. |
| 23 |
* @access private |
| 24 |
*/ |
| 25 |
private static $instance; |
| 26 |
|
| 27 |
/** |
| 28 |
* Process All |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @var object Class object. |
| 32 |
* @access public |
| 33 |
*/ |
| 34 |
public static $process_all; |
| 35 |
|
| 36 |
/** |
| 37 |
* Initiator |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* @return object initialized object of class. |
| 41 |
*/ |
| 42 |
public static function get_instance() { |
| 43 |
if ( ! isset( self::$instance ) ) { |
| 44 |
self::$instance = new self; |
| 45 |
} |
| 46 |
return self::$instance; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Constructor |
| 51 |
* |
| 52 |
* @since 1.0.0 |
| 53 |
*/ |
| 54 |
public function __construct() { |
| 55 |
|
| 56 |
// If plugin - 'Elementor' not exist then return. |
| 57 |
if ( class_exists( '\Elementor\Plugin' ) ) { |
| 58 |
|
| 59 |
// Core Helpers - Image. |
| 60 |
// @todo This file is required for Elementor. |
| 61 |
// Once we implement our logic for updating elementor data then we'll delete this file. |
| 62 |
require_once ABSPATH . 'wp-admin/includes/image.php'; |
| 63 |
|
| 64 |
// Core Helpers - Batch Processing. |
| 65 |
require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php'; |
| 66 |
require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php'; |
| 67 |
|
| 68 |
// Page Builder. |
| 69 |
require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-batch-process-elementor.php'; |
| 70 |
require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php'; |
| 71 |
|
| 72 |
self::$process_all = new CartFlows_Batch_Process_Elementor(); |
| 73 |
|
| 74 |
// Start image importing after site import complete. |
| 75 |
add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) ); |
| 76 |
add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) ); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Batch Process Complete. |
| 82 |
* |
| 83 |
* @return void |
| 84 |
*/ |
| 85 |
public function complete_batch_import() { |
| 86 |
wcf()->logger->import_log( '(✓) BATCH Process Complete!' ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Start Image Import |
| 91 |
* |
| 92 |
* @param integer $post_id Post Id. |
| 93 |
* |
| 94 |
* @return void |
| 95 |
*/ |
| 96 |
public function start_batch_process( $post_id = '' ) { |
| 97 |
|
| 98 |
wcf()->logger->import_log( '(✓) BATCH Started!' ); |
| 99 |
wcf()->logger->import_log( '(✓) Step ID ' . $post_id ); |
| 100 |
|
| 101 |
// Add "elementor" in import [queue]. |
| 102 |
// @todo Remove required `allow_url_fopen` support. |
| 103 |
if ( ini_get( 'allow_url_fopen' ) ) { |
| 104 |
if ( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 105 |
|
| 106 |
self::$process_all->push_to_queue( $post_id ); |
| 107 |
|
| 108 |
// Dispatch Queue. |
| 109 |
self::$process_all->save()->dispatch(); |
| 110 |
|
| 111 |
wcf()->logger->import_log( '(✓) Dispatch Request..' ); |
| 112 |
} |
| 113 |
} else { |
| 114 |
wcf()->logger->import_log( '(✕) Couldn\'t not import image due to allow_url_fopen() is disabled!' ); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Kicking this off by calling 'get_instance()' method |
| 122 |
*/ |
| 123 |
CartFlows_Batch_Process::get_instance(); |
| 124 |
|
| 125 |
endif; |
| 126 |
|