PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.0-beta1
Elementor Website Builder – more than just a page builder v3.13.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 All 457 releases
← All changes | app/modules/import-export/processes/import.php +29 -54 4.3.0-beta2 → 3.13.0-beta1 View file →
@@ -7,9 +7,8 @@
7 7 use Elementor\App\Modules\ImportExport\Compatibility\Kit_Library;
8 8 use Elementor\App\Modules\ImportExport\Utils;
9 9 use Elementor\Core\Base\Document;
10 10 use Elementor\Core\Kits\Documents\Kit;
11 -use Elementor\Modules\Components\Module as Components_Module;
12 11 use Elementor\Plugin;
13 12
14 13 use Elementor\App\Modules\ImportExport\Runners\Import\Elementor_Content;
15 14 use Elementor\App\Modules\ImportExport\Runners\Import\Import_Runner_Base;
@@ -18,16 +17,15 @@
18 17 use Elementor\App\Modules\ImportExport\Runners\Import\Taxonomies;
19 18 use Elementor\App\Modules\ImportExport\Runners\Import\Templates;
20 19 use Elementor\App\Modules\ImportExport\Runners\Import\Wp_Content;
21 20 use Elementor\App\Modules\ImportExport\Module;
21 +use Elementor\App\Modules\KitLibrary\Connect\Kit_Library as Kit_Library_Api;
22 22
23 23 class Import {
24 24 const MANIFEST_ERROR_KEY = 'manifest-error';
25 25
26 - const ZIP_FILE_ERROR_KEY = 'invalid-zip-file';
26 + const ZIP_FILE_ERROR_KEY = 'zip-file-error';
27 27
28 - const ZIP_ARCHIVE_ERROR_KEY = 'zip-archive-module-missing';
29 -
30 28 /**
31 29 * @var Import_Runner_Base[]
32 30 */
33 31 protected $runners = [];
@@ -139,15 +137,14 @@
139 137 */
140 138 private $runners_import_metadata = [];
141 139
142 140 /**
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.)
141 + * @param string $path session_id | zip_file_path
142 + * @param array $settings Use to determine which content to import.
143 + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.)
146 144 * @param array|null $old_instance An array of old instance parameters that will be used for creating new instance.
147 - * We are using it for quick creation of the instance when the import process is being split into chunks.
148 - *
149 - * @throws \Exception If the import session does not exist.
145 + * We are using it for quick creation of the instance when the import process is being split into chunks.
146 + * @throws \Exception
150 147 */
151 148 public function __construct( string $path, array $settings = [], array $old_instance = null ) {
152 149 if ( ! empty( $old_instance ) ) {
153 150 $this->set_import_object( $old_instance );
@@ -179,12 +176,8 @@
179 176 $this->site_settings = $this->read_site_settings_json();
180 177
181 178 $this->set_default_settings();
182 179 }
183 -
184 - add_filter( 'wp_php_error_args', function ( $args, $error ) {
185 - return $this->filter_php_error_args( $args, $error );
186 - }, 10, 2 );
187 180 }
188 181
189 182 /**
190 183 * Set the import object parameters.
@@ -221,12 +214,12 @@
221 214 *
222 215 * @param string $session_id
223 216 *
224 217 * @return Import
225 - * @throws \Exception If the import session does not exist.
218 + * @throws \Exception
226 219 */
227 220 public static function from_session( string $session_id ): Import {
228 - $import_sessions = Utils::get_import_sessions();
221 + $import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS );
229 222
230 223 if ( ! $import_sessions || ! isset( $import_sessions[ $session_id ] ) ) {
231 224 throw new \Exception( 'Couldn’t execute the import process because the import session does not exist.' );
232 225 }
@@ -303,9 +296,8 @@
303 296 ];
304 297
305 298 $this->init_import_session();
306 299
307 - remove_filter( 'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules( 'content-sanitizer' ), 'sanitize_content' ] );
308 300 add_filter( 'elementor/document/save/data', [ $this, 'prevent_saving_elements_on_post_creation' ], 10, 2 );
309 301
310 302 // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads.
311 303 Plugin::$instance->uploads_manager->set_elementor_upload_state( true );
@@ -398,9 +390,9 @@
398 390 *
399 391 * @return void
400 392 */
401 393 public function init_import_session( $save_instance_data = false ) {
402 - $import_sessions = Utils::get_import_sessions( true );
394 + $import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS );
403 395
404 396 $import_sessions[ $this->session_id ] = [
405 397 'session_id' => $this->session_id,
406 398 'kit_title' => $this->manifest['title'] ?? '',
@@ -445,9 +437,20 @@
445 437 if ( ! empty( $this->manifest['thumbnail'] ) ) {
446 438 return $this->manifest['thumbnail'];
447 439 }
448 440
449 - return apply_filters( 'elementor/import/kit_thumbnail', '', $this->kit_id, $this->settings_referrer );
441 + if ( empty( $this->kit_id ) ) {
442 + return '';
443 + }
444 +
445 + $api = new Kit_Library_Api();
446 + $kit = $api->get_by_id( $this->kit_id );
447 +
448 + if ( is_wp_error( $kit ) ) {
449 + return '';
450 + }
451 +
452 + return $kit->thumbnail;
450 453 }
451 454
452 455 public function get_runners_name(): array {
453 456 return array_keys( $this->runners );
@@ -560,9 +563,9 @@
560 563
561 564 /**
562 565 * Prevent saving elements on elementor post creation.
563 566 *
564 - * @param array $data
567 + * @param array $data
565 568 * @param Document $document
566 569 *
567 570 * @return array
568 571 */
@@ -585,19 +588,14 @@
585 588 * Extract the zip file.
586 589 *
587 590 * @param string $zip_path The path to the zip file.
588 591 * @return string The extracted directory path.
589 - * @throws \Error If import process fails, file validation errors occur, or data corruption is detected.
590 592 */
591 593 private function extract_zip( $zip_path ) {
592 594 $extraction_result = Plugin::$instance->uploads_manager->extract_and_validate_zip( $zip_path, [ 'json', 'xml' ] );
593 595
594 596 if ( is_wp_error( $extraction_result ) ) {
595 - if ( isset( $extraction_result->errors['zip_error'] ) ) {
596 - throw new \Error( static::ZIP_ARCHIVE_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
597 - }
598 -
599 - throw new \Error( static::ZIP_FILE_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
597 + throw new \Error( static::ZIP_FILE_ERROR_KEY );
600 598 }
601 599
602 600 return $extraction_result['extraction_directory'];
603 601 }
@@ -605,17 +603,14 @@
605 603 /**
606 604 * Get the manifest file from the extracted directory and adapt it if needed.
607 605 *
608 606 * @return string The manifest file content.
609 - *
610 - * @throws \Error If import validation fails or processing errors occur.
611 607 */
612 608 private function read_manifest_json() {
613 609 $manifest = Utils::read_json_file( $this->extracted_directory_path . 'manifest' );
614 610
615 611 if ( ! $manifest ) {
616 - Plugin::$instance->logger->get_logger()->error( static::MANIFEST_ERROR_KEY );
617 - throw new \Error( static::ZIP_FILE_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
612 + throw new \Error( static::MANIFEST_ERROR_KEY );
618 613 }
619 614
620 615 $this->init_adapters( $manifest );
621 616
@@ -722,9 +717,9 @@
722 717 * Get the data that requires updating/replacement when imported.
723 718 *
724 719 * @return array{post_ids: array, term_ids: array}
725 720 */
726 - private function get_imported_data_replacements(): array {
721 + private function get_imported_data_replacements() : array {
727 722 return [
728 723 'post_ids' => Utils::map_old_new_post_ids( $this->imported_data ),
729 724 'term_ids' => Utils::map_old_new_term_ids( $this->imported_data ),
730 725 ];
@@ -740,9 +735,8 @@
740 735 foreach ( $this->documents_data as $new_id => $data ) {
741 736 $document = Plugin::$instance->documents->get( $new_id );
742 737
743 738 if ( isset( $data['elements'] ) ) {
744 - $data['elements'] = Components_Module::prepare_imported_elements( $data['elements'], $imported_data_replacements['post_ids'] ?? [] );
745 739 $data['elements'] = $document->on_import_update_dynamic_content( $data['elements'], $imported_data_replacements );
746 740 }
747 741
748 742 if ( isset( $data['settings'] ) ) {
@@ -759,9 +753,9 @@
759 753 }
760 754 }
761 755
762 756 private function update_instance_data_in_import_session_option() {
763 - $import_sessions = Utils::get_import_sessions();
757 + $import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS );
764 758
765 759 $import_sessions[ $this->session_id ]['instance_data']['documents_data'] = $this->documents_data;
766 760 $import_sessions[ $this->session_id ]['instance_data']['imported_data'] = $this->imported_data;
767 761 $import_sessions[ $this->session_id ]['instance_data']['runners_import_metadata'] = $this->runners_import_metadata;
@@ -768,15 +762,11 @@
768 762
769 763 update_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, $import_sessions, false );
770 764 }
771 765
772 - public function finalize_import_session_option() {
773 - $import_sessions = Utils::get_import_sessions();
766 + private function finalize_import_session_option() {
767 + $import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS );
774 768
775 - if ( ! isset( $import_sessions[ $this->session_id ] ) ) {
776 - return;
777 - }
778 -
779 769 unset( $import_sessions[ $this->session_id ]['instance_data'] );
780 770
781 771 $import_sessions[ $this->session_id ]['end_timestamp'] = current_time( 'timestamp' );
782 772 $import_sessions[ $this->session_id ]['runners'] = $this->runners_import_metadata;
@@ -781,21 +771,6 @@
781 771 $import_sessions[ $this->session_id ]['end_timestamp'] = current_time( 'timestamp' );
782 772 $import_sessions[ $this->session_id ]['runners'] = $this->runners_import_metadata;
783 773
784 774 update_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, $import_sessions, false );
785 - }
786 -
787 - /**
788 - * Filter the php error args and return 408 status code if the error is a timeout.
789 - *
790 - * @param array $args
791 - * @param array $error
792 - * @return array
793 - */
794 - private function filter_php_error_args( $args, $error ) {
795 - if ( strpos( $error['message'], 'Maximum execution time' ) !== false ) {
796 - $args['response'] = 408;
797 - }
798 -
799 - return $args;
800 775 }
801 776 }