Optimize Database after Deleting Revisions - Version 4.9

Version Description

[04/10/2020] = * NEW: Deletion of orphaned term relationships

Download this release

Release Info

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

Code changes from version 4.8.8 to 4.9

classes/odb-cleaner.php CHANGED
@@ -679,7 +679,7 @@ class ODB_Cleaner {
679
  <?php
680
  } // if ($action == 'analyze_detail' || $action == 'run_detail')
681
 
682
- // LOOP THROUGH THE ORPHANS THEM
683
  $total_deleted = $this->odb_delete_oembed($results, $scheduler, $action);
684
 
685
  if ($scheduler) $odb_class->log_arr["oembeds"] = $total_deleted;
@@ -714,6 +714,7 @@ class ODB_Cleaner {
714
  ****************************************************************************************/
715
  if($odb_class->odb_rvg_options['clear_orphans'] == 'Y') {
716
 
 
717
  $results = $this->odb_get_orphans($scheduler);
718
 
719
  if (count($results) > 0) {
@@ -764,6 +765,7 @@ class ODB_Cleaner {
764
  <th align="left" class="odb-border-bottom"><?php _e('id', $odb_class->odb_txt_domain);?></th>
765
  <th align="left" class="odb-border-bottom"><?php _e('title', $odb_class->odb_txt_domain);?></th>
766
  <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('modified', $odb_class->odb_txt_domain);?></th>
 
767
  <th align="left" class="odb-border-bottom"><?php _e('meta key', $odb_class->odb_txt_domain);?></th>
768
  <th align="left" class="odb-border-bottom"><?php _e('meta value', $odb_class->odb_txt_domain);?></th>
769
  </tr>
@@ -793,7 +795,6 @@ class ODB_Cleaner {
793
  } // if (!$scheduler)
794
  } // if (count($results) > 0)
795
  } // if($odb_class->odb_rvg_options['clear_orphans'] == 'Y')
796
-
797
  ?>
798
  <div class="odb-found-number">
799
  <?php _e('TOTAL NUMBER OF ITEMS: ', $odb_class->odb_txt_domain);?>
@@ -1801,6 +1802,7 @@ function odb_confirm_delete() {
1801
  'post' AS type,
1802
  `post_title`,
1803
  `post_modified`,
 
1804
  '' AS meta_key,
1805
  '' AS meta_value
1806
  FROM %sposts
@@ -1814,13 +1816,16 @@ function odb_confirm_delete() {
1814
  array_push($res_arr, $results[$j]);
1815
  } // for ($j = 0; $j < count($results); $j++)
1816
 
1817
- // DELETE POSTMETA ORPHANS
1818
  $sql = sprintf ("
1819
  SELECT '%s' AS site,
1820
  `post_id` AS ID,
1821
  'meta' AS type,
1822
  '' AS post_title,
1823
- '' AS post_modified,`meta_key`, `meta_value`
 
 
 
1824
  FROM %spostmeta
1825
  WHERE post_id NOT IN (SELECT ID FROM %sposts)
1826
  ORDER BY `meta_key`
@@ -1830,10 +1835,35 @@ function odb_confirm_delete() {
1830
  for ($j = 0; $j < count($results); $j++) {
1831
  array_push($res_arr, $results[$j]);
1832
  } // for ($j = 0; $j < count($results); $j++)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1833
  } // for($i = 0; $i < count($odb_class->odb_ms_prefixes); $i++)
1834
  return $res_arr;
1835
  } // odb_get_orphans()
1836
-
1837
 
1838
  /********************************************************************************************
1839
  *
@@ -1845,16 +1875,18 @@ function odb_confirm_delete() {
1845
  global $wpdb, $odb_class;
1846
 
1847
  $total_deleted = count($results);
 
1848
  for($i = 0; $i < count($results); $i++) {
1849
  if (!$scheduler && ($action == 'analyze_detail' || $action == 'run_detail')) {
1850
  ?>
1851
  <tr>
1852
- <td align="right" valign="top"><?php echo ($i + 1); ?></td>
1853
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1854
  <td valign="top"><?php echo $results[$i]['type']?></td>
1855
  <td valign="top"><?php echo $results[$i]['ID']?></td>
1856
  <td valign="top"><?php echo $results[$i]['post_title']?></td>
1857
  <td valign="top" nowrap="nowrap"><?php echo substr($results[$i]['post_modified'], 0, 10); ?></td>
 
1858
  <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_key']; ?></td>
1859
  <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_value']; ?></td>
1860
  </tr>
@@ -1864,7 +1896,7 @@ function odb_confirm_delete() {
1864
  if ($scheduler || $action == 'run_summary' || $action == 'run_detail') {
1865
  for($j = 0; $j < count($results); $j++) {
1866
  // DELETE METADATA FOR THIS COMMENT (IF ANY)
1867
- if ($results[$j]['type'] == 'meta') {
1868
  $sql = sprintf ("
1869
  DELETE FROM %spostmeta
1870
  WHERE `post_id` = %d
@@ -1873,7 +1905,14 @@ function odb_confirm_delete() {
1873
  $sql = sprintf ("
1874
  DELETE FROM %sposts
1875
  WHERE `ID` = %d
1876
- ", $results[$j]['site'], $results[$j]['ID']);
 
 
 
 
 
 
 
1877
  } // if ($results[$j]['type'] == 'meta')
1878
  $wpdb->get_results($sql);
1879
  } // for($j = 0; $j < count($results); $j++)
679
  <?php
680
  } // if ($action == 'analyze_detail' || $action == 'run_detail')
681
 
682
+ // LOOP THROUGH THE OEMBEDS
683
  $total_deleted = $this->odb_delete_oembed($results, $scheduler, $action);
684
 
685
  if ($scheduler) $odb_class->log_arr["oembeds"] = $total_deleted;
714
  ****************************************************************************************/
715
  if($odb_class->odb_rvg_options['clear_orphans'] == 'Y') {
716
 
717
+ // POSTMETA AND MEDIA ORPHANS
718
  $results = $this->odb_get_orphans($scheduler);
719
 
720
  if (count($results) > 0) {
765
  <th align="left" class="odb-border-bottom"><?php _e('id', $odb_class->odb_txt_domain);?></th>
766
  <th align="left" class="odb-border-bottom"><?php _e('title', $odb_class->odb_txt_domain);?></th>
767
  <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('modified', $odb_class->odb_txt_domain);?></th>
768
+ <th align="left" class="odb-border-bottom"><?php _e('taxonomy', $odb_class->odb_txt_domain);?></th>
769
  <th align="left" class="odb-border-bottom"><?php _e('meta key', $odb_class->odb_txt_domain);?></th>
770
  <th align="left" class="odb-border-bottom"><?php _e('meta value', $odb_class->odb_txt_domain);?></th>
771
  </tr>
795
  } // if (!$scheduler)
796
  } // if (count($results) > 0)
797
  } // if($odb_class->odb_rvg_options['clear_orphans'] == 'Y')
 
798
  ?>
799
  <div class="odb-found-number">
800
  <?php _e('TOTAL NUMBER OF ITEMS: ', $odb_class->odb_txt_domain);?>
1802
  'post' AS type,
1803
  `post_title`,
1804
  `post_modified`,
1805
+ '' AS term_taxonomy_id,
1806
  '' AS meta_key,
1807
  '' AS meta_value
1808
  FROM %sposts
1816
  array_push($res_arr, $results[$j]);
1817
  } // for ($j = 0; $j < count($results); $j++)
1818
 
1819
+ // FIND POSTMETA ORPHANS
1820
  $sql = sprintf ("
1821
  SELECT '%s' AS site,
1822
  `post_id` AS ID,
1823
  'meta' AS type,
1824
  '' AS post_title,
1825
+ '' AS post_modified,
1826
+ '' AS term_taxonomy_id,
1827
+ `meta_key`,
1828
+ `meta_value`
1829
  FROM %spostmeta
1830
  WHERE post_id NOT IN (SELECT ID FROM %sposts)
1831
  ORDER BY `meta_key`
1835
  for ($j = 0; $j < count($results); $j++) {
1836
  array_push($res_arr, $results[$j]);
1837
  } // for ($j = 0; $j < count($results); $j++)
1838
+
1839
+ // FIND TERM RELATIONSHIP ORPHANS
1840
+ $sql = sprintf ("
1841
+ SELECT '%s' AS site,
1842
+ `object_id` AS ID,
1843
+ 'term relationship' AS type,
1844
+ `name` AS post_title,
1845
+ '' AS post_modified,
1846
+ r.term_taxonomy_id AS term_taxonomy_id,
1847
+ '' AS meta_key,
1848
+ '' AS meta_value
1849
+ FROM %sterm_relationships r,
1850
+ %sterm_taxonomy x,
1851
+ %sterms t
1852
+ WHERE r.term_taxonomy_id = x.term_taxonomy_id
1853
+ AND x.term_id = t.term_id
1854
+ AND `object_id` NOT IN (SELECT ID FROM %sposts)
1855
+ ORDER BY `object_id`
1856
+ ", $prefix, $prefix, $prefix, $prefix, $prefix);
1857
+ // echo $sql . '<br>';
1858
+
1859
+ $results = $wpdb->get_results($sql, ARRAY_A);
1860
+ for ($j = 0; $j < count($results); $j++) {
1861
+ array_push($res_arr, $results[$j]);
1862
+ } // for ($j = 0; $j < count($results); $j++)
1863
  } // for($i = 0; $i < count($odb_class->odb_ms_prefixes); $i++)
1864
  return $res_arr;
1865
  } // odb_get_orphans()
1866
+
1867
 
1868
  /********************************************************************************************
1869
  *
1875
  global $wpdb, $odb_class;
1876
 
1877
  $total_deleted = count($results);
1878
+
1879
  for($i = 0; $i < count($results); $i++) {
1880
  if (!$scheduler && ($action == 'analyze_detail' || $action == 'run_detail')) {
1881
  ?>
1882
  <tr>
1883
+ <td valign="top" align="right"><?php echo ($i + 1); ?></td>
1884
+ <td valign="top" align="left"><?php echo $results[$i]['site']?></td>
1885
  <td valign="top"><?php echo $results[$i]['type']?></td>
1886
  <td valign="top"><?php echo $results[$i]['ID']?></td>
1887
  <td valign="top"><?php echo $results[$i]['post_title']?></td>
1888
  <td valign="top" nowrap="nowrap"><?php echo substr($results[$i]['post_modified'], 0, 10); ?></td>
1889
+ <td valign="top" align="left"><?php echo $results[$i]['term_taxonomy_id']?></td>
1890
  <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_key']; ?></td>
1891
  <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_value']; ?></td>
1892
  </tr>
1896
  if ($scheduler || $action == 'run_summary' || $action == 'run_detail') {
1897
  for($j = 0; $j < count($results); $j++) {
1898
  // DELETE METADATA FOR THIS COMMENT (IF ANY)
1899
+ if ($results[$j]['type'] == 'post meta') {
1900
  $sql = sprintf ("
1901
  DELETE FROM %spostmeta
1902
  WHERE `post_id` = %d
1905
  $sql = sprintf ("
1906
  DELETE FROM %sposts
1907
  WHERE `ID` = %d
1908
+ ", $results[$j]['site'], $results[$j]['ID']);
1909
+ } else if ($results[$j]['type'] == 'term relationship') {
1910
+ //print_r($results[$j]);
1911
+ $sql = sprintf ("
1912
+ DELETE FROM %sterm_relationships
1913
+ WHERE `object_id` = %d
1914
+ AND `term_taxonomy_id` = %d
1915
+ ", $results[$j]['site'], $results[$j]['ID'], $results[$j]['term_taxonomy_id']);
1916
  } // if ($results[$j]['type'] == 'meta')
1917
  $wpdb->get_results($sql);
1918
  } // for($j = 0; $j < count($results); $j++)
readme.txt CHANGED
@@ -9,9 +9,9 @@ Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Contributors: cageehv
10
  Requires at least: 2.8
11
  Requires PHP: 5.0
12
- Tested up to: 5.3
13
- Stable tag: 4.8.8
14
- Version: 4.8.8
15
  License: GPLv2 or later
16
 
17
  == Description ==
@@ -111,6 +111,9 @@ http://cagewebdev.com/category/news-tech-art/wordpress/
111
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
112
 
113
  == Changelog ==
 
 
 
114
  = 4.8.8 [12/02/2019] =
115
  * BUG FIX: Fixed an (innocent) warning (while cleaning)
116
 
9
  Contributors: cageehv
10
  Requires at least: 2.8
11
  Requires PHP: 5.0
12
+ Tested up to: 5.4
13
+ Stable tag: 4.9
14
+ Version: 4.9
15
  License: GPLv2 or later
16
 
17
  == Description ==
111
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
112
 
113
  == Changelog ==
114
+ = 4.9 [04/10/2020] =
115
+ * NEW: Deletion of orphaned term relationships
116
+
117
  = 4.8.8 [12/02/2019] =
118
  * BUG FIX: Fixed an (innocent) warning (while cleaning)
119
 
rvg-optimize-database.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
- * @version 4.8.8
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.8.8
14
  */
15
 
16
  /********************************************************************************************
@@ -28,8 +28,8 @@ $odb_class = new OptimizeDatabase();
28
 
29
  class OptimizeDatabase {
30
  // VERSION
31
- var $odb_version = '4.8.8';
32
- var $odb_release_date = '12/02/2019';
33
 
34
  // PLUGIN OPTIONS
35
  var $odb_rvg_options = array();
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
+ * @version 4.9
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.9
14
  */
15
 
16
  /********************************************************************************************
28
 
29
  class OptimizeDatabase {
30
  // VERSION
31
+ var $odb_version = '4.9';
32
+ var $odb_release_date = '04/10/2020';
33
 
34
  // PLUGIN OPTIONS
35
  var $odb_rvg_options = array();