ChangeLog entry for this bug report
[phpmyadmin.git] / server_synchronize.php
blobbb08fd66608a0a97dbfb62d97597e7ee050f146d
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;
282 * Display the matching tables' names and difference, first
284 for($i = 0; $i < count($matching_tables); $i++) {
286 * Calculating the number of updates for each matching table
288 if (isset($update_array[$i]) && isset($update_array[$i][0]) &&
289 isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
290 $num_of_updates = sizeof($update_array[$i]);
291 } else {
292 $num_of_updates = 0;
295 * Calculating the number of insertions for each matching table
297 if (isset($insert_array[$i]) && isset($insert_array[$i][0]) &&
298 isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
299 $num_of_insertions = sizeof($insert_array[$i]);
300 } else {
301 $num_of_insertions = 0;
304 * Displays the name of the matching table
306 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
307 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
308 <td align="center">';
310 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
311 * number of index to be added and removed.
313 $num_alter_cols = 0;
314 $num_insert_cols = 0;
315 $num_remove_cols = 0;
316 $num_add_index = 0;
317 $num_remove_index = 0;
319 if (isset($alter_str_array[$i])) {
320 $num_alter_cols = sizeof($alter_str_array[$i]);
322 if (isset($add_column_array[$i])) {
323 $num_insert_cols = sizeof($add_column_array[$i]);
325 if (isset($uncommon_columns[$i])) {
326 $num_remove_cols = sizeof($uncommon_columns[$i]);
328 if (isset($add_indexes_array[$i])) {
329 $num_add_index = sizeof($add_indexes_array[$i]);
331 if (isset($remove_indexes_array[$i])) {
332 $num_remove_index = sizeof($remove_indexes_array[$i]);
334 if (isset($alter_indexes_array[$i])) {
335 $num_add_index += sizeof($alter_indexes_array[$i]);
336 $num_remove_index += sizeof($alter_indexes_array[$i]);
339 * Display the red button of structure synchronization if there exists any structure difference or index difference.
341 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
343 echo '<img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
344 alt="' . __('Click to select') . '"
345 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
346 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
347 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
350 * Display the green button of data synchronization if there exists any data difference.
352 if (isset($update_array[$i]) || isset($insert_array[$i])) {
353 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
355 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
356 alt="' . __('Click to select') . '"
357 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
358 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
361 echo '</td>
362 </tr>';
365 * Displays the tables' names present in source but missing from target
367 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
368 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
369 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
371 echo '<td align="center"><img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
372 alt="' . __('Click to select') . '"
373 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
374 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
376 if ($row_count[$j] > 0)
378 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
379 alt="' . __('Click to select') . '"
380 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
381 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
383 echo '</td>
384 </tr>';
386 foreach ($target_tables_uncommon as $tbl_nc_name) {
387 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
388 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
389 echo '</tr>';
392 * Displays the target tables names
394 echo '</table>';
396 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
397 foreach ($source_tables_uncommon as $tbl_nc_name) {
398 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
399 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>
400 </tr>';
402 foreach ($target_tables_uncommon as $tbl_nc_name) {
403 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
404 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
405 echo '</tr>';
407 echo '</table>';
408 echo '</div>';
411 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
412 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
415 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
416 border-left: 1px gray solid; border-bottom: 1px gray solid;
417 padding:0px; margin: 0px">
419 <table>
420 <thead>
421 <tr style="width: 100%;">
422 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
423 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
424 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
425 </tr>
426 <tr style="width: 100%;">
427 <th style="width: 10%;">' . __('Table name') . '</th>
428 <th style="width: 10%;">' . __('Create table'). '</th>
429 <th style="width: 11%;">' . __('Add column(s)') . '</th>
430 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
431 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
432 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
433 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
434 <th style="width: 10%;">'. __('Update row(s)') . '</th>
435 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
436 </tr>
437 </thead>
438 <tbody></tbody>
439 </table>
440 </div>';
442 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
444 echo '<fieldset>
445 <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>
446 </fieldset>
447 <fieldset class="tblFooters">';
448 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes')
449 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
450 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />' . '</fieldset>';
451 echo '</form>';
454 } // end if ((isset($_REQUEST['submit_connect'])))
457 * Display the page when 'Apply Selected Changes' is pressed
459 if (isset($_REQUEST['Table_ids'])) {
461 * Displays success message
463 echo '<div class="success">' . __('Selected target tables have been synchronized with source tables.') . '</div>';
465 $src_db = $_SESSION['src_db'];
466 $trg_db = $_SESSION['trg_db'];
467 $update_array = $_SESSION['update_array'];
468 $insert_array = $_SESSION['insert_array'];
469 $src_username = $_SESSION['src_username'];
470 $trg_username = $_SESSION['trg_username'];
471 $src_password = $_SESSION['src_password'];
472 $trg_password = $_SESSION['trg_password'];
473 $src_server = $_SESSION['src_server'];
474 $trg_server = $_SESSION['trg_server'];
475 $src_type = $_SESSION['src_type'];
476 $trg_type = $_SESSION['trg_type'];
477 $uncommon_tables = $_SESSION['uncommon_tables'];
478 $matching_tables = $_SESSION['matching_tables'];
479 $matching_tables_keys = $_SESSION['matching_tables_keys'];
480 $matching_tables_fields = $_SESSION['matching_fields'];
481 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
482 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
483 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
484 $row_count = $_SESSION['uncommon_tables_row_count'];
485 $target_tables = $_SESSION['target_tables'];
487 $delete_array = $_SESSION['delete_array'];
488 $uncommon_columns = $_SESSION['uncommon_columns'];
489 $source_columns = $_SESSION['source_columns'];
490 $alter_str_array = $_SESSION['alter_str_array'];
491 $criteria = $_SESSION['criteria'];
492 $target_tables_keys = $_SESSION['target_tables_keys'];
493 $add_column_array = $_SESSION['add_column_array'];
494 $add_indexes_array = $_SESSION['add_indexes_array'];
495 $alter_indexes_array = $_SESSION['alter_indexes_array'];
496 $remove_indexes_array = $_SESSION['remove_indexes_array'];
497 $source_indexes = $_SESSION['source_indexes'];
498 $target_indexes = $_SESSION['target_indexes'];
499 $uncommon_cols = $uncommon_columns;
502 * Creating link object for source and target databases
504 foreach ($cons as $con) {
505 if (${"{$con}_type"} != "cur") {
506 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
507 } else {
508 ${"{$con}_link"} = null;
509 // working on current server, so initialize this for tracking
510 // (does not work if user defined current server as a remote one)
511 $GLOBALS['db'] = ${"{$con}_db"};
513 } // end foreach ($cons as $con)
516 * Initializing arrays to save the table ids whose data and structure difference is to be applied
518 $matching_table_data_diff = array(); //stores id of matching table having data difference
519 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
520 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
521 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
523 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
524 if (isset($_REQUEST[$i])) {
525 $table_id = explode("US", $_REQUEST[$i]);
526 if (isset($table_id[1])) {
527 $uncommon_table_structure_diff[] = $table_id[1];
529 $table_id = explode("UD", $_REQUEST[$i]);
530 if (isset($table_id[1])) {
531 $uncommon_table_data_diff[] = $table_id[1];
533 $table_id = explode("MS", $_REQUEST[$i]);
534 if (isset($table_id[1])) {
535 $matching_table_structure_diff[] = $table_id[1];
538 $table_id = explode("MD", $_REQUEST[$i]);
539 if (isset($table_id[1])) {
540 $matching_table_data_diff[] = $table_id[1];
543 } // end for
545 * Applying the structure difference on selected matching tables
547 for($q = 0; $q < sizeof($matching_table_structure_diff); $q++)
549 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
551 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
552 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
554 unset($alter_str_array[$matching_table_structure_diff[$q]]);
556 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
558 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
559 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
561 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
563 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
565 unset($delete_array[$matching_table_structure_diff[$q]]);
567 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
568 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
570 unset($add_column_array[$matching_table_structure_diff[$q]]);
572 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
574 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
576 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
578 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
579 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
581 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
582 $remove_indexes_array, $matching_table_structure_diff[$q], false);
584 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
585 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
586 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
590 * Applying the data difference. First checks if structure diff is applied or not.
591 * If not, then apply structure difference first then apply data difference.
593 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
595 if ($_REQUEST['checked'] == 'true') {
597 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
598 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
600 if (isset($delete_array[$matching_table_data_diff[$p]])) {
602 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
604 unset($delete_array[$matching_table_data_diff[$p]]);
607 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
609 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
610 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
612 unset($alter_str_array[$matching_table_data_diff[$p]]);
614 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
616 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
617 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
619 if (isset($delete_array[$matching_table_data_diff[$p]])) {
621 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
623 unset($delete_array[$matching_table_data_diff[$p]]);
625 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
626 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
628 unset($add_column_array[$matching_table_data_diff[$p]]);
630 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
632 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
634 unset($uncommon_columns[$matching_table_data_diff[$p]]);
636 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
637 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
638 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
640 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
641 $remove_indexes_array, $matching_table_structure_diff[$q], false);
643 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
644 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
645 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
648 * Applying the data difference.
650 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
652 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
653 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
654 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
655 $alter_indexes_array, $delete_array, $update_array, false);
658 * Updating the session variables to the latest values of the arrays.
660 $_SESSION['delete_array'] = $delete_array;
661 $_SESSION['uncommon_columns'] = $uncommon_columns;
662 $_SESSION['alter_str_array'] = $alter_str_array;
663 $_SESSION['add_column_array'] = $add_column_array;
664 $_SESSION['add_indexes_array'] = $add_indexes_array;
665 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
666 $_SESSION['insert_array'] = $insert_array;
667 $_SESSION['update_array'] = $update_array;
670 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
672 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
674 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
675 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
677 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
680 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
681 * Before data synchronization, structure synchronization is confirmed.
683 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
685 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
686 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
688 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r],
689 $uncommon_tables_fields, false);
690 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
692 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
695 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
696 $_SESSION['uncommon_tables_fields'], false);
698 unset($row_count[$uncommon_table_data_diff[$r]]);
701 * Again all the tables from source and target database are displayed with their differences.
702 * The differences have been removed from tables that have been synchronized
704 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
705 . PMA_generate_common_hidden_inputs('', '');
707 PMA_syncDisplayHeaderSource($src_db);
708 $odd_row = false;
709 for($i = 0; $i < count($matching_tables); $i++) {
710 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
711 echo '<td align="center">' . htmlspecialchars($matching_tables[$i]) . '</td>
712 <td align="center">';
714 $num_alter_cols = 0;
715 $num_insert_cols = 0;
716 $num_remove_cols = 0;
717 $num_add_index = 0;
718 $num_remove_index = 0;
720 if (isset($alter_str_array[$i])) {
721 $num_alter_cols = sizeof($alter_str_array[$i]);
723 if (isset($add_column_array[$i])) {
724 $num_insert_cols = sizeof($add_column_array[$i]);
726 if (isset($uncommon_columns[$i])) {
727 $num_remove_cols = sizeof($uncommon_columns[$i]);
729 if (isset($add_indexes_array[$i])) {
730 $num_add_index = sizeof($add_indexes_array[$i]);
732 if (isset($remove_indexes_array[$i])) {
733 $num_remove_index = sizeof($remove_indexes_array[$i]);
736 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
737 echo '<img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
738 alt="' . __('Click to select') . '"
739 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
740 this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
742 if (!(in_array($i, $matching_table_data_diff))) {
744 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
745 if (isset($update_array[$i])) {
746 $num_of_updates = sizeof($update_array[$i]);
747 } else {
748 $num_of_updates = 0;
750 } else {
751 $num_of_updates = 0;
753 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
754 if (isset($insert_array[$i])) {
755 $num_of_insertions = sizeof($insert_array[$i]);
756 } else {
757 $num_of_insertions = 0;
759 } else {
760 $num_of_insertions = 0;
763 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
764 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
765 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
766 alt="' . __('Click to select') . '"
767 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
768 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
770 } else {
771 unset($update_array[$i]);
772 unset($insert_array[$i]);
774 echo '</td>
775 </tr>';
778 * placing updated value of arrays in session
781 $_SESSION['update_array'] = $update_array;
782 $_SESSION['insert_array'] = $insert_array;
784 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
785 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
786 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
787 <td align="center">';
789 * Display the difference only when it has not been applied
791 if (!(in_array($j, $uncommon_table_structure_diff))) {
792 if (isset($uncommon_tables[$j])) {
793 echo '<img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
794 alt="' . __('Click to select') . '"
795 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
797 } else {
798 unset($uncommon_tables[$j]);
801 * Display the difference only when it has not been applied
803 if (!(in_array($j, $uncommon_table_data_diff))) {
804 if (isset($row_count[$j]) && ($row_count > 0)) {
805 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
806 alt="' . __('Click to select') . '"
807 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
808 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
810 } else {
811 unset($row_count[$j]);
814 echo '</td>
815 </tr>';
818 * placing the latest values of arrays in session
821 $_SESSION['uncommon_tables'] = $uncommon_tables;
822 $_SESSION['uncommon_tables_row_count'] = $row_count;
826 * Displaying the target database tables
828 foreach ($target_tables_uncommon as $tbl_nc_name) {
829 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
830 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
831 echo '</tr>';
833 echo '</table>';
834 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
835 foreach ($source_tables_uncommon as $tbl_nc_name) {
836 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
837 if (in_array($tbl_nc_name, $uncommon_tables)) {
838 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>';
839 } else {
840 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
842 echo '
843 </tr>';
845 foreach ($target_tables_uncommon as $tbl_nc_name) {
846 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
847 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
848 echo '</tr>';
850 echo '</table>
851 </div>';
854 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
855 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
858 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
859 border-left: 1px gray solid; border-bottom: 1px gray solid;
860 padding:0px; margin: 0px">';
862 echo '<table>
863 <thead>
864 <tr style="width: 100%;">
865 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
866 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
867 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
868 </tr>
869 <tr style="width: 100%;">
870 <th style="width: 10%;">' . __('Table name') . '</th>
871 <th style="width: 10%;">' . __('Create table'). '</th>
872 <th style="width: 11%;">' . __('Add column(s)') . '</th>
873 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
874 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
875 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
876 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
877 <th style="width: 10%;">' . __('Update row(s)') . '</th>
878 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
879 </tr>
880 </thead>
881 <tbody></tbody>
882 </table>
883 </div>';
886 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
888 echo '<fieldset>
889 <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>
890 </fieldset>';
892 echo '<fieldset class="tblFooters">';
893 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes') . '"
894 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
895 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />'
896 . '</fieldset>';
897 echo '</form>';
901 * Displays the page when 'Synchronize Databases' is pressed.
904 if (isset($_REQUEST['synchronize_db'])) {
906 $src_db = $_SESSION['src_db'];
907 $trg_db = $_SESSION['trg_db'];
908 $update_array = $_SESSION['update_array'];
909 $insert_array = $_SESSION['insert_array'];
910 $src_username = $_SESSION['src_username'];
911 $trg_username = $_SESSION['trg_username'];
912 $src_password = $_SESSION['src_password'];
913 $trg_password = $_SESSION['trg_password'];
914 $matching_tables = $_SESSION['matching_tables'];
915 $matching_tables_keys = $_SESSION['matching_tables_keys'];
916 $matching_tables_fields = $_SESSION['matching_fields'];
917 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
918 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
919 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
920 $row_count = $_SESSION['uncommon_tables_row_count'];
921 $uncommon_tables = $_SESSION['uncommon_tables'];
922 $target_tables = $_SESSION['target_tables'];
924 $delete_array = $_SESSION['delete_array'];
925 $uncommon_columns = $_SESSION['uncommon_columns'];
926 $source_columns = $_SESSION['source_columns'];
927 $alter_str_array = $_SESSION['alter_str_array'];
928 $criteria = $_SESSION['criteria'];
929 $target_tables_keys = $_SESSION['target_tables_keys'];
930 $add_column_array = $_SESSION['add_column_array'];
931 $add_indexes_array = $_SESSION['add_indexes_array'];
932 $alter_indexes_array = $_SESSION['alter_indexes_array'];
933 $remove_indexes_array = $_SESSION['remove_indexes_array'];
934 $source_indexes = $_SESSION['source_indexes'];
935 $target_indexes = $_SESSION['target_indexes'];
936 $uncommon_cols = $uncommon_columns;
939 * Display success message.
941 echo '<div class="success">' . __('Target database has been synchronized with source database') . '</div>';
943 * Displaying all the tables of source and target database and now no difference is there.
945 PMA_syncDisplayHeaderSource($src_db);
947 $odd_row = false;
948 for($i = 0; $i < count($matching_tables); $i++)
950 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
951 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
952 <td></td>
953 </tr>';
955 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
956 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
957 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
958 echo '<td></td>
959 </tr>';
961 foreach ($target_tables_uncommon as $tbl_nc_name) {
962 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
963 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
964 echo '</tr>';
966 echo '</table>';
967 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
968 foreach ($source_tables_uncommon as $tbl_nc_name) {
969 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
970 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
971 </tr>';
973 foreach ($target_tables_uncommon as $tbl_nc_name) {
974 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
975 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
976 echo '</tr>';
978 echo '</table> </div>';
981 * connecting the source and target servers
983 if ('cur' != $_SESSION['src_type']) {
984 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
985 } else {
986 $src_link = $GLOBALS['userlink'];
987 // working on current server, so initialize this for tracking
988 // (does not work if user defined current server as a remote one)
989 $GLOBALS['db'] = $_SESSION['src_db'];
991 if ('cur' != $_SESSION['trg_type']) {
992 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
993 } else {
994 $trg_link = $GLOBALS['userlink'];
995 // working on current server, so initialize this for tracking
996 $GLOBALS['db'] = $_SESSION['trg_db'];
1000 * Displaying the queries.
1002 echo '<h5>' . __('The following queries have been executed:') . '</h5>';
1003 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1004 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1006 * Applying all sorts of differences for each matching table
1008 for($p = 0; $p < sizeof($matching_tables); $p++) {
1010 * If the check box is checked for deleting previous rows from the target database tables then
1011 * first find out rows to be deleted and then delete the rows.
1013 if (isset($_REQUEST['delete_rows'])) {
1014 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1015 $trg_db, $trg_link, $src_db, $src_link);
1017 if (isset($delete_array[$p])) {
1018 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1019 unset($delete_array[$p]);
1022 if (isset($alter_str_array[$p])) {
1023 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1024 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1025 unset($alter_str_array[$p]);
1027 if (! empty($add_column_array[$p])) {
1028 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1029 $trg_db, $trg_link, $src_db, $src_link);
1031 if (isset($delete_array[$p])) {
1032 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1033 unset($delete_array[$p]);
1035 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
1036 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1037 $p, $uncommon_cols, true);
1038 unset($add_column_array[$p]);
1040 if (isset($uncommon_columns[$p])) {
1041 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1042 unset($uncommon_columns[$p]);
1044 if (isset($matching_table_structure_diff) &&
1045 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1046 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1047 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1048 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1049 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1051 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1052 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1053 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1056 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1058 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1059 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1060 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1061 $alter_indexes_array, $delete_array, $update_array, true);
1065 * Creating and populating tables present in source but absent from target database.
1067 for($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1068 if (isset($uncommon_tables[$q])) {
1069 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1071 if (isset($row_count[$q])) {
1072 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1075 echo "</div>";
1079 * Displays the main page when none of the following buttons is pressed
1082 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1085 * Displays the sub-page heading
1087 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1088 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1089 . ' height="18" alt="" />'
1090 : '')
1091 . __('Synchronize')
1092 .'</h2>';
1094 echo '<div id="serverstatus">
1095 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1096 >' // TODO: add check if all var. are filled in
1097 . PMA_generate_common_hidden_inputs('', '');
1098 echo '<fieldset>';
1099 echo '<legend>' . __('Synchronize') . '</legend>';
1101 * Displays the forms
1104 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1105 'ASC', 0, true);
1107 if ($GLOBALS['cfg']['AllowArbitraryServer'] === false) {
1108 $possibly_disabled = ' disabled="disabled"';
1109 } else {
1110 $possibly_disabled = '';
1113 foreach ($cons as $type) {
1114 if ('src' == $type) {
1115 $database_header = __('Source database');
1116 } else {
1117 $database_header = __('Target database');
1120 $database_header .= PMA_showHint(PMA_sanitize(sprintf('%sAllowArbitraryServer%s', '[a@./Documentation.html#AllowArbitraryServer@_blank]', '[/a]')));
1122 <table id="serverconnection_<?php echo $type; ?>_remote" class="data">
1123 <caption class="tblHeaders"><?php echo $database_header; ?></caption>
1124 <tr class="odd">
1125 <td colspan="2" style="text-align: center">
1126 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1127 <?php
1128 if ($GLOBALS['cfg']['AllowArbitraryServer']) {
1129 $preselected_option = 'rmt';
1130 echo '<option value="rmt" selected="selected">' . __('Enter manually') . '</option>';
1131 } else {
1132 $preselected_option = 'cur';
1134 echo '<option value="cur"';
1135 if ('cur' == $preselected_option) {
1136 echo ' selected="selected"';
1138 echo '>' . __('Current connection') . '</option>';
1140 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1141 if (empty($tmp_server['host'])) {
1142 continue;
1145 if (!empty($tmp_server['verbose'])) {
1146 $label = $tmp_server['verbose'];
1147 } else {
1148 $label = $tmp_server['host'];
1149 if (!empty($tmp_server['port'])) {
1150 $label .= ':' . $tmp_server['port'];
1153 $value = $tmp_server['host'];
1154 $value .= '||||';
1155 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1156 $value .= '3306';
1157 } else {
1158 $value .= $tmp_server['port'];
1160 $value .= '||||';
1161 $value .= $tmp_server['socket'];
1162 $value .= '||||';
1163 $value .= $tmp_server['user'];
1164 $value .= '||||';
1165 $value .= $tmp_server['only_db'];
1166 echo '<option value="' . $value . '" >'
1167 . htmlspecialchars(sprintf(__('Configuration: %s'), $label)) . '</option>';
1168 } // end foreach
1170 </select>
1171 </td>
1172 </tr>
1173 <tr class="even toggler remote-server">
1174 <td><?php echo __('Server'); ?></td>
1175 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" <?php echo $possibly_disabled; ?>/></td>
1176 </tr>
1177 <tr class="odd toggler remote-server">
1178 <td><?php echo __('Port'); ?></td>
1179 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" <?php echo $possibly_disabled; ?> value="3306" maxlength="5" size="5" /></td>
1180 </tr>
1181 <tr class="even toggler remote-server">
1182 <td><?php echo __('Socket'); ?></td>
1183 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" <?php echo $possibly_disabled; ?>/></td>
1184 </tr>
1185 <tr class="odd toggler remote-server">
1186 <td><?php echo __('User name'); ?></td>
1187 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" <?php echo $possibly_disabled; ?>/></td>
1188 </tr>
1189 <tr class="even toggler remote-server">
1190 <td><?php echo __('Password'); ?></td>
1191 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" <?php echo $possibly_disabled; ?>/> </td>
1192 </tr>
1193 <tr class="odd toggler remote-server">
1194 <td><?php echo __('Database'); ?></td>
1195 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" <?php echo $possibly_disabled; ?>/></td>
1196 </tr>
1197 <tr class="even toggler current-server" style="display: none;">
1198 <td><?php echo __('Database'); ?></td>
1199 <td>
1200 <?php
1201 // these unset() do not complain if the elements do not exist
1202 unset($databases['mysql']);
1203 unset($databases['information_schema']);
1205 if (count($databases) == 0) {
1206 echo __('No databases');
1207 } else {
1208 echo '
1209 <select name="' . $type . '_db_sel">
1211 foreach ($databases as $db) {
1212 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1214 echo '</select>';
1216 echo '</td> </tr>
1217 </table>';
1219 unset ($types, $type);
1221 echo '
1222 </fieldset>
1223 <fieldset class="tblFooters">
1224 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1225 </fieldset>
1226 </form>
1227 </div>
1228 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1232 * Displays the footer
1234 require './libraries/footer.inc.php';