| @@ -5,22 +5,11 @@ | ||
| 5 | 5 | use Exception; |
| 6 | 6 | use Templately\Core\Importer\Form; |
| 7 | 7 | use Templately\Core\Importer\Runners\BaseRunner; |
| 8 | 8 | use Templately\Core\Importer\Utils\Utils; |
| 9 | -use Templately\Core\Importer\Utils\SessionData; | |
| 10 | -use Templately\Utils\Helper; | |
| 11 | 9 | |
| 12 | 10 | class DownloadZip extends BaseRunner { |
| 13 | - /** | |
| 14 | - * @var string | |
| 15 | - */ | |
| 16 | - private $download_key; | |
| 17 | 11 | |
| 18 | - /** | |
| 19 | - * @var string | |
| 20 | - */ | |
| 21 | - private $filePath; | |
| 22 | - | |
| 23 | 12 | public function get_name(): string { |
| 24 | 13 | return 'downloadzip'; |
| 25 | 14 | } |
| 26 | 15 | |
| @@ -50,9 +39,12 @@ | ||
| 50 | 39 | * Download the zip |
| 51 | 40 | */ |
| 52 | 41 | $this->download_zip( $_id ); |
| 53 | 42 | |
| 54 | - SessionData::mark_step_complete($this->session_id, 'download_zip'); | |
| 43 | + $progress['download_zip'] = true; | |
| 44 | + $this->update_session_data( [ | |
| 45 | + 'progress' => $progress, | |
| 46 | + ] ); | |
| 55 | 47 | $this->sse_message( [ |
| 56 | 48 | 'type' => 'continue', |
| 57 | 49 | 'action' => 'continue', |
| 58 | 50 | 'info' => 'download_zip', |
| @@ -66,27 +58,16 @@ | ||
| 66 | 58 | * @throws Exception |
| 67 | 59 | */ |
| 68 | 60 | private function download_zip( $id ) { |
| 69 | 61 | $this->sse_log( 'download', __( 'Downloading Template Pack', 'templately' ), 1 ); |
| 70 | - | |
| 71 | - // Forward the host platform (e.g. 'ai-builder') so the cloud scopes the | |
| 72 | - // pack download the same way as the REST/AJAX calls — without it this | |
| 73 | - // binary download bypasses Helper::make_api_request() and the cloud | |
| 74 | - // defaults to 'templately', re-gating AI Builder packs. Sourced from the | |
| 75 | - // request param to match the param-only resolution in Helper. | |
| 76 | - $requested_platform = isset( $_REQUEST['requested_platform'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 77 | - ? sanitize_text_field( wp_unslash( $_REQUEST['requested_platform'] ) ) | |
| 78 | - : 'templately'; | |
| 79 | - | |
| 80 | 62 | $response = wp_remote_get( $this->get_api_url( "v2", "import/pack/$id" ), [ |
| 81 | 63 | 'timeout' => 30, |
| 82 | 64 | 'headers' => [ |
| 83 | - 'Content-Type' => 'application/json', | |
| 84 | - 'Authorization' => 'Bearer ' . $this->api_key, | |
| 85 | - 'x-templately-ip' => Helper::get_ip(), | |
| 86 | - 'x-templately-url' => home_url('/'), | |
| 87 | - 'x-templately-version' => TEMPLATELY_VERSION, | |
| 88 | - 'x-templately-requested-platform' => $requested_platform, | |
| 65 | + 'Content-Type' => 'application/json', | |
| 66 | + 'Authorization' => 'Bearer ' . $this->api_key, | |
| 67 | + 'x-templately-ip' => Helper::get_ip(), | |
| 68 | + 'x-templately-url' => home_url('/'), | |
| 69 | + 'x-templately-version' => TEMPLATELY_VERSION, | |
| 89 | 70 | ] |
| 90 | 71 | ]); |
| 91 | 72 | |
| 92 | 73 | $response_code = wp_remote_retrieve_response_code($response); |
| @@ -102,10 +83,10 @@ | ||
| 102 | 83 | |
| 103 | 84 | // If the response body is JSON and it contains an error, throw an exception with the error message |
| 104 | 85 | if (isset($response_body['status']) && $response_body['status'] === 'error') { |
| 105 | 86 | $support_message = ''; |
| 106 | - if(strpos($response_body['message'], Helper::web_url( '', [ 'support' => 'open' ] )) === false){ | |
| 107 | - $support_message = sprintf(__(" Please try again or contact <a href='%s' target='_blank'>support</a>.", "templately"), Helper::web_url( '', [ 'support' => 'open' ] )); | |
| 87 | + if(strpos($response_body['message'], 'https://wpdeveloper.com/support') === false){ | |
| 88 | + $support_message = sprintf(__(" Please try again or contact <a href='%s' target='_blank'>support</a>.", "templately"), 'https://wpdeveloper.com/support'); | |
| 108 | 89 | } |
| 109 | 90 | $this->throw_non_retryable($response_body['message'] . $support_message); |
| 110 | 91 | } |
| 111 | 92 | } |
| @@ -118,11 +99,13 @@ | ||
| 118 | 99 | $this->dir_path = $this->tmp_dir . $this->session_id . DIRECTORY_SEPARATOR; |
| 119 | 100 | $this->filePath = $this->tmp_dir . "{$this->session_id}.zip"; |
| 120 | 101 | // $this->session_id = $session_id; |
| 121 | 102 | |
| 122 | - SessionData::set($this->session_id, 'session_id', $this->session_id); | |
| 123 | - SessionData::set($this->session_id, 'dir_path', $this->dir_path); | |
| 124 | - SessionData::set($this->session_id, 'download_key', $this->download_key); | |
| 103 | + $this->update_session_data([ | |
| 104 | + 'session_id' => $this->session_id, | |
| 105 | + 'dir_path' => $this->dir_path, | |
| 106 | + 'download_key' => $this->download_key, | |
| 107 | + ]); | |
| 125 | 108 | |
| 126 | 109 | if (file_put_contents($this->filePath, $response['body'])) { // phpcs:ignore |
| 127 | 110 | $this->sse_log('download', __('Downloading Template Pack', 'templately'), 100); |
| 128 | 111 | |