| @@ -36,10 +36,12 @@ | ||
| 36 | 36 | const REFERRER_KIT_LIBRARY = 'kit-library'; |
| 37 | 37 | |
| 38 | 38 | const REFERRER_LOCAL = 'local'; |
| 39 | 39 | |
| 40 | - const PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error'; | |
| 40 | + const PLUGIN_PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error'; | |
| 41 | 41 | |
| 42 | + const KIT_LIBRARY_ERROR_KEY = 'invalid-kit-library-zip-error'; | |
| 43 | + | |
| 42 | 44 | const NO_WRITE_PERMISSIONS_KEY = 'no-write-permissions'; |
| 43 | 45 | |
| 44 | 46 | const OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS = 'elementor_import_sessions'; |
| 45 | 47 | |
| @@ -453,14 +455,14 @@ | ||
| 453 | 455 | $permissions = $server->get_paths_permissions( $paths_to_check ); |
| 454 | 456 | |
| 455 | 457 | // WP Content dir has to be exists and writable. |
| 456 | 458 | if ( ! $permissions[ Server::KEY_PATH_WP_CONTENT_DIR ]['write'] ) { |
| 457 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_WP_CONTENT_DIR ); | |
| 459 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); | |
| 458 | 460 | } |
| 459 | 461 | |
| 460 | 462 | // WP Uploads dir has to be exists and writable. |
| 461 | 463 | if ( ! $permissions[ Server::KEY_PATH_UPLOADS_DIR ]['write'] ) { |
| 462 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_UPLOADS_DIR ); | |
| 464 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); | |
| 463 | 465 | } |
| 464 | 466 | |
| 465 | 467 | // Elementor uploads dir permissions is divided to 2 cases: |
| 466 | 468 | // 1. If the dir exists, it has to be writable. |
| @@ -465,9 +467,9 @@ | ||
| 465 | 467 | // Elementor uploads dir permissions is divided to 2 cases: |
| 466 | 468 | // 1. If the dir exists, it has to be writable. |
| 467 | 469 | // 2. If the dir doesn't exist, the parent dir has to be writable (wp uploads dir), so we can create it. |
| 468 | 470 | if ( $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) { |
| 469 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ); | |
| 471 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); | |
| 470 | 472 | } |
| 471 | 473 | } |
| 472 | 474 | |
| 473 | 475 | /** |
| @@ -498,27 +500,36 @@ | ||
| 498 | 500 | private function maybe_handle_ajax() { |
| 499 | 501 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 500 | 502 | $action = ElementorUtils::get_super_global_value( $_POST, 'action' ); |
| 501 | 503 | |
| 502 | - switch ( $action ) { | |
| 503 | - case static::EXPORT_TRIGGER_KEY: | |
| 504 | - $this->handle_export_kit(); | |
| 505 | - break; | |
| 504 | + try { | |
| 505 | + switch ( $action ) { | |
| 506 | + case static::EXPORT_TRIGGER_KEY: | |
| 507 | + $this->handle_export_kit(); | |
| 508 | + break; | |
| 506 | 509 | |
| 507 | - case static::UPLOAD_TRIGGER_KEY: | |
| 508 | - $this->handle_upload_kit(); | |
| 509 | - break; | |
| 510 | + case static::UPLOAD_TRIGGER_KEY: | |
| 511 | + $this->handle_upload_kit(); | |
| 512 | + break; | |
| 510 | 513 | |
| 511 | - case static::IMPORT_TRIGGER_KEY: | |
| 512 | - $this->handle_import_kit(); | |
| 513 | - break; | |
| 514 | + case static::IMPORT_TRIGGER_KEY: | |
| 515 | + $this->handle_import_kit(); | |
| 516 | + break; | |
| 514 | 517 | |
| 515 | - case static::IMPORT_RUNNER_TRIGGER_KEY: | |
| 516 | - $this->handle_import_kit__runner(); | |
| 517 | - break; | |
| 518 | + case static::IMPORT_RUNNER_TRIGGER_KEY: | |
| 519 | + $this->handle_import_kit__runner(); | |
| 520 | + break; | |
| 518 | 521 | |
| 519 | - default: | |
| 520 | - break; | |
| 522 | + default: | |
| 523 | + break; | |
| 524 | + } | |
| 525 | + } catch ( \Error $e ) { | |
| 526 | + Plugin::$instance->logger->get_logger()->error( $e->getMessage(), [ | |
| 527 | + 'meta' => [ | |
| 528 | + 'trace' => $e->getTraceAsString(), | |
| 529 | + ], | |
| 530 | + ] ); | |
| 531 | + wp_send_json_error( $e->getMessage(), 500 ); | |
| 521 | 532 | } |
| 522 | 533 | } |
| 523 | 534 | |
| 524 | 535 | /** |
| @@ -539,19 +550,21 @@ | ||
| 539 | 550 | throw new \Error( 'Invalid kit library nonce.' ); |
| 540 | 551 | } |
| 541 | 552 | |
| 542 | 553 | if ( ! filter_var( $file_url, FILTER_VALIDATE_URL ) || 0 !== strpos( $file_url, 'http' ) ) { |
| 543 | - throw new \Error( 'Invalid URL.' ); | |
| 554 | + throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); | |
| 544 | 555 | } |
| 545 | 556 | |
| 546 | 557 | $remote_zip_request = wp_remote_get( $file_url ); |
| 547 | 558 | |
| 548 | 559 | if ( is_wp_error( $remote_zip_request ) ) { |
| 549 | - throw new \Error( $remote_zip_request->get_error_message() ); | |
| 560 | + Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() ); | |
| 561 | + throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); | |
| 550 | 562 | } |
| 551 | 563 | |
| 552 | 564 | if ( 200 !== $remote_zip_request['response']['code'] ) { |
| 553 | - throw new \Error( $remote_zip_request['response']['message'] ); | |
| 565 | + Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] ); | |
| 566 | + throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); | |
| 554 | 567 | } |
| 555 | 568 | |
| 556 | 569 | $file_name = Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' ); |
| 557 | 570 | $referrer = static::REFERRER_KIT_LIBRARY; |
| @@ -560,9 +573,17 @@ | ||
| 560 | 573 | $file_name = ElementorUtils::get_super_global_value( $_FILES, 'e_import_file' )['tmp_name']; |
| 561 | 574 | $referrer = static::REFERRER_LOCAL; |
| 562 | 575 | } |
| 563 | 576 | |
| 577 | + Plugin::$instance->logger->get_logger()->info( 'Uploading Kit: ', [ | |
| 578 | + 'meta' => [ | |
| 579 | + 'kit_id' => ElementorUtils::get_super_global_value( $_POST, 'kit_id' ), | |
| 580 | + 'referrer' => $referrer, | |
| 581 | + ], | |
| 582 | + ] ); | |
| 583 | + | |
| 564 | 584 | $uploaded_kit = $this->upload_kit( $file_name, $referrer ); |
| 585 | + | |
| 565 | 586 | $session_dir = $uploaded_kit['session']; |
| 566 | 587 | $manifest = $uploaded_kit['manifest']; |
| 567 | 588 | $conflicts = $uploaded_kit['conflicts']; |
| 568 | 589 | |
| @@ -570,9 +591,9 @@ | ||
| 570 | 591 | Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) ); |
| 571 | 592 | } |
| 572 | 593 | |
| 573 | 594 | if ( isset( $manifest['plugins'] ) && ! current_user_can( 'install_plugins' ) ) { |
| 574 | - throw new \Error( static::PERMISSIONS_ERROR_KEY ); | |
| 595 | + throw new \Error( static::PLUGIN_PERMISSIONS_ERROR_KEY ); | |
| 575 | 596 | } |
| 576 | 597 | |
| 577 | 598 | $result = [ |
| 578 | 599 | 'session' => $session_dir, |