← All changes
|
app/modules/import-export/processes/import.php
+24
-16
4.1.4
→
3.26.0-dev5
View file →
| @@ -17,8 +17,9 @@ | ||
| 17 | 17 | use Elementor\App\Modules\ImportExport\Runners\Import\Taxonomies; |
| 18 | 18 | use Elementor\App\Modules\ImportExport\Runners\Import\Templates; |
| 19 | 19 | use Elementor\App\Modules\ImportExport\Runners\Import\Wp_Content; |
| 20 | 20 | use Elementor\App\Modules\ImportExport\Module; |
| 21 | +use Elementor\App\Modules\KitLibrary\Connect\Kit_Library as Kit_Library_Api; | |
| 21 | 22 | |
| 22 | 23 | class Import { |
| 23 | 24 | const MANIFEST_ERROR_KEY = 'manifest-error'; |
| 24 | 25 | |
| @@ -138,15 +139,14 @@ | ||
| 138 | 139 | */ |
| 139 | 140 | private $runners_import_metadata = []; |
| 140 | 141 | |
| 141 | 142 | /** |
| 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.) | |
| 143 | + * @param string $path session_id | zip_file_path | |
| 144 | + * @param array $settings Use to determine which content to import. | |
| 145 | + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 145 | 146 | * @param array|null $old_instance An array of old instance parameters that will be used for creating new instance. |
| 146 | - * We are using it for quick creation of the instance when the import process is being split into chunks. | |
| 147 | - * | |
| 148 | - * @throws \Exception If the import session does not exist. | |
| 147 | + * We are using it for quick creation of the instance when the import process is being split into chunks. | |
| 148 | + * @throws \Exception | |
| 149 | 149 | */ |
| 150 | 150 | public function __construct( string $path, array $settings = [], array $old_instance = null ) { |
| 151 | 151 | if ( ! empty( $old_instance ) ) { |
| 152 | 152 | $this->set_import_object( $old_instance ); |
| @@ -220,9 +220,9 @@ | ||
| 220 | 220 | * |
| 221 | 221 | * @param string $session_id |
| 222 | 222 | * |
| 223 | 223 | * @return Import |
| 224 | - * @throws \Exception If the import session does not exist. | |
| 224 | + * @throws \Exception | |
| 225 | 225 | */ |
| 226 | 226 | public static function from_session( string $session_id ): Import { |
| 227 | 227 | $import_sessions = Utils::get_import_sessions(); |
| 228 | 228 | |
| @@ -444,9 +444,20 @@ | ||
| 444 | 444 | if ( ! empty( $this->manifest['thumbnail'] ) ) { |
| 445 | 445 | return $this->manifest['thumbnail']; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - return apply_filters( 'elementor/import/kit_thumbnail', '', $this->kit_id, $this->settings_referrer ); | |
| 448 | + if ( empty( $this->kit_id ) ) { | |
| 449 | + return ''; | |
| 450 | + } | |
| 451 | + | |
| 452 | + $api = new Kit_Library_Api(); | |
| 453 | + $kit = $api->get_by_id( $this->kit_id ); | |
| 454 | + | |
| 455 | + if ( is_wp_error( $kit ) ) { | |
| 456 | + return ''; | |
| 457 | + } | |
| 458 | + | |
| 459 | + return $kit->thumbnail; | |
| 449 | 460 | } |
| 450 | 461 | |
| 451 | 462 | public function get_runners_name(): array { |
| 452 | 463 | return array_keys( $this->runners ); |
| @@ -559,9 +570,9 @@ | ||
| 559 | 570 | |
| 560 | 571 | /** |
| 561 | 572 | * Prevent saving elements on elementor post creation. |
| 562 | 573 | * |
| 563 | - * @param array $data | |
| 574 | + * @param array $data | |
| 564 | 575 | * @param Document $document |
| 565 | 576 | * |
| 566 | 577 | * @return array |
| 567 | 578 | */ |
| @@ -584,9 +595,8 @@ | ||
| 584 | 595 | * Extract the zip file. |
| 585 | 596 | * |
| 586 | 597 | * @param string $zip_path The path to the zip file. |
| 587 | 598 | * @return string The extracted directory path. |
| 588 | - * @throws \Error If import process fails, file validation errors occur, or data corruption is detected. | |
| 589 | 599 | */ |
| 590 | 600 | private function extract_zip( $zip_path ) { |
| 591 | 601 | $extraction_result = Plugin::$instance->uploads_manager->extract_and_validate_zip( $zip_path, [ 'json', 'xml' ] ); |
| 592 | 602 | |
| @@ -591,12 +601,12 @@ | ||
| 591 | 601 | $extraction_result = Plugin::$instance->uploads_manager->extract_and_validate_zip( $zip_path, [ 'json', 'xml' ] ); |
| 592 | 602 | |
| 593 | 603 | if ( is_wp_error( $extraction_result ) ) { |
| 594 | 604 | if ( isset( $extraction_result->errors['zip_error'] ) ) { |
| 595 | - throw new \Error( static::ZIP_ARCHIVE_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 605 | + throw new \Error( static::ZIP_ARCHIVE_ERROR_KEY ); | |
| 596 | 606 | } |
| 597 | 607 | |
| 598 | - throw new \Error( static::ZIP_FILE_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 608 | + throw new \Error( static::ZIP_FILE_ERROR_KEY ); | |
| 599 | 609 | } |
| 600 | 610 | |
| 601 | 611 | return $extraction_result['extraction_directory']; |
| 602 | 612 | } |
| @@ -604,10 +614,8 @@ | ||
| 604 | 614 | /** |
| 605 | 615 | * Get the manifest file from the extracted directory and adapt it if needed. |
| 606 | 616 | * |
| 607 | 617 | * @return string The manifest file content. |
| 608 | - * | |
| 609 | - * @throws \Error If import validation fails or processing errors occur. | |
| 610 | 618 | */ |
| 611 | 619 | private function read_manifest_json() { |
| 612 | 620 | $manifest = Utils::read_json_file( $this->extracted_directory_path . 'manifest' ); |
| 613 | 621 | |
| @@ -612,9 +620,9 @@ | ||
| 612 | 620 | $manifest = Utils::read_json_file( $this->extracted_directory_path . 'manifest' ); |
| 613 | 621 | |
| 614 | 622 | if ( ! $manifest ) { |
| 615 | 623 | Plugin::$instance->logger->get_logger()->error( static::MANIFEST_ERROR_KEY ); |
| 616 | - throw new \Error( static::ZIP_FILE_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 624 | + throw new \Error( static::ZIP_FILE_ERROR_KEY ); | |
| 617 | 625 | } |
| 618 | 626 | |
| 619 | 627 | $this->init_adapters( $manifest ); |
| 620 | 628 | |
| @@ -721,9 +729,9 @@ | ||
| 721 | 729 | * Get the data that requires updating/replacement when imported. |
| 722 | 730 | * |
| 723 | 731 | * @return array{post_ids: array, term_ids: array} |
| 724 | 732 | */ |
| 725 | - private function get_imported_data_replacements(): array { | |
| 733 | + private function get_imported_data_replacements() : array { | |
| 726 | 734 | return [ |
| 727 | 735 | 'post_ids' => Utils::map_old_new_post_ids( $this->imported_data ), |
| 728 | 736 | 'term_ids' => Utils::map_old_new_term_ids( $this->imported_data ), |
| 729 | 737 | ]; |