PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.1.10
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.1.10
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 +46 -45 3.6.13.1.10 View file →
@@ -2,26 +2,24 @@
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 -use Templately\Core\Importer\Runners\Attachments;
9 6 use Templately\Core\Importer\Runners\BaseRunner;
10 7 use Templately\Core\Importer\Runners\Customizer;
11 -use Templately\Core\Importer\Runners\Dependencies;
12 8 use Templately\Core\Importer\Runners\ElementorContent;
13 9 use Templately\Core\Importer\Runners\ExtraContent;
14 10 use Templately\Core\Importer\Runners\Finalizer;
15 11 use Templately\Core\Importer\Runners\GutenbergContent;
16 -use Templately\Core\Importer\Runners\Loop;
17 12 use Templately\Core\Importer\Runners\Templates;
18 13 use Templately\Core\Importer\Runners\WPContent;
19 14
20 15 class Import {
21 16 use LogHelper;
22 - use Loop;
23 17
18 + /**
19 + * @var FullSiteImport
20 + */
21 + public $full_site_import;
24 22
25 23 /**
26 24 * @var array
27 25 */
@@ -27,10 +25,8 @@
27 25 */
28 26 private $manifest;
29 27
30 28 private $runners;
31 - private $request_params;
32 - private $session_id;
33 29
34 30 private $imported_data = [];
35 31
36 32 /**
@@ -35,13 +31,13 @@
35 31
36 32 /**
37 33 * @throws Exception
38 34 */
39 - public function __construct( $args ) {
40 - $this->request_params = $args;
41 - $this->manifest = $args['manifest'];
42 - $this->session_id = $args['session_id'];
35 + public function __construct( $full_site_import ) {
36 + $this->full_site_import = $full_site_import;
43 37
38 + $this->manifest = $full_site_import->manifest;
39 +
44 40 $this->register_runners();
45 41 }
46 42
47 43 /**
@@ -49,43 +45,38 @@
49 45 */
50 46 private function register_runners() {
51 47 $this->runners = [
52 48 // 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 )
49 + new Customizer( $this->full_site_import ),
50 + new ExtraContent( $this->full_site_import ),
51 + new Templates( $this->full_site_import ),
52 + new GutenbergContent( $this->full_site_import ),
53 + new ElementorContent( $this->full_site_import ),
54 + new WPContent( $this->full_site_import ),
55 + new Finalizer( $this->full_site_import )
63 56 ];
64 -
65 - $this->runners = apply_filters( 'templately_import_runners', $this->runners, $this->request_params );
66 57 }
67 58
68 59 public function run( $callable = null ): array {
69 - $data = $this->request_params;
60 + $data = $this->full_site_import->get_request_params();
61 + $progress = $this->full_site_import->get_progress();
70 62
71 63 // Get the cached imported_data
72 - // $this->imported_data = $data['imported_data'] ?? [];
64 + $this->imported_data = $data['imported_data'] ?? [];
73 65
74 66 /**
75 67 * @var BaseRunner $runner
76 68 */
77 - $imported_data = $this->loop( $this->runners, function($id, $runner, $imported_data ) use($data) {
78 - $import = [];
79 -
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 + }
80 75 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 );
76 + if ( $runner->should_run( $data, $this->imported_data ) ) {
77 + $import = $runner->import( $data, $this->imported_data );
78 + $this->imported_data = array_merge_recursive( $this->imported_data, $import );
88 79
89 80 if( $runner->get_name() != 'finalize' ) {
90 81 $runner->log( 100 );
91 82 } else {
@@ -93,21 +84,31 @@
93 84 }
94 85 }
95 86 }catch (Exception $e){
96 87 error_log($e->getMessage());
88 + }
97 89
98 - // Re-throw NonRetirableErrorException to stop the import process
99 - if ($e instanceof NonRetirableErrorException) {
100 - throw $e;
101 - }
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;
102 105 }
106 + }
103 107
104 - return $imported_data;
105 - }, null, true);
106 -
107 - return $imported_data;
108 + return $this->imported_data;
108 109 }
109 110
110 111 public function get_runners() {
111 112 return $this->runners;
112 113 }
113 -}
114 +}