PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.10
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.10
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / src / App / Service / ScheduledExport.php
wp-all-export / src / App / Service Last commit date
Addons 4 years ago License 4 years ago Pro 4 years ago VariationOptions 4 years ago CategoriesService.php 4 years ago ScheduledExport.php 4 years ago SnippetParser.php 4 years ago WooCommerceVersion.php 4 years ago
ScheduledExport.php
123 lines
1 <?php
2
3 namespace Wpae\App\Service;
4
5
6 class ScheduledExport
7 {
8 /**
9 * @param $export
10 * @return JsonResponse
11 */
12 public function trigger($export)
13 {
14 if ((int)$export->executing) {
15 return new JsonResponse(array(
16 'status' => 403,
17 'message' => sprintf(__('Export #%s is currently in manually process. Request skipped.', 'wp_all_export_plugin'), $export->id)
18 ));
19 }
20 if ($export->processing and !$export->triggered) {
21 return new JsonResponse(array(
22 'status' => 403,
23 'message' => sprintf(__('Export #%s currently in process. Request skipped.', 'wp_all_export_plugin'), $export->id)
24 ));
25 }
26 if (!$export->processing and $export->triggered) {
27 return new JsonResponse(array(
28 'status' => 403,
29 'message' => sprintf(__('Export #%s already triggered. Request skipped.', 'wp_all_export_plugin'), $export->id)
30 ));
31 }
32
33 $export->set(array(
34 'triggered' => 1,
35 'exported' => 0,
36 'last_activity' => date('Y-m-d H:i:s')
37 ))->update();
38
39 return new JsonResponse(array(
40 'status' => 200,
41 'message' => sprintf(__('#%s Cron job triggered.', 'wp_all_export_plugin'), $export->id)
42 ));
43 }
44
45 /**
46 * @param $export
47 * @param $queue_exports
48 * @param $logger
49 */
50 public function process($export, $queue_exports, $logger)
51 {
52 if ($export->processing == 1 and (time() - strtotime($export->registered_on)) > 120) { // it means processor crashed, so it will reset processing to false, and terminate. Then next run it will work normally.
53 $export->set(array(
54 'processing' => 0
55 ))->update();
56 }
57
58 // start execution imports that is in the cron process
59 if (!(int)$export->triggered) {
60 if (!empty($export->parent_id) or empty($queue_exports)) {
61 wp_send_json(array(
62 'status' => 403,
63 'message' => sprintf(__('Export #%s is not triggered. Request skipped.', 'wp_all_export_plugin'), $export->id)
64 ));
65 }
66 } elseif ((int)$export->executing) {
67 wp_send_json(array(
68 'status' => 403,
69 'message' => sprintf(__('Export #%s is currently in manually process. Request skipped.', 'wp_all_export_plugin'), $export->id)
70 ));
71 } elseif ((int)$export->triggered and !(int)$export->processing) {
72 $response = $export->set(array('canceled' => 0))->execute($logger, true);
73
74 if (!(int)$export->triggered and !(int)$export->processing) {
75
76 // trigger update child exports with correct WHERE & JOIN filters
77 if (!empty($export->options['cpt']) and class_exists('WooCommerce') and in_array('shop_order', $export->options['cpt']) and empty($export->parent_id)) {
78 $queue_exports = XmlExportWooCommerceOrder::prepare_child_exports($export, true);
79
80 if (empty($queue_exports)) {
81 delete_option('wp_all_export_queue_' . $export->id);
82 } else {
83 update_option('wp_all_export_queue_' . $export->id, $queue_exports);
84 }
85 }
86 // remove child export from queue
87 if (!empty($export->parent_id)) {
88 $queue_exports = get_option('wp_all_export_queue_' . $export->parent_id);
89
90 if (!empty($queue_exports)) {
91 foreach ($queue_exports as $key => $queue_export) {
92 if ($queue_export == $export->id) {
93 unset($queue_exports[$key]);
94 }
95 }
96 }
97
98 if (empty($queue_exports)) {
99 delete_option('wp_all_export_queue_' . $export->parent_id);
100 } else {
101 update_option('wp_all_export_queue_' . $export->parent_id, $queue_exports);
102 }
103 }
104
105 wp_send_json(array(
106 'status' => 200,
107 'message' => sprintf(__('Export #%s complete', 'wp_all_export_plugin'), $export->id)
108 ));
109 } else {
110 wp_send_json(array(
111 'status' => 200,
112 'message' => sprintf(__('Records Processed %s.', 'wp_all_export_plugin'), (int)$export->exported)
113 ));
114 }
115
116 } else {
117 wp_send_json(array(
118 'status' => 403,
119 'message' => sprintf(__('Export #%s already processing. Request skipped.', 'wp_all_export_plugin'), $export->id)
120 ));
121 }
122 }
123 }