createVersion() public static method

Creates tracking version of a table / view (in other words: create a job to track future changes on the table).
public static createVersion ( string $dbname, string $tablename, string $version, string $tracking_set = '', boolean $is_view = false ) : integer
$dbname string name of database
$tablename string name of table
$version string version
$tracking_set string set of tracking statements
$is_view boolean if table is a view
return integer result of version insertion
コード例 #1
0
ファイル: tracking.lib.php プロジェクト: rclakmal/phpmyadmin
/**
 * Create tracking version for multiple tables
 *
 * @param array $selected list of selected tables
 *
 * @return void
 */
function PMA_createTrackingForMultipleTables($selected)
{
    $tracking_set = PMA_getTrackingSet();
    foreach ($selected as $selected_table) {
        Tracker::createVersion($GLOBALS['db'], $selected_table, $_REQUEST['version'], $tracking_set, $GLOBALS['dbi']->getTable($GLOBALS['db'], $selected_table)->isView());
    }
}
コード例 #2
0
 /**
  * Test for Tracker::createVersion()
  *
  * @return void
  * @test
  */
 public function testCreateVersion()
 {
     if (!setupForTestsUsingDate()) {
         $this->markTestSkipped("Cannot override internal function date()");
     }
     $GLOBALS['cfg']['Server']['tracking_add_drop_table'] = true;
     $GLOBALS['cfg']['Server']['tracking_add_drop_view'] = true;
     $GLOBALS['cfg']['Server']['user'] = "******";
     $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock();
     /**
      * set up mock objects
      * passing null to with() for an argument is equivalent
      * to passing $this->anything()
      */
     $getColumnsResult = array(array('Field' => 'field1', 'Type' => 'int(11)', 'Key' => 'PRI'), array('Field' => 'field2', 'Type' => 'text', 'Key' => ''));
     $dbi->expects($this->once())->method('getColumns')->with('pma_test', 'pma_tbl')->will($this->returnValue($getColumnsResult));
     $getIndexesResult = array(array('Table' => 'pma_tbl', 'Field' => 'field1', 'Key' => 'PRIMARY'));
     $dbi->expects($this->once())->method('getTableIndexes')->with('pma_test', 'pma_tbl')->will($this->returnValue($getIndexesResult));
     $tableStatusArray = array(array('Name' => 'pma_tbl', 'Rows' => '1', 'Create_time' => '2013-02-22 02:04:04', 'Update_time' => '2013-02-22 21:46:48'));
     $dbi->expects($this->any())->method('tryQuery')->with($this->equalTo("SHOW CREATE TABLE `pma_test`.`pma_tbl`"))->will($this->returnValue("CREATE TABLE `pma_test`.`pma_tbl` (\n                    `id` int(11) NOT NULL AUTO_INCREMENT,\n                    `username` text NOT NULL\n                    )"));
     $date = date('Y-m-d H:i:s');
     $expectedMainQuery = "/*NOTRACK*/" . "\nINSERT INTO `pmadb`.`tracking` (db_name, table_name, version, date_created, date_updated," . " schema_snapshot, schema_sql, data_sql, tracking ) values (\n        'pma_test',\n        'pma_tbl',\n        '1',\n        '" . $date . "',\n        '" . $date . "',\n        'a:2:{s:7:\"COLUMNS\";a:2:{" . "i:0;a:3:{s:5:\"Field\";s:6:\"field1\";s:4:\"Type\";s:7:\"int(11)\";" . "s:3:\"Key\";s:3:\"PRI\";}" . "i:1;a:3:{s:5:\"Field\";s:6:\"field2\";s:4:\"Type\";s:4:\"text\";" . "s:3:\"Key\";s:0:\"\";}}" . "s:7:\"INDEXES\";a:1:{" . "i:0;a:3:{s:5:\"Table\";s:7:\"pma_tbl\";s:5:\"Field\";s:6:\"field1\";" . "s:3:\"Key\";s:7:\"PRIMARY\";}}}',\n        '# log " . $date . " pma_test_user" . "\nDROP VIEW IF EXISTS `pma_tbl`;" . "\n# log " . $date . " pma_test_user" . "\n\n;" . "\n',\n        '" . "\n',\n        '11' )";
     $GLOBALS['controllink'] = null;
     $queryResults = array(array("SHOW TABLE STATUS FROM `pma_test` LIKE 'pma_tbl'", null, 1, true, $tableStatusArray), array($expectedMainQuery, null, 0, false, 'executed'));
     $dbi->expects($this->any())->method('query')->will($this->returnValueMap($queryResults));
     $GLOBALS['dbi'] = $dbi;
     $this->assertEquals('executed', Tracker::createVersion('pma_test', 'pma_tbl', '1', '11', true));
     tearDownForTestsUsingDate();
 }