| @@ -34,21 +34,47 @@ | ||
| 34 | 34 | return ! empty( $this->manifest['extra-content'] ) && !empty($data['import_demo_content']); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function import( $data, $imported_data ): array { |
| 38 | - $contents = $this->manifest['extra-content'] ?? []; | |
| 38 | + $extra_content = []; | |
| 39 | + $contents = $this->manifest['extra-content']; | |
| 40 | + $progress = $this->origin->get_progress(); | |
| 39 | 41 | |
| 40 | - $extra_content = $this->loop( $contents, function($type, $content, $extra_content ) { | |
| 41 | - switch ( $type ) { | |
| 42 | - case 'form': | |
| 43 | - $import = $this->import_form( $content ); | |
| 44 | - $extra_content['form'] = $import; | |
| 45 | - break; | |
| 46 | - case 'data': | |
| 47 | - break; | |
| 42 | + if(empty($progress)){ | |
| 43 | + $this->log( 0 ); | |
| 44 | + $progress = ["__started__"]; | |
| 45 | + $this->origin->update_progress( $progress); | |
| 46 | + } | |
| 47 | + | |
| 48 | + if( ! empty( $contents ) ) { | |
| 49 | + foreach( $contents as $type => $content ) { | |
| 50 | + // If the template has been processed, skip it | |
| 51 | + if (in_array($type, $progress)) { | |
| 52 | + continue; | |
| 53 | + } | |
| 54 | + | |
| 55 | + switch ( $type ) { | |
| 56 | + case 'form': | |
| 57 | + $import = $this->import_form( $content ); | |
| 58 | + $extra_content['form'] = $import; | |
| 59 | + break; | |
| 60 | + case 'data': | |
| 61 | + break; | |
| 62 | + } | |
| 63 | + | |
| 64 | + $progress[] = $type; | |
| 65 | + $this->origin->update_progress($progress, [ 'extra-content' => $extra_content ]); | |
| 66 | + | |
| 67 | + if( end( $contents ) !== $content){ | |
| 68 | + $this->sse_message( [ | |
| 69 | + 'type' => 'continue', | |
| 70 | + 'action' => 'continue', | |
| 71 | + 'results' => __METHOD__ . '::' . __LINE__, | |
| 72 | + ] ); | |
| 73 | + exit; | |
| 74 | + } | |
| 48 | 75 | } |
| 49 | - return $extra_content; | |
| 50 | - }); | |
| 76 | + } | |
| 51 | 77 | |
| 52 | 78 | return [ 'extra-content' => $extra_content ]; |
| 53 | 79 | } |
| 54 | 80 | |