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

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