PluginProbe
Optimize Database after Deleting Revisions / 4.1
Optimize Database after Deleting Revisions v4.1
3.4.7 3.4.8 3.4.9 3.5 3.5.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.3 All 144 releases
rvg-optimize-database / classes / odb-scheduler.php

odb-scheduler.php in Optimize Database after Deleting Revisions 4.1, at classes/odb-scheduler.php

120 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /************************************************************************************************
3 *
4 * SCHEDULER CLASS
5 *
6 ************************************************************************************************/
7 ?>
8 <?php
9 class ODB_Scheduler
10 {
11 /********************************************************************************************
12 * CONSTRUCTOR
13 ********************************************************************************************/
14 function __construct()
15 {
16 global $odb_class;
17
18 // ADD EXTRA CRON SCHEDULES
19 add_filter('cron_schedules', array(&$this, 'odb_extra_cron_schedules'));
20
21 // ADD SCHEDULER
22 add_action('odb_scheduler', array(&$odb_class, 'odb_start_scheduler'));
23 } // __construct()
24
25
26 /*******************************************************************************
27 * ADD EXTRA SCHEDULE FOR THE CRONTAB
28 * http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
29 *
30 * v4.0.1 Localization fixed
31 * v4.0.3 ($schedules) added as a parameter
32 *******************************************************************************/
33 function odb_extra_cron_schedules($schedules)
34 {
35 global $odb_class;
36
37 $schedules['weekly'] = array(
38 'interval' => 604800,
39 'display' => __('Once Weekly', $odb_class->odb_txt_domain)
40 );
41 // FOR DEBUGGING
42 $schedules['fiveminutes'] = array(
43 'interval' => 300,
44 'display' => __('Every Five Minutes', $odb_class->odb_txt_domain)
45 );
46 return $schedules;
47 } // odb_extra_cron_schedules()
48
49
50 /*******************************************************************************
51 * UPDATE SCHEDULER (IF NEEDED)
52 *******************************************************************************/
53 function odb_update_scheduler()
54 {
55 global $odb_class;
56
57 if($odb_class->odb_rvg_options['schedule_type'] == '')
58 { // SHOULDN'T BE SCHEDULED
59 wp_clear_scheduled_hook('odb_scheduler');
60 $odb_class->odb_rvg_options['schedule_hour'] = '';
61 $odb_class->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $odb_class->odb_rvg_options);
62 }
63 else
64 { // JOB SHOULD BE SCHEDULED: SCHEDULE IT
65 if($odb_class->odb_rvg_options['schedule_type'] != 'daily' &&
66 $odb_class->odb_rvg_options['schedule_type'] != 'weekly')
67 {
68 $odb_class->odb_rvg_options['schedule_hour'] = '';
69 $odb_class->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $odb_class->odb_rvg_options);
70 }
71
72 if (!wp_next_scheduled('odb_scheduler'))
73 wp_schedule_event($this->odb_calculate_time(), $odb_class->odb_rvg_options['schedule_type'], 'odb_scheduler');
74 } // if($odb_class->odb_rvg_options['schedule_type'] == '')
75 } // odb_update_scheduler()
76
77
78 /*******************************************************************************
79 * SCHEDULE CHANGED ON SETTINGS PAGE: RESCHEDULE
80 *******************************************************************************/
81 function odb_reschedule()
82 {
83 global $odb_class;
84
85 wp_clear_scheduled_hook('odb_scheduler');
86 wp_schedule_event($this->odb_calculate_time(), $odb_class->odb_rvg_options['schedule_type'], 'odb_scheduler');
87 } // odb_reschedule()
88
89
90 /*******************************************************************************
91 * CALCULATE SCHEDULE TIME
92 *******************************************************************************/
93 function odb_calculate_time()
94 {
95 global $odb_class;
96
97 if ($odb_class->odb_rvg_options['schedule_type'] == 'daily' ||
98 $odb_class->odb_rvg_options['schedule_type'] == 'weekly')
99 {
100 // 'daily' OR 'weekly'
101 $current_datetime = Date('YmdHis');
102 $current_date = substr($current_datetime, 0, 8);
103 $current_hour = substr($current_datetime, 8, 2);
104
105 if($odb_class->odb_rvg_options['schedule_hour'] <= $current_hour)
106 // NEXT RUN WILL BE TOMORROW
107 $date = date('YmdHis', strtotime($current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000'.' + 1 day'));
108 else
109 // NEXT RUN WILL BE TODAY
110 $date = $current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000';
111 $time = strtotime($date);
112 }
113 else
114 // 'hourly' OR 'twicedaily'
115 $time = time();
116
117 return $time;
118 } // odb_calculate_time()
119 } // ODB_Scheduler
120 ?>