[fusionregistry-commitlog] SF.net SVN: fusionregistry: [26] trunk/upload/sources/components_acp/ f
Brought to you by:
copland007
|
From: SVN c. <fus...@li...> - 2008-02-04 04:45:12
|
Revision: 26
http://fusionregistry.svn.sourceforge.net/fusionregistry/?rev=26&view=rev
Author: copland007
Date: 2008-02-03 20:45:18 -0800 (Sun, 03 Feb 2008)
Log Message:
-----------
Added database cleanup tool to remove duplicate rows in field_entries related to bug #1742529
Modified Paths:
--------------
trunk/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php
Modified: trunk/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php
===================================================================
--- trunk/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php 2008-02-04 04:42:06 UTC (rev 25)
+++ trunk/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php 2008-02-04 04:45:18 UTC (rev 26)
@@ -101,6 +101,14 @@
$this->orphan_remove();
break;
+ case 'db_search_1742529':
+ $this->db_search_1742529();
+ break;
+
+ case 'db_remove_1742529':
+ $this->db_remove_1742529();
+ break;
+
default:
$this->main_menu();
break;
@@ -109,6 +117,133 @@
/**
+ * Find those duplicate ibf_registry_field_entry rows!
+ *
+ * Basic chain of events are to loop through the field_entry table
+ * for each item_id, then loop through each set of entry_id and
+ * field_id for that item. Find the largest value entry_id, mark the
+ * rest for removal.
+ */
+ function db_search_1742529()
+ {
+ $marked_for_death = $this->execute_db_search_1742529();
+
+ //-------------------------------
+ // Construct menu HTML
+ //-------------------------------
+
+ $this->ipsclass->html .= $this->ipsclass->skin_acp_global->information_box( "Fusion Registry Duplicate Row Locator", "Below are all the duplicate rows in the ibf_registry_field_entry table that were found.<br /><br />". $this->ad_registry_loader->imgs['warning'] ." <b>This operation is not undo-able! Once you choose to remove these duplicate rows they will be gone, please make a backup of your ibf_registry_field_entries sql table before proceeding!!</b>".'<br /> ' ) . "<br >";
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code', 'db_remove_1742529' ),
+ 2 => array( 'act' , REGISTRY_URL ),
+ 3 => array( 'menu', 'tools' ),
+ 4 => array( 'section', 'components' ),
+ ) );
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Duplicate ibf_registry_field_entry rows to be deleted" );
+
+ // If they don't have any, let them know
+ if ( count($marked_for_death) <= 0 )
+ {
+ $this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Congratulations! You have no duplicate rows to clean up!" ) );
+ }
+ else
+ {
+ // Otherwise print them all out baby!
+ $list_html = join(', ', $marked_for_death);
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( $list_html ) );
+ }
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->end_form('Remove '. count($marked_for_death) .' Duplicate Rows');
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->end_table();
+
+ $this->ipsclass->admin->output();
+ }
+
+
+ /**
+ * Do the actual removal of dup entries
+ */
+ function db_remove_1742529()
+ {
+ $output = array();
+
+ $marked_for_death = $this->execute_db_search_1742529();
+
+ // If we don't get anything in our returned array, there's nothing to do ;)
+ if ( count($marked_for_death) > 0 )
+ {
+ $rm_list = join("','", $marked_for_death);
+ $this->ipsclass->DB->simple_exec_query( array( 'delete' => 'registry_field_entries', 'where' => "entry_id IN ( '$rm_list' )" ) );
+
+ // Report our mischief ways :)
+ $text = "<b>Duplicate rows removed</b><br /><br />".implode( "<br />", $output );
+ $url = "act=".REGISTRY_URL."§ion=components&menu=tools";
+ $time = 5;
+
+ // Big brother is watching :)
+ $this->ipsclass->admin->save_log("Removed Duplicate Fusion Registry sql field_entries");
+ }
+ else
+ {
+ $text = "<b>No duplicate rows were found, therefore none were removed ;)</b>";
+ $url = "act=".REGISTRY_URL."§ion=components&menu=tools";
+ $time = 5;
+ }
+
+ // End of the show, c'ya
+ $this->ipsclass->admin->redirect( $url, $text, 0, $time );
+ }
+
+
+ /**
+ * Helper function to search for dup entries in field_entries table
+ */
+ function execute_db_search_1742529()
+ {
+ $marked_for_death = array();
+
+ // Loop through for each item
+ $item_query_id = $this->ipsclass->DB->query("SELECT DISTINCT (item_id) FROM ibf_registry_field_entries");
+ while ( $item_row = $this->ipsclass->DB->fetch_row($item_query_id) )
+ {
+ $dup_rows = array(); // Bad boy rows marked for death
+ $max_rows = array(); // Keep track of max values (valid rows)
+
+ $entry_query_id = $this->ipsclass->DB->query("SELECT entry_id,field_id FROM ibf_registry_field_entries WHERE item_id='$item_row[item_id]'");
+
+ // Loop through each entry_id for each item_id
+ while ( $entry_row = $this->ipsclass->DB->fetch_row($entry_query_id) )
+ {
+ if ( isset( $max_rows[$entry_row[field_id]] ) ) {
+ if ( $entry_row[entry_id] > $max_rows[$entry_row[field_id]] )
+ {
+ // This looks better, keep it, mark the last known max for death
+ array_push($dup_rows, $max_rows[$entry_row[field_id]]);
+ $max_rows[$entry_row[field_id]] = $entry_row[entry_id];
+ }
+ }
+ else
+ {
+ // There isn't a max row set yet, so set it now
+ $max_rows[$entry_row[field_id]] = $entry_row[entry_id];
+ }
+ }
+
+ // Push to big array
+ foreach ($dup_rows as $dup_id)
+ {
+ array_push($marked_for_death, $dup_id);
+ }
+ }
+
+ return $marked_for_death;
+ }
+
+
+ /**
* Find those Orphans!
*
* Basic chain of events are to compare all the known file names
@@ -761,6 +896,26 @@
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
+ $this->ipsclass->html .= '<br />';
+
+ //-------------------------------
+ // Find/Remove Duplicate DB records from bug #1742529
+ //-------------------------------
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code', 'db_search_1742529' ),
+ 2 => array( 'act' , REGISTRY_URL ),
+ 3 => array( 'menu', 'tools' ),
+ 4 => array( 'section', 'components' ),
+ ) );
+
+ $desc = 'The \'Cleanup Database - bug #1742529 fix\' tool is used to locate any duplicate rows in the ibf_registry_field_entries that the Fusion Registry had once created. The duplicate rows were created as the result of a bug in the code that was present until version 3.0.5. Under normal circumstances there should be no duplicate rows.<br /><br />The first step of this tool is just to search for duplicate rows, no action will be taken unless you confirm the findings on the next step.';
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Cleanup Database - bug #1742529 fix", $desc );
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->end_form('Search for Duplicate Rows');
+
+ $this->ipsclass->html .= $this->ipsclass->adskin->end_table();
+
// That's all folk!
$this->ipsclass->admin->output();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|