| @@ -37,34 +37,18 @@ | ||
| 37 | 37 | $path = $this->dir_path . 'wp-content' . DIRECTORY_SEPARATOR; |
| 38 | 38 | $post_types = $this->filter_post_types( $data['selected_post_types'] ?? [] ); |
| 39 | 39 | $taxonomies = []; |
| 40 | 40 | $terms = []; |
| 41 | - $results = [ | |
| 42 | - "wp-content" => $data["imported_data"]["wp-content"] ?? [], | |
| 43 | - "terms" => $data["imported_data"]["terms"] ?? [], | |
| 44 | - ]; | |
| 41 | + $results = []; | |
| 45 | 42 | |
| 46 | 43 | $this->import_actions(); |
| 47 | 44 | |
| 48 | - $contents = $imported_data['wp-content_manifest_content'] ?? $this->manifest['wp-content']; | |
| 49 | - $this->processed = $imported_data['wp-content_processed'] ?? []; | |
| 45 | + $contents = $this->manifest['wp-content']; | |
| 50 | 46 | $this->total = array_reduce( $contents, function ( $carry, $item ) { |
| 51 | 47 | return $carry + count( $item ); |
| 52 | 48 | }, 0 ); |
| 53 | 49 | |
| 54 | - $processed_templates = $this->origin->get_progress(); | |
| 55 | - | |
| 56 | - if(empty($processed_templates)){ | |
| 57 | - $this->log( 0 ); | |
| 58 | - $processed_templates = ["__started__"]; | |
| 59 | - $this->origin->update_progress( $processed_templates, ['wp-content_manifest_content' => $contents]); | |
| 60 | - } | |
| 61 | - | |
| 62 | 50 | foreach ( $post_types as $type ) { |
| 63 | - if (in_array($type, $processed_templates)) { | |
| 64 | - continue; | |
| 65 | - } | |
| 66 | - | |
| 67 | 51 | if(empty($data['import_demo_content']) && !in_array($type, ['wp_navigation', 'nav_menu_item'])) { |
| 68 | 52 | continue; |
| 69 | 53 | } |
| 70 | 54 | $import = $this->import_type_data( $type, $path, $imported_data, $taxonomies, $terms ); |
| @@ -71,29 +55,11 @@ | ||
| 71 | 55 | |
| 72 | 56 | if ( empty( $import['posts'] ) ) { |
| 73 | 57 | continue; |
| 74 | 58 | } |
| 75 | - if(isset($import['posts']['__attachments'])){ | |
| 76 | - $results['wp-content']['__attachments'][ $type ] = $import['posts']['__attachments']; | |
| 77 | - unset($import['posts']['__attachments']); | |
| 78 | - } | |
| 79 | 59 | $results['wp-content'][ $type ] = $import['posts']; |
| 80 | 60 | $results['terms'][ $type ] = $import['terms']; |
| 81 | 61 | $imported_data = array_merge( $imported_data, $results ); |
| 82 | - | |
| 83 | - // Add the template to the processed templates and update the session data | |
| 84 | - $processed_templates[] = $type; | |
| 85 | - $this->origin->update_progress( $processed_templates, $results); | |
| 86 | - | |
| 87 | - // If it's not the last item, send the SSE message and exit | |
| 88 | - if( end($post_types) !== $type) { | |
| 89 | - $this->sse_message( [ | |
| 90 | - 'type' => 'continue', | |
| 91 | - 'action' => 'continue', | |
| 92 | - 'results' => __METHOD__ . '::' . __LINE__, | |
| 93 | - ] ); | |
| 94 | - exit; | |
| 95 | - } | |
| 96 | 62 | } |
| 97 | 63 | |
| 98 | 64 | $this->import_actions( true ); |
| 99 | 65 | |
| @@ -128,10 +94,8 @@ | ||
| 128 | 94 | |
| 129 | 95 | private function import_type_data( $type, $path, $imported_data, $taxonomies, $terms ): array { |
| 130 | 96 | $args = [ |
| 131 | 97 | 'fetch_attachments' => true, |
| 132 | - 'origin' => $this->origin, | |
| 133 | - 'json' => $this->json, | |
| 134 | 98 | 'posts' => Utils::map_old_new_post_ids( $imported_data ), |
| 135 | 99 | 'terms' => Utils::map_old_new_term_ids( $imported_data ), |
| 136 | 100 | 'taxonomies' => ! empty( $taxonomies[ $type ] ) ? $taxonomies[ $type ] : [], |
| 137 | 101 | 'posts_meta' => [ |
| @@ -142,12 +106,9 @@ | ||
| 142 | 106 | ], |
| 143 | 107 | ]; |
| 144 | 108 | |
| 145 | 109 | if ( isset( $imported_data['archive_settings'] ) ) { |
| 146 | - foreach ($imported_data['archive_settings'] as $key => $archive_settings) { | |
| 147 | - $args['posts'][ $archive_settings['old_id'] ] = $archive_settings['page_id']; | |
| 148 | - $args['posts'][ $archive_settings['archive_id'] ] = $archive_settings['page_id']; | |
| 149 | - } | |
| 110 | + $args['posts'][ $imported_data['archive_settings']['old_id'] ] = $imported_data['archive_settings']['page_id']; | |
| 150 | 111 | } |
| 151 | 112 | |
| 152 | 113 | $file = $path . $type . '/' . $type . '.xml'; |
| 153 | 114 | |
| @@ -185,10 +146,8 @@ | ||
| 185 | 146 | $this->processed[ $post['post_type'] ] = count($commonItems); |
| 186 | 147 | |
| 187 | 148 | $type = $post['post_type']; |
| 188 | 149 | $title = $post['post_title']; |
| 189 | - | |
| 190 | - $this->origin->update_progress( null, ['wp-content_processed' => $this->processed]); | |
| 191 | 150 | } elseif ( isset( $post['term_id'] ) ) { |
| 192 | 151 | /** |
| 193 | 152 | * FIXME: We should fix it later, with a proper count of terms and make a total with post itself. |
| 194 | 153 | */ |
| @@ -213,10 +172,9 @@ | ||
| 213 | 172 | $this->log( $progress); |
| 214 | 173 | } |
| 215 | 174 | |
| 216 | 175 | public function update_total( $WPImport ) { |
| 217 | - $session_data = $this->origin->get_session_data(); | |
| 218 | - $contents = $session_data['imported_data']['wp-content_manifest_content']; | |
| 176 | + $contents = &$this->manifest['wp-content']; | |
| 219 | 177 | |
| 220 | 178 | foreach ($WPImport->posts as $key => $post) { |
| 221 | 179 | $postType = $post['post_type']; |
| 222 | 180 | $postId = $post['post_id']; |
| @@ -229,7 +187,6 @@ | ||
| 229 | 187 | $this->total = array_reduce( $contents, function ( $carry, $item ) { |
| 230 | 188 | return $carry + count( $item ); |
| 231 | 189 | }, 0 ); |
| 232 | 190 | |
| 233 | - $this->origin->update_progress( null, ['wp-content_manifest_content' => $contents]); | |
| 234 | 191 | } |
| 235 | 192 | } |