MDL-65130 privacy: Fix memory hungry test

This commit is contained in:
Andrew Nicols 2019-03-21 09:52:24 +08:00
parent 51114517be
commit 09d02b3914
2 changed files with 40 additions and 10 deletions

View File

@ -898,6 +898,27 @@ class database_manager {
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
}
/**
* Get the list of install.xml files.
*
* @return array
*/
public function get_install_xml_files(): array {
global $CFG;
require_once($CFG->libdir.'/adminlib.php');
$files = [];
$dbdirs = get_db_directories();
foreach ($dbdirs as $dbdir) {
$filename = "{$dbdir}/install.xml";
if (file_exists($filename)) {
$files[] = $filename;
}
}
return $files;
}
/**
* Reads the install.xml files for Moodle core and modules and returns an array of
* xmldb_structure object with xmldb_table from these files.
@ -909,10 +930,10 @@ class database_manager {
$schema = new xmldb_structure('export');
$schema->setVersion($CFG->version);
$dbdirs = get_db_directories();
foreach ($dbdirs as $dbdir) {
$xmldb_file = new xmldb_file($dbdir.'/install.xml');
if (!$xmldb_file->fileExists() or !$xmldb_file->loadXMLStructure()) {
foreach ($this->get_install_xml_file_list() as $filename) {
$xmldb_file = new xmldb_file($filename);
if (!$xmldb_file->loadXMLStructure()) {
continue;
}
$structure = $xmldb_file->getStructure();

View File

@ -292,15 +292,24 @@ class provider_testcase extends advanced_testcase {
public function test_table_coverage() {
global $DB;
$dbman = $DB->get_manager();
$schema = $dbman->get_install_xml_schema();
$tables = [];
foreach ($schema->getTables() as $table) {
if ($table->getName() === 'role_sortorder') {
// TODO MDL-62459 this table is not used anywhere. Remove the table and this statement.
foreach ($dbman->get_install_xml_files() as $filename) {
$xmldbfile = new xmldb_file($filename);
if (!$xmldbfile->loadXMLStructure()) {
continue;
}
if ($fields = $this->get_userid_fields($table)) {
$tables[$table->getName()] = ' - ' . $table->getName() . ' (' . join(', ', $fields) . ')';
$structure = $xmldbfile->getStructure();
$tablelist = $structure->getTables();
foreach ($tablelist as $table) {
if ($table->getName() === 'role_sortorder') {
// TODO MDL-62459 this table is not used anywhere. Remove the table and this statement.
continue;
}
if ($fields = $this->get_userid_fields($table)) {
$tables[$table->getName()] = ' - ' . $table->getName() . ' (' . join(', ', $fields) . ')';
}
}
}