Optimize Database after Deleting Revisions - Version 4.1.7

Version Description

[06/23/2016] = * CHANGE: Orphaned media items will be deleted too now

Download this release

Release Info

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

Code changes from version 4.1.6 to 4.1.7

classes/odb-cleaner.php CHANGED
@@ -1066,14 +1066,15 @@ class ODB_Cleaner
1066
 
1067
 
1068
  /********************************************************************************************
1069
- * DELETE ORPHAN POSTMETA RECORDS
1070
  ********************************************************************************************/
1071
  function odb_delete_orphans()
1072
  {
1073
  global $wpdb, $odb_class;
1074
 
1075
- $meta_orphans = 0;
1076
- $post_orphans = 0;
 
1077
 
1078
  // LOOP THROUGH THE NETWORK
1079
  for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
@@ -1117,9 +1118,31 @@ class ODB_Cleaner
1117
  ", $odb_class->odb_ms_prefixes[$i], $odb_class->odb_ms_prefixes[$i]);
1118
  $wpdb->get_results($sql_delete);
1119
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1120
  } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1121
-
1122
- return ($meta_orphans + $post_orphans);
1123
  } // odb_delete_orphans()
1124
 
1125
 
1066
 
1067
 
1068
  /********************************************************************************************
1069
+ * DELETE ORPHAN POSTMETA AND MEDIA RECORDS
1070
  ********************************************************************************************/
1071
  function odb_delete_orphans()
1072
  {
1073
  global $wpdb, $odb_class;
1074
 
1075
+ $meta_orphans = 0;
1076
+ $post_orphans = 0;
1077
+ $media_orphans = 0; // v4.1.7
1078
 
1079
  // LOOP THROUGH THE NETWORK
1080
  for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1118
  ", $odb_class->odb_ms_prefixes[$i], $odb_class->odb_ms_prefixes[$i]);
1119
  $wpdb->get_results($sql_delete);
1120
  }
1121
+
1122
+ // DELETE MEDIA ORPHANS (v4.1.7)
1123
+ $sql_delete = sprintf ("
1124
+ SELECT `ID`
1125
+ FROM %sposts
1126
+ WHERE `post_type` = 'attachment'
1127
+ AND `post_mime_type` LIKE 'image/%%'
1128
+ AND `post_parent` != 0
1129
+ AND `post_parent` NOT IN (SELECT `ID` FROM %sposts)
1130
+ ", $odb_class->odb_ms_prefixes[$i], $odb_class->odb_ms_prefixes[$i]);
1131
+
1132
+ $results = $wpdb->get_results($sql_delete);
1133
+ $media_orphans = count($results);
1134
+
1135
+ if($media_orphans > 0)
1136
+ { for ($j=0; $j<$media_orphans; $j++)
1137
+ { $sql_delete = sprintf("
1138
+ DELETE FROM %sposts WHERE `ID` = %d
1139
+ ", $odb_class->odb_ms_prefixes[$i], $results[$j]->ID);
1140
+
1141
+ $wpdb->get_results($sql_delete);
1142
+ } // for ($j=0; $j<count($results); $j++)
1143
+ } // if($media_orphans > 0)
1144
  } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1145
+ return ($meta_orphans + $post_orphans + $media_orphans);
 
1146
  } // odb_delete_orphans()
1147
 
1148
 
readme.txt CHANGED
@@ -7,9 +7,9 @@ Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, cl
7
  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.5.2
11
- Stable tag: 4.1.6
12
- Version: 4.1.6
13
  License: GPLv2 or later
14
 
15
  == Description ==
@@ -101,6 +101,9 @@ http://cagewebdev.com/index.php/wordpress-plugins/
101
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
102
 
103
  == Changelog ==
 
 
 
104
  = 4.1.6 [05/20/2016] =
105
  * NEW: Belarus (be_BY) translation added (thanks Natasha!)
106
 
7
  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.5.3
11
+ Stable tag: 4.1.7
12
+ Version: 4.1.7
13
  License: GPLv2 or later
14
 
15
  == Description ==
101
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
102
 
103
  == Changelog ==
104
+ = 4.1.7 [06/23/2016] =
105
+ * CHANGE: Orphaned media items will be deleted too now
106
+
107
  = 4.1.6 [05/20/2016] =
108
  * NEW: Belarus (be_BY) translation added (thanks Natasha!)
109
 
rvg-optimize-database.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
- * @version 4.1.6
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.1.6
14
  */
15
 
16
  /********************************************************************************************
@@ -25,8 +25,8 @@ $odb_class = new OptimizeDatabase();
25
  class OptimizeDatabase
26
  {
27
  // VERSION
28
- var $odb_version = '4.1.6';
29
- var $odb_release_date = '05/20/2016';
30
 
31
  // PLUGIN OPTIONS
32
  var $odb_rvg_options = array();
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
+ * @version 4.1.7
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.1.7
14
  */
15
 
16
  /********************************************************************************************
25
  class OptimizeDatabase
26
  {
27
  // VERSION
28
+ var $odb_version = '4.1.7';
29
+ var $odb_release_date = '06/23/2016';
30
 
31
  // PLUGIN OPTIONS
32
  var $odb_rvg_options = array();