PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.4
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.4
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 / Runners / BaseRunner.php

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

102 lines 2.3 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\Runners;
4
5 use Exception;
6 use Templately\Builder\Factory\TemplateFactory;
7 use Templately\Core\Importer\FullSiteImport;
8 use Templately\Core\Importer\Import;
9 use Templately\Core\Importer\LogHelper;
10 use Templately\Core\Importer\Utils\ImportHelper;
11 use Templately\Core\Importer\Utils\Utils;
12
13 abstract class BaseRunner {
14 use LogHelper;
15 use Loop;
16
17 const META_SESSION_KEY = '_templately_import_session_id';
18 /**
19 * @var FullSiteImport
20 */
21 protected $dev_mode;
22 protected $origin;
23 protected $platform;
24 protected $manifest;
25 protected $dir_path;
26 protected $session_id;
27
28 /**
29 * @var ImportHelper
30 */
31 protected $json;
32
33 /**
34 * @var TemplateFactory
35 */
36 protected $factory;
37
38 /**
39 * @throws Exception
40 */
41 public function __construct( $request_params ) {
42 $this->dev_mode = defined('TEMPLATELY_DEV') && TEMPLATELY_DEV;
43 $this->origin = $request_params['origin'];
44 $this->dir_path = $request_params['dir_path'];
45 $this->manifest = &$request_params['manifest'];
46 $this->platform = $this->manifest['platform'] ?? '';
47 $this->session_id = $request_params['session_id'];
48
49
50 $this->factory = new TemplateFactory( $this->platform );
51 $this->json = Utils::get_json_helper( $this->platform );
52 $this->json->session_id = $this->session_id;
53
54 if ( empty( $this->platform ) ) {
55 throw new Exception( __( 'Platform is not specified. Please try again after specifying the platform.', 'templately' ) );
56 }
57 }
58
59 public function should_log(): bool {
60 return true;
61 }
62
63 public function get_action(): string {
64 return 'updateLog';
65 }
66
67 abstract public function get_name(): string;
68
69 abstract public function get_label(): string;
70
71 abstract public function should_run( $data, $imported_data = [] ): bool;
72
73 abstract public function import( $data, $imported_data ): array;
74
75 abstract public function log_message() : string;
76
77 public function log( $progress = 0, $message = null, $action = null ) {
78 if( ! $this->should_log() ) {
79 return;
80 }
81
82 if( $message == null ) {
83 $message = $this->log_message();
84 }
85
86 if( $action == null ) {
87 $action = $this->get_action();
88 }
89
90 $this->sse_log( $this->get_name(), $message, min( $progress, 100 ), $action );
91 }
92
93 /**
94 * @throws Exception
95 */
96 protected function throw($message, $code = 0) {
97 if ($this->dev_mode) {
98 error_log(print_r($message, 1));
99 }
100 throw new Exception($message);
101 }
102 }