bug #3057481 Unchecking ignore does not work for duplicated insert rows
[phpmyadmin/dkf.git] / server_synchronize.php
blob32a6cb53389bd0fd726092a7dcd4c8190aaa01c9
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 /**
15 * Does the common work
17 $GLOBALS['js_include'][] = 'server_synchronize.js';
18 require_once './libraries/server_common.inc.php';
20 /**
21 * Contains all the functions specific to synchronization
23 require './libraries/server_synchronize.lib.php';
25 /**
26 * Increases the time limit up to the configured maximum
28 @set_time_limit($cfg['ExecTimeLimit']);
30 /**
31 * Displays the links
33 require './libraries/server_links.inc.php';
35 /**
36 * Enables warnings on the page
38 //$cfg['Error_Handler']['display'] = true;
39 //$cfg['Error_Handler']['gather'] = true;
41 /**
42 * Save the value of token generated for this page
44 if (isset($_REQUEST['token'])) {
45 $_SESSION['token'] = $_REQUEST['token'];
48 // variable for code saving
49 $cons = array ("src", "trg");
51 /**
52 * Displays the page when 'Go' is pressed
55 if ((isset($_REQUEST['submit_connect']))) {
56 foreach ($cons as $con) {
57 ${"{$con}_host"} = $_REQUEST[$con . '_host'];
58 ${"{$con}_username"} = $_REQUEST[$con . '_username'];
59 ${"{$con}_password"} = $_REQUEST[$con . '_pass'];
60 ${"{$con}_port"} = $_REQUEST[$con . '_port'];
61 ${"{$con}_socket"} = $_REQUEST[$con . '_socket'];
62 ${"{$con}_db"} = $_REQUEST[$con . '_db'];
63 ${"{$con}_type"} = $_REQUEST[$con . '_type'];
65 if (${"{$con}_type"} == 'cur') {
66 ${"{$con}_connection"} = null;
67 ${"{$con}_server"} = null;
68 ${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];
69 continue;
72 if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {
73 ${"{$con}_server"}['socket'] = ${"{$con}_socket"};
74 } else {
75 ${"{$con}_server"}['host'] = ${"{$con}_host"};
76 if (isset(${"{$con}_port"}) && ! empty(${"{$con}_port"}) && ((int)${"{$con}_port"} * 1) > 0) {
77 ${"{$con}_server"}['port'] = (int)${"{$con}_port"};
81 ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true);
82 } // end foreach ($cons as $con)
84 if ((! $src_connection && $src_type != 'cur') || (! $trg_connection && $trg_type != 'cur')) {
85 /**
86 * Displays the connection error string if
87 * connections are not established
90 echo '<div class="error">';
91 if(! $src_connection && $src_type != 'cur') {
92 echo __('Could not connect to the source') . '<br />';
94 if(! $trg_connection && $trg_type != 'cur'){
95 echo __('Could not connect to the target');
97 echo '</div>';
98 unset($_REQUEST['submit_connect']);
100 } else {
102 * Creating the link object for both source and target databases and
103 * selecting the source and target databases using these links
105 foreach ($cons as $con) {
106 if (${"{$con}_connection"} != null) {
107 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
108 } else {
109 ${"{$con}_link"} = null;
111 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
112 } // end foreach ($cons as $con)
114 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
116 * Displays error string if the database(s) did not exist
118 echo '<div class="error">';
119 if ($src_db_selected != 1) {
120 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
122 if ($trg_db_selected != 1) {
123 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
125 echo '</div>';
126 unset($_REQUEST['submit_connect']);
128 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
131 * Using PMA_DBI_get_tables() to get all the tables
132 * from target and source databases.
134 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
135 $source_tables_num = sizeof($src_tables);
137 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
138 $target_tables_num = sizeof($trg_tables);
141 * initializing arrays to save matching and non-matching
142 * table names from target and source databases.
144 $unmatched_num_src = 0;
145 $source_tables_uncommon = array();
146 $unmatched_num_trg = 0;
147 $target_tables_uncommon = array();
148 $matching_tables = array();
149 $matching_tables_num = 0;
152 * Using PMA_getMatchingTables to find which of the tables' names match
153 * in target and source database.
155 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
157 * Finding the uncommon tables for the target database
158 * using function PMA_getNonMatchingTargetTables()
160 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
163 * Initializing several arrays to save the data and structure
164 * difference between the source and target databases.
166 $row_count = array(); //number of rows in source table that needs to be created in target database
167 $fields_num = array(); //number of fields in each matching table
168 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
169 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
170 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
171 // each row of matching table.
172 $matching_tables_fields = array(); //contains the fields' names for each matching table
173 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
174 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
175 $matching_tables_num = sizeof($matching_tables);
177 $source_columns = array(); //contains the full columns' information for all the source tables' columns
178 $target_columns = array(); //contains the full columns' information for all the target tables' columns
179 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
180 $source_indexes = array(); //contains indexes on all the source tables
181 $target_indexes = array(); //contains indexes on all the target tables
182 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
183 $target_tables_keys = array(); //contains the keys of all the target tables
184 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
185 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
186 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
187 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
189 * The criteria array contains all the criteria against which columns are compared for differences.
191 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
193 for($i = 0; $i < sizeof($matching_tables); $i++) {
195 * Finding out all the differences structure, data and index diff for all the matching tables only
197 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
198 $delete_array, $fields_num, $i, $matching_tables_keys);
200 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
201 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
203 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
204 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);
207 for($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
209 * Finding out the number of rows to be added in tables that need to be added in target database
211 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
214 * Storing all arrays in session for use when page is reloaded for each button press
216 $_SESSION['matching_tables'] = $matching_tables;
217 $_SESSION['update_array'] = $update_array;
218 $_SESSION['insert_array'] = $insert_array;
219 $_SESSION['src_db'] = $src_db;
220 $_SESSION['trg_db'] = $trg_db;
221 $_SESSION['matching_fields'] = $matching_tables_fields;
222 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
223 $_SESSION['src_username'] = $src_username ;
224 $_SESSION['trg_username'] = $trg_username;
225 $_SESSION['src_password'] = $src_password;
226 $_SESSION['trg_password'] = $trg_password;
227 $_SESSION['trg_password'] = $trg_password;
228 $_SESSION['src_server'] = $src_server;
229 $_SESSION['trg_server'] = $trg_server;
230 $_SESSION['src_type'] = $src_type;
231 $_SESSION['trg_type'] = $trg_type;
232 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
233 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
234 $_SESSION['uncommon_tables_row_count'] = $row_count;
235 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
236 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
237 $_SESSION['delete_array'] = $delete_array;
238 $_SESSION['uncommon_columns'] = $uncommon_columns;
239 $_SESSION['source_columns'] = $source_columns;
240 $_SESSION['alter_str_array'] = $alter_str_array;
241 $_SESSION['target_tables_keys'] = $target_tables_keys;
242 $_SESSION['add_column_array'] = $add_column_array;
243 $_SESSION['criteria'] = $criteria;
244 $_SESSION['target_tables'] = $trg_tables;
245 $_SESSION['add_indexes_array'] = $add_indexes_array;
246 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
247 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
248 $_SESSION['source_indexes'] = $source_indexes;
249 $_SESSION['target_indexes'] = $target_indexes;
252 * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization
254 echo '<form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">'
255 . PMA_generate_common_hidden_inputs('', '');
256 echo '<table id="serverstatustraffic" class="data" width = "60%">
257 <tr>
258 <td> <h2>'
259 . ($GLOBALS['cfg']['MainPageIconic']
260 ? '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="32"'
261 . ' height="32" alt="" />'
262 : '')
263 . __('Structure Synchronization')
264 .'</h2>' .'</td>';
265 echo '<td> <h2>'
266 . ($GLOBALS['cfg']['MainPageIconic']
267 ? '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="32"'
268 . ' height="32" alt="" />'
269 : '')
270 . __('Data Synchronization')
271 . '</h2>' .'</td>';
272 echo '</tr>
273 </table>';
276 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
278 PMA_syncDisplayHeaderSource($src_db);
279 $odd_row = false;
281 * Display the matching tables' names and difference, first
283 for($i = 0; $i < count($matching_tables); $i++) {
285 * Calculating the number of updates for each matching table
287 if (isset($update_array[$i]) && isset($update_array[$i][0]) &&
288 isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
289 $num_of_updates = sizeof($update_array[$i]);
290 } else {
291 $num_of_updates = 0;
294 * Calculating the number of insertions for each matching table
296 if (isset($insert_array[$i]) && isset($insert_array[$i][0]) &&
297 isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
298 $num_of_insertions = sizeof($insert_array[$i]);
299 } else {
300 $num_of_insertions = 0;
303 * Displays the name of the matching table
305 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
306 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
307 <td align="center">';
309 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
310 * number of index to be added and removed.
312 $num_alter_cols = 0;
313 $num_insert_cols = 0;
314 $num_remove_cols = 0;
315 $num_add_index = 0;
316 $num_remove_index = 0;
318 if (isset($alter_str_array[$i])) {
319 $num_alter_cols = sizeof($alter_str_array[$i]);
321 if (isset($add_column_array[$i])) {
322 $num_insert_cols = sizeof($add_column_array[$i]);
324 if (isset($uncommon_columns[$i])) {
325 $num_remove_cols = sizeof($uncommon_columns[$i]);
327 if (isset($add_indexes_array[$i])) {
328 $num_add_index = sizeof($add_indexes_array[$i]);
330 if (isset($remove_indexes_array[$i])) {
331 $num_remove_index = sizeof($remove_indexes_array[$i]);
333 if (isset($alter_indexes_array[$i])) {
334 $num_add_index += sizeof($alter_indexes_array[$i]);
335 $num_remove_index += sizeof($alter_indexes_array[$i]);
338 * Display the red button of structure synchronization if there exists any structure difference or index difference.
340 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
342 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
343 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
344 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
345 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
346 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
349 * Display the green button of data synchronization if there exists any data difference.
351 if (isset($update_array[$i]) || isset($insert_array[$i])) {
352 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
354 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
355 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
356 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
357 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
360 echo '</td>
361 </tr>';
364 * Displays the tables' names present in source but missing from target
366 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
367 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
368 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
370 echo '<td align="center"><img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
371 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
372 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
373 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
375 if ($row_count[$j] > 0)
377 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
378 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
379 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
380 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
382 echo '</td>
383 </tr>';
385 foreach ($target_tables_uncommon as $tbl_nc_name) {
386 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
387 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
388 echo '</tr>';
391 * Displays the target tables names
393 echo '</table>';
395 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
396 foreach ($source_tables_uncommon as $tbl_nc_name) {
397 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
398 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>
399 </tr>';
401 foreach ($target_tables_uncommon as $tbl_nc_name) {
402 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
403 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
404 echo '</tr>';
406 echo '</table>';
407 echo '</div>';
410 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
411 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
414 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
415 border-left: 1px gray solid; border-bottom: 1px gray solid;
416 padding:0px; margin: 0px">
418 <table>
419 <thead>
420 <tr style="width: 100%;">
421 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
422 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
423 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
424 </tr>
425 <tr style="width: 100%;">
426 <th style="width: 10%;">' . __('Table name') . '</th>
427 <th style="width: 10%;">' . __('Create table'). '</th>
428 <th style="width: 11%;">' . __('Add column(s)') . '</th>
429 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
430 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
431 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
432 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
433 <th style="width: 10%;">'. __('Update row(s)') . '</th>
434 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
435 </tr>
436 </thead>
437 <tbody></tbody>
438 </table>
439 </div>';
441 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
443 echo '<fieldset>
444 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
445 </fieldset>
446 <fieldset class="tblFooters">';
447 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes')
448 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
449 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />' . '</fieldset>';
450 echo '</form>';
453 } // end if ((isset($_REQUEST['submit_connect'])))
456 * Display the page when 'Apply Selected Changes' is pressed
458 if (isset($_REQUEST['Table_ids'])) {
460 * Displays success message
462 echo '<div class="success">' . __('Selected target tables have been synchronized with source tables.') . '</div>';
464 $src_db = $_SESSION['src_db'];
465 $trg_db = $_SESSION['trg_db'];
466 $update_array = $_SESSION['update_array'];
467 $insert_array = $_SESSION['insert_array'];
468 $src_username = $_SESSION['src_username'];
469 $trg_username = $_SESSION['trg_username'];
470 $src_password = $_SESSION['src_password'];
471 $trg_password = $_SESSION['trg_password'];
472 $src_server = $_SESSION['src_server'];
473 $trg_server = $_SESSION['trg_server'];
474 $src_type = $_SESSION['src_type'];
475 $trg_type = $_SESSION['trg_type'];
476 $uncommon_tables = $_SESSION['uncommon_tables'];
477 $matching_tables = $_SESSION['matching_tables'];
478 $matching_tables_keys = $_SESSION['matching_tables_keys'];
479 $matching_tables_fields = $_SESSION['matching_fields'];
480 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
481 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
482 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
483 $row_count = $_SESSION['uncommon_tables_row_count'];
484 $target_tables = $_SESSION['target_tables'];
486 $delete_array = $_SESSION['delete_array'];
487 $uncommon_columns = $_SESSION['uncommon_columns'];
488 $source_columns = $_SESSION['source_columns'];
489 $alter_str_array = $_SESSION['alter_str_array'];
490 $criteria = $_SESSION['criteria'];
491 $target_tables_keys = $_SESSION['target_tables_keys'];
492 $add_column_array = $_SESSION['add_column_array'];
493 $add_indexes_array = $_SESSION['add_indexes_array'];
494 $alter_indexes_array = $_SESSION['alter_indexes_array'];
495 $remove_indexes_array = $_SESSION['remove_indexes_array'];
496 $source_indexes = $_SESSION['source_indexes'];
497 $target_indexes = $_SESSION['target_indexes'];
498 $uncommon_cols = $uncommon_columns;
501 * Creating link object for source and target databases
503 foreach ($cons as $con) {
504 if (${"{$con}_type"} != "cur") {
505 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
506 } else {
507 ${"{$con}_link"} = null;
508 // working on current server, so initialize this for tracking
509 // (does not work if user defined current server as a remote one)
510 $GLOBALS['db'] = ${"{$con}_db"};
512 } // end foreach ($cons as $con)
515 * Initializing arrays to save the table ids whose data and structure difference is to be applied
517 $matching_table_data_diff = array(); //stores id of matching table having data difference
518 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
519 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
520 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
522 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
523 if (isset($_REQUEST[$i])) {
524 $table_id = explode("US", $_REQUEST[$i]);
525 if (isset($table_id[1])) {
526 $uncommon_table_structure_diff[] = $table_id[1];
528 $table_id = explode("UD", $_REQUEST[$i]);
529 if (isset($table_id[1])) {
530 $uncommon_table_data_diff[] = $table_id[1];
532 $table_id = explode("MS", $_REQUEST[$i]);
533 if (isset($table_id[1])) {
534 $matching_table_structure_diff[] = $table_id[1];
537 $table_id = explode("MD", $_REQUEST[$i]);
538 if (isset($table_id[1])) {
539 $matching_table_data_diff[] = $table_id[1];
542 } // end for
544 * Applying the structure difference on selected matching tables
546 for($q = 0; $q < sizeof($matching_table_structure_diff); $q++)
548 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
550 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
551 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
553 unset($alter_str_array[$matching_table_structure_diff[$q]]);
555 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
557 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
558 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
560 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
562 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
564 unset($delete_array[$matching_table_structure_diff[$q]]);
566 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
567 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
569 unset($add_column_array[$matching_table_structure_diff[$q]]);
571 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
573 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
575 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
577 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
578 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
580 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
581 $remove_indexes_array, $matching_table_structure_diff[$q], false);
583 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
584 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
585 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
589 * Applying the data difference. First checks if structure diff is applied or not.
590 * If not, then apply structure difference first then apply data difference.
592 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
594 if ($_REQUEST['checked'] == 'true') {
596 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
597 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
599 if (isset($delete_array[$matching_table_data_diff[$p]])) {
601 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
603 unset($delete_array[$matching_table_data_diff[$p]]);
606 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
608 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
609 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
611 unset($alter_str_array[$matching_table_data_diff[$p]]);
613 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
615 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
616 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
618 if (isset($delete_array[$matching_table_data_diff[$p]])) {
620 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
622 unset($delete_array[$matching_table_data_diff[$p]]);
624 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
625 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
627 unset($add_column_array[$matching_table_data_diff[$p]]);
629 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
631 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
633 unset($uncommon_columns[$matching_table_data_diff[$p]]);
635 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
636 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
637 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
639 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
640 $remove_indexes_array, $matching_table_structure_diff[$q], false);
642 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
643 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
644 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
647 * Applying the data difference.
649 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
651 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
652 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
653 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
654 $alter_indexes_array, $delete_array, $update_array, false);
657 * Updating the session variables to the latest values of the arrays.
659 $_SESSION['delete_array'] = $delete_array;
660 $_SESSION['uncommon_columns'] = $uncommon_columns;
661 $_SESSION['alter_str_array'] = $alter_str_array;
662 $_SESSION['add_column_array'] = $add_column_array;
663 $_SESSION['add_indexes_array'] = $add_indexes_array;
664 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
665 $_SESSION['insert_array'] = $insert_array;
666 $_SESSION['update_array'] = $update_array;
669 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
671 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
673 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
674 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
676 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
679 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
680 * Before data synchronization, structure synchronization is confirmed.
682 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
684 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
685 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
687 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r],
688 $uncommon_tables_fields, false);
689 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
691 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
694 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
695 $_SESSION['uncommon_tables_fields'], false);
697 unset($row_count[$uncommon_table_data_diff[$r]]);
700 * Again all the tables from source and target database are displayed with their differences.
701 * The differences have been removed from tables that have been synchronized
703 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
704 . PMA_generate_common_hidden_inputs('', '');
706 PMA_syncDisplayHeaderSource($src_db);
707 $odd_row = false;
708 for($i = 0; $i < count($matching_tables); $i++) {
709 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
710 echo '<td align="center">' . htmlspecialchars($matching_tables[$i]) . '</td>
711 <td align="center">';
713 $num_alter_cols = 0;
714 $num_insert_cols = 0;
715 $num_remove_cols = 0;
716 $num_add_index = 0;
717 $num_remove_index = 0;
719 if (isset($alter_str_array[$i])) {
720 $num_alter_cols = sizeof($alter_str_array[$i]);
722 if (isset($add_column_array[$i])) {
723 $num_insert_cols = sizeof($add_column_array[$i]);
725 if (isset($uncommon_columns[$i])) {
726 $num_remove_cols = sizeof($uncommon_columns[$i]);
728 if (isset($add_indexes_array[$i])) {
729 $num_add_index = sizeof($add_indexes_array[$i]);
731 if (isset($remove_indexes_array[$i])) {
732 $num_remove_index = sizeof($remove_indexes_array[$i]);
735 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
736 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
737 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
738 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
739 this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
741 if (!(in_array($i, $matching_table_data_diff))) {
743 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
744 if (isset($update_array[$i])) {
745 $num_of_updates = sizeof($update_array[$i]);
746 } else {
747 $num_of_updates = 0;
749 } else {
750 $num_of_updates = 0;
752 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
753 if (isset($insert_array[$i])) {
754 $num_of_insertions = sizeof($insert_array[$i]);
755 } else {
756 $num_of_insertions = 0;
758 } else {
759 $num_of_insertions = 0;
762 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
763 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
764 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
765 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
766 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
767 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
769 } else {
770 unset($update_array[$i]);
771 unset($insert_array[$i]);
773 echo '</td>
774 </tr>';
777 * placing updated value of arrays in session
780 $_SESSION['update_array'] = $update_array;
781 $_SESSION['insert_array'] = $insert_array;
783 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
784 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
785 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
786 <td align="center">';
788 * Display the difference only when it has not been applied
790 if (!(in_array($j, $uncommon_table_structure_diff))) {
791 if (isset($uncommon_tables[$j])) {
792 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
793 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
794 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
796 } else {
797 unset($uncommon_tables[$j]);
800 * Display the difference only when it has not been applied
802 if (!(in_array($j, $uncommon_table_data_diff))) {
803 if (isset($row_count[$j]) && ($row_count > 0)) {
804 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
805 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
806 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
807 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
809 } else {
810 unset($row_count[$j]);
813 echo '</td>
814 </tr>';
817 * placing the latest values of arrays in session
820 $_SESSION['uncommon_tables'] = $uncommon_tables;
821 $_SESSION['uncommon_tables_row_count'] = $row_count;
825 * Displaying the target database tables
827 foreach ($target_tables_uncommon as $tbl_nc_name) {
828 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
829 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
830 echo '</tr>';
832 echo '</table>';
833 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
834 foreach ($source_tables_uncommon as $tbl_nc_name) {
835 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
836 if (in_array($tbl_nc_name, $uncommon_tables)) {
837 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>';
838 } else {
839 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
841 echo '
842 </tr>';
844 foreach ($target_tables_uncommon as $tbl_nc_name) {
845 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
846 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
847 echo '</tr>';
849 echo '</table>
850 </div>';
853 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
854 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
857 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
858 border-left: 1px gray solid; border-bottom: 1px gray solid;
859 padding:0px; margin: 0px">';
861 echo '<table>
862 <thead>
863 <tr style="width: 100%;">
864 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
865 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
866 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
867 </tr>
868 <tr style="width: 100%;">
869 <th style="width: 10%;">' . __('Table name') . '</th>
870 <th style="width: 10%;">' . __('Create table'). '</th>
871 <th style="width: 11%;">' . __('Add column(s)') . '</th>
872 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
873 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
874 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
875 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
876 <th style="width: 10%;">' . __('Update row(s)') . '</th>
877 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
878 </tr>
879 </thead>
880 <tbody></tbody>
881 </table>
882 </div>';
885 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
887 echo '<fieldset>
888 <p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
889 </fieldset>';
891 echo '<fieldset class="tblFooters">';
892 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes') . '"
893 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
894 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />'
895 . '</fieldset>';
896 echo '</form>';
900 * Displays the page when 'Synchronize Databases' is pressed.
903 if (isset($_REQUEST['synchronize_db'])) {
905 $src_db = $_SESSION['src_db'];
906 $trg_db = $_SESSION['trg_db'];
907 $update_array = $_SESSION['update_array'];
908 $insert_array = $_SESSION['insert_array'];
909 $src_username = $_SESSION['src_username'];
910 $trg_username = $_SESSION['trg_username'];
911 $src_password = $_SESSION['src_password'];
912 $trg_password = $_SESSION['trg_password'];
913 $matching_tables = $_SESSION['matching_tables'];
914 $matching_tables_keys = $_SESSION['matching_tables_keys'];
915 $matching_tables_fields = $_SESSION['matching_fields'];
916 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
917 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
918 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
919 $row_count = $_SESSION['uncommon_tables_row_count'];
920 $uncommon_tables = $_SESSION['uncommon_tables'];
921 $target_tables = $_SESSION['target_tables'];
923 $delete_array = $_SESSION['delete_array'];
924 $uncommon_columns = $_SESSION['uncommon_columns'];
925 $source_columns = $_SESSION['source_columns'];
926 $alter_str_array = $_SESSION['alter_str_array'];
927 $criteria = $_SESSION['criteria'];
928 $target_tables_keys = $_SESSION['target_tables_keys'];
929 $add_column_array = $_SESSION['add_column_array'];
930 $add_indexes_array = $_SESSION['add_indexes_array'];
931 $alter_indexes_array = $_SESSION['alter_indexes_array'];
932 $remove_indexes_array = $_SESSION['remove_indexes_array'];
933 $source_indexes = $_SESSION['source_indexes'];
934 $target_indexes = $_SESSION['target_indexes'];
935 $uncommon_cols = $uncommon_columns;
938 * Display success message.
940 echo '<div class="success">' . __('Target database has been synchronized with source database') . '</div>';
942 * Displaying all the tables of source and target database and now no difference is there.
944 PMA_syncDisplayHeaderSource($src_db);
946 $odd_row = false;
947 for($i = 0; $i < count($matching_tables); $i++)
949 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
950 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
951 <td></td>
952 </tr>';
954 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
955 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
956 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
957 echo '<td></td>
958 </tr>';
960 foreach ($target_tables_uncommon as $tbl_nc_name) {
961 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
962 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
963 echo '</tr>';
965 echo '</table>';
966 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
967 foreach ($source_tables_uncommon as $tbl_nc_name) {
968 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
969 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
970 </tr>';
972 foreach ($target_tables_uncommon as $tbl_nc_name) {
973 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
974 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
975 echo '</tr>';
977 echo '</table> </div>';
980 * connecting the source and target servers
982 if ('cur' != $_SESSION['src_type']) {
983 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
984 } else {
985 $src_link = $GLOBALS['userlink'];
986 // working on current server, so initialize this for tracking
987 // (does not work if user defined current server as a remote one)
988 $GLOBALS['db'] = $_SESSION['src_db'];
990 if ('cur' != $_SESSION['trg_type']) {
991 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
992 } else {
993 $trg_link = $GLOBALS['userlink'];
994 // working on current server, so initialize this for tracking
995 $GLOBALS['db'] = $_SESSION['trg_db'];
999 * Displaying the queries.
1001 echo '<h5>' . __('The following queries have been executed:') . '</h5>';
1002 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1003 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1005 * Applying all sorts of differences for each matching table
1007 for($p = 0; $p < sizeof($matching_tables); $p++) {
1009 * If the check box is checked for deleting previous rows from the target database tables then
1010 * first find out rows to be deleted and then delete the rows.
1012 if (isset($_REQUEST['delete_rows'])) {
1013 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1014 $trg_db, $trg_link, $src_db, $src_link);
1016 if (isset($delete_array[$p])) {
1017 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1018 unset($delete_array[$p]);
1021 if (isset($alter_str_array[$p])) {
1022 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1023 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1024 unset($alter_str_array[$p]);
1026 if (! empty($add_column_array[$p])) {
1027 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1028 $trg_db, $trg_link, $src_db, $src_link);
1030 if (isset($delete_array[$p])) {
1031 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1032 unset($delete_array[$p]);
1034 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
1035 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1036 $p, $uncommon_cols, true);
1037 unset($add_column_array[$p]);
1039 if (isset($uncommon_columns[$p])) {
1040 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1041 unset($uncommon_columns[$p]);
1043 if (isset($matching_table_structure_diff) &&
1044 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1045 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1046 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1047 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1048 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1050 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1051 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1052 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1055 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1057 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1058 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1059 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1060 $alter_indexes_array, $delete_array, $update_array, true);
1064 * Creating and populating tables present in source but absent from target database.
1066 for($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1067 if (isset($uncommon_tables[$q])) {
1068 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1070 if (isset($row_count[$q])) {
1071 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1074 echo "</div>";
1078 * Displays the main page when none of the following buttons is pressed
1081 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1084 * Displays the sub-page heading
1086 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1087 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1088 . ' height="18" alt="" />'
1089 : '')
1090 . __('Synchronize')
1091 .'</h2>';
1093 echo '<div id="serverstatus">
1094 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1095 >' // TODO: add check if all var. are filled in
1096 . PMA_generate_common_hidden_inputs('', '');
1097 echo '<fieldset>';
1098 echo '<legend>' . __('Synchronize') . '</legend>';
1100 * Displays the forms
1103 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1104 'ASC', 0, true);
1106 foreach ($cons as $type) {
1107 if ('src' == $type) {
1108 $database_header = __('Source database');
1109 } else {
1110 $database_header = __('Target database');
1113 <table id="serverconnection_<?php echo $type; ?>_remote" class="data">
1114 <tr>
1115 <th colspan="2"><?php echo $database_header; ?></th>
1116 </tr>
1117 <tr class="odd">
1118 <td colspan="2" style="text-align: center">
1119 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1120 <option value="rmt"><?php echo __('Enter manually'); ?></option>
1121 <option value="cur"><?php echo __('Current connection'); ?></option>
1122 <?php
1123 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1124 if (empty($tmp_server['host'])) {
1125 continue;
1128 if (!empty($tmp_server['verbose'])) {
1129 $label = $tmp_server['verbose'];
1130 } else {
1131 $label = $tmp_server['host'];
1132 if (!empty($tmp_server['port'])) {
1133 $label .= ':' . $tmp_server['port'];
1136 $value = $tmp_server['host'];
1137 $value .= '||||';
1138 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1139 $value .= '3306';
1140 } else {
1141 $value .= $tmp_server['port'];
1143 $value .= '||||';
1144 $value .= $tmp_server['socket'];
1145 $value .= '||||';
1146 $value .= $tmp_server['user'];
1147 $value .= '||||';
1148 $value .= $tmp_server['only_db'];
1149 echo '<option value="' . $value . '">'
1150 . htmlspecialchars(sprintf(__('Configuration: %s'), $label)) . '</option>' . "\n";
1151 } // end foreach
1153 </select>
1154 </td>
1155 </tr>
1156 <tr class="even toggler remote-server">
1157 <td><?php echo __('Host'); ?></td>
1158 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" /></td>
1159 </tr>
1160 <tr class="odd toggler remote-server">
1161 <td><?php echo __('Port'); ?></td>
1162 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" value="3306" maxlength="5" size="5" /></td>
1163 </tr>
1164 <tr class="even toggler remote-server">
1165 <td><?php echo __('Socket'); ?></td>
1166 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" /></td>
1167 </tr>
1168 <tr class="odd toggler remote-server">
1169 <td><?php echo __('User name'); ?></td>
1170 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" /></td>
1171 </tr>
1172 <tr class="even toggler remote-server">
1173 <td><?php echo __('Password'); ?></td>
1174 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1175 </tr>
1176 <tr class="odd toggler remote-server">
1177 <td><?php echo __('Database'); ?></td>
1178 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" /></td>
1179 </tr>
1180 <tr class="even toggler current-server" style="display: none;">
1181 <td><?php echo __('Database'); ?></td>
1182 <td>
1183 <?php
1184 // these unset() do not complain if the elements do not exist
1185 unset($databases['mysql']);
1186 unset($databases['information_schema']);
1188 if (count($databases) == 0) {
1189 echo __('No databases');
1190 } else {
1191 echo '
1192 <select name="' . $type . '_db_sel">
1194 foreach ($databases as $db) {
1195 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1197 echo '</select>';
1199 echo '</td> </tr>
1200 </table>';
1202 unset ($types, $type);
1204 echo '
1205 </fieldset>
1206 <fieldset class="tblFooters">
1207 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1208 </fieldset>
1209 </form>
1210 </div>
1211 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1215 * Displays the footer
1217 require './libraries/footer.inc.php';