PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.1
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
templately / includes / Core / Importer / Import.php

Import.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.4.1, at includes/Core/Importer/Import.php

108 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Core\Importer;
4
5 use Exception;
6 use Templately\Core\Importer\Runners\AIContent;
7 use Templately\Core\Importer\Runners\Attachments;
8 use Templately\Core\Importer\Runners\BaseRunner;
9 use Templately\Core\Importer\Runners\Customizer;
10 use Templately\Core\Importer\Runners\Dependencies;
11 use Templately\Core\Importer\Runners\ElementorContent;
12 use Templately\Core\Importer\Runners\ExtraContent;
13 use Templately\Core\Importer\Runners\Finalizer;
14 use Templately\Core\Importer\Runners\GutenbergContent;
15 use Templately\Core\Importer\Runners\Loop;
16 use Templately\Core\Importer\Runners\Templates;
17 use Templately\Core\Importer\Runners\WPContent;
18
19 class Import {
20 use LogHelper;
21 use Loop;
22
23
24 /**
25 * @var array
26 */
27 private $manifest;
28
29 private $runners;
30 private $request_params;
31 private $session_id;
32
33 private $imported_data = [];
34
35 /**
36 * @throws Exception
37 */
38 public function __construct( $args ) {
39 $this->request_params = $args;
40 $this->manifest = $args['manifest'];
41 $this->session_id = $args['session_id'];
42
43 $this->register_runners();
44 }
45
46 /**
47 * @throws Exception
48 */
49 private function register_runners() {
50 $this->runners = [
51 // TODO: Site Settings Import Runner
52 new Dependencies( $this->request_params ),
53 new Attachments( $this->request_params ),
54 new Customizer( $this->request_params ),
55 new ExtraContent( $this->request_params ),
56 new Templates( $this->request_params ),
57 new GutenbergContent( $this->request_params ),
58 new ElementorContent( $this->request_params ),
59 new WPContent( $this->request_params ),
60 // new AIContent( $this->request_params ),
61 new Finalizer( $this->request_params )
62 ];
63 }
64
65 public function run( $callable = null ): array {
66 $data = $this->request_params;
67
68 // Get the cached imported_data
69 // $this->imported_data = $data['imported_data'] ?? [];
70
71 /**
72 * @var BaseRunner $runner
73 */
74 $imported_data = $this->loop( $this->runners, function($id, $runner, $imported_data ) use($data) {
75 $import = [];
76
77 try{
78 if ( $runner->should_run( $data, $imported_data ) ) {
79 $progress = $this->get_progress();
80 if(!in_array($runner->get_name(), $progress)){
81 $runner->log( 0 );
82 $progress[] = $runner->get_name();
83 $this->update_progress( $progress);
84 }
85 $import = $runner->import( $data, $imported_data );
86 $imported_data = array_merge_recursive( $imported_data, $import );
87
88 if( $runner->get_name() != 'finalize' ) {
89 $runner->log( 100 );
90 } else {
91 $runner->log( 100, $runner->log_message() );
92 }
93 }
94 }catch (Exception $e){
95 error_log($e->getMessage());
96 }
97
98 return $imported_data;
99 }, null, true);
100
101 return $imported_data;
102 }
103
104 public function get_runners() {
105 return $this->runners;
106 }
107 }
108