MDL-32003 fix PHP4-isms in core xmldb code
This commit is contained in:
@@ -333,7 +333,7 @@ class database_manager {
|
||||
$loaded = $xmldb_file->loadXMLStructure();
|
||||
if (!$loaded || !$xmldb_file->isLoaded()) {
|
||||
// Show info about the error if we can find it
|
||||
if ($structure =& $xmldb_file->getStructure()) {
|
||||
if ($structure = $xmldb_file->getStructure()) {
|
||||
if ($errors = $structure->getAllErrors()) {
|
||||
throw new ddl_exception('ddlxmlfileerror', null, 'Errors found in XMLDB file: '. implode (', ', $errors));
|
||||
}
|
||||
|
||||
@@ -322,7 +322,8 @@ abstract class sql_generator {
|
||||
}
|
||||
// make sure sequence field is unique
|
||||
if ($sequencefield and $xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
|
||||
$field = reset($xmldb_key->getFields());
|
||||
$fields = $xmldb_key->getFields();
|
||||
$field = reset($fields);
|
||||
if ($sequencefield === $field) {
|
||||
$sequencefield = null;
|
||||
}
|
||||
|
||||
@@ -1233,6 +1233,7 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$index = new xmldb_index('secondname');
|
||||
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
|
||||
$dbman->add_index($table, $index);
|
||||
$this->assertTrue($dbman->index_exists($table, $index));
|
||||
}
|
||||
|
||||
public function testFindIndexName() {
|
||||
@@ -1291,6 +1292,9 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$key = new xmldb_key('id-course-grade');
|
||||
$key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// No easy way to test it, this just makes sure no errors are encountered.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testAddForeignUniqueKey() {
|
||||
@@ -1302,6 +1306,9 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$key = new xmldb_key('course');
|
||||
$key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'test_table0', array('id'));
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// No easy way to test it, this just makes sure no errors are encountered.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testDropKey() {
|
||||
@@ -1315,6 +1322,9 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
$dbman->drop_key($table, $key);
|
||||
|
||||
// No easy way to test it, this just makes sure no errors are encountered.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testAddForeignKey() {
|
||||
@@ -1326,6 +1336,9 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$key = new xmldb_key('course');
|
||||
$key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// No easy way to test it, this just makes sure no errors are encountered.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testDropForeignKey() {
|
||||
@@ -1339,6 +1352,9 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
$dbman->drop_key($table, $key);
|
||||
|
||||
// No easy way to test it, this just makes sure no errors are encountered.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testRenameField() {
|
||||
@@ -1357,7 +1373,6 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$this->assertTrue(array_key_exists('newfieldname', $columns));
|
||||
}
|
||||
|
||||
|
||||
public function testIndexExists() {
|
||||
// Skipping: this is just a test of find_index_name
|
||||
}
|
||||
|
||||
@@ -4443,6 +4443,9 @@ class dml_testcase extends database_driver_testcase {
|
||||
$DB->get_fieldset_sql("SELECT id FROM {{$tablename}} WHERE course = :select", array('select'=>1));
|
||||
$DB->set_field_select($tablename, 'course', '1', "id = :select", array('select'=>1));
|
||||
$DB->delete_records_select($tablename, "id = :select", array('select'=>1));
|
||||
|
||||
// if we get here test passed ok
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function test_limits_and_offsets() {
|
||||
|
||||
@@ -72,7 +72,7 @@ class xmldb_file extends xmldb_object {
|
||||
return false;
|
||||
}
|
||||
|
||||
function &getStructure() {
|
||||
function getStructure() {
|
||||
return $this->xmldb_structure;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ class xmldb_file extends xmldb_object {
|
||||
*/
|
||||
function saveXMLFile() {
|
||||
|
||||
$structure =& $this->getStructure();
|
||||
$structure = $this->getStructure();
|
||||
|
||||
$result = file_put_contents($this->path, $structure->xmlOutput());
|
||||
|
||||
|
||||
@@ -101,9 +101,9 @@ class xmldb_index extends xmldb_object {
|
||||
|
||||
/**
|
||||
* Get the index fields
|
||||
* @return array reference to fields array
|
||||
* @return array
|
||||
*/
|
||||
function &getFields() {
|
||||
function getFields() {
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,17 +114,17 @@ class xmldb_key extends xmldb_object {
|
||||
|
||||
/**
|
||||
* Get the key fields
|
||||
* @return array reference to fields array
|
||||
* @return array
|
||||
*/
|
||||
function &getFields() {
|
||||
function getFields() {
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key reftable
|
||||
* @return string reference
|
||||
* @return string
|
||||
*/
|
||||
function &getRefTable() {
|
||||
function getRefTable() {
|
||||
return $this->reftable;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ class xmldb_key extends xmldb_object {
|
||||
* Get the key reffields
|
||||
* @return array reference to ref fields
|
||||
*/
|
||||
function &getRefFields() {
|
||||
function getRefFields() {
|
||||
return $this->reffields;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ class xmldb_object {
|
||||
* @param array $arr
|
||||
* @return bool
|
||||
*/
|
||||
function checkNameValues(&$arr) {
|
||||
function checkNameValues($arr) {
|
||||
$result = true;
|
||||
// TODO: Perhaps, add support for reserved words
|
||||
|
||||
@@ -236,7 +236,7 @@ class xmldb_object {
|
||||
/**
|
||||
* Reconstruct previous/next attributes.
|
||||
* @param array $arr
|
||||
* @return bool
|
||||
* @return bool true if $arr modified
|
||||
*/
|
||||
function fixPrevNext(&$arr) {
|
||||
global $CFG;
|
||||
@@ -271,9 +271,9 @@ class xmldb_object {
|
||||
* This function will check that all the elements in one array
|
||||
* have a consistent info in their previous/next fields
|
||||
* @param array $arr
|
||||
* @return bool
|
||||
* @return bool true means ok, false invalid prev/next present
|
||||
*/
|
||||
function checkPreviousNextValues(&$arr) {
|
||||
function checkPreviousNextValues($arr) {
|
||||
global $CFG;
|
||||
if (!empty($CFG->xmldbdisablenextprevchecking)) {
|
||||
return true;
|
||||
@@ -430,14 +430,13 @@ class xmldb_object {
|
||||
* @param array $arr
|
||||
* @return mixed
|
||||
*/
|
||||
function &findObjectInArray($objectname, $arr) {
|
||||
function findObjectInArray($objectname, $arr) {
|
||||
foreach ($arr as $i => $object) {
|
||||
if ($objectname == $object->getName()) {
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
$null = NULL;
|
||||
return $null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,35 +69,33 @@ class xmldb_structure extends xmldb_object {
|
||||
* @param string $tablename
|
||||
* @return xmldb_table
|
||||
*/
|
||||
function &getTable($tablename) {
|
||||
function getTable($tablename) {
|
||||
$i = $this->findTableInArray($tablename);
|
||||
if ($i !== NULL) {
|
||||
return $this->tables[$i];
|
||||
}
|
||||
$null = NULL;
|
||||
return $null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position of one table in the array.
|
||||
* @param string $tablename
|
||||
* @return xmldb_table
|
||||
* @return mixed
|
||||
*/
|
||||
function &findTableInArray($tablename) {
|
||||
function findTableInArray($tablename) {
|
||||
foreach ($this->tables as $i => $table) {
|
||||
if ($tablename == $table->getName()) {
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
$null = NULL;
|
||||
return $null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will reorder the array of tables
|
||||
* @return bool success
|
||||
*/
|
||||
function orderTables() {
|
||||
protected function orderTables() {
|
||||
$result = $this->orderElements($this->tables);
|
||||
if ($result) {
|
||||
$this->setTables($result);
|
||||
@@ -109,9 +107,9 @@ class xmldb_structure extends xmldb_object {
|
||||
|
||||
/**
|
||||
* Returns the tables of the structure
|
||||
* @return array reference to table arrays
|
||||
* @return array
|
||||
*/
|
||||
function &getTables() {
|
||||
function getTables() {
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
@@ -129,23 +127,22 @@ class xmldb_structure extends xmldb_object {
|
||||
* @param xmldb_table $table
|
||||
* @param mixed $after
|
||||
*/
|
||||
function addTable(&$table, $after=NULL) {
|
||||
function addTable($table, $after=NULL) {
|
||||
|
||||
// Calculate the previous and next tables
|
||||
$prevtable = NULL;
|
||||
$nexttable = NULL;
|
||||
|
||||
if (!$after) {
|
||||
$alltables =& $this->getTables();
|
||||
if ($alltables) {
|
||||
end($alltables);
|
||||
$prevtable =& $alltables[key($alltables)];
|
||||
if ($this->tables) {
|
||||
end($this->tables);
|
||||
$prevtable = $this->tables[key($alltables)];
|
||||
}
|
||||
} else {
|
||||
$prevtable =& $this->getTable($after);
|
||||
$prevtable = $this->getTable($after);
|
||||
}
|
||||
if ($prevtable && $prevtable->getNext()) {
|
||||
$nexttable =& $this->getTable($prevtable->getNext());
|
||||
$nexttable = $this->getTable($prevtable->getNext());
|
||||
}
|
||||
|
||||
// Set current table previous and next attributes
|
||||
@@ -161,7 +158,7 @@ class xmldb_structure extends xmldb_object {
|
||||
$table->setLoaded(true);
|
||||
$table->setChanged(true);
|
||||
// Add the new table
|
||||
$this->tables[] =& $table;
|
||||
$this->tables[] = $table;
|
||||
// Reorder the whole structure
|
||||
$this->orderTables($this->tables);
|
||||
// Recalculate the hash
|
||||
@@ -177,12 +174,12 @@ class xmldb_structure extends xmldb_object {
|
||||
*/
|
||||
function deleteTable($tablename) {
|
||||
|
||||
$table =& $this->getTable($tablename);
|
||||
$table = $this->getTable($tablename);
|
||||
if ($table) {
|
||||
$i = $this->findTableInArray($tablename);
|
||||
// Look for prev and next table
|
||||
$prevtable =& $this->getTable($table->getPrevious());
|
||||
$nexttable =& $this->getTable($table->getNext());
|
||||
$prevtable = $this->getTable($table->getPrevious());
|
||||
$nexttable = $this->getTable($table->getNext());
|
||||
// Change their previous and next attributes
|
||||
if ($prevtable) {
|
||||
$prevtable->setNext($table->getNext());
|
||||
@@ -206,7 +203,7 @@ class xmldb_structure extends xmldb_object {
|
||||
* Set the tables
|
||||
* @param array $tables
|
||||
*/
|
||||
function setTables(&$tables) {
|
||||
function setTables($tables) {
|
||||
$this->tables = $tables;
|
||||
}
|
||||
|
||||
@@ -315,7 +312,7 @@ class xmldb_structure extends xmldb_object {
|
||||
$key = $this->name . $this->path . $this->comment;
|
||||
if ($this->tables) {
|
||||
foreach ($this->tables as $tbl) {
|
||||
$table =& $this->getTable($tbl->getName());
|
||||
$table = $this->getTable($tbl->getName());
|
||||
if ($recursive) {
|
||||
$table->calculateHash($recursive);
|
||||
}
|
||||
@@ -368,9 +365,8 @@ class xmldb_structure extends xmldb_object {
|
||||
|
||||
// Check if some foreign key in the whole structure is using it
|
||||
// (by comparing the reftable with the tablename)
|
||||
$alltables = $this->getTables();
|
||||
if ($alltables) {
|
||||
foreach ($alltables as $table) {
|
||||
if ($this->tables) {
|
||||
foreach ($this->tables as $table) {
|
||||
$keys = $table->getKeys();
|
||||
if ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
@@ -425,9 +421,8 @@ class xmldb_structure extends xmldb_object {
|
||||
}
|
||||
// Check if some foreign key in the whole structure is using it
|
||||
// By comparing the reftable and refields with the field)
|
||||
$alltables = $this->getTables();
|
||||
if ($alltables) {
|
||||
foreach ($alltables as $table) {
|
||||
if ($this->tables) {
|
||||
foreach ($this->tables as $table) {
|
||||
$keys = $table->getKeys();
|
||||
if ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
@@ -468,9 +463,8 @@ class xmldb_structure extends xmldb_object {
|
||||
// (by comparing the reftable and reffields with the fields in the key)
|
||||
$mytable = $this->getTable($tablename);
|
||||
$mykey = $mytable->getKey($keyname);
|
||||
$alltables = $this->getTables();
|
||||
if ($alltables && $mykey) {
|
||||
foreach ($alltables as $table) {
|
||||
if ($this->tables && $mykey) {
|
||||
foreach ($this->tables as $table) {
|
||||
$allkeys = $table->getKeys();
|
||||
if ($allkeys) {
|
||||
foreach ($allkeys as $key) {
|
||||
@@ -531,8 +525,8 @@ class xmldb_structure extends xmldb_object {
|
||||
$errors[] = $this->getError();
|
||||
}
|
||||
// Delegate to tables
|
||||
if ($tables = $this->getTables()) {
|
||||
foreach ($tables as $table) {
|
||||
if ($this->tables) {
|
||||
foreach ($this->tables as $table) {
|
||||
if ($tableerrors = $table->getAllErrors()) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user