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