getTrackedData() public static méthode

Gets the record of a tracking job.
public static getTrackedData ( string $dbname, string $tablename, string $version ) : mixed
$dbname string name of database
$tablename string name of table
$version string version number
Résultat mixed record DDM log, DDL log, structure snapshot, tracked statements.
Exemple #1
0
    if (!empty($_REQUEST['selected_tbl'])) {
        if ($_REQUEST['submit_mult'] == 'delete_tracking') {
            foreach ($_REQUEST['selected_tbl'] as $table) {
                Tracker::deleteTracking($GLOBALS['db'], $table);
            }
            PMA\libraries\Message::success(__('Tracking data deleted successfully.'))->display();
        } elseif ($_REQUEST['submit_mult'] == 'track') {
            echo PMA_getHtmlForDataDefinitionAndManipulationStatements('db_tracking.php' . $url_query, 0, $GLOBALS['db'], $_REQUEST['selected_tbl']);
            exit;
        }
    } else {
        PMA\libraries\Message::notice(__('No tables selected.'))->display();
    }
}
// Get tracked data about the database
$data = 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)) {
        echo PMA_getHtmlForCreateTable($db);
    }
    exit;
}
// ---------------------------------------------------------------------------
$cfgRelation = PMA_getRelationsParam();
// Prepare statement to get HEAD version
$all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' . PMA\libraries\Util::backquote($cfgRelation['tracking']) . ' WHERE db_name = \'' . PMA\libraries\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 (is_object($all_tables_result) && $GLOBALS['dbi']->numRows($all_tables_result) > 0) {
Exemple #2
0
        sprintf(
            __('Tracking of %s is activated.'),
            htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
        )
    );
    $response->addHTML($msg->getDisplay());
}

$url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
$url_params['goto'] = 'tbl_tracking.php';
$url_params['back'] = 'tbl_tracking.php';

// Init vars for tracking report
if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
    $data = Tracker::getTrackedData(
        $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
    );

    $selection_schema = false;
    $selection_data   = false;
    $selection_both  = false;

    if (! isset($_REQUEST['logtype'])) {
        $_REQUEST['logtype'] = 'schema_and_data';
    }
    if ($_REQUEST['logtype'] == 'schema') {
        $selection_schema = true;
    } elseif ($_REQUEST['logtype'] == 'data') {
        $selection_data   = true;
    } else {
        $selection_both   = true;
 /**
  * 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)
 {
     $sql_query = " SELECT * FROM `pmadb`.`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\\libraries\\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 = Tracker::getTrackedData("pma'db", "pma'table", "1.0");
     $this->assertEquals($expectedArray, $result);
 }
Exemple #4
0
/**
 * 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 = 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\libraries\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['controllink'] = null;
     $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->once())->method('query')->will($this->returnValue("executed_1"));
     $dbi->expects($this->once())->method('fetchAssoc')->with("executed_1")->will($this->returnValue($fetchArrayReturn));
     $dbi->expects($this->any())->method('escapeString')->will($this->returnValueMap(array(array("pma'db", "pma\\'db"), array("pma'table", "pma\\'table"), array("1.0", "1.0"))));
     $GLOBALS['dbi'] = $dbi;
     $result = Tracker::getTrackedData("pma'db", "pma'table", "1.0");
     $this->assertEquals($expectedArray, $result);
 }