| @@ -11,18 +11,29 @@ | ||
| 11 | 11 | use Templately\Core\Importer\Utils\Utils; |
| 12 | 12 | |
| 13 | 13 | abstract class BaseRunner { |
| 14 | 14 | use LogHelper; |
| 15 | + use Loop; | |
| 15 | 16 | |
| 16 | 17 | const META_SESSION_KEY = '_templately_import_session_id'; |
| 17 | 18 | /** |
| 18 | 19 | * @var FullSiteImport |
| 19 | 20 | */ |
| 21 | + protected $dev_mode; | |
| 20 | 22 | protected $origin; |
| 21 | 23 | protected $platform; |
| 22 | 24 | protected $manifest; |
| 25 | + protected $prv_dir; | |
| 23 | 26 | protected $dir_path; |
| 24 | 27 | protected $session_id; |
| 28 | + /** | |
| 29 | + * @var array|mixed | |
| 30 | + */ | |
| 31 | + public $ai_page_ids = []; | |
| 32 | + /** | |
| 33 | + * @var string|null | |
| 34 | + */ | |
| 35 | + public $process_id = null; | |
| 25 | 36 | |
| 26 | 37 | /** |
| 27 | 38 | * @var ImportHelper |
| 28 | 39 | */ |
| @@ -35,19 +46,25 @@ | ||
| 35 | 46 | |
| 36 | 47 | /** |
| 37 | 48 | * @throws Exception |
| 38 | 49 | */ |
| 39 | - public function __construct( FullSiteImport $full_site_import ) { | |
| 40 | - $this->origin = $full_site_import; | |
| 41 | - $this->dir_path = $full_site_import->dir_path; | |
| 42 | - $this->manifest = &$full_site_import->manifest; | |
| 43 | - $this->platform = $this->manifest['platform'] ?? ''; | |
| 44 | - $this->session_id = $full_site_import->session_id; | |
| 50 | + public function __construct( $request_params ) { | |
| 51 | + $this->dev_mode = defined('TEMPLATELY_DEV') && TEMPLATELY_DEV; | |
| 52 | + $this->origin = $request_params['origin']; | |
| 53 | + $this->prv_dir = $request_params['prv_dir']; | |
| 54 | + $this->dir_path = $request_params['dir_path']; | |
| 55 | + $this->manifest = &$request_params['manifest']; | |
| 56 | + $this->platform = $this->manifest['platform'] ?? ''; | |
| 57 | + $this->session_id = $request_params['session_id']; | |
| 45 | 58 | |
| 46 | 59 | |
| 47 | 60 | $this->factory = new TemplateFactory( $this->platform ); |
| 48 | 61 | $this->json = Utils::get_json_helper( $this->platform ); |
| 62 | + $this->json->session_id = $this->session_id; | |
| 49 | 63 | |
| 64 | + $this->ai_page_ids = $request_params['ai_page_ids'] ?? []; | |
| 65 | + $this->process_id = $request_params['process_id'] ?? null; | |
| 66 | + | |
| 50 | 67 | if ( empty( $this->platform ) ) { |
| 51 | 68 | throw new Exception( __( 'Platform is not specified. Please try again after specifying the platform.', 'templately' ) ); |
| 52 | 69 | } |
| 53 | 70 | } |
| @@ -83,6 +100,31 @@ | ||
| 83 | 100 | $action = $this->get_action(); |
| 84 | 101 | } |
| 85 | 102 | |
| 86 | 103 | $this->sse_log( $this->get_name(), $message, min( $progress, 100 ), $action ); |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * @throws Exception | |
| 108 | + */ | |
| 109 | + protected function throw($message, $code = 0) { | |
| 110 | + if ($this->dev_mode) { | |
| 111 | + error_log(print_r($message, 1)); | |
| 112 | + } | |
| 113 | + throw new Exception($message); | |
| 114 | + } | |
| 115 | + | |
| 116 | + protected function is_ai_content($old_template_id ): bool { | |
| 117 | + if(empty($this->process_id) || empty($this->ai_page_ids) || !is_array($this->ai_page_ids)){ | |
| 118 | + return false; | |
| 119 | + } | |
| 120 | + // Get array of AI page IDs, filtering out any non-numeric values | |
| 121 | + $ai_page_ids = array_reduce($this->ai_page_ids, 'array_merge', array()); | |
| 122 | + // $ai_page_ids = array_filter( | |
| 123 | + // array_map('intval', explode(',', $this->ai_page_ids ?? '')) | |
| 124 | + // ); | |
| 125 | + | |
| 126 | + $is_ai_content = in_array($old_template_id, $ai_page_ids); | |
| 127 | + | |
| 128 | + return $is_ai_content; | |
| 87 | 129 | } |
| 88 | 130 | } |