Optimize Database after Deleting Revisions - Version 2.4

Version Description

[05/24/2013] = * NEW: you can set a time (hour) for the scheduler to run (thanks to frekel) * NEW: '1-click run button' in the admin bar (thanks to JB ORSI)

Download this release

Release Info

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

Code changes from version 2.3.1 to 2.4

Files changed (2) hide show
  1. readme.txt +11 -4
  2. rvg-optimize-db.php +85 -12
readme.txt CHANGED
@@ -6,10 +6,10 @@ Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-rev
6
  Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, clean up, trash, spam, trashed, spammed, database size, scheduler
7
  Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
- Requires at least: 2.3.1
10
  Tested up to: 3.5.1
11
- Stable tag: 2.3.1
12
- Version: 2.3.1
13
 
14
  == Description ==
15
 
@@ -22,7 +22,7 @@ This plugin is a 'One Click' WordPress Database Cleaner / Optimizer.
22
  * Deletes 'orphan postmeta items'
23
  * Optimizes the database tables (optionally you can exclude certain tables from optimization)
24
  * Creates a log file of the optimizations (optional)
25
- * Optimization can be scheduled to automatically run once hourly, twice daily, once daily or once weekly (optional)
26
 
27
  = Settings =
28
  You can find the settings page in the WP Admin Panel » Settings » Optimize DB Options.
@@ -48,6 +48,10 @@ http://wordpress.org/extend/plugins/rvg-optimize-database/
48
 
49
  == Changelog ==
50
 
 
 
 
 
51
  = 2.3.1 [05/03/2013] =
52
  * BUG FIX: fixed a problem with 'invalid header' (during installation)
53
 
@@ -162,3 +166,6 @@ http://wordpress.org/extend/plugins/rvg-optimize-database/
162
 
163
  = Why do I see 'Table does not support optimize, doing recreate + analyze instead' while optimizing my database? =
164
  * That is because the table type of that table is not 'MyISAM'
 
 
 
6
  Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, clean up, trash, spam, trashed, spammed, database size, scheduler
7
  Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
+ Requires at least: 2.4
10
  Tested up to: 3.5.1
11
+ Stable tag: 2.4
12
+ Version: 2.4
13
 
14
  == Description ==
15
 
22
  * Deletes 'orphan postmeta items'
23
  * Optimizes the database tables (optionally you can exclude certain tables from optimization)
24
  * Creates a log file of the optimizations (optional)
25
+ * Optimization can be scheduled to automatically run once hourly, twice daily, once daily or once weekly at a specific time (optional)
26
 
27
  = Settings =
28
  You can find the settings page in the WP Admin Panel » Settings » Optimize DB Options.
48
 
49
  == Changelog ==
50
 
51
+ = 2.4 [05/24/2013] =
52
+ * NEW: you can set a time (hour) for the scheduler to run (thanks to frekel)
53
+ * NEW: '1-click run button' in the admin bar (thanks to JB ORSI)
54
+
55
  = 2.3.1 [05/03/2013] =
56
  * BUG FIX: fixed a problem with 'invalid header' (during installation)
57
 
166
 
167
  = Why do I see 'Table does not support optimize, doing recreate + analyze instead' while optimizing my database? =
168
  * That is because the table type of that table is not 'MyISAM'
169
+
170
+ = I scheduled the optimization for 8pm but it runs at 6pm (my local time) =
171
+ * The scheduler uses the local time of the web server which can differ from your own local time
rvg-optimize-db.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
- $odb_version = '2.3.1';
3
- $odb_release_date = '`05/03/2013';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
- * @version 2.3.1
7
  */
8
  /*
9
  Plugin Name: Optimize Database after Deleting Revisions
10
  Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/
11
  Description: Optimizes the Wordpress Database after Cleaning it out - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
12
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
13
- Version: 2.3.1
14
  Author URI: http://cagewebdev.com
15
  */
16
  ?>
@@ -42,6 +42,19 @@ function rvg_odb_admin_menu()
42
  add_action( 'admin_menu', 'rvg_odb_admin_menu' );
43
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  /********************************************************************************************
46
 
47
  ACTIONS FOR THE SCHEDULER
@@ -93,6 +106,11 @@ function rvg_activate_plugin()
93
  function rvg_odb_options_page() {
94
  global $odb_version, $odb_release_date, $wpdb, $table_prefix;
95
 
 
 
 
 
 
96
  # jQuery FRAMEWORK
97
  echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>';
98
 
@@ -150,13 +168,36 @@ function rvg_odb_options_page() {
150
  $rvg_odb_schedule = $_POST['rvg_odb_schedule'];
151
  update_option('rvg_odb_schedule', $rvg_odb_schedule);
152
 
 
 
 
 
 
153
  // CLEAR CURRENT SCHEDULE (IF ANY)
154
  wp_clear_scheduled_hook('rvg_optimize_database');
155
 
156
  // HAS TO BE SCHEDULED
157
  if($rvg_odb_schedule != '')
158
  if( !wp_next_scheduled( 'rvg_optimize_database' ))
159
- wp_schedule_event( time(), $rvg_odb_schedule, 'rvg_optimize_database' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  // UPDATED MESSAGE
162
  echo "<div class='updated'><p><strong>Optimize Database after Deleting Revisions OPTIONS UPDATED</strong> - Click <a href='tools.php?page=rvg-optimize-db.php' style='font-weight:bold'>HERE</a> to run the optimization</p></div>";
@@ -175,9 +216,20 @@ function rvg_odb_options_page() {
175
  if(!$rvg_odb_logging_on) $rvg_odb_logging_on = 'N';
176
 
177
  $rvg_odb_schedule = get_option('rvg_odb_schedule');
178
- if(!$rvg_odb_schedule) $rvg_odb_schedule = '';
 
 
179
  ?>
180
-
 
 
 
 
 
 
 
 
 
181
  <form name="options" method="post" action="">
182
  <div class="wrap">
183
  <h2>Using Optimize Database after Deleting Revisions</h2>
@@ -225,17 +277,33 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
225
  <td width="50%" valign="top"><input name="rvg_odb_logging_on" type="checkbox" value="Y" <?php echo $rvg_odb_logging_on_checked?> /></td>
226
  </tr>
227
  <tr>
228
- <td width="50%" align="right" valign="top"><span style="font-weight:bold;">Scheduler</span></td>
229
- <td width="50%" valign="top"><select name="rvg_odb_schedule" id="rvg_odb_schedule">
230
  <option selected="selected" value="">NOT SCHEDULED</option>
231
  <option value="hourly">run optimization HOURLY</option>
232
  <option value="twicedaily">run optimization TWICE A DAY</option>
233
  <option value="daily">run optimization DAILY</option>
234
  <option value="weekly">run optimization WEEKLY</option>
235
- <?php /*?> <option value="test">run optimization TEST</option><?php */?>
236
  </select>
237
  <script type="text/javascript">
238
  document.options.rvg_odb_schedule.value = '<?php echo $rvg_odb_schedule; ?>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  </script></td>
240
  </tr>
241
  </table></td>
@@ -303,6 +371,9 @@ function rvg_optimize_db()
303
  {
304
  global $wpdb, $odb_version, $table_prefix;
305
 
 
 
 
306
  if(isset($_REQUEST['action']))
307
  if($_REQUEST['action'] == "delete_log")
308
  @unlink(dirname(__FILE__).'/rvg-optimize-db-log.html');
@@ -399,7 +470,7 @@ function rvg_optimize_db()
399
  {
400
  ?>
401
  <br />
402
- <strong>Next scheduled run:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $nextrun?></span>
403
  <?php
404
  }
405
  if($total_savings)
@@ -447,7 +518,9 @@ function rvg_optimize_db()
447
  $start_size = rvg_get_db_size();
448
 
449
  // TIMESTAMP FOR LOG FILE
450
- $log_arr = array("time" => date("m/d/Y").'<br />'.date("H:i:s"));
 
 
451
 
452
  // FIND REVISIONS
453
  $results = rvg_get_revisions($max_revisions);
1
  <?php
2
+ $odb_version = '2.4';
3
+ $odb_release_date = '05/24/2013';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
+ * @version 2.4
7
  */
8
  /*
9
  Plugin Name: Optimize Database after Deleting Revisions
10
  Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/
11
  Description: Optimizes the Wordpress Database after Cleaning it out - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
12
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
13
+ Version: 2.4
14
  Author URI: http://cagewebdev.com
15
  */
16
  ?>
42
  add_action( 'admin_menu', 'rvg_odb_admin_menu' );
43
 
44
 
45
+ /********************************************************************************************
46
+
47
+ ADD THE '1 CLICK OPTIMIZE DATABASE' ITEM TO THE ADMIN BAR
48
+
49
+ *********************************************************************************************/
50
+ function rvg_odb_admin_bar()
51
+ { global $wp_admin_bar;
52
+ if ( !is_super_admin() || !is_admin_bar_showing() ) return;
53
+ $wp_admin_bar->add_menu( array('id' => 'optimize','title' => __( 'Optimize DB (1 click)'),'href' => __('/wp-admin/tools.php?page=rvg-optimize-db.php&action=run'),) );
54
+ }
55
+ add_action( 'wp_before_admin_bar_render', 'rvg_odb_admin_bar' );
56
+
57
+
58
  /********************************************************************************************
59
 
60
  ACTIONS FOR THE SCHEDULER
106
  function rvg_odb_options_page() {
107
  global $odb_version, $odb_release_date, $wpdb, $table_prefix;
108
 
109
+ $timezone_format = _x('YmdGis', 'timezone date format');
110
+ $current_datetime = date_i18n($timezone_format);
111
+ $current_date = substr($current_datetime, 0, 8);
112
+ $current_hour = substr($current_datetime, 8, 2);
113
+
114
  # jQuery FRAMEWORK
115
  echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>';
116
 
168
  $rvg_odb_schedule = $_POST['rvg_odb_schedule'];
169
  update_option('rvg_odb_schedule', $rvg_odb_schedule);
170
 
171
+ $rvg_odb_schedulehour = '';
172
+ if(isset($_POST['rvg_odb_schedulehour']))
173
+ $rvg_odb_schedulehour = $_POST['rvg_odb_schedulehour'];
174
+ update_option('rvg_odb_schedulehour', $rvg_odb_schedulehour);
175
+
176
  // CLEAR CURRENT SCHEDULE (IF ANY)
177
  wp_clear_scheduled_hook('rvg_optimize_database');
178
 
179
  // HAS TO BE SCHEDULED
180
  if($rvg_odb_schedule != '')
181
  if( !wp_next_scheduled( 'rvg_optimize_database' ))
182
+ {
183
+ $time = 0;
184
+ if($rvg_odb_schedulehour == '')
185
+ { $time = time();
186
+ }
187
+ else
188
+ {
189
+ if($rvg_odb_schedulehour <= $current_hour)
190
+ // NEXT RUN TOMORROW
191
+ $newdatetime = date('YmdHis', strtotime($current_date.$rvg_odb_schedulehour.'0000'.' + 1 day'));
192
+ else
193
+ // NEXT RUN TODAY
194
+ $newdatetime = $current_date.$rvg_odb_schedulehour.'0000';
195
+ // DATE TO UNIX TIMESTAMP (EPOCH)
196
+ $time = strtotime($newdatetime);
197
+ }
198
+ // SCHEDULE THE EVENT
199
+ wp_schedule_event( $time, $rvg_odb_schedule, 'rvg_optimize_database' );
200
+ }
201
 
202
  // UPDATED MESSAGE
203
  echo "<div class='updated'><p><strong>Optimize Database after Deleting Revisions OPTIONS UPDATED</strong> - Click <a href='tools.php?page=rvg-optimize-db.php' style='font-weight:bold'>HERE</a> to run the optimization</p></div>";
216
  if(!$rvg_odb_logging_on) $rvg_odb_logging_on = 'N';
217
 
218
  $rvg_odb_schedule = get_option('rvg_odb_schedule');
219
+ if(!$rvg_odb_schedule) $rvg_odb_schedule = '';
220
+
221
+ $rvg_odb_schedulehour = get_option('rvg_odb_schedulehour');
222
  ?>
223
+ <script type="text/javascript">
224
+ function schedule_changed()
225
+ {
226
+ document.options.rvg_odb_schedulehour.value = '<?php echo$current_hour?>';
227
+ if(document.options.rvg_odb_schedule.value == '' || document.options.rvg_odb_schedule.value == 'hourly')
228
+ document.options.rvg_odb_schedulehour.disabled = true;
229
+ else
230
+ document.options.rvg_odb_schedulehour.disabled = false;
231
+ }
232
+ </script>
233
  <form name="options" method="post" action="">
234
  <div class="wrap">
235
  <h2>Using Optimize Database after Deleting Revisions</h2>
277
  <td width="50%" valign="top"><input name="rvg_odb_logging_on" type="checkbox" value="Y" <?php echo $rvg_odb_logging_on_checked?> /></td>
278
  </tr>
279
  <tr>
280
+ <td width="50%" align="right"><span style="font-weight:bold;">Scheduler</span></td>
281
+ <td width="50%"><select name="rvg_odb_schedule" id="rvg_odb_schedule" onchange="schedule_changed();">
282
  <option selected="selected" value="">NOT SCHEDULED</option>
283
  <option value="hourly">run optimization HOURLY</option>
284
  <option value="twicedaily">run optimization TWICE A DAY</option>
285
  <option value="daily">run optimization DAILY</option>
286
  <option value="weekly">run optimization WEEKLY</option>
287
+ <?php /*?> <option value="test">run optimization TEST</option><?php */?>
288
  </select>
289
  <script type="text/javascript">
290
  document.options.rvg_odb_schedule.value = '<?php echo $rvg_odb_schedule; ?>';
291
+ </script>
292
+ <span style="font-weight:bold;">Time</span>
293
+ <select name="rvg_odb_schedulehour" id="rvg_odb_schedulehour">
294
+ <?php
295
+ for($i=0; $i<=23; $i++)
296
+ { if($i<10) $i = '0'.$i;
297
+ ?>
298
+ <option value="<?=$i?>">
299
+ <?=$i.':00'.' hrs'?>
300
+ </option>
301
+ <?php
302
+ }
303
+ ?>
304
+ </select>
305
+ <script type="text/javascript">
306
+ document.options.rvg_odb_schedulehour.value = '<?php echo $rvg_odb_schedulehour; ?>';
307
  </script></td>
308
  </tr>
309
  </table></td>
371
  {
372
  global $wpdb, $odb_version, $table_prefix;
373
 
374
+ $timezone_format = _x('G:i', 'timezone date format');
375
+ $current_hour = date_i18n($timezone_format);
376
+
377
  if(isset($_REQUEST['action']))
378
  if($_REQUEST['action'] == "delete_log")
379
  @unlink(dirname(__FILE__).'/rvg-optimize-db-log.html');
470
  {
471
  ?>
472
  <br />
473
+ <strong>Next scheduled run:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $nextrun?> hrs (current server time: <?php echo $current_hour?>)</span>
474
  <?php
475
  }
476
  if($total_savings)
518
  $start_size = rvg_get_db_size();
519
 
520
  // TIMESTAMP FOR LOG FILE
521
+ $timezone_format = _x('m/d/YH:i:s', 'timezone date format');
522
+ $current_datetime = date_i18n($timezone_format);
523
+ $log_arr = array("time" => substr($current_datetime, 0, 10).'<br />'.substr($current_datetime,10));
524
 
525
  // FIND REVISIONS
526
  $results = rvg_get_revisions($max_revisions);