← All changes
|
app/modules/import-export-customization/processes/import.php
+14
-62
4.0.7
→
3.31.2
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. |
| @@ -312,9 +295,8 @@ | ||
| 312 | 295 | 'include' => $this->settings_include, |
| 313 | 296 | 'manifest' => $this->manifest, |
| 314 | 297 | 'site_settings' => $this->site_settings, |
| 315 | 298 | 'selected_plugins' => $this->settings_selected_plugins, |
| 316 | - 'customization' => $this->settings_customization, | |
| 317 | 299 | 'extracted_directory_path' => $this->extracted_directory_path, |
| 318 | 300 | 'selected_custom_post_types' => $this->settings_selected_custom_post_types, |
| 319 | 301 | ]; |
| 320 | 302 | |
| @@ -367,9 +349,8 @@ | ||
| 367 | 349 | 'include' => $this->settings_include, |
| 368 | 350 | 'manifest' => $this->manifest, |
| 369 | 351 | 'site_settings' => $this->site_settings, |
| 370 | 352 | 'selected_plugins' => $this->settings_selected_plugins, |
| 371 | - 'customization' => $this->settings_customization, | |
| 372 | 353 | 'extracted_directory_path' => $this->extracted_directory_path, |
| 373 | 354 | 'selected_custom_post_types' => $this->settings_selected_custom_post_types, |
| 374 | 355 | ]; |
| 375 | 356 | |
| @@ -406,9 +387,8 @@ | ||
| 406 | 387 | |
| 407 | 388 | return [ |
| 408 | 389 | 'status' => 'success', |
| 409 | 390 | 'runner' => $runner_name, |
| 410 | - 'imported_data' => $this->imported_data, | |
| 411 | 391 | ]; |
| 412 | 392 | } |
| 413 | 393 | |
| 414 | 394 | /** |
| @@ -417,18 +397,17 @@ | ||
| 417 | 397 | * @return void |
| 418 | 398 | */ |
| 419 | 399 | public function init_import_session( $save_instance_data = false ) { |
| 420 | 400 | $import_sessions = Utils::get_import_sessions( true ); |
| 421 | - $existing_session = $import_sessions[ $this->session_id ] ?? []; | |
| 422 | 401 | |
| 423 | 402 | $import_sessions[ $this->session_id ] = [ |
| 424 | 403 | 'session_id' => $this->session_id, |
| 425 | 404 | 'kit_title' => $this->manifest['title'] ?? '', |
| 426 | 405 | 'kit_name' => $this->manifest['name'] ?? '', |
| 427 | - 'kit_thumbnail' => $existing_session['kit_thumbnail'] ?? $this->get_kit_thumbnail(), | |
| 428 | - 'kit_source' => $existing_session['kit_source'] ?? $this->settings_referrer, | |
| 406 | + 'kit_thumbnail' => $this->get_kit_thumbnail(), | |
| 407 | + 'kit_source' => $this->settings_referrer, | |
| 429 | 408 | 'user_id' => get_current_user_id(), |
| 430 | - 'start_timestamp' => $existing_session['start_timestamp'] ?? current_time( 'timestamp' ), | |
| 409 | + 'start_timestamp' => current_time( 'timestamp' ), | |
| 431 | 410 | ]; |
| 432 | 411 | |
| 433 | 412 | if ( $save_instance_data ) { |
| 434 | 413 | $import_sessions[ $this->session_id ]['instance_data'] = [ |
| @@ -438,9 +417,8 @@ | ||
| 438 | 417 | |
| 439 | 418 | 'manifest' => $this->manifest, |
| 440 | 419 | 'site_settings' => $this->site_settings, |
| 441 | 420 | |
| 442 | - 'kit_id' => $this->kit_id, | |
| 443 | 421 | 'settings_include' => $this->settings_include, |
| 444 | 422 | 'settings_referrer' => $this->settings_referrer, |
| 445 | 423 | 'settings_conflicts' => $this->settings_conflicts, |
| 446 | 424 | 'settings_selected_override_conditions' => $this->settings_selected_override_conditions, |
| @@ -445,9 +423,8 @@ | ||
| 445 | 423 | 'settings_conflicts' => $this->settings_conflicts, |
| 446 | 424 | 'settings_selected_override_conditions' => $this->settings_selected_override_conditions, |
| 447 | 425 | 'settings_selected_custom_post_types' => $this->settings_selected_custom_post_types, |
| 448 | 426 | 'settings_selected_plugins' => $this->settings_selected_plugins, |
| 449 | - 'settings_customization' => $this->settings_customization, | |
| 450 | 427 | |
| 451 | 428 | 'documents_data' => $this->documents_data, |
| 452 | 429 | 'imported_data' => $this->imported_data, |
| 453 | 430 | 'runners_import_metadata' => $this->runners_import_metadata, |
| @@ -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. |