| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | use Templately\Core\Importer\Runners\BaseRunner; |
| 8 | 8 | |
| 9 | 9 | class ExtraContent extends BaseRunner { |
| 10 | 10 | |
| 11 | + protected static $imported_form = []; | |
| 12 | + | |
| 11 | 13 | public function get_name(): string { |
| 12 | 14 | return 'extra-content'; |
| 13 | 15 | } |
| 14 | 16 | |
| @@ -34,11 +36,23 @@ | ||
| 34 | 36 | |
| 35 | 37 | public function import( $data, $imported_data ): array { |
| 36 | 38 | $extra_content = []; |
| 37 | 39 | $contents = $this->manifest['extra-content']; |
| 40 | + $progress = $this->origin->get_progress(); | |
| 38 | 41 | |
| 42 | + if(empty($progress)){ | |
| 43 | + $this->log( 0 ); | |
| 44 | + $progress = ["__started__"]; | |
| 45 | + $this->origin->update_progress( $progress); | |
| 46 | + } | |
| 47 | + | |
| 39 | 48 | if( ! empty( $contents ) ) { |
| 40 | 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 | + | |
| 41 | 55 | switch ( $type ) { |
| 42 | 56 | case 'form': |
| 43 | 57 | $import = $this->import_form( $content ); |
| 44 | 58 | $extra_content['form'] = $import; |
| @@ -45,14 +59,23 @@ | ||
| 45 | 59 | break; |
| 46 | 60 | case 'data': |
| 47 | 61 | break; |
| 48 | 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 | + } | |
| 49 | 75 | } |
| 50 | - | |
| 51 | - // $imported_data = array_merge( $imported_data, [ 'extra-content' => $this->extra_content ] ); | |
| 52 | 76 | } |
| 53 | 77 | |
| 54 | - | |
| 55 | 78 | return [ 'extra-content' => $extra_content ]; |
| 56 | 79 | } |
| 57 | 80 | |
| 58 | 81 | private function import_form( $contents ): array { |
| @@ -75,13 +98,20 @@ | ||
| 75 | 98 | } |
| 76 | 99 | |
| 77 | 100 | foreach ( $form_list as $form ) { |
| 78 | 101 | try { |
| 102 | + $form_id = isset( $form['identifier'] ) ? $form['settings'][$form['identifier']] : $form['settings']['form_list']; | |
| 103 | + if(isset(self::$imported_form[ $plugin_name ][ $form_id ])){ | |
| 104 | + $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form_id ]; | |
| 105 | + continue; | |
| 106 | + } | |
| 107 | + | |
| 79 | 108 | $file_path = $root_path . wp_unslash( $form['file_path'] ); |
| 80 | 109 | $import = new Form( $plugin_name, $file_path, $form ); |
| 81 | 110 | $data = $import->run(); |
| 82 | 111 | |
| 83 | - $result[$json_id][ $plugin_name ][ $form['id'] ] = $data; | |
| 112 | + self::$imported_form[ $plugin_name ][ $form_id ] = (string) $data; | |
| 113 | + $result[$json_id][ $plugin_name ][ $form['id'] ] = (string) $data; | |
| 84 | 114 | } catch ( Exception $e ) { |
| 85 | 115 | continue; |
| 86 | 116 | } |
| 87 | 117 | } |