/** * A method for creating a table from the currently parsed database XML schema file. * * @param string $table The name of the table to create, excluding table prefix. * @param Date $oDate An optional date for creating split tables. Will use current * date if the date is required for creation, but not supplied. * @param boolean $suppressTempTableError When true, do not produce an error debugging * message if trying to create a temporary table * that already exists. * @return mixed The name of the table created, or false if the table was not able * to be created. */ function createTable($table, $oDate = null, $suppressTempTableError = false) { $aConf = $GLOBALS['_MAX']['CONF']; if (!$this->_checkInit()) { return false; } // Does the table exist? if (!is_array($this->aDefinition['tables'][$table])) { OA::debug('Cannot find table ' . $table . ' in the XML schema file', PEAR_LOG_ERR); return false; } $tableName = $this->_generateTableName($table, $oDate); // Prepare the options array $aOptions = array(); if ($this->temporary) { $aOptions['temporary'] = true; } $aOptions['type'] = $aConf['table']['type']; // Merge any primary keys into the options array if (isset($this->aDefinition['tables'][$table]['indexes'])) { if (is_array($this->aDefinition['tables'][$table]['indexes'])) { foreach ($this->aDefinition['tables'][$table]['indexes'] as $key => $aIndex) { if (isset($aIndex['primary']) && $aIndex['primary']) { $aOptions['primary'] = $aIndex['fields']; $indexName = $tableName . '_pkey'; } else { // Eventually strip the leading table name prefix from the index and // add the currently generated table name. This should ensure that // index names are unique database-wide, required at least by PgSQL // // The index name is cut at 64 chars // $indexName = $this->_generateIndexName($tableName, $key); } // Does the index name need to be udpated to match either // the prefixed table name, or the the split table name, or // simply it has a wrong name in the xml definition? if ($key != $indexName) { // Eventually strip the hardcoded leading table name and add the // correct prefix to the index name $this->aDefinition['tables'][$table]['indexes'][$indexName] = $this->aDefinition['tables'][$table]['indexes'][$key]; unset($this->aDefinition['tables'][$table]['indexes'][$key]); } } } } // Create the table OA::debug('Creating the ' . $tableName . ' table', PEAR_LOG_DEBUG); OA::disableErrorHandling(); OA_DB::setCaseSensitive(); $result = $this->oSchema->createTable($tableName, $this->aDefinition['tables'][$table], false, $aOptions); OA_DB::disableCaseSensitive(); OA::enableErrorHandling(); if (PEAR::isError($result) || !$result) { $showError = true; if ($this->temporary && $suppressTempTableError) { $showError = false; } if ($showError) { OA::debug('Unable to create the table ' . $table, PEAR_LOG_ERR); if (PEAR::isError($result)) { OA::debug($result->getUserInfo(), PEAR_LOG_ERR); } } return false; } return $tableName; }