| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Templately\Core\Importer\Runners; |
| 4 | 4 | |
| 5 | -use Templately\Core\Importer\Utils\FluentImport; | |
| 6 | 5 | use Templately\Core\Importer\Utils\Utils; |
| 7 | 6 | use Templately\Core\Importer\WPImport; |
| 8 | 7 | use Templately\Utils\Helper; |
| 9 | 8 | |
| @@ -39,16 +38,17 @@ | ||
| 39 | 38 | $post_types = $this->filter_post_types( $data['selected_post_types'] ?? [] ); |
| 40 | 39 | |
| 41 | 40 | $this->import_actions(); |
| 42 | 41 | |
| 43 | - $contents = $this->get_loop_result($this->manifest['wp-content'], 'wp-content_manifest_content', false); | |
| 44 | - $this->processed = $this->get_loop_result([], 'wp-content_processed', false); | |
| 42 | + $contents = $this->get_progress($this->manifest['wp-content'], 'wp-content_manifest_content', false); | |
| 43 | + $this->processed = $this->get_progress([], 'wp-content_processed', false); | |
| 45 | 44 | $this->total = array_reduce( $contents, function ( $carry, $item ) { |
| 46 | 45 | return $carry + count( $item ); |
| 47 | 46 | }, 0 ); |
| 48 | 47 | |
| 49 | 48 | |
| 50 | - $results = $this->loop( $post_types, function($key, $type, $results ) use($path, $imported_data, $data) { | |
| 49 | + $results = $this->loop( $post_types, function($key, $type ) use($path, $imported_data, $data) { | |
| 50 | + $results = []; | |
| 51 | 51 | if(empty($data['import_demo_content']) && !in_array($type, ['wp_navigation', 'nav_menu_item'])) { |
| 52 | 52 | return $results; |
| 53 | 53 | } |
| 54 | 54 | $import = $this->import_type_data( $type, $path, $imported_data ); |
| @@ -120,15 +120,8 @@ | ||
| 120 | 120 | $args['posts'][ $archive_settings['archive_id'] ] = $archive_settings['page_id']; |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if($type == 'fluent-products'){ | |
| 125 | - $file = $path . $type . '/' . 'products.json'; | |
| 126 | - $fluent_import = new FluentImport( $file ); | |
| 127 | - $result = $fluent_import->import(); | |
| 128 | - return $result; | |
| 129 | - } | |
| 130 | - | |
| 131 | 124 | $file = $path . $type . '/' . $type . '.xml'; |
| 132 | 125 | |
| 133 | 126 | if ( ! file_exists( $file ) ) { |
| 134 | 127 | return []; |
| @@ -151,9 +144,9 @@ | ||
| 151 | 144 | protected function import_actions( $remove = false ) { |
| 152 | 145 | if ( ! $remove ) { |
| 153 | 146 | add_action( 'templately_import.process_post', [ $this, 'post_log' ], 10, 2 ); |
| 154 | 147 | add_action( 'templately_import.process_term', [ $this, 'post_log' ], 10, 2 ); |
| 155 | - add_action( 'templately_import_start', [ $this, 'update_total' ], 10 ); | |
| 148 | + add_action( 'import_start', [ $this, 'update_total' ], 10 ); | |
| 156 | 149 | |
| 157 | 150 | return; |
| 158 | 151 | } |
| 159 | 152 | |
| @@ -158,9 +151,9 @@ | ||
| 158 | 151 | } |
| 159 | 152 | |
| 160 | 153 | remove_action( 'templately_import.process_post', [ $this, 'post_log' ] ); |
| 161 | 154 | remove_action( 'templately_import.process_term', [ $this, 'post_log' ] ); |
| 162 | - remove_action( 'templately_import_start', [ $this, 'update_total' ] ); | |
| 155 | + remove_action( 'import_start', [ $this, 'update_total' ] ); | |
| 163 | 156 | } |
| 164 | 157 | |
| 165 | 158 | public function post_log( $post, $result ) { |
| 166 | 159 | if ( isset( $post['post_type'] ) ) { |
| @@ -173,9 +166,9 @@ | ||
| 173 | 166 | |
| 174 | 167 | $type = $post['post_type']; |
| 175 | 168 | $title = $post['post_title']; |
| 176 | 169 | |
| 177 | - $this->set_loop_result( $this->processed, 'wp-content_processed'); | |
| 170 | + $this->update_progress( $this->processed, null, 'wp-content_processed', false); | |
| 178 | 171 | } elseif ( isset( $post['term_id'] ) ) { |
| 179 | 172 | /** |
| 180 | 173 | * FIXME: We should fix it later, with a proper count of terms and make a total with post itself. |
| 181 | 174 | */ |
| @@ -200,9 +193,9 @@ | ||
| 200 | 193 | $this->log( $progress); |
| 201 | 194 | } |
| 202 | 195 | |
| 203 | 196 | public function update_total( $WPImport ) { |
| 204 | - $contents = $this->get_loop_result([], 'wp-content_manifest_content', false); | |
| 197 | + $contents = $this->get_progress([], 'wp-content_manifest_content', false); | |
| 205 | 198 | |
| 206 | 199 | foreach ($WPImport->posts as $key => $post) { |
| 207 | 200 | $postType = $post['post_type']; |
| 208 | 201 | $postId = $post['post_id']; |
| @@ -215,7 +208,7 @@ | ||
| 215 | 208 | $this->total = array_reduce( $contents, function ( $carry, $item ) { |
| 216 | 209 | return $carry + count( $item ); |
| 217 | 210 | }, 0 ); |
| 218 | 211 | |
| 219 | - $this->set_loop_result( $contents, 'wp-content_manifest_content'); | |
| 212 | + $this->update_progress( $contents, null, 'wp-content_manifest_content', false); | |
| 220 | 213 | } |
| 221 | 214 | } |