Optimize Database after Deleting Revisions - Version 4.5

Version Description

[01/08/2018] = * CHANGE: Revamped and improved the scheduler code

Download this release

Release Info

Developer cageehv
Plugin Icon 128x128 Optimize Database after Deleting Revisions
Version 4.5
Comparing to
See all releases

Code changes from version 4.4.3 to 4.5

classes/odb-cleaner.php CHANGED
@@ -40,7 +40,8 @@ class ODB_Cleaner {
40
 
41
  // TIMESTAMP FOR LOG FILE
42
  $ct = ($scheduler) ? ' (cron)' : '';
43
- $current_datetime = Date('m/d/YH:i:s');
 
44
  $odb_class->log_arr = array("time" => substr($current_datetime, 0, 10).'<br>'.substr($current_datetime,10).$ct);
45
 
46
  $odb_class->log_arr["after"] = 0;
40
 
41
  // TIMESTAMP FOR LOG FILE
42
  $ct = ($scheduler) ? ' (cron)' : '';
43
+ // v4.5
44
+ $current_datetime = current_time('m/d/YH:i:s', 0);
45
  $odb_class->log_arr = array("time" => substr($current_datetime, 0, 10).'<br>'.substr($current_datetime,10).$ct);
46
 
47
  $odb_class->log_arr["after"] = 0;
classes/odb-displayer.php CHANGED
@@ -50,8 +50,6 @@ class ODB_Displayer {
50
  function display_current_settings() {
51
  global $odb_class;
52
 
53
- $current_hour = Date('H:i');
54
-
55
  $y = __('YES', $odb_class->odb_txt_domain);
56
  $n = __('NO', $odb_class->odb_txt_domain);
57
 
@@ -107,34 +105,37 @@ class ODB_Displayer {
107
 
108
  if ($rpt == '') $rpt = '(' . __('NONE', $odb_class->odb_txt_domain) . ')';
109
 
110
- echo '<span class="odb-bold">'.__('Delete revisions of', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$rpt.'</span><br />';
111
 
112
  if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
113
- echo '<span class="odb-bold">'.__('Delete revisions older than', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$odb_class->odb_rvg_options['older_than'].' '.__("days", $odb_class->odb_txt_domain).'</span><br />';
114
  }
115
 
116
  if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
117
- echo '<span class="odb-bold">'.__('Maximum number of - most recent - revisions to keep per post / page', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$odb_class->odb_rvg_options['nr_of_revisions'].'</span><br />';
118
  }
119
 
120
  echo '
121
- <span class="odb-bold">'.__('Delete trashed items', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$trash.'</span><br />
122
- <span class="odb-bold">'.__('Delete spammed items', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$spam.'</span><br />
123
- <span class="odb-bold">'.__('Delete unused tags', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$tag.'</span><br />
124
- <span class="odb-bold">'.__('Delete transients', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$trans.'</span><br />
125
- <span class="odb-bold">'.__('Delete pingbacks and trackbacks', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$ping.'</span><br />
126
- <span class="odb-bold">'.__('Keep a log', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$log.'</span><br />
127
- <span class="odb-bold">'.__('Optimize InnoDB tables', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$innodb.'</span><br />
128
- <span class="odb-bold">'.__('Last run', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$odb_class->odb_rvg_options['last_run'].' '.__('hrs', $odb_class->odb_txt_domain).'</span><br />
129
- <span class="odb-bold">'.__('Number of excluded tables', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.count($odb_class->odb_rvg_excluded_tabs).'</span><br />
130
- <span class="odb-bold">'.__('Scheduler', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$schedule.'</span><br />
131
  ';
132
 
133
  if($odb_class->odb_rvg_options['schedule_type'] != '') {
134
- $timestamp = wp_next_scheduled('odb_scheduler');
135
- $nextrun = Date('M j, Y @ H:i', $timestamp);
 
 
 
136
  echo '
137
- <span class="odb-bold">'.__('Next scheduled run',$odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$nextrun.' '.__('hrs', $odb_class->odb_txt_domain).' ('.__('current server time', $odb_class->odb_txt_domain).': '.$current_hour.' '.__('hrs', $odb_class->odb_txt_domain).')</span><br>
138
  ';
139
  } // if($odb_class->odb_rvg_options['schedule_type'] != '')
140
 
@@ -143,6 +144,16 @@ class ODB_Displayer {
143
  </div><!-- /odb-current-settings -->
144
  ';
145
  } // display_current_settings()
 
 
 
 
 
 
 
 
 
 
146
 
147
 
148
  /********************************************************************************************
50
  function display_current_settings() {
51
  global $odb_class;
52
 
 
 
53
  $y = __('YES', $odb_class->odb_txt_domain);
54
  $n = __('NO', $odb_class->odb_txt_domain);
55
 
105
 
106
  if ($rpt == '') $rpt = '(' . __('NONE', $odb_class->odb_txt_domain) . ')';
107
 
108
+ echo '<span class="odb-bold">'.__('Delete revisions of', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$rpt.'</span><br>';
109
 
110
  if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
111
+ echo '<span class="odb-bold">'.__('Delete revisions older than', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$odb_class->odb_rvg_options['older_than'].' '.__("days", $odb_class->odb_txt_domain).'</span><br>';
112
  }
113
 
114
  if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
115
+ echo '<span class="odb-bold">'.__('Maximum number of - most recent - revisions to keep per post / page', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$odb_class->odb_rvg_options['nr_of_revisions'].'</span><br>';
116
  }
117
 
118
  echo '
119
+ <span class="odb-bold">'.__('Delete trashed items', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$trash.'</span><br>
120
+ <span class="odb-bold">'.__('Delete spammed items', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$spam.'</span><br>
121
+ <span class="odb-bold">'.__('Delete unused tags', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$tag.'</span><br>
122
+ <span class="odb-bold">'.__('Delete transients', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$trans.'</span><br>
123
+ <span class="odb-bold">'.__('Delete pingbacks and trackbacks', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$ping.'</span><br>
124
+ <span class="odb-bold">'.__('Keep a log', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$log.'</span><br>
125
+ <span class="odb-bold">'.__('Optimize InnoDB tables', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$innodb.'</span><br>
126
+ <span class="odb-bold">'.__('Number of excluded tables', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.count($odb_class->odb_rvg_excluded_tabs).'</span><br>
127
+ <span class="odb-bold">'.__('Last run', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$odb_class->odb_rvg_options['last_run'].' '.__('hrs', $odb_class->odb_txt_domain).'</span><br>
128
+ <span class="odb-bold">'.__('Scheduler', $odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$schedule.'</span><br>
129
  ';
130
 
131
  if($odb_class->odb_rvg_options['schedule_type'] != '') {
132
+ // v4.5
133
+ $current_timestamp = current_time('timestamp', 1);
134
+ $cron_timestamp = wp_next_scheduled('odb_scheduler');
135
+ $diff_secs = $cron_timestamp - $current_timestamp;
136
+ $nextrun = $this->secondsToTime($diff_secs) . '<br>';
137
  echo '
138
+ <span class="odb-bold">'.__('Next scheduled run',$odb_class->odb_txt_domain).':</span> <span class="odb-bold odb-blue">'.$nextrun.'</span><br>
139
  ';
140
  } // if($odb_class->odb_rvg_options['schedule_type'] != '')
141
 
144
  </div><!-- /odb-current-settings -->
145
  ';
146
  } // display_current_settings()
147
+
148
+
149
+ /********************************************************************************************
150
+ * CONVERT SECONDS TO DAYS, HOURS, MINUTES AND SECONDS
151
+ ********************************************************************************************/
152
+ function secondsToTime($seconds) {
153
+ $dtF = new \DateTime('@0');
154
+ $dtT = new \DateTime("@$seconds");
155
+ return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
156
+ } // secondsToTime()
157
 
158
 
159
  /********************************************************************************************
classes/odb-scheduler.php CHANGED
@@ -89,21 +89,27 @@ class ODB_Scheduler {
89
 
90
 
91
  /*******************************************************************************
92
- * CALCULATE SCHEDULE TIME
93
- * v4.4.3 Fixed timing issues
 
94
  *******************************************************************************/
95
  function odb_calculate_time() {
96
  global $odb_class;
97
 
98
- // SERVER TIME, BASED ON TIMEZONE WEBSITE v4.4.3
99
- $current_date = substr($odb_class->odb_current_date, 0, 8);
100
- $current_hour = substr($odb_class->odb_current_date, 8, 2);
 
 
 
 
 
101
 
102
  if ($odb_class->odb_rvg_options['schedule_type'] == 'daily' ||
103
  $odb_class->odb_rvg_options['schedule_type'] == 'weekly' ||
104
  $odb_class->odb_rvg_options['schedule_type'] == 'monthly'
105
  ) {
106
- // 'daily' OR 'weekly' OR 'monthly'
107
  if($odb_class->odb_rvg_options['schedule_hour'] <= $current_hour) {
108
  // NEXT RUN WILL BE TOMORROW
109
  $date = date('YmdHis', strtotime($current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000'.' + 1 day'));
@@ -111,25 +117,16 @@ class ODB_Scheduler {
111
  // NEXT RUN WILL BE TODAY
112
  $date = $current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000';
113
  } // if($odb_class->odb_rvg_options['schedule_hour'] <= $current_hour)
114
- $time = strtotime($date);
115
  } else {
116
  // 'hourly' OR 'twicedaily'
117
 
118
- // ADD ONE HOUR
119
- $t = $odb_class->odb_timestamp + 3600;
120
- // CONVERT TIMESTAMP TO DATE (yyyymmddhhmmss)
121
- $d = date('YmdHis', $t);
122
- // GET THE NEW HOUR
123
- $h = substr($d, 8, 2);
124
- // CUT OFF THE TIME
125
- $d = substr($d, 0, 8);
126
- // ADD THE HOUR WITH MINS = '00' AND SECS = '00'
127
- $date = $d.$h.'0000';
128
- // CONVERT THE NEW DATE TO A TIMESTAMP
129
- $time = strtotime($d.$h.'0000');
130
  } // if ($odb_class->odb_rvg_options['schedule_type'] == 'daily' ...
131
 
132
- return $time;
 
133
  } // odb_calculate_time()
134
  } // ODB_Scheduler
135
  ?>
89
 
90
 
91
  /*******************************************************************************
92
+ * CALCULATE SCHEDULE TIME, BASED ON THE SCHEDULE TYPE
93
+ *
94
+ * v4.5 Fixed time issues
95
  *******************************************************************************/
96
  function odb_calculate_time() {
97
  global $odb_class;
98
 
99
+ // CURRENT TIME (WITH TIMEZONE)
100
+ $timestamp = current_time('timestamp', 1);
101
+ // YYYYMMDDHHMMSS
102
+ $ymdhis = date('YmdHis', $timestamp);
103
+
104
+ // CHOP TIME, YYYYMMDD
105
+ $current_date = substr($ymdhis, 0, 8);
106
+ $current_hour = substr($ymdhis, 8, 2);
107
 
108
  if ($odb_class->odb_rvg_options['schedule_type'] == 'daily' ||
109
  $odb_class->odb_rvg_options['schedule_type'] == 'weekly' ||
110
  $odb_class->odb_rvg_options['schedule_type'] == 'monthly'
111
  ) {
112
+ // 'daily', 'weekly' OR 'monthly'
113
  if($odb_class->odb_rvg_options['schedule_hour'] <= $current_hour) {
114
  // NEXT RUN WILL BE TOMORROW
115
  $date = date('YmdHis', strtotime($current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000'.' + 1 day'));
117
  // NEXT RUN WILL BE TODAY
118
  $date = $current_date.$odb_class->odb_rvg_options['schedule_hour'].'0000';
119
  } // if($odb_class->odb_rvg_options['schedule_hour'] <= $current_hour)
 
120
  } else {
121
  // 'hourly' OR 'twicedaily'
122
 
123
+ // ADD ONE HOUR TO THE CURRENT TIME: IT WILL RUN THE NEXT FULL HOUR (16:00 FOR INSTANCE)
124
+ $ts = $timestamp + 3600;
125
+ $date = date('YmdH0000', $ts);
 
 
 
 
 
 
 
 
 
126
  } // if ($odb_class->odb_rvg_options['schedule_type'] == 'daily' ...
127
 
128
+ // CONVERT TO TIMESTAMP
129
+ return strtotime($date);
130
  } // odb_calculate_time()
131
  } // ODB_Scheduler
132
  ?>
readme.txt CHANGED
@@ -8,8 +8,8 @@ Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.8
10
  Tested up to: 4.9.1
11
- Stable tag: 4.4.3
12
- Version: 4.4.3
13
  License: GPLv2 or later
14
 
15
  == Description ==
@@ -102,6 +102,9 @@ http://cagewebdev.com/wordpress-plugins/
102
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
103
 
104
  == Changelog ==
 
 
 
105
  = 4.4.3 [01/06/2018] =
106
  * BUG FIX: Fixed some scheduler time issues
107
 
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.8
10
  Tested up to: 4.9.1
11
+ Stable tag: 4.5
12
+ Version: 4.5
13
  License: GPLv2 or later
14
 
15
  == Description ==
102
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
103
 
104
  == Changelog ==
105
+ = 4.5 [01/08/2018] =
106
+ * CHANGE: Revamped and improved the scheduler code
107
+
108
  = 4.4.3 [01/06/2018] =
109
  * BUG FIX: Fixed some scheduler time issues
110
 
rvg-optimize-database.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
- * @version 4.4.3
5
  */
6
  /*
7
  Plugin Name: Optimize Database after Deleting Revisions
@@ -10,7 +10,7 @@ Description: Optimizes the Wordpress Database after Cleaning it out
10
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
11
  Author URI: http://cagewebdev.com
12
  Network: True
13
- Version: 4.4.3
14
  */
15
 
16
  /********************************************************************************************
@@ -24,8 +24,8 @@ $odb_class = new OptimizeDatabase();
24
 
25
  class OptimizeDatabase {
26
  // VERSION
27
- var $odb_version = '4.4.3';
28
- var $odb_release_date = '01/06/2018';
29
 
30
  // PLUGIN OPTIONS
31
  var $odb_rvg_options = array();
@@ -79,11 +79,6 @@ class OptimizeDatabase {
79
  function __construct() {
80
  // INITIALIZE PLUGIN
81
  add_action('init', array(&$this, 'odb_init'));
82
-
83
- // SERVER TIME, BASED ON THE TIMEZONE OF THE SITE v4.4.3
84
- date_default_timezone_set(get_option('timezone_string'));
85
- $this->odb_current_date = date('YmdHis');
86
- $this->odb_timestamp = strtotime($this->odb_current_date, time());
87
  } // __construct()
88
 
89
 
@@ -589,7 +584,7 @@ class OptimizeDatabase {
589
  $this->odb_displayer_obj->display_start_buttons($action);
590
 
591
  // REGISTER THE LAST RUN
592
- $this->odb_rvg_options['last_run'] = Date('M j, Y @ H:i');
593
  $this->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $this->odb_rvg_options);
594
  // DELETE REDUNDANT DATA
595
  $this->odb_cleaner_obj->odb_run_cleaner($scheduler);
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
+ * @version 4.5
5
  */
6
  /*
7
  Plugin Name: Optimize Database after Deleting Revisions
10
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
11
  Author URI: http://cagewebdev.com
12
  Network: True
13
+ Version: 4.5
14
  */
15
 
16
  /********************************************************************************************
24
 
25
  class OptimizeDatabase {
26
  // VERSION
27
+ var $odb_version = '4.5';
28
+ var $odb_release_date = '01/08/2018';
29
 
30
  // PLUGIN OPTIONS
31
  var $odb_rvg_options = array();
79
  function __construct() {
80
  // INITIALIZE PLUGIN
81
  add_action('init', array(&$this, 'odb_init'));
 
 
 
 
 
82
  } // __construct()
83
 
84
 
584
  $this->odb_displayer_obj->display_start_buttons($action);
585
 
586
  // REGISTER THE LAST RUN
587
+ $this->odb_rvg_options['last_run'] = current_time('M j, Y @ H:i', 0);
588
  $this->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $this->odb_rvg_options);
589
  // DELETE REDUNDANT DATA
590
  $this->odb_cleaner_obj->odb_run_cleaner($scheduler);