PluginProbe
Optimize Database after Deleting Revisions / 4.0.1
Optimize Database after Deleting Revisions v4.0.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.0.1, at classes/odb-scheduler.php

119 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 *******************************************************************************/
32 function odb_extra_cron_schedules()
33 {
34 global $odb_class;
35
36 $schedules['weekly'] = array(
37 'interval' => 604800,
38 'display' => __('Once Weekly', $odb_class->odb_txt_domain)
39 );
40 // FOR DEBUGGING
41 $schedules['fiveminutes'] = array(
42 'interval' => 300,
43 'display' => __('Every Five Minutes', $odb_class->odb_txt_domain)
44 );
45 return $schedules;
46 } // odb_extra_cron_schedules()
47
48
49 /*******************************************************************************
50 * UPDATE SCHEDULER (IF NEEDED)
51 *******************************************************************************/
52 function odb_update_scheduler()
53 {
54 global $odb_class;
55
56 if($odb_class->odb_rvg_options['schedule_type'] == '')
57 { // SHOULDN'T BE SCHEDULED
58 wp_clear_scheduled_hook('odb_scheduler');
59 $odb_class->odb_rvg_options['schedule_hour'] = '';
60 $odb_class->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $odb_class->odb_rvg_options);
61 }
62 else
63 { // JOB SHOULD BE SCHEDULED: SCHEDULE IT
64 if($odb_class->odb_rvg_options['schedule_type'] != 'daily' &&
65 $odb_class->odb_rvg_options['schedule_type'] != 'weekly')
66 {
67 $odb_class->odb_rvg_options['schedule_hour'] = '';
68 $odb_class->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $odb_class->odb_rvg_options);
69 }
70
71 if (!wp_next_scheduled('odb_scheduler'))
72 wp_schedule_event($this->odb_calculate_time(), $odb_class->odb_rvg_options['schedule_type'], 'odb_scheduler');
73 } // if($odb_class->odb_rvg_options['schedule_type'] == '')
74 } // odb_update_scheduler()
75
76
77 /*******************************************************************************
78 * SCHEDULE CHANGED ON SETTINGS PAGE: RESCHEDULE
79 *******************************************************************************/
80 function odb_reschedule()
81 {
82 global $odb_class;
83
84 wp_clear_scheduled_hook('odb_scheduler');
85 wp_schedule_event($this->odb_calculate_time(), $odb_class->odb_rvg_options['schedule_type'], 'odb_scheduler');
86 } // odb_reschedule()
87
88
89 /*******************************************************************************
90 * CALCULATE SCHEDULE TIME
91 *******************************************************************************/
92 function odb_calculate_time()
93 {
94 global $odb_class;
95
96 if ($odb_class->odb_rvg_options['schedule_type'] == 'daily' ||
97 $odb_class->odb_rvg_options['schedule_type'] == 'weekly')
98 {
99 // 'daily' OR 'weekly'
100 $current_datetime = Date('YmdHis');
101 $current_date = substr($current_datetime, 0, 8);
102 $current_hour = substr($current_datetime, 8, 2);
103
104 if($odb_class->odb_rvg_options['schedule_hour'] <= $current_hour)
105 // NEXT RUN WILL BE TOMORROW
106 $date = date('YmdHis', strtotime($current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000'.' + 1 day'));
107 else
108 // NEXT RUN WILL BE TODAY
109 $date = $current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000';
110 $time = strtotime($date);
111 }
112 else
113 // 'hourly' OR 'twicedaily': ONE MINUTE DELAY FOR THE FIRST RUN
114 $time = time();
115
116 return $time;
117 } // odb_calculate_time()
118 } // ODB_Scheduler
119 ?>