| @@ -45,14 +45,14 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | private function register_runners() { |
| 47 | 47 | $this->runners = [ |
| 48 | 48 | // TODO: Site Settings Import Runner |
| 49 | + new Customizer( $this->full_site_import ), | |
| 49 | 50 | new ExtraContent( $this->full_site_import ), |
| 50 | 51 | new Templates( $this->full_site_import ), |
| 51 | 52 | new GutenbergContent( $this->full_site_import ), |
| 52 | 53 | new ElementorContent( $this->full_site_import ), |
| 53 | 54 | new WPContent( $this->full_site_import ), |
| 54 | - new Customizer( $this->full_site_import ), | |
| 55 | 55 | new Finalizer( $this->full_site_import ) |
| 56 | 56 | ]; |
| 57 | 57 | } |
| 58 | 58 | |
| @@ -57,19 +57,24 @@ | ||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function run( $callable = null ): array { |
| 60 | 60 | $data = $this->full_site_import->get_request_params(); |
| 61 | + $progress = $this->full_site_import->get_progress(); | |
| 61 | 62 | |
| 63 | + // Get the cached imported_data | |
| 64 | + $this->imported_data = $data['imported_data'] ?? []; | |
| 65 | + | |
| 62 | 66 | /** |
| 63 | 67 | * @var BaseRunner $runner |
| 64 | 68 | */ |
| 65 | - foreach ( $this->runners as $runner ) { | |
| 69 | + foreach ( $this->runners as $id => $runner ) { | |
| 70 | + $import = null; | |
| 71 | + // If the template has been processed, skip it | |
| 72 | + if (in_array($id, $progress)) { | |
| 73 | + continue; | |
| 74 | + } | |
| 66 | 75 | try{ |
| 67 | 76 | if ( $runner->should_run( $data, $this->imported_data ) ) { |
| 68 | - if( $runner->get_name() != 'finalize' ) { | |
| 69 | - $runner->log(); | |
| 70 | - } | |
| 71 | - | |
| 72 | 77 | $import = $runner->import( $data, $this->imported_data ); |
| 73 | 78 | $this->imported_data = array_merge_recursive( $this->imported_data, $import ); |
| 74 | 79 | |
| 75 | 80 | if( $runner->get_name() != 'finalize' ) { |
| @@ -79,8 +84,25 @@ | ||
| 79 | 84 | } |
| 80 | 85 | } |
| 81 | 86 | }catch (Exception $e){ |
| 82 | 87 | error_log($e->getMessage()); |
| 88 | + } | |
| 89 | + | |
| 90 | + // Update the progress | |
| 91 | + $progress[] = $id; | |
| 92 | + $this->full_site_import->update_progress($progress, $import); | |
| 93 | + | |
| 94 | + if(end($this->runners) !== $runner) { | |
| 95 | + // $_runner = $this->runners[$id + 1]; | |
| 96 | + // if($_runner){ | |
| 97 | + // $_runner->log(); | |
| 98 | + // } | |
| 99 | + $this->sse_message( [ | |
| 100 | + 'type' => 'continue', | |
| 101 | + 'action' => 'continue', | |
| 102 | + 'results' => $runner->get_label(), | |
| 103 | + ] ); | |
| 104 | + exit; | |
| 83 | 105 | } |
| 84 | 106 | } |
| 85 | 107 | |
| 86 | 108 | return $this->imported_data; |