PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.6.9.1
JetBackup – Backup, Restore & Migrate v1.6.9.1
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 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.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / core / schedule / SGScheduleAdapterWordpress.php
backup / com / core / schedule Last commit date
SGIScheduleAdapter.php 5 years ago SGSchedule.php 5 years ago SGScheduleAdapterWordpress.php 4 years ago
SGScheduleAdapterWordpress.php
142 lines
1 <?php
2
3 require_once(SG_SCHEDULE_PATH . 'SGIScheduleAdapter.php');
4
5 class SGScheduleAdapterWordpress implements SGIScheduleAdapter
6 {
7 public static function create($cron, $id = SG_SCHEDULER_DEFAULT_ID)
8 {
9 if (!self::isCronAvailable()) {
10 return false;
11 }
12
13 $cronExecutionData = self::getCronExecutionData($cron);
14 $time = $cronExecutionData['time'];
15 $recurrence = $cronExecutionData['recurrence'];
16
17 $args = array((int) $id);
18 wp_schedule_event($time, $recurrence, SG_SCHEDULE_ACTION, $args);
19 }
20
21 public static function getCronExecutionData($cron)
22 {
23 $recurrence = '';
24 $tmpTime = self::getTmpTime($cron['intervalHour']);
25 $tmpTimeUTC = strtotime(backupGuardConvertDateTimezoneToUTC(@date('Y-m-d H:i:s', $tmpTime)));
26
27 if ($cron['interval'] == BG_SCHEDULE_INTERVAL_HOURLY) {
28 $recurrence = 'hourly';
29 $time = strtotime(backupGuardCeliDateTimezone(time() + 3600));
30 $time = strtotime(backupGuardConvertDateTimezone(@date('Y-m-d H:i:s', $time), true));
31 } else if ($cron['interval'] == BG_SCHEDULE_INTERVAL_DAILY) {
32 $recurrence = 'daily';
33 if ($tmpTimeUTC <= time()) {
34 $time = strtotime('Next day ' . sprintf("%02d:00", $cron['intervalHour']));
35 } else {
36 $time = $tmpTime;
37 }
38 } else if ($cron['interval'] == BG_SCHEDULE_INTERVAL_WEEKLY) {
39 $recurrence = 'weekly';
40 $dayOfInterval = $cron['dayOfInterval'];
41
42 switch ($dayOfInterval) {
43 case 2:
44 $dayOfInterval = 'Tuesday';
45 break;
46 case 3:
47 $dayOfInterval = 'Wednesday';
48 break;
49 case 4:
50 $dayOfInterval = 'Thursday';
51 break;
52 case 5:
53 $dayOfInterval = 'Friday';
54 break;
55 case 6:
56 $dayOfInterval = 'Saturday';
57 break;
58 case 7:
59 $dayOfInterval = 'Sunday';
60 break;
61 default:
62 $dayOfInterval = 'Monday';
63 break;
64 }
65
66 if ($tmpTimeUTC <= time()) {
67 $time = strtotime('Next ' . $dayOfInterval . ' ' . sprintf("%02d:00", $cron['intervalHour']));
68 } else {
69 $time = strtotime('this ' . $dayOfInterval . ' ' . sprintf("%02d:00", $cron['intervalHour']));
70 }
71 } else if ($cron['interval'] == BG_SCHEDULE_INTERVAL_MONTHLY) {
72 $recurrence = 'monthly';
73 $dayOfInterval = $cron['dayOfInterval'];
74 $today = (int) date('d');
75
76 if ($today > $dayOfInterval) {
77 $time = strtotime('first day of next month ' . sprintf("%02d:00", $cron['intervalHour']));
78 $time += ($dayOfInterval - 1) * SG_ONE_DAY_IN_SECONDS;
79 } else if ($today == $dayOfInterval) {
80 if ($tmpTimeUTC > time()) {
81 $time = $tmpTime;
82 } else {
83 $time = strtotime('first day of next month ' . sprintf("%02d:00", $cron['intervalHour']));
84 $time += ($dayOfInterval - 1) * SG_ONE_DAY_IN_SECONDS;
85 }
86 } else {
87 $time = $tmpTime + ($dayOfInterval - $today) * SG_ONE_DAY_IN_SECONDS;
88 }
89 } else {
90 $recurrence = 'yearly';
91 $dayOfInterval = $cron['dayOfInterval'];
92 $monthOfInterval = $cron['monthOfInterval'];
93 $monthOfIntervalName = date('F', mktime(0, 0, 0, $monthOfInterval, 10));
94 $today = (int) date('d');
95 $thisMonth = (int) date('n');
96
97 if ($thisMonth > $monthOfInterval) {
98 $time = strtotime($dayOfInterval . ' ' . $monthOfIntervalName . ' next year ' . sprintf('%02d:00', $cron['intervalHour']));
99 } else if ($thisMonth == $monthOfInterval) {
100 if ($today > $dayOfInterval) {
101 $time = strtotime($dayOfInterval . ' ' . $monthOfIntervalName . ' next year ' . sprintf('%02d:00', $cron['intervalHour']));
102 } else if ($today == $dayOfInterval) {
103 if ($tmpTimeUTC > time()) {
104 $time = strtotime($dayOfInterval . ' ' . $monthOfIntervalName . ' this year ' . sprintf('%02d:00', $cron['intervalHour']));
105 } else {
106 $time = strtotime($dayOfInterval . ' ' . $monthOfIntervalName . ' next year ' . sprintf('%02d:00', $cron['intervalHour']));
107 }
108 } else {
109 $time = strtotime($dayOfInterval . ' ' . $monthOfIntervalName . ' this year ' . sprintf('%02d:00', $cron['intervalHour']));
110 }
111 } else {
112 $time = strtotime($dayOfInterval . ' ' . $monthOfIntervalName . ' this year ' . sprintf('%02d:00', $cron['intervalHour']));
113 }
114 }
115
116 return array(
117 'time' => strtotime(backupGuardConvertDateTimezoneToUTC(@date("Y-m-d H:i:s", $time))),
118 'recurrence' => $recurrence
119 );
120 }
121
122 public static function remove($id = SG_SCHEDULER_DEFAULT_ID)
123 {
124 $args = array((int) $id);
125 wp_clear_scheduled_hook(SG_SCHEDULE_ACTION, $args);
126 }
127
128 public static function getTmpTime($hours)
129 {
130 return (int) strtotime('Today ' . sprintf("%02d:00", $hours));
131 }
132
133 public static function isCronAvailable($force = false)
134 {
135 if ($force) {
136 return !defined('DISABLE_WP_CRON') || !DISABLE_WP_CRON;
137 }
138
139 return true;
140 }
141 }
142