← All changes
|
app/modules/import-export-customization/processes/import.php
+33
-81
4.2.4
→
3.31.4
View file →
| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | use Elementor\App\Modules\ImportExportCustomization\Compatibility\Base_Adapter; |
| 6 | 6 | use Elementor\App\Modules\ImportExportCustomization\Compatibility\Envato; |
| 7 | 7 | use Elementor\App\Modules\ImportExportCustomization\Compatibility\Kit_Library; |
| 8 | -use Elementor\App\Modules\ImportExportCustomization\Compatibility\Customization; | |
| 9 | 8 | use Elementor\App\Modules\ImportExportCustomization\Utils; |
| 10 | 9 | use Elementor\Core\Base\Document; |
| 11 | 10 | use Elementor\Core\Kits\Documents\Kit; |
| 12 | 11 | use Elementor\Plugin; |
| @@ -18,9 +17,8 @@ | ||
| 18 | 17 | use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Taxonomies; |
| 19 | 18 | use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Templates; |
| 20 | 19 | use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Wp_Content; |
| 21 | 20 | use Elementor\App\Modules\ImportExportCustomization\Module; |
| 22 | -use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Floating_Elements; | |
| 23 | 21 | |
| 24 | 22 | class Import { |
| 25 | 23 | const MANIFEST_ERROR_KEY = 'manifest-error'; |
| 26 | 24 | |
| @@ -125,15 +123,8 @@ | ||
| 125 | 123 | */ |
| 126 | 124 | private $settings_selected_plugins; |
| 127 | 125 | |
| 128 | 126 | /** |
| 129 | - * Customization settings for selective import. | |
| 130 | - * | |
| 131 | - * @var array | |
| 132 | - */ | |
| 133 | - private $settings_customization; | |
| 134 | - | |
| 135 | - /** | |
| 136 | 127 | * The imported data output. |
| 137 | 128 | * |
| 138 | 129 | * @var array |
| 139 | 130 | */ |
| @@ -147,11 +138,11 @@ | ||
| 147 | 138 | */ |
| 148 | 139 | private $runners_import_metadata = []; |
| 149 | 140 | |
| 150 | 141 | /** |
| 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.) | |
| 142 | + * @param string $path session_id | zip_file_path | |
| 143 | + * @param array $settings Use to determine which content to import. | |
| 144 | + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 154 | 145 | * @param array|null $old_instance An array of old instance parameters that will be used for creating new instance. |
| 155 | 146 | * We are using it for quick creation of the instance when the import process is being split into chunks. |
| 156 | 147 | * @throws \Exception If the import session does not exist. |
| 157 | 148 | */ |
| @@ -177,12 +168,11 @@ | ||
| 177 | 168 | $this->settings_referrer = ! empty( $settings['referrer'] ) ? $settings['referrer'] : 'local'; |
| 178 | 169 | $this->settings_include = ! empty( $settings['include'] ) ? $settings['include'] : null; |
| 179 | 170 | |
| 180 | 171 | // Using isset and not empty is important since empty array is valid option. |
| 181 | - $this->settings_selected_override_conditions = $settings['customization']['templates']['themeBuilder']['overrideConditions'] ?? null; | |
| 182 | - $this->settings_selected_custom_post_types = $settings['customization']['content']['customPostTypes'] ?? null; | |
| 172 | + $this->settings_selected_override_conditions = $settings['overrideConditions'] ?? null; | |
| 173 | + $this->settings_selected_custom_post_types = $settings['selectedCustomPostTypes'] ?? null; | |
| 183 | 174 | $this->settings_selected_plugins = $settings['plugins'] ?? null; |
| 184 | - $this->settings_customization = $settings['customization'] ?? null; | |
| 185 | 175 | |
| 186 | 176 | $this->manifest = $this->read_manifest_json(); |
| 187 | 177 | $this->site_settings = $this->read_site_settings_json(); |
| 188 | 178 | |
| @@ -211,9 +201,8 @@ | ||
| 211 | 201 | |
| 212 | 202 | $this->manifest = $instance_data['manifest']; |
| 213 | 203 | $this->site_settings = $instance_data['site_settings']; |
| 214 | 204 | |
| 215 | - $this->kit_id = $instance_data['kit_id'] ?? ''; | |
| 216 | 205 | $this->settings_include = $instance_data['settings_include']; |
| 217 | 206 | $this->settings_referrer = $instance_data['settings_referrer']; |
| 218 | 207 | $this->settings_conflicts = $instance_data['settings_conflicts']; |
| 219 | 208 | $this->settings_selected_override_conditions = $instance_data['settings_selected_override_conditions']; |
| @@ -218,9 +207,8 @@ | ||
| 218 | 207 | $this->settings_conflicts = $instance_data['settings_conflicts']; |
| 219 | 208 | $this->settings_selected_override_conditions = $instance_data['settings_selected_override_conditions']; |
| 220 | 209 | $this->settings_selected_custom_post_types = $instance_data['settings_selected_custom_post_types']; |
| 221 | 210 | $this->settings_selected_plugins = $instance_data['settings_selected_plugins']; |
| 222 | - $this->settings_customization = $instance_data['settings_customization']; | |
| 223 | 211 | |
| 224 | 212 | $this->documents_data = $instance_data['documents_data']; |
| 225 | 213 | $this->imported_data = $instance_data['imported_data']; |
| 226 | 214 | $this->runners_import_metadata = $instance_data['runners_import_metadata']; |
| @@ -262,9 +250,8 @@ | ||
| 262 | 250 | $this->register( new Templates() ); |
| 263 | 251 | $this->register( new Taxonomies() ); |
| 264 | 252 | $this->register( new Elementor_Content() ); |
| 265 | 253 | $this->register( new Wp_Content() ); |
| 266 | - $this->register( new Floating_Elements() ); | |
| 267 | 254 | } |
| 268 | 255 | |
| 269 | 256 | /** |
| 270 | 257 | * Set default settings for the import. |
| @@ -288,12 +275,8 @@ | ||
| 288 | 275 | |
| 289 | 276 | if ( ! is_array( $this->get_settings_selected_plugins() ) ) { |
| 290 | 277 | $this->settings_selected_plugins( $this->get_default_settings_plugins() ); |
| 291 | 278 | } |
| 292 | - | |
| 293 | - if ( ! is_array( $this->get_settings_customization() ) ) { | |
| 294 | - $this->settings_customization( $this->get_default_settings_customization() ); | |
| 295 | - } | |
| 296 | 279 | } |
| 297 | 280 | |
| 298 | 281 | /** |
| 299 | 282 | * Execute the import process. |
| @@ -306,9 +289,17 @@ | ||
| 306 | 289 | if ( empty( $this->runners ) ) { |
| 307 | 290 | throw new \Exception( 'Couldn’t execute the import process because no import runners have been specified. Try again by specifying import runners.' ); |
| 308 | 291 | } |
| 309 | 292 | |
| 310 | - $data = $this->build_runner_data(); | |
| 293 | + $data = [ | |
| 294 | + 'session_id' => $this->session_id, | |
| 295 | + 'include' => $this->settings_include, | |
| 296 | + 'manifest' => $this->manifest, | |
| 297 | + 'site_settings' => $this->site_settings, | |
| 298 | + 'selected_plugins' => $this->settings_selected_plugins, | |
| 299 | + 'extracted_directory_path' => $this->extracted_directory_path, | |
| 300 | + 'selected_custom_post_types' => $this->settings_selected_custom_post_types, | |
| 301 | + ]; | |
| 311 | 302 | |
| 312 | 303 | $this->init_import_session(); |
| 313 | 304 | |
| 314 | 305 | remove_filter( 'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules( 'content-sanitizer' ), 'sanitize_content' ] ); |
| @@ -352,9 +343,17 @@ | ||
| 352 | 343 | if ( empty( $this->runners ) ) { |
| 353 | 344 | throw new \Exception( 'Couldn’t execute the import process because no import runners have been specified. Try again by specifying import runners.' ); |
| 354 | 345 | } |
| 355 | 346 | |
| 356 | - $data = $this->build_runner_data(); | |
| 347 | + $data = [ | |
| 348 | + 'session_id' => $this->session_id, | |
| 349 | + 'include' => $this->settings_include, | |
| 350 | + 'manifest' => $this->manifest, | |
| 351 | + 'site_settings' => $this->site_settings, | |
| 352 | + 'selected_plugins' => $this->settings_selected_plugins, | |
| 353 | + 'extracted_directory_path' => $this->extracted_directory_path, | |
| 354 | + 'selected_custom_post_types' => $this->settings_selected_custom_post_types, | |
| 355 | + ]; | |
| 357 | 356 | |
| 358 | 357 | add_filter( 'elementor/document/save/data', [ $this, 'prevent_saving_elements_on_post_creation' ], 10, 2 ); |
| 359 | 358 | |
| 360 | 359 | // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads. |
| @@ -388,9 +387,8 @@ | ||
| 388 | 387 | |
| 389 | 388 | return [ |
| 390 | 389 | 'status' => 'success', |
| 391 | 390 | 'runner' => $runner_name, |
| 392 | - 'imported_data' => $this->imported_data, | |
| 393 | 391 | ]; |
| 394 | 392 | } |
| 395 | 393 | |
| 396 | 394 | /** |
| @@ -399,18 +397,17 @@ | ||
| 399 | 397 | * @return void |
| 400 | 398 | */ |
| 401 | 399 | public function init_import_session( $save_instance_data = false ) { |
| 402 | 400 | $import_sessions = Utils::get_import_sessions( true ); |
| 403 | - $existing_session = $import_sessions[ $this->session_id ] ?? []; | |
| 404 | 401 | |
| 405 | 402 | $import_sessions[ $this->session_id ] = [ |
| 406 | 403 | 'session_id' => $this->session_id, |
| 407 | 404 | 'kit_title' => $this->manifest['title'] ?? '', |
| 408 | 405 | '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, | |
| 406 | + 'kit_thumbnail' => $this->get_kit_thumbnail(), | |
| 407 | + 'kit_source' => $this->settings_referrer, | |
| 411 | 408 | 'user_id' => get_current_user_id(), |
| 412 | - 'start_timestamp' => $existing_session['start_timestamp'] ?? current_time( 'timestamp' ), | |
| 409 | + 'start_timestamp' => current_time( 'timestamp' ), | |
| 413 | 410 | ]; |
| 414 | 411 | |
| 415 | 412 | if ( $save_instance_data ) { |
| 416 | 413 | $import_sessions[ $this->session_id ]['instance_data'] = [ |
| @@ -420,9 +417,8 @@ | ||
| 420 | 417 | |
| 421 | 418 | 'manifest' => $this->manifest, |
| 422 | 419 | 'site_settings' => $this->site_settings, |
| 423 | 420 | |
| 424 | - 'kit_id' => $this->kit_id, | |
| 425 | 421 | 'settings_include' => $this->settings_include, |
| 426 | 422 | 'settings_referrer' => $this->settings_referrer, |
| 427 | 423 | 'settings_conflicts' => $this->settings_conflicts, |
| 428 | 424 | 'settings_selected_override_conditions' => $this->settings_selected_override_conditions, |
| @@ -427,9 +423,8 @@ | ||
| 427 | 423 | 'settings_conflicts' => $this->settings_conflicts, |
| 428 | 424 | 'settings_selected_override_conditions' => $this->settings_selected_override_conditions, |
| 429 | 425 | 'settings_selected_custom_post_types' => $this->settings_selected_custom_post_types, |
| 430 | 426 | 'settings_selected_plugins' => $this->settings_selected_plugins, |
| 431 | - 'settings_customization' => $this->settings_customization, | |
| 432 | 427 | |
| 433 | 428 | 'documents_data' => $this->documents_data, |
| 434 | 429 | 'imported_data' => $this->imported_data, |
| 435 | 430 | 'runners_import_metadata' => $this->runners_import_metadata, |
| @@ -452,29 +447,11 @@ | ||
| 452 | 447 | return apply_filters( 'elementor/import/kit_thumbnail', '', $this->kit_id, $this->settings_referrer ); |
| 453 | 448 | } |
| 454 | 449 | |
| 455 | 450 | 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 | - ) ); | |
| 451 | + return array_keys( $this->runners ); | |
| 462 | 452 | } |
| 463 | 453 | |
| 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 | 454 | public function get_manifest() { |
| 478 | 455 | return $this->manifest; |
| 479 | 456 | } |
| 480 | 457 | |
| @@ -513,11 +490,8 @@ | ||
| 513 | 490 | |
| 514 | 491 | case 'plugins': |
| 515 | 492 | return $this->get_settings_selected_plugins(); |
| 516 | 493 | |
| 517 | - case 'customization': | |
| 518 | - return $this->get_settings_customization(); | |
| 519 | - | |
| 520 | 494 | default: |
| 521 | 495 | return []; |
| 522 | 496 | } |
| 523 | 497 | } |
| @@ -584,9 +558,9 @@ | ||
| 584 | 558 | |
| 585 | 559 | /** |
| 586 | 560 | * Prevent saving elements on elementor post creation. |
| 587 | 561 | * |
| 588 | - * @param array $data | |
| 562 | + * @param array $data | |
| 589 | 563 | * @param Document $document |
| 590 | 564 | * |
| 591 | 565 | * @return array |
| 592 | 566 | */ |
| @@ -609,9 +583,8 @@ | ||
| 609 | 583 | * Extract the zip file. |
| 610 | 584 | * |
| 611 | 585 | * @param string $zip_path The path to the zip file. |
| 612 | 586 | * @return string The extracted directory path. |
| 613 | - * @throws \Error If import process fails, file validation errors occur, or data corruption is detected. | |
| 614 | 587 | */ |
| 615 | 588 | private function extract_zip( $zip_path ) { |
| 616 | 589 | $extraction_result = Plugin::$instance->uploads_manager->extract_and_validate_zip( $zip_path, [ 'json', 'xml' ] ); |
| 617 | 590 | |
| @@ -629,9 +602,8 @@ | ||
| 629 | 602 | /** |
| 630 | 603 | * Get the manifest file from the extracted directory and adapt it if needed. |
| 631 | 604 | * |
| 632 | 605 | * @return string The manifest file content. |
| 633 | - * @throws \Error If import validation fails or processing errors occur. | |
| 634 | 606 | */ |
| 635 | 607 | private function read_manifest_json() { |
| 636 | 608 | $manifest = Utils::read_json_file( $this->extracted_directory_path . 'manifest' ); |
| 637 | 609 | |
| @@ -657,9 +629,9 @@ | ||
| 657 | 629 | private function init_adapters( array $manifest_data ) { |
| 658 | 630 | $this->adapters = []; |
| 659 | 631 | |
| 660 | 632 | /** @var Base_Adapter[] $adapter_types */ |
| 661 | - $adapter_types = [ Customization::class, Envato::class, Kit_Library::class ]; | |
| 633 | + $adapter_types = [ Envato::class, Kit_Library::class ]; | |
| 662 | 634 | |
| 663 | 635 | foreach ( $adapter_types as $adapter_type ) { |
| 664 | 636 | if ( $adapter_type::is_compatibility_needed( $manifest_data, [ 'referrer' => $this->get_settings_referrer() ] ) ) { |
| 665 | 637 | $this->adapters[] = new $adapter_type( $this ); |
| @@ -687,17 +659,15 @@ | ||
| 687 | 659 | * |
| 688 | 660 | * @return array Custom post types names. |
| 689 | 661 | */ |
| 690 | 662 | private function get_default_settings_custom_post_types() { |
| 691 | - $excluded = [ 'page', 'nav_menu_item' ]; | |
| 692 | - | |
| 693 | - if ( empty( $this->manifest['content']['post'] ?? [] ) && empty( $this->manifest['wp-content']['post'] ?? [] ) ) { | |
| 694 | - $excluded[] = 'post'; | |
| 663 | + if ( empty( $this->manifest['custom-post-type-title'] ) ) { | |
| 664 | + return []; | |
| 695 | 665 | } |
| 696 | 666 | |
| 697 | - $manifest_post_types = array_keys( $this->manifest['custom-post-type-title'] ?? [] ); | |
| 667 | + $manifest_post_types = array_keys( $this->manifest['custom-post-type-title'] ); | |
| 698 | 668 | |
| 699 | - return array_merge( $manifest_post_types, Utils::get_builtin_wp_post_types( $excluded ) ); | |
| 669 | + return array_diff( $manifest_post_types, Utils::get_builtin_wp_post_types() ); | |
| 700 | 670 | } |
| 701 | 671 | |
| 702 | 672 | /** |
| 703 | 673 | * Get the default settings of elementor templates conditions to override. |
| @@ -740,26 +710,8 @@ | ||
| 740 | 710 | * @return array |
| 741 | 711 | */ |
| 742 | 712 | private function get_default_settings_include() { |
| 743 | 713 | return [ 'templates', 'plugins', 'content', 'settings' ]; |
| 744 | - } | |
| 745 | - | |
| 746 | - public function settings_customization( $customization ) { | |
| 747 | - $this->settings_customization = $customization; | |
| 748 | - return $this; | |
| 749 | - } | |
| 750 | - | |
| 751 | - public function get_settings_customization() { | |
| 752 | - return $this->settings_customization; | |
| 753 | - } | |
| 754 | - | |
| 755 | - private function get_default_settings_customization() { | |
| 756 | - return [ | |
| 757 | - 'settings' => null, | |
| 758 | - 'templates' => null, | |
| 759 | - 'content' => null, | |
| 760 | - 'plugins' => null, | |
| 761 | - ]; | |
| 762 | 714 | } |
| 763 | 715 | |
| 764 | 716 | /** |
| 765 | 717 | * Get the data that requires updating/replacement when imported. |