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