This commit is contained in:
parent
e1d295f31b
commit
8784fe6644
@ -368,7 +368,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict
|
||||
case 'string':
|
||||
case 'array':
|
||||
case 'object':
|
||||
case 'varchar':
|
||||
case 'varchar':
|
||||
case 'gzip':
|
||||
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
|
||||
// TODO: $this->conn->options['default_text_field_length'];
|
||||
|
||||
|
@ -875,21 +875,21 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function export($directory = null)
|
||||
{
|
||||
if ($directory !== null) {
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
foreach ($it as $file) {
|
||||
$e = explode('.', $file->getFileName());
|
||||
if (end($e) === 'php' && count($e) === 2) {
|
||||
require_once $e->getPathName();
|
||||
}
|
||||
$sql = $this->exportSql($directory);
|
||||
|
||||
foreach ($sql as $query) {
|
||||
try {
|
||||
$this->conn->exec($query);
|
||||
} catch (Doctrine_Connection_Exception $e) {
|
||||
// we only want to silence table already exists errors
|
||||
if($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->exportClasses(get_declared_classes());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* export
|
||||
* exportClasses
|
||||
* method for exporting Doctrine_Record classes to a schema
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
|
||||
@ -899,51 +899,31 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function exportClasses(array $classes)
|
||||
{
|
||||
$parent = new ReflectionClass('Doctrine_Record');
|
||||
$sql = $this->exportClassesSql($classes);
|
||||
|
||||
foreach ($classes as $name) {
|
||||
$class = new ReflectionClass($name);
|
||||
$conn = Doctrine_Manager::getInstance()->getConnectionForComponent($name);
|
||||
|
||||
if ($class->isSubclassOf($parent) && ! $class->isAbstract()) {
|
||||
$record = new $name();
|
||||
$table = $record->getTable();
|
||||
|
||||
$conn->export->exportTable($table);
|
||||
foreach ($sql as $query) {
|
||||
try {
|
||||
$this->conn->exec($query);
|
||||
} catch (Doctrine_Connection_Exception $e) {
|
||||
// we only want to silence table already exists errors
|
||||
if($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
|
||||
print $query."<br>";
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* export
|
||||
* returns the sql for exporting Doctrine_Record classes to a schema
|
||||
*
|
||||
* if the directory parameter is given this method first iterates
|
||||
* recursively trhough the given directory in order to find any model classes
|
||||
*
|
||||
* Then it iterates through all declared classes and creates tables for the ones
|
||||
* that extend Doctrine_Record and are not abstract classes
|
||||
* exportClassesSql
|
||||
* method for exporting Doctrine_Record classes to a schema
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
|
||||
* occurred during the create table operation
|
||||
* @param string $directory optional directory parameter
|
||||
* @param array $classes
|
||||
* @return void
|
||||
*/
|
||||
public function exportSql($directory = null)
|
||||
public function exportClassesSql(array $classes)
|
||||
{
|
||||
$declared = get_declared_classes();
|
||||
|
||||
if ($directory !== null) {
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
foreach ($it as $file) {
|
||||
$e = explode('.', $file->getFileName());
|
||||
if (end($e) === 'php' && count($e) === 2) {
|
||||
require_once $file->getPathName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$parent = new ReflectionClass('Doctrine_Record');
|
||||
|
||||
$sql = array();
|
||||
@ -951,7 +931,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
|
||||
// we iterate trhough the diff of previously declared classes
|
||||
// and currently declared classes
|
||||
foreach (array_diff(get_declared_classes(), $declared) as $name) {
|
||||
foreach ($classes as $name) {
|
||||
$class = new ReflectionClass($name);
|
||||
$conn = Doctrine_Manager::getInstance()->getConnectionForComponent($name);
|
||||
|
||||
@ -978,13 +958,48 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
foreach ($fks as $tableName => $fk) {
|
||||
foreach ($fk as $k => $definition) {
|
||||
if (is_array($definition)) {
|
||||
|
||||
$sql[] = $this->createForeignKeySql($definition['table'], $definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
/**
|
||||
* exportSql
|
||||
* returns the sql for exporting Doctrine_Record classes to a schema
|
||||
*
|
||||
* if the directory parameter is given this method first iterates
|
||||
* recursively trhough the given directory in order to find any model classes
|
||||
*
|
||||
* Then it iterates through all declared classes and creates tables for the ones
|
||||
* that extend Doctrine_Record and are not abstract classes
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
|
||||
* occurred during the create table operation
|
||||
* @param string $directory optional directory parameter
|
||||
* @return void
|
||||
*/
|
||||
public function exportSql($directory = null)
|
||||
{
|
||||
$declared = get_declared_classes();
|
||||
|
||||
if ($directory !== null) {
|
||||
foreach ((array) $directory as $dir) {
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
foreach ($it as $file) {
|
||||
$e = explode('.', $file->getFileName());
|
||||
if (end($e) === 'php' && count($e) === 2) {
|
||||
require_once $file->getPathName();
|
||||
}
|
||||
}
|
||||
}
|
||||
$declared = array_diff(get_declared_classes(), $declared);
|
||||
}
|
||||
|
||||
return $this->exportClassesSql($declared);
|
||||
}
|
||||
/**
|
||||
* exportTable
|
||||
* exports given table into database based on column and option definitions
|
||||
|
@ -155,7 +155,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createTable($name, array $fields, array $options = array())
|
||||
public function createTableSql($name, array $fields, array $options = array())
|
||||
{
|
||||
if ( ! $name) {
|
||||
throw new Doctrine_Export_Exception('no valid table name specified');
|
||||
@ -168,7 +168,8 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
|
||||
$autoinc = false;
|
||||
foreach($fields as $field) {
|
||||
if(isset($field['autoincrement']) && $field['autoincrement']) {
|
||||
if(isset($field['autoincrement']) && $field['autoincrement'] ||
|
||||
(isset($field['autoinc']) && $field['autoinc'])) {
|
||||
$autoinc = true;
|
||||
break;
|
||||
}
|
||||
@ -177,19 +178,6 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
if ( ! $autoinc && isset($options['primary']) && ! empty($options['primary'])) {
|
||||
$queryFields.= ', PRIMARY KEY('.implode(', ', array_values($options['primary'])).')';
|
||||
}
|
||||
|
||||
// sqlite doesn't support foreign key declaration but it parses those anyway
|
||||
|
||||
$fk = array();
|
||||
if (isset($options['foreignKeys']) && ! empty($options['foreignKeys'])) {
|
||||
foreach ($options['foreignKeys'] as $definition) {
|
||||
//$queryFields .= ', ' . $this->getForeignKeyDeclaration($definition);
|
||||
|
||||
if (isset($definition['onDelete'])) {
|
||||
$fk[] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['indexes']) && ! empty($options['indexes'])) {
|
||||
foreach ($options['indexes'] as $index => $definition) {
|
||||
@ -199,15 +187,19 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
$query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')';
|
||||
|
||||
|
||||
return $query;
|
||||
|
||||
|
||||
/**
|
||||
try {
|
||||
/**
|
||||
|
||||
if ( ! empty($fk)) {
|
||||
$this->conn->beginTransaction();
|
||||
}
|
||||
*/
|
||||
|
||||
$ret = $this->conn->exec($query);
|
||||
/**
|
||||
|
||||
if ( ! empty($fk)) {
|
||||
foreach ($fk as $definition) {
|
||||
|
||||
@ -228,13 +220,15 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
|
||||
$this->conn->commit();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
} catch(Doctrine_Exception $e) {
|
||||
|
||||
$this->conn->rollback();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* getAdvancedForeignKeyOptions
|
||||
@ -316,6 +310,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
public function dropSequenceSql($sequenceName)
|
||||
{
|
||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($sequenceName), true);
|
||||
|
||||
return 'DROP TABLE ' . $sequenceName;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user