* Schema snapshot */ if (isset($_REQUEST['snapshot'])) { ?> <h3><?php echo $strTrackingStructureSnapshot; ?> [<a href="tbl_tracking.php?<?php echo $url_query; ?> "><?php echo $strTrackingReportClose; ?> </a>]</h3> <?php $data = PMA_Tracker::getTrackedData($_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']); // Get first DROP TABLE and CREATE TABLE statements $drop_create_statements = $data['ddlog'][0]['statement']; if (strstr($data['ddlog'][0]['statement'], 'DROP TABLE')) { $drop_create_statements .= $data['ddlog'][1]['statement']; } // Print SQL code PMA_showMessage(sprintf($strTrackingVersionSnapshotSQL, $_REQUEST['version']), $drop_create_statements); // Unserialize snapshot $temp = unserialize($data['schema_snapshot']); $columns = $temp['COLUMNS']; $indexes = $temp['INDEXES']; ?> <h3><?php echo $strStructure; ?>
/** * Function to get html for schema snapshot * * @param string $url_query url query * * @return string */ function PMA_getHtmlForSchemaSnapshot($url_query) { $html = '<h3>' . __('Structure snapshot') . ' [<a href="tbl_tracking.php' . $url_query . '">' . __('Close') . '</a>]</h3>'; $data = PMA_Tracker::getTrackedData($_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']); // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements $drop_create_statements = $data['ddlog'][0]['statement']; if (mb_strstr($data['ddlog'][0]['statement'], 'DROP TABLE') || mb_strstr($data['ddlog'][0]['statement'], 'DROP VIEW')) { $drop_create_statements .= $data['ddlog'][1]['statement']; } // Print SQL code $html .= PMA_Util::getMessage(sprintf(__('Version %s snapshot (SQL code)'), htmlspecialchars($_REQUEST['version'])), $drop_create_statements); // Unserialize snapshot $temp = unserialize($data['schema_snapshot']); $columns = $temp['COLUMNS']; $indexes = $temp['INDEXES']; $html .= PMA_getHtmlForColumns($columns); if (count($indexes) > 0) { $html .= PMA_getHtmlForIndexes($indexes); } // endif $html .= '<br /><hr /><br />'; return $html; }
/** * Test for PMA_Tracker::getTrackedData() * * @param array $fetchArrayReturn Value to be returned by mocked fetchArray * @param array $expectedArray Expected array * * @return void * @test * @dataProvider getTrackedDataProvider */ public function testGetTrackedData($fetchArrayReturn, $expectedArray) { $GLOBALS['cfg']['Server']['pmadb'] = 'pma_db'; $GLOBALS['cfg']['Server']['tracking'] = 'tracking'; $reflection = new \ReflectionProperty('PMA_Tracker', 'pma_table'); $reflection->setAccessible(true); $reflection->setValue(null, "`pma_db`.`tracking`"); $sql_query = " SELECT * FROM `pma_db`.`tracking`" . " WHERE `db_name` = 'pma''db' " . " AND `table_name` = 'pma''table' " . " AND `version` = '1.0' ". " ORDER BY `version` DESC LIMIT 1"; $GLOBALS['controllink'] = null; $dbi = $this->getMockBuilder('PMA_DatabaseInterface') ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->at(0)) ->method('query') ->with($sql_query, null, 0, false) ->will($this->returnValue("executed_1")); $dbi->expects($this->at(1)) ->method('fetchAssoc') ->with("executed_1") ->will($this->returnValue($fetchArrayReturn)); $GLOBALS['dbi'] = $dbi; $result = PMA_Tracker::getTrackedData("pma'db", "pma'table", "1.0"); $this->assertEquals( $expectedArray, $result ); }
// Work to do? // (here, do not use $_REQUEST['db] as it can be crafted) if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) { PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']); /** * If in an Ajax request, generate the success message and use * {@link PMA_Response()} to send the output */ if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->addJSON('message', PMA_Message::success()); exit; } } // Get tracked data about the database $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1'); // No tables present and no log exist if ($num_tables == 0 && count($data['ddlog']) == 0) { echo '<p>' . __('No tables found in database.') . '</p>' . "\n"; if (empty($db_is_system_schema)) { include 'libraries/display_create_table.lib.php'; } exit; } // --------------------------------------------------------------------------- $cfgRelation = PMA_getRelationsParam(); // Prepare statement to get HEAD version $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' . PMA_Util::backquote($cfgRelation['db']) . '.' . PMA_Util::backquote($cfgRelation['tracking']) . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' . ' GROUP BY table_name' . ' ORDER BY table_name ASC'; $all_tables_result = PMA_queryAsControlUser($all_tables_query); // If a HEAD version exists if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {