PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Analytics / AnalyticsEventWithTimeDto.php
wp-staging / Framework / Analytics Last commit date
Actions 1 day ago AnalyticsCleanup.php 1 day ago AnalyticsConsent.php 1 day ago AnalyticsEventDto.php 1 day ago AnalyticsEventWithTimeDto.php 1 day ago AnalyticsGenericEventHandler.php 1 day ago AnalyticsSender.php 1 day ago ErrorCode.php 1 day ago WithAnalyticsAPI.php 1 day ago WithAnalyticsSiteInfo.php 1 day ago
AnalyticsEventWithTimeDto.php
133 lines
1 <?php
2
3 namespace WPStaging\Framework\Analytics;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Filesystem\DebugLogReader;
7
8 abstract class AnalyticsEventWithTimeDto extends AnalyticsEventDto
9 {
10
11 protected $finished_at = null;
12
13
14 protected $stale_at = null;
15
16
17 protected $error_at = null;
18
19
20 protected $cancelled_at = null;
21
22
23 protected $start_at = null;
24
25 public function enqueueStartEvent($jobId, $eventData)
26 {
27 $this->job_identifier = $jobId;
28 $this->start_at = time();
29 $this->event_hash = microtime(true) . rand();
30
31 try {
32 $this->saveEvent($jobId, $this);
33 } catch (\Exception $e) {
34 \WPStaging\functions\debug_log("WP STAGING: Could not register start event analytics data for job ID $jobId.", 'debug', false);
35 }
36 }
37
38 public function enqueueFinishEvent($jobId, $eventData, $eventOverrides = [])
39 {
40 try {
41 $event = $this->getEventByJobId($jobId);
42 } catch (\Exception $e) {
43 \WPStaging\functions\debug_log("WP STAGING: Could not register finish event analytics data for job ID $jobId", 'debug', false);
44
45 return;
46 }
47
48 $event->finished_at = time();
49 $event->duration = time() - $event->start_at;
50 $event->ready_to_send = true;
51
52
53 foreach ($eventOverrides as $key => $value) {
54 $event->$key = $value;
55 }
56
57 try {
58 $this->saveEvent($jobId, $event);
59 } catch (\Exception $e) {
60 \WPStaging\functions\debug_log("WP STAGING: Could not save finish event analytics data for job ID $jobId.", 'debug', false);
61 }
62 }
63
64
65
66
67 public static function enqueueCancelEvent($jobId)
68 {
69 try {
70 $event = static::getEventByJobId($jobId);
71 } catch (\Exception $e) {
72 \WPStaging\functions\debug_log("WP STAGING: Could not register cancel event analytics data for job ID $jobId", 'debug', false);
73
74 return;
75 }
76
77
78 if ($event->cancelled_at) {
79 return;
80 }
81
82
83
84
85
86
87 if ($event->error_at) {
88 return;
89 }
90
91 $event->finished_at = null;
92 $event->cancelled_at = time();
93 $event->duration = time() - $event->start_at;
94 $event->ready_to_send = true;
95
96 try {
97 static::saveEvent($jobId, $event);
98 } catch (\Exception $e) {
99 \WPStaging\functions\debug_log("WP STAGING: Could not save cancel event analytics data for job ID $jobId.", 'debug', false);
100 }
101 }
102
103
104
105
106 public static function enqueueErrorEvent($jobId, $errorMessage, string $errorCode = '')
107 {
108 try {
109 $event = static::getEventByJobId($jobId);
110 } catch (\Exception $e) {
111 \WPStaging\functions\debug_log("WP STAGING: Could not register cancel event analytics data for job ID $jobId", 'debug', false);
112
113 return;
114 }
115
116 $lastDebugLogErrors = WPStaging::make(DebugLogReader::class)->getLastLogEntries(8 * KB_IN_BYTES);
117
118 $event->finished_at = null;
119 $event->error_at = time();
120 $event->error_message = $errorMessage;
121 $event->error_code = ErrorCode::sanitize($errorCode);
122 $event->last_debug_logs = $lastDebugLogErrors;
123 $event->duration = time() - $event->start_at;
124 $event->ready_to_send = true;
125
126 try {
127 static::saveEvent($jobId, $event);
128 } catch (\Exception $e) {
129 \WPStaging\functions\debug_log("WP STAGING: Could not save cancel event analytics data for job ID $jobId.", 'debug', false);
130 }
131 }
132 }
133