Optimize Database after Deleting Revisions - Version 2.2.6

Version Description

[03/05/2013] = * Text change: 'logging on' changed to 'keep a log' (thanks to: Neil Parks) * NEW: number of orphans deleted now also shown in the log file * NEW: 'Go To Optimizer' button on options page (thanks to: RonDsy)

Download this release

Release Info

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

Code changes from version 2.2.5 to 2.2.6

Files changed (2) hide show
  1. readme.txt +8 -3
  2. rvg-optimize-db.php +57 -36
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.2.5
10
  Tested up to: 3.5.1
11
- Stable tag: 2.2.5
12
- Version: 2.2.5
13
 
14
  == Description ==
15
 
@@ -48,6 +48,11 @@ http://wordpress.org/extend/plugins/rvg-optimize-database/
48
 
49
  == Changelog ==
50
 
 
 
 
 
 
51
  = 2.2.5 [02/20/2013] =
52
  * Bug fix: fixed an (innocent) PHP warning (in error.log)
53
 
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.2.6
10
  Tested up to: 3.5.1
11
+ Stable tag: 2.2.6
12
+ Version: 2.2.6
13
 
14
  == Description ==
15
 
48
 
49
  == Changelog ==
50
 
51
+ = 2.2.6 [03/05/2013] =
52
+ * Text change: 'logging on' changed to 'keep a log' (thanks to: Neil Parks)
53
+ * NEW: number of orphans deleted now also shown in the log file
54
+ * NEW: 'Go To Optimizer' button on options page (thanks to: RonDsy)
55
+
56
  = 2.2.5 [02/20/2013] =
57
  * Bug fix: fixed an (innocent) PHP warning (in error.log)
58
 
rvg-optimize-db.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
- $odb_version = '2.2.5';
3
- $odb_release_date = '02/20/2013';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
- * @version 2.2.5
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.2.5
14
  Author URI: http://cagewebdev.com
15
  */
16
  ?>
@@ -213,7 +213,7 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
213
  <td width="50%" valign="top"><input name="rvg_clear_spam" type="checkbox" value="Y" <?php echo $rvg_clear_spam_checked?> /></td>
214
  </tr>
215
  <tr>
216
- <td width="50%" align="right" valign="top"><span style="font-weight:bold;">Logging on</span></td>
217
  <td width="50%" valign="top"><input name="rvg_odb_logging_on" type="checkbox" value="Y" <?php echo $rvg_odb_logging_on_checked?> /></td>
218
  </tr>
219
  <tr>
@@ -276,16 +276,18 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
276
  </blockquote>
277
  <p class="submit">
278
  <input class="button-primary button-large" type='submit' name='info_update' value='Save Options' style="font-weight:bold;" />
 
 
279
  </p>
280
  </div>
281
  </form>
282
  <?php
283
- }
284
 
285
 
286
  /********************************************************************************************
287
 
288
- MAIN FUNCTION FOR DELETING REVISIONS, TRASH, SPAM AND OPTIMIZING DATABASE TABLES
289
 
290
  *********************************************************************************************/
291
  function rvg_optimize_db()
@@ -380,7 +382,7 @@ function rvg_optimize_db()
380
  <strong>Maximum number of - most recent - revisions to keep per post / page:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $max_revisions?></span><br />
381
  <strong>Delete trashed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
382
  <strong>Delete spammed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_spam_yn?></span><br />
383
- <strong>Logging on:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $rvg_odb_logging_on_yn?></span><br />
384
  <strong>Number of excluded tables:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $number_excluded?></span><br />
385
  <strong>Scheduler:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $rvg_odb_schedule_txt?></span>
386
  <?php
@@ -395,7 +397,7 @@ function rvg_optimize_db()
395
  {
396
  ?>
397
  <br />
398
- <strong>Total savings so far:</strong> <span style="font-weight:bold;color:#00F;"><?php echo rvg_format_size($total_savings); ?></span>
399
  <?php
400
  }
401
  ?>
@@ -584,6 +586,13 @@ function rvg_optimize_db()
584
  // NUMBER OF SPAM DELETED FOR LOG FILE
585
  $log_arr["spam"] = $total_deleted;
586
  ?>
 
 
 
 
 
 
 
587
  <?php
588
  $total_deleted = rvg_delete_orphans(true);
589
  if($total_deleted)
@@ -608,6 +617,8 @@ function rvg_optimize_db()
608
  </table>
609
  <?php
610
  }
 
 
611
  ?>
612
  <?php
613
  /****************************************************************************************
@@ -673,7 +684,7 @@ function rvg_optimize_db()
673
  <td align="right" style="font-weight:bold;border-top:solid 1px #999;"><?php echo rvg_format_size(($start_size - $end_size),3); ?></td>
674
  </tr>
675
  <tr>
676
- <td align="right" style="font-weight:bold;">TOTAL SAVINGS SO FAR</td>
677
  <td align="right" style="font-weight:bold;border-top:solid 1px #999;"><?php echo rvg_format_size($total_savings,3); ?></td>
678
  </tr>
679
  </table>
@@ -770,6 +781,11 @@ function rvg_optimize_db_cron()
770
 
771
  // NUMBER OF SPAM DELETED FOR LOG FILE
772
  $log_arr["spam"] = $total_deleted;
 
 
 
 
 
773
 
774
  // OPTIMIZE DATABASE TABLES
775
  $cnt = rvg_optimize_tables(false);
@@ -788,7 +804,7 @@ function rvg_optimize_db_cron()
788
 
789
  $total_savings = get_option('rvg_odb_total_savings');
790
  $total_savings += ($start_size - $end_size);
791
- update_option('rvg_odb_total_savings',$total_savings);
792
 
793
  } // rvg_optimize_db_cron()
794
  ?>
@@ -1085,7 +1101,7 @@ function rvg_write_log($log_arr)
1085
  <html xmlns="http://www.w3.org/1999/xhtml">
1086
  <head>
1087
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1088
- <title>Untitled Document</title>
1089
  <style type="text/css">
1090
  body, td, th {
1091
  font-family: Arial, Helvetica, sans-serif;
@@ -1111,22 +1127,24 @@ td {
1111
  </head>
1112
  <body>
1113
  <div id="header">
1114
- <h2><a href="http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/" target="_blank">Optimize Database after Deleting Revisions v'.$odb_version.'</a></h2>
1115
- A WordPress Plugin by <a href="http://cagewebdev.com" target="_blank"><strong>CAGE Web Design | Rolf van Gelder</strong></a>, Eindhoven, The Netherlands</strong>
1116
  </div>
1117
  <table width="100%" border="0" cellspacing="6" cellpadding="1">
1118
  <tr>
1119
- <th width="12%" align="left" valign="top">time</th>
1120
- <th width="12%" align="right" valign="top">deleted<br />
1121
  revisions</th>
1122
- <th width="12%" align="right" valign="top">deleted<br />
1123
  trash</th>
1124
- <th width="12%" align="right" valign="top">deleted<br />
1125
  spam</th>
1126
- <th width="12%" align="right" valign="top">nr of optimized tables</th>
1127
- <th width="12%" align="right" valign="top">database size BEFORE</th>
1128
- <th width="12%" align="right" valign="top">database size AFTER</th>
1129
- <th width="12%" align="right" valign="top">SAVINGS</th>
 
 
1130
  </tr>
1131
  </table>
1132
  ';
@@ -1138,14 +1156,15 @@ td {
1138
  $html = '
1139
  <table width="100%" border="0" cellspacing="6" cellpadding="0">
1140
  <tr>
1141
- <td width="12%" valign="top"><strong>'.$log_arr["time"].'</strong></td>
1142
- <td width="12%" align="right" valign="top">'.$log_arr["revisions"].'</td>
1143
- <td width="12%" align="right" valign="top">'.$log_arr["trash"].'</td>
1144
- <td width="12%" align="right" valign="top">'.$log_arr["spam"].'</td>
1145
- <td width="12%" align="right" valign="top">'.$log_arr["tables"].'</td>
1146
- <td width="12%" align="right" valign="top">'.$log_arr["before"].'</td>
1147
- <td width="12%" align="right" valign="top">'.$log_arr["after"].'</td>
1148
- <td width="12%" align="right" valign="top">'.$log_arr["savings"].'</td>
 
1149
  </tr>
1150
  </table>
1151
  ';
@@ -1174,10 +1193,10 @@ function rvg_get_revisions($max_revisions)
1174
  HAVING COUNT(*) > ".$max_revisions."
1175
  ORDER BY UCASE(`post_title`)
1176
  ";
1177
- // echo $sql.'<br />';
1178
  return $wpdb -> get_results($sql);
1179
 
1180
- } // rvg_get_revisions()
1181
  ?>
1182
  <?php
1183
  /********************************************************************************************
@@ -1199,9 +1218,10 @@ function rvg_get_trash()
1199
  WHERE `comment_approved` = 'trash'
1200
  ORDER BY post_type, UCASE(title)
1201
  ";
 
1202
  return $wpdb -> get_results($sql);
1203
 
1204
- } // rvg_get_trash()
1205
  ?>
1206
  <?php
1207
  /********************************************************************************************
@@ -1219,9 +1239,10 @@ function rvg_get_spam()
1219
  WHERE `comment_approved` = 'spam'
1220
  ORDER BY UCASE(`comment_author`)
1221
  ";
 
1222
  return $wpdb -> get_results($sql);
1223
 
1224
- } // rvg_get_trash()
1225
  ?>
1226
  <?php
1227
  /********************************************************************************************
@@ -1244,7 +1265,7 @@ function rvg_get_db_size()
1244
 
1245
  return $res[0]->size;
1246
 
1247
- } // rvg_get_db_size()
1248
  ?>
1249
  <?php
1250
  /********************************************************************************************
@@ -1260,5 +1281,5 @@ function rvg_format_size($size, $precision=1)
1260
  $table_size = (round($size/1024,$precision)).' KB';
1261
 
1262
  return $table_size;
1263
- } // rvg_format_size()
1264
  ?>
1
  <?php
2
+ $odb_version = '2.2.6';
3
+ $odb_release_date = '03/05/2013';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
+ * @version 2.2.6
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.2.6
14
  Author URI: http://cagewebdev.com
15
  */
16
  ?>
213
  <td width="50%" valign="top"><input name="rvg_clear_spam" type="checkbox" value="Y" <?php echo $rvg_clear_spam_checked?> /></td>
214
  </tr>
215
  <tr>
216
+ <td width="50%" align="right" valign="top"><span style="font-weight:bold;">Keep a log</span></td>
217
  <td width="50%" valign="top"><input name="rvg_odb_logging_on" type="checkbox" value="Y" <?php echo $rvg_odb_logging_on_checked?> /></td>
218
  </tr>
219
  <tr>
276
  </blockquote>
277
  <p class="submit">
278
  <input class="button-primary button-large" type='submit' name='info_update' value='Save Options' style="font-weight:bold;" />
279
+ &nbsp;
280
+ <input class="button" type="button" name="delete_log" value="Go To Optimizer" onclick="self.location='tools.php?page=rvg-optimize-db.php'" style="font-weight:normal;" />
281
  </p>
282
  </div>
283
  </form>
284
  <?php
285
+ } // rvg_odb_options_page
286
 
287
 
288
  /********************************************************************************************
289
 
290
+ MAIN FUNCTION FOR DELETING REVISIONS, TRASH, SPAM, ORPHANS AND OPTIMIZING DATABASE TABLES
291
 
292
  *********************************************************************************************/
293
  function rvg_optimize_db()
382
  <strong>Maximum number of - most recent - revisions to keep per post / page:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $max_revisions?></span><br />
383
  <strong>Delete trashed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
384
  <strong>Delete spammed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_spam_yn?></span><br />
385
+ <strong>Keep a log:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $rvg_odb_logging_on_yn?></span><br />
386
  <strong>Number of excluded tables:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $number_excluded?></span><br />
387
  <strong>Scheduler:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $rvg_odb_schedule_txt?></span>
388
  <?php
397
  {
398
  ?>
399
  <br />
400
+ <strong>Total savings since the first run:</strong> <span style="font-weight:bold;color:#00F;"><?php echo rvg_format_size($total_savings); ?></span>
401
  <?php
402
  }
403
  ?>
586
  // NUMBER OF SPAM DELETED FOR LOG FILE
587
  $log_arr["spam"] = $total_deleted;
588
  ?>
589
+ <?php
590
+ /****************************************************************************************
591
+
592
+ DELETE ORPHANS
593
+
594
+ ******************************************************************************************/
595
+ ?>
596
  <?php
597
  $total_deleted = rvg_delete_orphans(true);
598
  if($total_deleted)
617
  </table>
618
  <?php
619
  }
620
+ // FOR LOG FILE
621
+ $log_arr["orphans"] = $total_deleted;
622
  ?>
623
  <?php
624
  /****************************************************************************************
684
  <td align="right" style="font-weight:bold;border-top:solid 1px #999;"><?php echo rvg_format_size(($start_size - $end_size),3); ?></td>
685
  </tr>
686
  <tr>
687
+ <td align="right" style="font-weight:bold;">TOTAL SAVINGS SINCE THE FIRST RUN</td>
688
  <td align="right" style="font-weight:bold;border-top:solid 1px #999;"><?php echo rvg_format_size($total_savings,3); ?></td>
689
  </tr>
690
  </table>
781
 
782
  // NUMBER OF SPAM DELETED FOR LOG FILE
783
  $log_arr["spam"] = $total_deleted;
784
+
785
+ // DELETE ORPHANS
786
+ $total_deleted = rvg_delete_orphans(false);
787
+ // NUMBER OF ORPHANS DELETED (FOR LOG FILE)
788
+ $log_arr["orphans"] = $total_deleted;
789
 
790
  // OPTIMIZE DATABASE TABLES
791
  $cnt = rvg_optimize_tables(false);
804
 
805
  $total_savings = get_option('rvg_odb_total_savings');
806
  $total_savings += ($start_size - $end_size);
807
+ update_option('rvg_odb_total_savings',$total_savings);
808
 
809
  } // rvg_optimize_db_cron()
810
  ?>
1101
  <html xmlns="http://www.w3.org/1999/xhtml">
1102
  <head>
1103
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1104
+ <title>Optimize Database after Deleting Revisions v'.$odb_version.' - LOG</title>
1105
  <style type="text/css">
1106
  body, td, th {
1107
  font-family: Arial, Helvetica, sans-serif;
1127
  </head>
1128
  <body>
1129
  <div id="header">
1130
+ <h2><a href="http://wordpress.org/extend/plugins/rvg-optimize-database/" target="_blank">Optimize Database after Deleting Revisions v'.$odb_version.'</a></h2>
1131
+ A WordPress Plugin by <a href="http://cagewebdev.com" target="_blank"><strong>CAGE Web Design</strong></a> | <a href="http://cage.nl/rg_biography.php" target="_blank"><strong>Rolf van Gelder</strong></a>, Eindhoven, The Netherlands</strong>
1132
  </div>
1133
  <table width="100%" border="0" cellspacing="6" cellpadding="1">
1134
  <tr>
1135
+ <th width="11%" align="left" valign="top">time</th>
1136
+ <th width="11%" align="right" valign="top">deleted<br />
1137
  revisions</th>
1138
+ <th width="11%" align="right" valign="top">deleted<br />
1139
  trash</th>
1140
+ <th width="11%" align="right" valign="top">deleted<br />
1141
  spam</th>
1142
+ <th width="11%" align="right" valign="top">deleted<br />
1143
+ orphans</th>
1144
+ <th width="11%" align="right" valign="top">nr of optimized tables</th>
1145
+ <th width="11%" align="right" valign="top">database size BEFORE</th>
1146
+ <th width="11%" align="right" valign="top">database size AFTER</th>
1147
+ <th width="11%" align="right" valign="top">SAVINGS</th>
1148
  </tr>
1149
  </table>
1150
  ';
1156
  $html = '
1157
  <table width="100%" border="0" cellspacing="6" cellpadding="0">
1158
  <tr>
1159
+ <td width="11%" valign="top"><strong>'.$log_arr["time"].'</strong></td>
1160
+ <td width="11%" align="right" valign="top">'.$log_arr["revisions"].'</td>
1161
+ <td width="11%" align="right" valign="top">'.$log_arr["trash"].'</td>
1162
+ <td width="11%" align="right" valign="top">'.$log_arr["spam"].'</td>
1163
+ <td width="11%" align="right" valign="top">'.$log_arr["orphans"].'</td>
1164
+ <td width="11%" align="right" valign="top">'.$log_arr["tables"].'</td>
1165
+ <td width="11%" align="right" valign="top">'.$log_arr["before"].'</td>
1166
+ <td width="11%" align="right" valign="top">'.$log_arr["after"].'</td>
1167
+ <td width="11%" align="right" valign="top">'.$log_arr["savings"].'</td>
1168
  </tr>
1169
  </table>
1170
  ';
1193
  HAVING COUNT(*) > ".$max_revisions."
1194
  ORDER BY UCASE(`post_title`)
1195
  ";
1196
+
1197
  return $wpdb -> get_results($sql);
1198
 
1199
+ } // rvg_get_revisions
1200
  ?>
1201
  <?php
1202
  /********************************************************************************************
1218
  WHERE `comment_approved` = 'trash'
1219
  ORDER BY post_type, UCASE(title)
1220
  ";
1221
+
1222
  return $wpdb -> get_results($sql);
1223
 
1224
+ } // rvg_get_trash
1225
  ?>
1226
  <?php
1227
  /********************************************************************************************
1239
  WHERE `comment_approved` = 'spam'
1240
  ORDER BY UCASE(`comment_author`)
1241
  ";
1242
+
1243
  return $wpdb -> get_results($sql);
1244
 
1245
+ } // rvg_get_trash
1246
  ?>
1247
  <?php
1248
  /********************************************************************************************
1265
 
1266
  return $res[0]->size;
1267
 
1268
+ } // rvg_get_db_size
1269
  ?>
1270
  <?php
1271
  /********************************************************************************************
1281
  $table_size = (round($size/1024,$precision)).' KB';
1282
 
1283
  return $table_size;
1284
+ } // rvg_format_size
1285
  ?>