← All changes
|
app/modules/import-export-customization/processes/import.php
+33
-36
4.2.2
→
3.32.0-dev3
View file →
| @@ -18,9 +18,8 @@ | ||
| 18 | 18 | use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Taxonomies; |
| 19 | 19 | use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Templates; |
| 20 | 20 | use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Wp_Content; |
| 21 | 21 | use Elementor\App\Modules\ImportExportCustomization\Module; |
| 22 | -use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Floating_Elements; | |
| 23 | 22 | |
| 24 | 23 | class Import { |
| 25 | 24 | const MANIFEST_ERROR_KEY = 'manifest-error'; |
| 26 | 25 | |
| @@ -147,11 +146,11 @@ | ||
| 147 | 146 | */ |
| 148 | 147 | private $runners_import_metadata = []; |
| 149 | 148 | |
| 150 | 149 | /** |
| 151 | - * @param string $path session_id | zip_file_path | |
| 152 | - * @param array $settings Use to determine which content to import. | |
| 153 | - * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 150 | + * @param string $path session_id | zip_file_path | |
| 151 | + * @param array $settings Use to determine which content to import. | |
| 152 | + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 154 | 153 | * @param array|null $old_instance An array of old instance parameters that will be used for creating new instance. |
| 155 | 154 | * We are using it for quick creation of the instance when the import process is being split into chunks. |
| 156 | 155 | * @throws \Exception If the import session does not exist. |
| 157 | 156 | */ |
| @@ -211,9 +210,8 @@ | ||
| 211 | 210 | |
| 212 | 211 | $this->manifest = $instance_data['manifest']; |
| 213 | 212 | $this->site_settings = $instance_data['site_settings']; |
| 214 | 213 | |
| 215 | - $this->kit_id = $instance_data['kit_id'] ?? ''; | |
| 216 | 214 | $this->settings_include = $instance_data['settings_include']; |
| 217 | 215 | $this->settings_referrer = $instance_data['settings_referrer']; |
| 218 | 216 | $this->settings_conflicts = $instance_data['settings_conflicts']; |
| 219 | 217 | $this->settings_selected_override_conditions = $instance_data['settings_selected_override_conditions']; |
| @@ -262,9 +260,8 @@ | ||
| 262 | 260 | $this->register( new Templates() ); |
| 263 | 261 | $this->register( new Taxonomies() ); |
| 264 | 262 | $this->register( new Elementor_Content() ); |
| 265 | 263 | $this->register( new Wp_Content() ); |
| 266 | - $this->register( new Floating_Elements() ); | |
| 267 | 264 | } |
| 268 | 265 | |
| 269 | 266 | /** |
| 270 | 267 | * Set default settings for the import. |
| @@ -306,9 +303,18 @@ | ||
| 306 | 303 | if ( empty( $this->runners ) ) { |
| 307 | 304 | throw new \Exception( 'Couldn’t execute the import process because no import runners have been specified. Try again by specifying import runners.' ); |
| 308 | 305 | } |
| 309 | 306 | |
| 310 | - $data = $this->build_runner_data(); | |
| 307 | + $data = [ | |
| 308 | + 'session_id' => $this->session_id, | |
| 309 | + 'include' => $this->settings_include, | |
| 310 | + 'manifest' => $this->manifest, | |
| 311 | + 'site_settings' => $this->site_settings, | |
| 312 | + 'selected_plugins' => $this->settings_selected_plugins, | |
| 313 | + 'customization' => $this->settings_customization, | |
| 314 | + 'extracted_directory_path' => $this->extracted_directory_path, | |
| 315 | + 'selected_custom_post_types' => $this->settings_selected_custom_post_types, | |
| 316 | + ]; | |
| 311 | 317 | |
| 312 | 318 | $this->init_import_session(); |
| 313 | 319 | |
| 314 | 320 | remove_filter( 'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules( 'content-sanitizer' ), 'sanitize_content' ] ); |
| @@ -352,9 +358,18 @@ | ||
| 352 | 358 | if ( empty( $this->runners ) ) { |
| 353 | 359 | throw new \Exception( 'Couldn’t execute the import process because no import runners have been specified. Try again by specifying import runners.' ); |
| 354 | 360 | } |
| 355 | 361 | |
| 356 | - $data = $this->build_runner_data(); | |
| 362 | + $data = [ | |
| 363 | + 'session_id' => $this->session_id, | |
| 364 | + 'include' => $this->settings_include, | |
| 365 | + 'manifest' => $this->manifest, | |
| 366 | + 'site_settings' => $this->site_settings, | |
| 367 | + 'selected_plugins' => $this->settings_selected_plugins, | |
| 368 | + 'customization' => $this->settings_customization, | |
| 369 | + 'extracted_directory_path' => $this->extracted_directory_path, | |
| 370 | + 'selected_custom_post_types' => $this->settings_selected_custom_post_types, | |
| 371 | + ]; | |
| 357 | 372 | |
| 358 | 373 | add_filter( 'elementor/document/save/data', [ $this, 'prevent_saving_elements_on_post_creation' ], 10, 2 ); |
| 359 | 374 | |
| 360 | 375 | // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads. |
| @@ -399,18 +414,17 @@ | ||
| 399 | 414 | * @return void |
| 400 | 415 | */ |
| 401 | 416 | public function init_import_session( $save_instance_data = false ) { |
| 402 | 417 | $import_sessions = Utils::get_import_sessions( true ); |
| 403 | - $existing_session = $import_sessions[ $this->session_id ] ?? []; | |
| 404 | 418 | |
| 405 | 419 | $import_sessions[ $this->session_id ] = [ |
| 406 | 420 | 'session_id' => $this->session_id, |
| 407 | 421 | 'kit_title' => $this->manifest['title'] ?? '', |
| 408 | 422 | 'kit_name' => $this->manifest['name'] ?? '', |
| 409 | - 'kit_thumbnail' => $existing_session['kit_thumbnail'] ?? $this->get_kit_thumbnail(), | |
| 410 | - 'kit_source' => $existing_session['kit_source'] ?? $this->settings_referrer, | |
| 423 | + 'kit_thumbnail' => $this->get_kit_thumbnail(), | |
| 424 | + 'kit_source' => $this->settings_referrer, | |
| 411 | 425 | 'user_id' => get_current_user_id(), |
| 412 | - 'start_timestamp' => $existing_session['start_timestamp'] ?? current_time( 'timestamp' ), | |
| 426 | + 'start_timestamp' => current_time( 'timestamp' ), | |
| 413 | 427 | ]; |
| 414 | 428 | |
| 415 | 429 | if ( $save_instance_data ) { |
| 416 | 430 | $import_sessions[ $this->session_id ]['instance_data'] = [ |
| @@ -420,9 +434,8 @@ | ||
| 420 | 434 | |
| 421 | 435 | 'manifest' => $this->manifest, |
| 422 | 436 | 'site_settings' => $this->site_settings, |
| 423 | 437 | |
| 424 | - 'kit_id' => $this->kit_id, | |
| 425 | 438 | 'settings_include' => $this->settings_include, |
| 426 | 439 | 'settings_referrer' => $this->settings_referrer, |
| 427 | 440 | 'settings_conflicts' => $this->settings_conflicts, |
| 428 | 441 | 'settings_selected_override_conditions' => $this->settings_selected_override_conditions, |
| @@ -452,29 +465,11 @@ | ||
| 452 | 465 | return apply_filters( 'elementor/import/kit_thumbnail', '', $this->kit_id, $this->settings_referrer ); |
| 453 | 466 | } |
| 454 | 467 | |
| 455 | 468 | public function get_runners_name(): array { |
| 456 | - $data = $this->build_runner_data(); | |
| 457 | - | |
| 458 | - return array_keys( array_filter( | |
| 459 | - $this->runners, | |
| 460 | - fn( $runner ) => $runner->should_import( $data ) | |
| 461 | - ) ); | |
| 469 | + return array_keys( $this->runners ); | |
| 462 | 470 | } |
| 463 | 471 | |
| 464 | - private function build_runner_data(): array { | |
| 465 | - return [ | |
| 466 | - 'session_id' => $this->session_id, | |
| 467 | - 'include' => $this->settings_include, | |
| 468 | - 'manifest' => $this->manifest, | |
| 469 | - 'site_settings' => $this->site_settings, | |
| 470 | - 'selected_plugins' => $this->settings_selected_plugins, | |
| 471 | - 'customization' => $this->settings_customization, | |
| 472 | - 'extracted_directory_path' => $this->extracted_directory_path, | |
| 473 | - 'selected_custom_post_types' => $this->settings_selected_custom_post_types, | |
| 474 | - ]; | |
| 475 | - } | |
| 476 | - | |
| 477 | 472 | public function get_manifest() { |
| 478 | 473 | return $this->manifest; |
| 479 | 474 | } |
| 480 | 475 | |
| @@ -584,9 +579,9 @@ | ||
| 584 | 579 | |
| 585 | 580 | /** |
| 586 | 581 | * Prevent saving elements on elementor post creation. |
| 587 | 582 | * |
| 588 | - * @param array $data | |
| 583 | + * @param array $data | |
| 589 | 584 | * @param Document $document |
| 590 | 585 | * |
| 591 | 586 | * @return array |
| 592 | 587 | */ |
| @@ -609,9 +604,8 @@ | ||
| 609 | 604 | * Extract the zip file. |
| 610 | 605 | * |
| 611 | 606 | * @param string $zip_path The path to the zip file. |
| 612 | 607 | * @return string The extracted directory path. |
| 613 | - * @throws \Error If import process fails, file validation errors occur, or data corruption is detected. | |
| 614 | 608 | */ |
| 615 | 609 | private function extract_zip( $zip_path ) { |
| 616 | 610 | $extraction_result = Plugin::$instance->uploads_manager->extract_and_validate_zip( $zip_path, [ 'json', 'xml' ] ); |
| 617 | 611 | |
| @@ -629,9 +623,8 @@ | ||
| 629 | 623 | /** |
| 630 | 624 | * Get the manifest file from the extracted directory and adapt it if needed. |
| 631 | 625 | * |
| 632 | 626 | * @return string The manifest file content. |
| 633 | - * @throws \Error If import validation fails or processing errors occur. | |
| 634 | 627 | */ |
| 635 | 628 | private function read_manifest_json() { |
| 636 | 629 | $manifest = Utils::read_json_file( $this->extracted_directory_path . 'manifest' ); |
| 637 | 630 | |
| @@ -687,8 +680,12 @@ | ||
| 687 | 680 | * |
| 688 | 681 | * @return array Custom post types names. |
| 689 | 682 | */ |
| 690 | 683 | private function get_default_settings_custom_post_types() { |
| 684 | + if ( empty( $this->manifest['custom-post-type-title'] ) ) { | |
| 685 | + return []; | |
| 686 | + } | |
| 687 | + | |
| 691 | 688 | $excluded = [ 'page', 'nav_menu_item' ]; |
| 692 | 689 | |
| 693 | 690 | if ( empty( $this->manifest['content']['post'] ?? [] ) && empty( $this->manifest['wp-content']['post'] ?? [] ) ) { |
| 694 | 691 | $excluded[] = 'post'; |
| @@ -693,9 +690,9 @@ | ||
| 693 | 690 | if ( empty( $this->manifest['content']['post'] ?? [] ) && empty( $this->manifest['wp-content']['post'] ?? [] ) ) { |
| 694 | 691 | $excluded[] = 'post'; |
| 695 | 692 | } |
| 696 | 693 | |
| 697 | - $manifest_post_types = array_keys( $this->manifest['custom-post-type-title'] ?? [] ); | |
| 694 | + $manifest_post_types = array_keys( $this->manifest['custom-post-type-title'] ); | |
| 698 | 695 | |
| 699 | 696 | return array_merge( $manifest_post_types, Utils::get_builtin_wp_post_types( $excluded ) ); |
| 700 | 697 | } |
| 701 | 698 | |