/** * Defines the relation parameters for the current user * just a copy of the functions used for relations ;-) * but added some stuff to check what will work * * @access protected * @return array the relation parameters for the current user */ function PMA_checkRelationsParam() { $cfgRelation = array(); $cfgRelation['PMA_VERSION'] = PMA_VERSION; $workToTable = array('relwork' => 'relation', 'displaywork' => array('relation', 'table_info'), 'bookmarkwork' => 'bookmarktable', 'pdfwork' => array('table_coords', 'pdf_pages'), 'commwork' => 'column_info', 'mimework' => 'column_info', 'historywork' => 'history', 'recentwork' => 'recent', 'favoritework' => 'favorite', 'uiprefswork' => 'table_uiprefs', 'trackingwork' => 'tracking', 'userconfigwork' => 'userconfig', 'menuswork' => array('users', 'usergroups'), 'navwork' => 'navigationhiding', 'savedsearcheswork' => 'savedsearches', 'centralcolumnswork' => 'central_columns', 'designersettingswork' => 'designer_settings', 'exporttemplateswork' => 'export_templates'); foreach ($workToTable as $work => $table) { $cfgRelation[$work] = false; } $cfgRelation['allworks'] = false; $cfgRelation['user'] = null; $cfgRelation['db'] = null; if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) || !$GLOBALS['dbi']->selectDb($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink'])) { // No server selected -> no bookmark table // we return the array with the falses in it, // to avoid some 'Uninitialized string offset' errors later $GLOBALS['cfg']['Server']['pmadb'] = false; return $cfgRelation; } $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user']; $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; // Now I just check if all tables that i need are present so I can for // example enable relations but not pdf... // I was thinking of checking if they have all required columns but I // fear it might be too slow $tab_query = 'SHOW TABLES FROM ' . PMA\libraries\Util::backquote($GLOBALS['cfg']['Server']['pmadb']); $tab_rs = PMA_queryAsControlUser($tab_query, false, PMA\libraries\DatabaseInterface::QUERY_STORE); if (!$tab_rs) { // query failed ... ? //$GLOBALS['cfg']['Server']['pmadb'] = false; return $cfgRelation; } while ($curr_table = @$GLOBALS['dbi']->fetchRow($tab_rs)) { if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { $cfgRelation['relation'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) { $cfgRelation['table_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { $cfgRelation['table_coords'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) { $cfgRelation['column_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { $cfgRelation['pdf_pages'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { $cfgRelation['history'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { $cfgRelation['recent'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['favorite']) { $cfgRelation['favorite'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { $cfgRelation['table_uiprefs'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { $cfgRelation['userconfig'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) { $cfgRelation['users'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) { $cfgRelation['usergroups'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['navigationhiding']) { $cfgRelation['navigationhiding'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['savedsearches']) { $cfgRelation['savedsearches'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['central_columns']) { $cfgRelation['central_columns'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_settings']) { $cfgRelation['designer_settings'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['export_templates']) { $cfgRelation['export_templates'] = $curr_table[0]; } } // end while $GLOBALS['dbi']->freeResult($tab_rs); if (isset($cfgRelation['relation'])) { $cfgRelation['relwork'] = true; } if (isset($cfgRelation['relation']) && isset($cfgRelation['table_info'])) { $cfgRelation['displaywork'] = true; } if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { $cfgRelation['pdfwork'] = true; } if (isset($cfgRelation['column_info'])) { $cfgRelation['commwork'] = true; // phpMyAdmin 4.3+ // Check for input transformations upgrade. $cfgRelation['mimework'] = PMA_tryUpgradeTransformations(); } if (isset($cfgRelation['history'])) { $cfgRelation['historywork'] = true; } if (isset($cfgRelation['recent'])) { $cfgRelation['recentwork'] = true; } if (isset($cfgRelation['favorite'])) { $cfgRelation['favoritework'] = true; } if (isset($cfgRelation['table_uiprefs'])) { $cfgRelation['uiprefswork'] = true; } if (isset($cfgRelation['tracking'])) { $cfgRelation['trackingwork'] = true; } if (isset($cfgRelation['userconfig'])) { $cfgRelation['userconfigwork'] = true; } if (isset($cfgRelation['bookmark'])) { $cfgRelation['bookmarkwork'] = true; } if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) { $cfgRelation['menuswork'] = true; } if (isset($cfgRelation['navigationhiding'])) { $cfgRelation['navwork'] = true; } if (isset($cfgRelation['savedsearches'])) { $cfgRelation['savedsearcheswork'] = true; } if (isset($cfgRelation['central_columns'])) { $cfgRelation['centralcolumnswork'] = true; } if (isset($cfgRelation['designer_settings'])) { $cfgRelation['designersettingswork'] = true; } if (isset($cfgRelation['export_templates'])) { $cfgRelation['exporttemplateswork'] = true; } $allWorks = true; foreach ($workToTable as $work => $table) { if (!$cfgRelation[$work]) { if (is_string($table)) { if (isset($GLOBALS['cfg']['Server'][$table]) && $GLOBALS['cfg']['Server'][$table] !== false) { $allWorks = false; break; } } else { if (is_array($table)) { $oneNull = false; foreach ($table as $t) { if (isset($GLOBALS['cfg']['Server'][$t]) && $GLOBALS['cfg']['Server'][$t] === false) { $oneNull = true; break; } } if (!$oneNull) { $allWorks = false; break; } } } } } $cfgRelation['allworks'] = $allWorks; return $cfgRelation; }
/** * Defines the relation parameters for the current user * just a copy of the functions used for relations ;-) * but added some stuff to check what will work * * @access protected * @return array the relation parameters for the current user */ function PMA_checkRelationsParam() { $cfgRelation = array(); $cfgRelation['relwork'] = false; $cfgRelation['displaywork'] = false; $cfgRelation['bookmarkwork'] = false; $cfgRelation['pdfwork'] = false; $cfgRelation['commwork'] = false; $cfgRelation['mimework'] = false; $cfgRelation['historywork'] = false; $cfgRelation['recentwork'] = false; $cfgRelation['favoritework'] = false; $cfgRelation['uiprefswork'] = false; $cfgRelation['trackingwork'] = false; $cfgRelation['userconfigwork'] = false; $cfgRelation['menuswork'] = false; $cfgRelation['navwork'] = false; $cfgRelation['allworks'] = false; $cfgRelation['savedsearcheswork'] = false; $cfgRelation['central_columnswork'] = false; $cfgRelation['user'] = null; $cfgRelation['db'] = null; if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) || !$GLOBALS['dbi']->selectDb($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink'])) { // No server selected -> no bookmark table // we return the array with the falses in it, // to avoid some 'Uninitialized string offset' errors later $GLOBALS['cfg']['Server']['pmadb'] = false; return $cfgRelation; } $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user']; $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; // Now I just check if all tables that i need are present so I can for // example enable relations but not pdf... // I was thinking of checking if they have all required columns but I // fear it might be too slow $tab_query = 'SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']); $tab_rs = PMA_queryAsControlUser($tab_query, false, PMA_DatabaseInterface::QUERY_STORE); if (!$tab_rs) { // query failed ... ? //$GLOBALS['cfg']['Server']['pmadb'] = false; return $cfgRelation; } while ($curr_table = @$GLOBALS['dbi']->fetchRow($tab_rs)) { if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { $cfgRelation['relation'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) { $cfgRelation['table_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { $cfgRelation['table_coords'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) { $cfgRelation['column_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { $cfgRelation['pdf_pages'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { $cfgRelation['history'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { $cfgRelation['recent'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['favorite']) { $cfgRelation['favorite'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { $cfgRelation['table_uiprefs'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { $cfgRelation['userconfig'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) { $cfgRelation['users'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) { $cfgRelation['usergroups'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['navigationhiding']) { $cfgRelation['navigationhiding'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['savedsearches']) { $cfgRelation['savedsearches'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['central_columns']) { $cfgRelation['central_columns'] = $curr_table[0]; } } // end while $GLOBALS['dbi']->freeResult($tab_rs); if (isset($cfgRelation['relation'])) { $cfgRelation['relwork'] = true; if (isset($cfgRelation['table_info'])) { $cfgRelation['displaywork'] = true; } } if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { $cfgRelation['pdfwork'] = true; } if (isset($cfgRelation['column_info'])) { $cfgRelation['commwork'] = true; // phpMyAdmin 4.3+ // Check for input transformations upgrade. $cfgRelation['mimework'] = PMA_tryUpgradeTransformations(); } if (isset($cfgRelation['history'])) { $cfgRelation['historywork'] = true; } if (isset($cfgRelation['recent'])) { $cfgRelation['recentwork'] = true; } if (isset($cfgRelation['favorite'])) { $cfgRelation['favoritework'] = true; } if (isset($cfgRelation['table_uiprefs'])) { $cfgRelation['uiprefswork'] = true; } if (isset($cfgRelation['tracking'])) { $cfgRelation['trackingwork'] = true; } if (isset($cfgRelation['userconfig'])) { $cfgRelation['userconfigwork'] = true; } if (isset($cfgRelation['bookmark'])) { $cfgRelation['bookmarkwork'] = true; } if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) { $cfgRelation['menuswork'] = true; } if (isset($cfgRelation['navigationhiding'])) { $cfgRelation['navwork'] = true; } if (isset($cfgRelation['savedsearches'])) { $cfgRelation['savedsearcheswork'] = true; } if (isset($cfgRelation['central_columns'])) { $cfgRelation['central_columnswork'] = true; } if ($cfgRelation['relwork'] && $cfgRelation['displaywork'] && $cfgRelation['pdfwork'] && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfgRelation['historywork'] && $cfgRelation['recentwork'] && $cfgRelation['uiprefswork'] && $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork'] && $cfgRelation['central_columnswork'] && $cfgRelation['menuswork'] && $cfgRelation['navwork'] && $cfgRelation['savedsearcheswork'] && $cfgRelation['favoritework']) { $cfgRelation['allworks'] = true; } return $cfgRelation; }
/** * Test for PMA_tryUpgradeTransformations * * @return void */ public function testPMATryUpgradeTransformations() { $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->any())->method('tryQuery')->will($this->returnValue(true)); $dbi->expects($this->any())->method('numRows')->will($this->returnValue(0)); $dbi->expects($this->any())->method('getError')->will($this->onConsecutiveCalls(true, false)); $GLOBALS['dbi'] = $dbi; $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb'; $GLOBALS['cfg']['Server']['column_info'] = 'column_info'; // Case 1 $actual = PMA_tryUpgradeTransformations(); $this->assertEquals(false, $actual); // Case 2 $actual = PMA_tryUpgradeTransformations(); $this->assertEquals(true, $actual); }