Skip to content

Commit cbe273f

Browse files
Merge branch 'dashboard' of https://github.com/Wealcoder/animation-addons-for-elementor into dashboard
2 parents fce7ee8 + 8f09dfb commit cbe273f

File tree

10 files changed

+509
-37
lines changed

10 files changed

+509
-37
lines changed

inc/admin/base/WXRImporter.php

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function get_preliminary_information($file)
251251
break;
252252
}
253253
}
254-
254+
255255
$data->version = $this->version;
256256

257257
return $data;
@@ -325,6 +325,8 @@ public function parse_authors($file)
325325
return $authors;
326326
}
327327

328+
329+
328330
/**
329331
* The main controller for the actual import stage.
330332
*
@@ -350,26 +352,35 @@ public function import($file)
350352
if (is_wp_error($result)) {
351353
return $result;
352354
}
353-
355+
$data = (array) $this->get_preliminary_information($file);
356+
$total_init = 0;
357+
$temp_title = '';
358+
if (!is_wp_error($data)) {
359+
$total_init = $data['post_count'] + $data['media_count'] + $data['comment_count'] + $data['term_count'];
360+
$temp_title = isset($data['title']) ? $data['title'] : '';
361+
}
362+
354363
// Let's run the actual importer now, woot
355364
$reader = $this->get_reader($file);
356365
if (is_wp_error($reader)) {
357366
return $reader;
358367
}
359-
368+
360369
// Set the version to compatibility mode first
361370
$this->version = '1.0';
362371

363372
// Reset other variables
364373
$this->base_url = '';
374+
375+
$aae_counter_progress = 0;
365376

366377
// Start parsing!
367378
while ($reader->read()) {
368379
// Only deal with element opens
369380
if ($reader->nodeType !== XMLReader::ELEMENT) {
370381
continue;
371382
}
372-
383+
373384
switch ($reader->name) {
374385
case 'wp:wxr_version':
375386
// Upgrade to the correct version
@@ -399,9 +410,18 @@ public function import($file)
399410
case 'item':
400411
$node = $reader->expand();
401412
$parsed = $this->parse_post_node($node);
413+
$aae_counter_progress += 1;
414+
update_option('aaeaddon_template_import_progress', [
415+
'type' => 'single',
416+
'total_items' => $total_init,
417+
'title' => $temp_title,
418+
'progress' => $aae_counter_progress,
419+
'data' => [
420+
'📝 Posts: ' . $aae_counter_progress,
421+
]
422+
]);
402423
if (is_wp_error($parsed)) {
403424
$this->log_error($parsed);
404-
405425
// Skip the rest of this post
406426
$reader->next();
407427
break;
@@ -417,14 +437,23 @@ public function import($file)
417437
$node = $reader->expand();
418438

419439
$parsed = $this->parse_author_node($node);
440+
$aae_counter_progress += 1;
420441
if (is_wp_error($parsed)) {
421442
$this->log_error($parsed);
422443

423444
// Skip the rest of this post
424445
$reader->next();
425446
break;
426447
}
427-
448+
update_option('aaeaddon_template_import_progress', [
449+
'type' => 'single',
450+
'total_items' => $total_init,
451+
'title' => $temp_title,
452+
'progress' => $aae_counter_progress,
453+
'data' => [
454+
'📝 Posts: ' . $aae_counter_progress,
455+
]
456+
]);
428457
$status = $this->process_author($parsed['data'], $parsed['meta']);
429458
if (is_wp_error($status)) {
430459
$this->log_error($status);
@@ -445,7 +474,16 @@ public function import($file)
445474
$reader->next();
446475
break;
447476
}
448-
477+
$aae_counter_progress += 1;
478+
update_option('aaeaddon_template_import_progress', [
479+
'type' => 'single',
480+
'total_items' => $total_init,
481+
'title' => $temp_title,
482+
'progress' => $aae_counter_progress,
483+
'data' => [
484+
'📝 Category: ' . $aae_counter_progress,
485+
]
486+
]);
449487
$status = $this->process_term($parsed['data'], $parsed['meta']);
450488

451489
// Handled everything in this node, move on to the next
@@ -456,6 +494,16 @@ public function import($file)
456494
$node = $reader->expand();
457495

458496
$parsed = $this->parse_term_node($node, 'tag');
497+
$aae_counter_progress += 1;
498+
update_option('aaeaddon_template_import_progress', [
499+
'type' => 'single',
500+
'total_items' => $total_init,
501+
'title' => $temp_title,
502+
'progress' => $aae_counter_progress,
503+
'data' => [
504+
'📝 Terms: ' . $aae_counter_progress,
505+
]
506+
]);
459507
if (is_wp_error($parsed)) {
460508
$this->log_error($parsed);
461509

@@ -474,14 +522,23 @@ public function import($file)
474522
$node = $reader->expand();
475523

476524
$parsed = $this->parse_term_node($node);
525+
$aae_counter_progress += 1;
477526
if (is_wp_error($parsed)) {
478527
$this->log_error($parsed);
479528

480529
// Skip the rest of this post
481530
$reader->next();
482531
break;
483532
}
484-
533+
update_option('aaeaddon_template_import_progress', [
534+
'type' => 'single',
535+
'progress' => $aae_counter_progress,
536+
'title' => $temp_title,
537+
'total_items' => $total_init,
538+
'data' => [
539+
'📝 Terms: ' . $aae_counter_progress,
540+
]
541+
]);
485542
$status = $this->process_term($parsed['data'], $parsed['meta']);
486543

487544
// Handled everything in this node, move on to the next
@@ -496,14 +553,13 @@ public function import($file)
496553

497554
// Now that we've done the main processing, do any required
498555
// post-processing and remapping.
499-
$this->post_process();
556+
$this->post_process();
500557

501558
if ($this->options['aggressive_url_search']) {
502559
$this->replace_attachment_urls_in_content();
503-
}
504-
560+
$aae_counter_progress += 1;
561+
}
505562
$this->remap_featured_images();
506-
507563
$this->import_end();
508564
}
509565

@@ -2248,6 +2304,7 @@ protected function replace_attachment_urls_in_content()
22482304
*/
22492305
function remap_featured_images()
22502306
{
2307+
22512308
if (empty($this->featured_images)) {
22522309
return;
22532310
}

inc/admin/dashboard/src/pages/DemoImporting.jsx

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { LoadingSpinner } from "@/components/shared/LoadingSpinner";
22
import { Progress } from "@/components/ui/progress";
33
import DemoImportingBG from "../../public/images/demo-importing-bg.png";
4-
import { useCallback, useEffect, useState } from "react";
4+
import { use, useCallback, useEffect, useState } from "react";
55
import { debounceFn } from "@/lib/utils";
66
import { useTNavigation } from "@/hooks/app.hooks";
7+
import { set } from "react-hook-form";
78

89
const DemoImporting = () => {
910
const [currenTemplate, setCurrenTemplate] = useState(false);
1011
const [msg, setMsg] = useState("");
12+
const [templateTitle, setTemplateTitle] = useState("");
1113
const [tempstate, setTempState] = useState(null);
1214
const [progress, setProgress] = useState(0);
1315

@@ -46,14 +48,23 @@ const DemoImporting = () => {
4648
};
4749

4850
const [step, setStep] = useState("Varifying");
51+
const [totalReport, setTotalReport] = useState();
4952
useEffect(() => {
5053
if (!currenTemplate) {
5154
getTemplate(templateid);
55+
5256
} else {
53-
runImport(currenTemplate);
54-
}
55-
}, [currenTemplate]);
57+
58+
runImport(currenTemplate);
59+
60+
const interval = setInterval(() => {
61+
progressReport();
62+
}, 5000);
5663

64+
return () => clearInterval(interval); // cleanup on unmount
65+
}
66+
}, [currenTemplate]);
67+
5768
const getTemplate = useCallback(
5869
debounceFn(async (id) => {
5970
try {
@@ -81,7 +92,60 @@ const DemoImporting = () => {
8192
}
8293
}),
8394
[]
84-
);
95+
);
96+
const progressReport = async () => {
97+
const url = new URL(window.location.href);
98+
const tab = url.searchParams.get("tab");
99+
if(tab && tab == 'complete-import') {
100+
return; // If the tab is complete-import, do not fetch progress
101+
}
102+
const formData = new URLSearchParams();
103+
formData.append("action", "aaeaddon_heartbeat_data");
104+
formData.append("nonce", WCF_ADDONS_ADMIN.nonce);
105+
const response = await fetch(WCF_ADDONS_ADMIN.ajaxurl, {
106+
method: "POST",
107+
headers: {
108+
"Content-Type": "application/x-www-form-urlencoded",
109+
},
110+
body: formData.toString(),
111+
});
112+
113+
if (!response.ok) {
114+
throw new Error(`HTTP error! status: ${response.status}`);
115+
}
116+
const contentType = response.headers.get("content-type");
117+
118+
if (contentType && contentType.includes("application/json")) {
119+
const data = await response.json();
120+
121+
if (data?.import_porgress?.type === 'single') {
122+
const importCount = data.import_porgress.progress || 0;
123+
const totalCount = data.import_porgress.total_items || 1;
124+
125+
// 🔹 Content Import Only (0-100%)
126+
const contentProgress = Math.min(Math.round((importCount / totalCount) * 100), 100);
127+
128+
// 🔸 Total Import (starting from plugin/theme install)
129+
const baseProgress = Math.floor(Math.random() * (44 - 40 + 1)) + 40;
130+
const scaledImport = 50 * (importCount / totalCount);
131+
const totalProgress = Math.min(Math.round(baseProgress + scaledImport), 100);
132+
setTemplateTitle(data.import_porgress?.title);
133+
134+
// 👇 You set both
135+
setProgress((prev) => Math.max(prev, totalProgress));
136+
setMsg(
137+
`📦 Content Import: ${contentProgress}% (${importCount} of ${totalCount})\n`
138+
);
139+
140+
if (totalProgress >= 100) {
141+
shouldStop = true;
142+
clearInterval(intervalId);
143+
}
144+
}
145+
}
146+
147+
}
148+
85149

86150
const runImport = useCallback(
87151
debounceFn(async (tpldata) => {
@@ -130,7 +194,7 @@ const DemoImporting = () => {
130194
if (data?.state && data.state !== "") {
131195
setMsg(data.state);
132196
}
133-
197+
134198
runImport(tpldata);
135199
}
136200

@@ -188,9 +252,11 @@ const DemoImporting = () => {
188252
: "Creating your website..."}{" "}
189253
</h3>
190254
<p className="mt-1.5 text-text-secondary">
191-
Please wait, your website is being created. It will take upto 10
255+
Please wait, your website is being created. It will take few
192256
minute. Do not reload.
193257
</p>
258+
259+
<p className="total-State mt-1.5 text-text-secondary">{totalReport}</p>
194260
</div>
195261
<div className="mb-8">
196262
<img
@@ -200,9 +266,10 @@ const DemoImporting = () => {
200266
/>
201267
</div>
202268
<div>
269+
<h4 className="text-xl font-medium mb-2">{templateTitle}</h4>
203270
<p className="text-text-secondary">
204271
<span className="text-text"></span> {msg}
205-
</p>
272+
</p>
206273
<div className="mt-4">
207274
<span>
208275
<Progress value={progress} />

inc/admin/plugin-installer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ public function dependency_status(){
215215
wp_send_json_error(__('You are not allowed to do this action', 'animation-addons-for-elementor'));
216216
}
217217

218+
delete_option('aaeaddon_template_import_progress');
219+
delete_option('aaeaddon_template_import_state');
220+
218221
// Ensure $_POST['dependencies'] exists
219222
if (!isset($_POST['dependencies'])) {
220223
wp_send_json_error(__('Missing dependencies data', 'animation-addons-for-elementor'));

0 commit comments

Comments
 (0)