code cleanup (first part)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* PMA_getMatchingTables places matching tables in source
|
||||
* and target databases in $matching_tables array whereas
|
||||
* $uncommon_source_tables array gets the tables present in
|
||||
* source database but are absent from target database.'
|
||||
* source database but are absent from target database.
|
||||
* Criterion for matching tables is just comparing their names.
|
||||
*
|
||||
* @param $trg_tables array of target database table names,
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables, &$uncommon_source_tables)
|
||||
{
|
||||
for($k=0; $k< sizeof($src_tables); $k++)
|
||||
{
|
||||
for($k=0; $k< sizeof($src_tables); $k++) {
|
||||
$present_in_target = false;
|
||||
for($l=0; $l< sizeof($trg_tables); $l++)
|
||||
{
|
||||
for($l=0; $l < sizeof($trg_tables); $l++) {
|
||||
if ($src_tables[$k] === $trg_tables[$l]) {
|
||||
$present_in_target = true;
|
||||
$matching_tables[] = $src_tables[$k];
|
||||
@@ -47,8 +45,7 @@ function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables, &$un
|
||||
|
||||
function PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, &$uncommon_target_tables)
|
||||
{
|
||||
for($c=0; $c<sizeof($trg_tables) ;$c++)
|
||||
{
|
||||
for($c=0; $c<sizeof($trg_tables) ;$c++) {
|
||||
$match = false;
|
||||
for($d=0; $d < sizeof($matching_tables); $d++)
|
||||
{
|
||||
@@ -101,8 +98,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
$fld_results = PMA_DBI_get_fields($src_db, $matching_table[$matching_table_index], $src_link);
|
||||
$is_key = array();
|
||||
if (isset($fld_results)) {
|
||||
foreach ($fld_results as $each_field)
|
||||
{
|
||||
foreach ($fld_results as $each_field) {
|
||||
$field_name = $each_field['Field'];
|
||||
if ($each_field['Key'] == 'PRI') {
|
||||
$is_key[] = $field_name;
|
||||
@@ -121,10 +117,8 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
$all_keys_match = true;
|
||||
$trg_keys = array();
|
||||
|
||||
if (isset($trg_fld_results))
|
||||
{
|
||||
foreach ($trg_fld_results as $each_field)
|
||||
{
|
||||
if (isset($trg_fld_results)) {
|
||||
foreach ($trg_fld_results as $each_field) {
|
||||
if ($each_field['Key'] == 'PRI') {
|
||||
$trg_keys[] = $each_field['Field'];
|
||||
if (! (in_array($each_field['Field'], $is_key))) {
|
||||
@@ -139,8 +133,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
$insert_field = 0;
|
||||
$starting_index = 0;
|
||||
|
||||
for ($j = 0; $j < $source_size; $j++)
|
||||
{
|
||||
for ($j = 0; $j < $source_size; $j++) {
|
||||
$starting_index = 0;
|
||||
$update_field = 0;
|
||||
|
||||
@@ -153,8 +146,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
if (sizeof($is_key) == 1) {
|
||||
$trg_select_query .= $is_key[0]. "='" . $source_result_set[$j] . "'";
|
||||
} elseif (sizeof($is_key) > 1){
|
||||
for ($k=0; $k < sizeof($is_key); $k++)
|
||||
{
|
||||
for ($k=0; $k < sizeof($is_key); $k++) {
|
||||
$trg_select_query .= $is_key[$k] . "='" . $source_result_set[$j][$is_key[$k]] . "'";
|
||||
if ($k < (sizeof($is_key)-1)){
|
||||
$trg_select_query .= " AND ";
|
||||
@@ -172,8 +164,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
if (sizeof($is_key) == 1) {
|
||||
$src_select_query .= $is_key[0] . "='" . $source_result_set[$j] . "'";
|
||||
} else if(sizeof($is_key) > 1){
|
||||
for ($k=0; $k< sizeof($is_key); $k++)
|
||||
{
|
||||
for ($k=0; $k< sizeof($is_key); $k++) {
|
||||
$src_select_query .= $is_key[$k] . "='" . $source_result_set[$j][$is_key[$k]] . "'";
|
||||
if ($k < (sizeof($is_key) - 1)){
|
||||
$src_select_query .= " AND ";
|
||||
@@ -188,8 +179,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
* Placing the primary key, value of primary key, field to be updated, and the
|
||||
* new value of field to be updated in each row of the update array.
|
||||
*/
|
||||
for ($m = 0; ($m < $fields_num[$matching_table_index]) && ($starting_index == 0) ; $m++)
|
||||
{
|
||||
for ($m = 0; ($m < $fields_num[$matching_table_index]) && ($starting_index == 0) ; $m++) {
|
||||
if (isset($src_result_set[0][$fld[$m]])) {
|
||||
if (isset($target_result_set[0][$fld[$m]])) {
|
||||
if (($src_result_set[0][$fld[$m]] != $target_result_set[0][$fld[$m]]) && (! (in_array($fld[$m], $is_key)))) {
|
||||
@@ -198,8 +188,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
$update_array[$matching_table_index][$update_row][$is_key[0]] = $source_result_set[$j];
|
||||
}
|
||||
} elseif (sizeof($is_key) > 1) {
|
||||
for($n=0; $n<sizeof($is_key); $n++)
|
||||
{
|
||||
for ($n=0; $n < sizeof($is_key); $n++) {
|
||||
if (isset($src_result_set[0][$is_key[$n]])) {
|
||||
$update_array[$matching_table_index][$update_row][$is_key[$n]] = $src_result_set[0][$is_key[$n]];
|
||||
}
|
||||
@@ -223,8 +212,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
|
||||
}
|
||||
} elseif (sizeof($is_key) > 1) {
|
||||
for($n = 0; $n < sizeof($is_key); $n++)
|
||||
{
|
||||
for ($n = 0; $n < sizeof($is_key); $n++) {
|
||||
if (isset($src_result_set[0][$is_key[$n]])) {
|
||||
$update_array[$matching_table_index][$update_row][$is_key[$n]] = $src_result_set[0][$is_key[$n]];
|
||||
}
|
||||
@@ -271,15 +259,14 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Placing the primay key, and the value of primary key of the row that is to be inserted in the target table
|
||||
* Placing the primary key, and the value of primary key of the row that is to be inserted in the target table
|
||||
*/
|
||||
if (sizeof($is_key) == 1) {
|
||||
if (isset($source_result_set[$j])) {
|
||||
$insert_array[$matching_table_index][$insert_row][$is_key[0]] = $source_result_set[$j];
|
||||
}
|
||||
} elseif (sizeof($is_key) > 1) {
|
||||
for($l = 0; $l < sizeof($is_key); $l++)
|
||||
{
|
||||
for($l = 0; $l < sizeof($is_key); $l++) {
|
||||
if (isset($source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]])) {
|
||||
$insert_array[$matching_table_index][$insert_row][$is_key[$l]] = $source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]];
|
||||
}
|
||||
@@ -289,7 +276,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Placing the primay key, and the value of primary key of the row that is to be inserted in the target table
|
||||
* Placing the primary key, and the value of primary key of the row that is to be inserted in the target table
|
||||
* This condition is met when there is an additional column in the source table
|
||||
*/
|
||||
if (sizeof($is_key) == 1) {
|
||||
@@ -297,8 +284,7 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, &$matching
|
||||
$insert_array[$matching_table_index][$insert_row][$is_key[0]] = $source_result_set[$j];
|
||||
}
|
||||
} elseif (sizeof($is_key) > 1) {
|
||||
for($l = 0; $l < sizeof($is_key); $l++)
|
||||
{
|
||||
for ($l = 0; $l < sizeof($is_key); $l++) {
|
||||
if (isset($source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]])) {
|
||||
$insert_array[$matching_table_index][$insert_row][$is_key[$l]] = $source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]];
|
||||
}
|
||||
@@ -337,8 +323,8 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, $ma
|
||||
$source_size = sizeof($source_key_values);
|
||||
}
|
||||
$all_keys_match = 1;
|
||||
for ($a=0; $a<sizeof($trg_keys[$matching_table_index]); $a++)
|
||||
{ if (isset($trg_keys[$matching_table_index][$a])) {
|
||||
for ($a = 0; $a < sizeof($trg_keys[$matching_table_index]); $a++) {
|
||||
if (isset($trg_keys[$matching_table_index][$a])) {
|
||||
if (! (in_array($trg_keys[$matching_table_index][$a], $src_keys[$matching_table_index]))) {
|
||||
$all_keys_match = 0;
|
||||
}
|
||||
@@ -363,14 +349,11 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, $ma
|
||||
} elseif ((sizeof($trg_keys[$matching_table_index]) > 1) && $all_keys_match) {
|
||||
$row = 0;
|
||||
if (isset($target_key_values)) {
|
||||
for ($i=0; $i < sizeof($target_key_values); $i++)
|
||||
{
|
||||
for ($i = 0; $i < sizeof($target_key_values); $i++) {
|
||||
$is_present = false;
|
||||
for ($j=0; $j < sizeof($source_key_values) && ($is_present == false) ; $j++)
|
||||
{
|
||||
for ($j = 0; $j < sizeof($source_key_values) && ($is_present == false) ; $j++) {
|
||||
$check = true;
|
||||
for ($k=0; $k < sizeof($trg_keys[$matching_table_index]); $k++)
|
||||
{
|
||||
for ($k = 0; $k < sizeof($trg_keys[$matching_table_index]); $k++) {
|
||||
if ($target_key_values[$i][$trg_keys[$matching_table_index][$k]] != $source_key_values[$j][$trg_keys[$matching_table_index][$k]]) {
|
||||
$check = false;
|
||||
}
|
||||
@@ -380,8 +363,7 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, $ma
|
||||
}
|
||||
}
|
||||
if (! ($is_present)) {
|
||||
for ($l=0; $l<sizeof($trg_keys[$matching_table_index]); $l++)
|
||||
{
|
||||
for ($l = 0; $l < sizeof($trg_keys[$matching_table_index]); $l++) {
|
||||
$delete_array[$matching_table_index][$row][$trg_keys[$matching_table_index][$l]] = $target_key_values[$i][$trg_keys[$matching_table_index][$l]];
|
||||
}
|
||||
$row++;
|
||||
|
Reference in New Issue
Block a user