/** * Merges the incoming structure definition with the existing structure. * * @return void * * @since 11.1 * * @throws Exception on error. * @note Currently supports XML format only. * @todo IF it is not in XML format, convert it first. */ protected function mergeStructure() { // Currently only support XML format anyway. // Initialise variables. $prefix = $this->db->getPrefix(); $tables = $this->db->getTableList(); $result = true; if ($this->from instanceof SimpleXMLElement) { $xml = $this->from; } else { $xml = new SimpleXMLElement($this->from); } // Get all the table definitions. $xmlTables = $xml->xpath('database/table_structure'); foreach ($xmlTables as $table) { // Convert the magic prefix into the real table name. $tableName = (string) $table['name']; $tableName = preg_replace('|^#__|', $prefix, $tableName); if (in_array($tableName, $tables)) { // The table already exists. Now check if there is any difference. if ($queries = $this->getAlterTableSQL($xml->database->table_structure)) { // Run the queries to upgrade the data structure. foreach ($queries as $query) { $this->db->setQuery((string) $query); if (!$this->db->query()) { $this->addLog('Fail: ' . $this->db->getQuery()); throw new Exception($this->db->getErrorMsg()); } else { $this->addLog('Pass: '******'Fail: ' . $this->db->getQuery()); throw new Exception($this->db->getErrorMsg()); } else { $this->addLog('Pass: ' . $this->db->getQuery()); } } } }
/** * Tests the JDatabaseMySQLi getTableList method. * * @return void * * @since 11.4 */ public function testGetTableList() { $this->assertThat($this->object->getTableList(), $this->isType('array'), 'The list of tables for the database is returned in an array.'); }