Skip to content

Commit

Permalink
Merge branch 'QA_4_7'
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Mar 13, 2017
2 parents da8c1e5 + 5d18e0b commit 562d37a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -102,6 +102,7 @@ phpMyAdmin - ChangeLog
- issue #12846 Fix new version check for sites with wrongly configured curl
- issue #12951 When exporting to Excel, the default is now to include column names in the first row
- issue #13059 Removed debugging code
- issue #13029 Fixed table tracking for nested table groups

4.6.6 (2017-01-23)
- issue #12759 Fix Notice regarding 'Undefined index: old_usergroup'
Expand Down
48 changes: 22 additions & 26 deletions libraries/tracking.lib.php
Expand Up @@ -1524,50 +1524,46 @@ class="checkall" id="<?php echo $checkbox_id;?>"
}

/**
* Get untracked tables
* Helper function: Recursive function for getting table names from $table_list
*
* @param string $db current database
*
* @return array $untracked_tables
*/
function PMA_getUntrackedTables($db)
{
function PMA_extractTableNames($table_list, $db, $testing=false) {
$untracked_tables = array();
$sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];

// Get list of tables
$table_list = PMA\libraries\Util::getTableList($db);

// For each table try to get the tracking version
foreach ($table_list as $key => $value) {
// If $value is a table group.
if (array_key_exists(('is' . $sep . 'group'), $value)
if (is_array($value) && array_key_exists(('is' . $sep . 'group'), $value)
&& $value['is' . $sep . 'group']
) {
foreach ($value as $temp_table) {
// If $temp_table is a table with the value for 'Name' is set,
// rather than a property of the table group.
if (is_array($temp_table)
&& array_key_exists('Name', $temp_table)
) {
$tracking_version = Tracker::getVersion(
$db,
$temp_table['Name']
);
if ($tracking_version == -1) {
$untracked_tables[] = $temp_table['Name'];
}
}
}
} else { // If $value is a table.
if (Tracker::getVersion($db, $value['Name']) == -1) {
$untracked_tables = array_merge(PMA_extractTableNames($value, $db), $untracked_tables); //Recursion step
}
else {
if (is_array($value) && ($testing || Tracker::getVersion($db, $value['Name']) == -1)) {
$untracked_tables[] = $value['Name'];
}
}
}
return $untracked_tables;
}


/**
* Get untracked tables
*
* @param string $db current database
*
* @return array $untracked_tables
*/
function PMA_getUntrackedTables($db)
{
$table_list = PMA\libraries\Util::getTableList($db);
$untracked_tables = PMA_extractTableNames($table_list, $db); //Use helper function to get table list recursively.
return $untracked_tables;
}

/**
* Display tracked tables
*
Expand Down
41 changes: 41 additions & 0 deletions test/libraries/PMA_tbl_tracking_test.php
Expand Up @@ -47,6 +47,7 @@ protected function setUp()
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['ActionLinksMode'] = 'both';
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = "_";

$_SESSION['relation'][$GLOBALS['server']] = array(
'PMA_VERSION' => PMA_VERSION,
Expand Down Expand Up @@ -113,6 +114,46 @@ public function testPMAFilterTracking()
);
}

/**
* Tests for PMA_extractTableNames() method from nested table_list.
*
* @return void
* @test
*/
public function testPMAextractTableNames()
{
$table_list = array(
"hello_"=>array(
"is_group"=>1,
"lovely_"=>array(
"is_group"=>1,
"hello_lovely_world"=>array(
"Name"=>"hello_lovely_world"
),
"hello_lovely_world2"=>array(
"Name"=>"hello_lovely_world2"
)
),
"hello_world"=>array(
"Name"=>"hello_world"
)
)
);
$untracked_tables = PMA_extractTableNames($table_list, 'db', true);
$this->assertContains(
"hello_world",
$untracked_tables
);
$this->assertContains(
"hello_lovely_world",
$untracked_tables
);
$this->assertContains(
"hello_lovely_world2",
$untracked_tables
);
}

/**
* Tests for PMA_getHtmlForDataDefinitionAndManipulationStatements() method.
*
Expand Down

0 comments on commit 562d37a

Please sign in to comment.