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

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

88 lines 2.0 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
16 const META_SESSION_KEY = '_templately_import_session_id';
17 /**
18 * @var FullSiteImport
19 */
20 protected $origin;
21 protected $platform;
22 protected $manifest;
23 protected $dir_path;
24 protected $session_id;
25
26 /**
27 * @var ImportHelper
28 */
29 protected $json;
30
31 /**
32 * @var TemplateFactory
33 */
34 protected $factory;
35
36 /**
37 * @throws Exception
38 */
39 public function __construct( FullSiteImport $full_site_import ) {
40 $this->origin = $full_site_import;
41 $this->dir_path = $full_site_import->dir_path;
42 $this->manifest = &$full_site_import->manifest;
43 $this->platform = $this->manifest['platform'] ?? '';
44 $this->session_id = $full_site_import->session_id;
45
46
47 $this->factory = new TemplateFactory( $this->platform );
48 $this->json = Utils::get_json_helper( $this->platform );
49
50 if ( empty( $this->platform ) ) {
51 throw new Exception( __( 'Platform is not specified. Please try again after specifying the platform.', 'templately' ) );
52 }
53 }
54
55 public function should_log(): bool {
56 return true;
57 }
58
59 public function get_action(): string {
60 return 'updateLog';
61 }
62
63 abstract public function get_name(): string;
64
65 abstract public function get_label(): string;
66
67 abstract public function should_run( $data, $imported_data = [] ): bool;
68
69 abstract public function import( $data, $imported_data ): array;
70
71 abstract public function log_message() : string;
72
73 public function log( $progress = 0, $message = null, $action = null ) {
74 if( ! $this->should_log() ) {
75 return;
76 }
77
78 if( $message == null ) {
79 $message = $this->log_message();
80 }
81
82 if( $action == null ) {
83 $action = $this->get_action();
84 }
85
86 $this->sse_log( $this->get_name(), $message, min( $progress, 100 ), $action );
87 }
88 }