| @@ -48,14 +48,12 @@ | ||
| 48 | 48 | |
| 49 | 49 | foreach ( $this->type_to_check as $type ) { |
| 50 | 50 | $contents = ! empty ( $this->manifest[ $type ] ) ? $this->manifest[ $type ] : []; |
| 51 | 51 | if ( $type == 'templates' ) { |
| 52 | - // $imported_data["templates"]["__attachments"][691] | |
| 53 | - $this->prepare( $data, $contents, $type, null, $imported_data ); | |
| 52 | + $this->prepare( $data, $contents, $type ); | |
| 54 | 53 | } else { |
| 55 | 54 | foreach ( $contents as $post_type => $templates ) { |
| 56 | - // $imported_data["content"]["__attachments"][$post_type][11] | |
| 57 | - $this->prepare( $data, $templates, $type, $post_type, $imported_data ); | |
| 55 | + $this->prepare( $data, $templates, $type, $post_type ); | |
| 58 | 56 | } |
| 59 | 57 | } |
| 60 | 58 | } |
| 61 | 59 | $this->options = &$data; |
| @@ -62,27 +60,14 @@ | ||
| 62 | 60 | |
| 63 | 61 | return ! empty( $data ) || $this->platform == 'gutenberg'; |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | - private function prepare( &$data, $templates, $type, $sub_type = null, $imported_data = [] ) { | |
| 64 | + private function prepare( &$data, $templates, $type, $sub_type = null ) { | |
| 67 | 65 | if ( empty( $templates ) || ! is_array( $templates ) ) { |
| 68 | 66 | return; |
| 69 | 67 | } |
| 70 | 68 | foreach ( $templates as $id => $template ) { |
| 71 | - // Check for __attachments in both template and imported_data | |
| 72 | - $has_attachment = !empty($template['__attachments']); | |
| 73 | - | |
| 74 | - if (!$has_attachment && !empty($imported_data)) { | |
| 75 | - if ($sub_type) { | |
| 76 | - // $imported_data["content"]["__attachments"]["page"][11] | |
| 77 | - $has_attachment = isset($imported_data[$type]['__attachments'][$sub_type][$id]); | |
| 78 | - } else { | |
| 79 | - // $imported_data["templates"]["__attachments"][691] | |
| 80 | - $has_attachment = isset($imported_data[$type]['__attachments'][$id]); | |
| 81 | - } | |
| 82 | - } | |
| 83 | - | |
| 84 | - if ( ! isset( $template['data'] ) && !$has_attachment && !isset($template['has_logo']) && !$this->is_ai_content($id) && !isset($template["page_settings"]["fluent_cart_store_settings"]) ) { | |
| 69 | + if ( ! isset( $template['data'] ) && !isset( $template['__attachments']) && !isset($template['has_logo']) && !$this->is_ai_content($id) && !isset($template["page_settings"]["fluent_cart_store_settings"]) ) { | |
| 85 | 70 | continue; |
| 86 | 71 | } |
| 87 | 72 | |
| 88 | 73 | // if ( ! isset( $template['data']['form'] ) && ! isset( $template['data']['nav_menus'] )) { |
| @@ -111,10 +96,8 @@ | ||
| 111 | 96 | } |
| 112 | 97 | |
| 113 | 98 | add_action('templately_import.finalize_gutenberg_attachment', [$this, 'post_log'], 10, 2); |
| 114 | 99 | |
| 115 | - $this->update_settings(); | |
| 116 | - | |
| 117 | 100 | $this->loop( $this->options, function($type, $contents ) { |
| 118 | 101 | $this->type = $type; |
| 119 | 102 | |
| 120 | 103 | if ( $type == 'templates' ) { |
| @@ -143,9 +126,9 @@ | ||
| 143 | 126 | } |
| 144 | 127 | |
| 145 | 128 | private function finalize_imports( $templates, $type, $post_type = null ) { |
| 146 | 129 | // used for counting |
| 147 | - $processed = $this->get_loop_result([], 'finalized_imports', false); | |
| 130 | + $processed = $this->get_progress([], 'finalized_imports', false); | |
| 148 | 131 | $path = $this->dir_path . $this->type . DIRECTORY_SEPARATOR; |
| 149 | 132 | |
| 150 | 133 | if ( ! empty( $this->sub_type ) ) { |
| 151 | 134 | $path .= $this->sub_type . DIRECTORY_SEPARATOR; |
| @@ -167,9 +150,9 @@ | ||
| 167 | 150 | |
| 168 | 151 | $processed_pages = get_option("templately_ai_processed_pages", []); |
| 169 | 152 | $updated_ids = $processed_pages[$this->process_id] ?? []; |
| 170 | 153 | $ai_paths = $this->generateAiFilePaths($old_template_id); |
| 171 | - if($this->is_ai_content($old_template_id) && !file_exists($ai_paths['ai_file_path'])){ | |
| 154 | + if(!empty($this->process_id) && is_numeric($this->process_id) && $this->is_ai_content($old_template_id) && !file_exists($ai_paths['ai_file_path'])){ | |
| 172 | 155 | // Use the static timeout-aware wait handler from AIUtils |
| 173 | 156 | AIUtils::handle_sse_wait_with_timeout( |
| 174 | 157 | $this->session_id, |
| 175 | 158 | 'ai_content_time', |
| @@ -197,9 +180,9 @@ | ||
| 197 | 180 | $this->json->prepare( $template_json, $template_settings, $this->extra_content['form'][ $old_template_id ] ?? [], $params )->update(); |
| 198 | 181 | |
| 199 | 182 | $processed[] = $old_template_id; |
| 200 | 183 | // Add the template to the processed templates and update the session data |
| 201 | - $this->set_loop_result( $processed, 'finalized_imports'); | |
| 184 | + $this->update_progress( $processed, null, 'finalized_imports', false); | |
| 202 | 185 | // Broadcast Log |
| 203 | 186 | $progress = floor( ( 100 * count($processed) ) / $this->total_counts ); |
| 204 | 187 | if(empty($progress)){ |
| 205 | 188 | $xyz = 0; |
| @@ -215,36 +198,8 @@ | ||
| 215 | 198 | } |
| 216 | 199 | |
| 217 | 200 | public function post_log($id, $size_dimension = null){ |
| 218 | 201 | $this->log(-1, "Imported attachment: $id" . ( $size_dimension ? " - $size_dimension" : ''), 'eventLog'); |
| 219 | - } | |
| 220 | - | |
| 221 | - private function update_settings() { | |
| 222 | - $data = $this->data; | |
| 223 | - $map_post_ids = $this->json->map_post_ids; | |
| 224 | - $saved_options = get_option('fluent_cart_store_settings', []); | |
| 225 | - $mapped_keys = [ | |
| 226 | - 'checkout_page_id', | |
| 227 | - 'custom_payment_page_id', | |
| 228 | - 'registration_page_id', | |
| 229 | - 'login_page_id', | |
| 230 | - 'cart_page_id', | |
| 231 | - 'receipt_page_id', | |
| 232 | - 'shop_page_id', | |
| 233 | - 'customer_profile_page_id', | |
| 234 | - ]; | |
| 235 | - | |
| 236 | - foreach ($mapped_keys as $key) { | |
| 237 | - $old_id = $saved_options[$key] ?? null; | |
| 238 | - if (!empty($old_id) && isset($map_post_ids[$old_id])) { | |
| 239 | - $saved_options[$key] = $map_post_ids[$old_id]; | |
| 240 | - } | |
| 241 | - else if(isset($saved_options[$key])){ | |
| 242 | - unset($saved_options[$key]); | |
| 243 | - } | |
| 244 | - } | |
| 245 | - | |
| 246 | - update_option('fluent_cart_store_settings', $saved_options); | |
| 247 | 202 | } |
| 248 | 203 | |
| 249 | 204 | |
| 250 | 205 | |