PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/Core/Importer/Import.php +47 -44 3.6.23.2.2 View file →
@@ -2,26 +2,25 @@
2 2
3 3 namespace Templately\Core\Importer;
4 4
5 5 use Exception;
6 -use Templately\Core\Importer\Exception\NonRetirableErrorException;
7 -use Templately\Core\Importer\Runners\AIContent;
8 6 use Templately\Core\Importer\Runners\Attachments;
9 7 use Templately\Core\Importer\Runners\BaseRunner;
10 8 use Templately\Core\Importer\Runners\Customizer;
11 -use Templately\Core\Importer\Runners\Dependencies;
12 9 use Templately\Core\Importer\Runners\ElementorContent;
13 10 use Templately\Core\Importer\Runners\ExtraContent;
14 11 use Templately\Core\Importer\Runners\Finalizer;
15 12 use Templately\Core\Importer\Runners\GutenbergContent;
16 -use Templately\Core\Importer\Runners\Loop;
17 13 use Templately\Core\Importer\Runners\Templates;
18 14 use Templately\Core\Importer\Runners\WPContent;
19 15
20 16 class Import {
21 17 use LogHelper;
22 - use Loop;
23 18
19 + /**
20 + * @var FullSiteImport
21 + */
22 + public $full_site_import;
24 23
25 24 /**
26 25 * @var array
27 26 */
@@ -27,10 +26,8 @@
27 26 */
28 27 private $manifest;
29 28
30 29 private $runners;
31 - private $request_params;
32 - private $session_id;
33 30
34 31 private $imported_data = [];
35 32
36 33 /**
@@ -35,13 +32,13 @@
35 32
36 33 /**
37 34 * @throws Exception
38 35 */
39 - public function __construct( $args ) {
40 - $this->request_params = $args;
41 - $this->manifest = $args['manifest'];
42 - $this->session_id = $args['session_id'];
36 + public function __construct( $full_site_import ) {
37 + $this->full_site_import = $full_site_import;
43 38
39 + $this->manifest = $full_site_import->manifest;
40 +
44 41 $this->register_runners();
45 42 }
46 43
47 44 /**
@@ -49,43 +46,39 @@
49 46 */
50 47 private function register_runners() {
51 48 $this->runners = [
52 49 // TODO: Site Settings Import Runner
53 - new Dependencies( $this->request_params ),
54 - new Attachments( $this->request_params ),
55 - new Customizer( $this->request_params ),
56 - new ExtraContent( $this->request_params ),
57 - new Templates( $this->request_params ),
58 - new GutenbergContent( $this->request_params ),
59 - new ElementorContent( $this->request_params ),
60 - new WPContent( $this->request_params ),
61 - // new AIContent( $this->request_params ),
62 - new Finalizer( $this->request_params )
50 + new Attachments( $this->full_site_import ),
51 + new Customizer( $this->full_site_import ),
52 + new ExtraContent( $this->full_site_import ),
53 + new Templates( $this->full_site_import ),
54 + new GutenbergContent( $this->full_site_import ),
55 + new ElementorContent( $this->full_site_import ),
56 + new WPContent( $this->full_site_import ),
57 + new Finalizer( $this->full_site_import )
63 58 ];
64 -
65 - $this->runners = apply_filters( 'templately_import_runners', $this->runners, $this->request_params );
66 59 }
67 60
68 61 public function run( $callable = null ): array {
69 - $data = $this->request_params;
62 + $data = $this->full_site_import->get_request_params();
63 + $progress = $this->full_site_import->get_progress();
70 64
71 65 // Get the cached imported_data
72 - // $this->imported_data = $data['imported_data'] ?? [];
66 + $this->imported_data = $data['imported_data'] ?? [];
73 67
74 68 /**
75 69 * @var BaseRunner $runner
76 70 */
77 - $imported_data = $this->loop( $this->runners, function($id, $runner, $imported_data ) use($data) {
78 - $import = [];
79 -
71 + foreach ( $this->runners as $id => $runner ) {
72 + $import = null;
73 + // If the template has been processed, skip it
74 + if (in_array($id, $progress)) {
75 + continue;
76 + }
80 77 try{
81 - if ( $runner->should_run( $data, $imported_data ) ) {
82 - if (!$this->is_key_processed($runner->get_name(), 'runner_start')) {
83 - $runner->log( 0 );
84 - $this->mark_key_processed($runner->get_name(), 'runner_start');
85 - }
86 - $import = $runner->import( $data, $imported_data );
87 - $imported_data = array_merge( $imported_data, $import );
78 + if ( $runner->should_run( $data, $this->imported_data ) ) {
79 + $import = $runner->import( $data, $this->imported_data );
80 + $this->imported_data = array_merge_recursive( $this->imported_data, $import );
88 81
89 82 if( $runner->get_name() != 'finalize' ) {
90 83 $runner->log( 100 );
91 84 } else {
@@ -93,21 +86,31 @@
93 86 }
94 87 }
95 88 }catch (Exception $e){
96 89 error_log($e->getMessage());
90 + }
97 91
98 - // Re-throw NonRetirableErrorException to stop the import process
99 - if ($e instanceof NonRetirableErrorException) {
100 - throw $e;
101 - }
92 + // Update the progress
93 + $progress[] = $id;
94 + $this->full_site_import->update_progress($progress, $import);
95 +
96 + if(end($this->runners) !== $runner) {
97 + // $_runner = $this->runners[$id + 1];
98 + // if($_runner){
99 + // $_runner->log();
100 + // }
101 + $this->sse_message( [
102 + 'type' => 'continue',
103 + 'action' => 'continue',
104 + 'results' => $runner->get_label(),
105 + ] );
106 + exit;
102 107 }
108 + }
103 109
104 - return $imported_data;
105 - }, null, true);
106 -
107 - return $imported_data;
110 + return $this->imported_data;
108 111 }
109 112
110 113 public function get_runners() {
111 114 return $this->runners;
112 115 }
113 -}
116 +}