PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 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 All 112 releases
templately / modules / full-site-import / Concerns / NormalizesResult.php

NormalizesResult.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/full-site-import/Concerns/NormalizesResult.php

88 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Modules\FullSiteImport\Concerns;
4
5 use Elementor\Plugin;
6 use Error;
7 use Exception;
8 use Templately\Modules\FullSiteImport\Exception\FatalErrorException;
9 use Templately\Modules\FullSiteImport\Exception\RetryableErrorException;
10 use Templately\Modules\FullSiteImport\Exception\UnknownErrorException;
11 use Templately\Modules\FullSiteImport\Runners\Finalizer;
12 use Templately\Modules\FullSiteImport\Utils\LogHandler;
13 use Templately\Modules\FullSiteImport\Utils\Utils;
14 use Templately\Modules\FullSiteImport\Utils\SessionData;
15 use Templately\Modules\FullSiteImport\Utils\AIUtils;
16 use Templately\Utils\Helper;
17 use Templately\Utils\Options;
18
19 /**
20 * NormalizesResult — extracted verbatim from FullSiteImport (behavior-preserving).
21 * Composed back into FullSiteImport via `use`; $this and method resolution unchanged.
22 */
23 trait NormalizesResult {
24 private function normalize_imported_data($data) {
25 $request_params = $this->get_session_data();
26 $attachments = !empty($data['attachments']['succeed']) ? count($data['attachments']['succeed']) : 0;
27 $attachments_fail = !empty($data['attachments']['failed']) ? count($data['attachments']['failed']) : 0;
28 $attachments_errors = !empty($data['attachments_errors']) ? $data['attachments_errors'] : [];
29 $templates = !empty($data['templates']['succeed']) ? count($data['templates']['succeed']) : 0;
30 $template_types = !empty($data['templates']['template_types']) ? $data['templates']['template_types'] : [];
31 $dependency_data = !empty($data['dependency_data']) ? $data['dependency_data'] : [];
32
33 $post_types = [];
34 $content_templates = [];
35 if (!empty($data['content']) && is_array($data['content'])) {
36 foreach ($data['content'] as $type => $type_data) {
37 $content_templates[$type] = !empty($type_data['succeed']) ? count($type_data['succeed']) : 0;
38 $post_types[] = $this->get_post_type_label_by_slug($type);
39 }
40 }
41
42 $contents = [];
43 if (!empty($data['wp-content']) && is_array($data['wp-content'])) {
44 foreach ($data['wp-content'] as $type => $type_data) {
45 $contents[$type] = !empty($type_data['succeed']) ? count($type_data['succeed']) : 0;
46 if (!in_array($type, ['wp_navigation', 'nav_menu_item'])) {
47 $post_types[] = $this->get_post_type_label_by_slug($type);
48 }
49 }
50 }
51
52 $_processed_pages = AIUtils::get_processed_pages_data($request_params['process_id']);
53 $ai_content = [
54 'requested' => $request_params['ai_page_ids'] ?? [],
55 'processed' => $_processed_pages,
56 ];
57
58
59 $result = [
60 'attachments' => $attachments,
61 'attachments_fail' => $attachments_fail,
62 'attachments_errors' => $attachments_errors,
63 'templates' => $templates,
64 'contents' => $content_templates,
65 'wp-content' => $contents,
66 'post_types' => $post_types,
67 'template_types' => $template_types,
68 'ai_content' => $ai_content,
69 'dependency_data' => $dependency_data,
70 'home_url' => home_url('/'),
71 ];
72
73 Helper::log($data);
74 Helper::log($result);
75
76 return $result;
77 }
78
79 protected function get_post_type_label_by_slug($slug) {
80 $post_type_obj = get_post_type_object($slug);
81 if ($post_type_obj) {
82 return $post_type_obj->label;
83 }
84 return null;
85 }
86
87 }
88