Commit e2d8a916 authored by lsmith's avatar lsmith

- fixed class name in comments

parent ebbfcf4c
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
/** /**
* Doctrine_Migration_Builder * Doctrine_Builder_Migration
* *
* @package Doctrine * @package Doctrine
* @subpackage Builder * @subpackage Builder
...@@ -35,7 +35,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -35,7 +35,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
{ {
/** /**
* migrationsPath * migrationsPath
* *
* The path to your migration classes directory * The path to your migration classes directory
* *
* @var string * @var string
...@@ -44,7 +44,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -44,7 +44,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
/** /**
* suffix * suffix
* *
* File suffix to use when writing class definitions * File suffix to use when writing class definitions
* *
* @var string $suffix * @var string $suffix
...@@ -70,7 +70,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -70,7 +70,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
if ($migrationsPath) { if ($migrationsPath) {
$this->setMigrationsPath($migrationsPath); $this->setMigrationsPath($migrationsPath);
} }
$this->_loadTemplate(); $this->_loadTemplate();
} }
...@@ -99,12 +99,12 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -99,12 +99,12 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
/** /**
* loadTemplate * loadTemplate
* *
* Loads the class template used for generating classes * Loads the class template used for generating classes
* *
* @return void * @return void
*/ */
protected function _loadTemplate() protected function _loadTemplate()
{ {
if (isset(self::$_tpl)) { if (isset(self::$_tpl)) {
return; return;
...@@ -139,18 +139,18 @@ END; ...@@ -139,18 +139,18 @@ END;
$directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models'; $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
Doctrine::generateModelsFromDb($directory); Doctrine::generateModelsFromDb($directory);
$result = $this->generateMigrationsFromModels($directory); $result = $this->generateMigrationsFromModels($directory);
Doctrine_Lib::removeDirectories($directory); Doctrine_Lib::removeDirectories($directory);
return $result; return $result;
} }
/** /**
* generateMigrationsFromModels * generateMigrationsFromModels
* *
* @param string $modelsPath * @param string $modelsPath
* @return void * @return void
*/ */
public function generateMigrationsFromModels($modelsPath = null) public function generateMigrationsFromModels($modelsPath = null)
...@@ -160,47 +160,47 @@ END; ...@@ -160,47 +160,47 @@ END;
} else { } else {
$models = Doctrine::getLoadedModels(); $models = Doctrine::getLoadedModels();
} }
$foreignKeys = array(); $foreignKeys = array();
foreach ($models as $model) { foreach ($models as $model) {
$export = Doctrine::getTable($model)->getExportableFormat(); $export = Doctrine::getTable($model)->getExportableFormat();
$foreignKeys[$export['tableName']] = $export['options']['foreignKeys']; $foreignKeys[$export['tableName']] = $export['options']['foreignKeys'];
$up = $this->buildCreateTable($export); $up = $this->buildCreateTable($export);
$down = $this->buildDropTable($export); $down = $this->buildDropTable($export);
$className = 'Add' . Doctrine::classify($export['tableName']); $className = 'Add' . Doctrine::classify($export['tableName']);
$this->generateMigrationClass($className, array(), $up, $down); $this->generateMigrationClass($className, array(), $up, $down);
} }
$className = 'ApplyForeignKeyConstraints'; $className = 'ApplyForeignKeyConstraints';
$up = ''; $up = '';
$down = ''; $down = '';
foreach ($foreignKeys as $tableName => $definitions) { foreach ($foreignKeys as $tableName => $definitions) {
$tableForeignKeyNames[$tableName] = array(); $tableForeignKeyNames[$tableName] = array();
foreach ($definitions as $definition) { foreach ($definitions as $definition) {
$definition['name'] = $tableName . '_' . $definition['foreignTable'] . '_' . $definition['local'] . '_' . $definition['foreign']; $definition['name'] = $tableName . '_' . $definition['foreignTable'] . '_' . $definition['local'] . '_' . $definition['foreign'];
$up .= $this->buildCreateForeignKey($tableName, $definition); $up .= $this->buildCreateForeignKey($tableName, $definition);
$down .= $this->buildDropForeignKey($tableName, $definition); $down .= $this->buildDropForeignKey($tableName, $definition);
} }
} }
$this->generateMigrationClass($className, array(), $up, $down); $this->generateMigrationClass($className, array(), $up, $down);
return true; return true;
} }
/** /**
* buildCreateForeignKey * buildCreateForeignKey
* *
* @param string $tableName * @param string $tableName
* @param string $definition * @param string $definition
* @return void * @return void
*/ */
public function buildCreateForeignKey($tableName, $definition) public function buildCreateForeignKey($tableName, $definition)
...@@ -211,8 +211,8 @@ END; ...@@ -211,8 +211,8 @@ END;
/** /**
* buildDropForeignKey * buildDropForeignKey
* *
* @param string $tableName * @param string $tableName
* @param string $definition * @param string $definition
* @return void * @return void
*/ */
public function buildDropForeignKey($tableName, $definition) public function buildDropForeignKey($tableName, $definition)
...@@ -223,26 +223,26 @@ END; ...@@ -223,26 +223,26 @@ END;
/** /**
* buildCreateTable * buildCreateTable
* *
* @param string $tableData * @param string $tableData
* @return void * @return void
*/ */
public function buildCreateTable($tableData) public function buildCreateTable($tableData)
{ {
$code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', "; $code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', ";
$code .= var_export($tableData['columns'], true) . ", "; $code .= var_export($tableData['columns'], true) . ", ";
$code .= var_export(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']), true); $code .= var_export(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']), true);
$code .= ");"; $code .= ");";
return $code; return $code;
} }
/** /**
* buildDropTable * buildDropTable
* *
* @param string $tableData * @param string $tableData
* @return string * @return string
*/ */
public function buildDropTable($tableData) public function buildDropTable($tableData)
...@@ -263,16 +263,16 @@ END; ...@@ -263,16 +263,16 @@ END;
if ( ! $this->getMigrationsPath()) { if ( ! $this->getMigrationsPath()) {
throw new Doctrine_Migration_Exception('You must specify the path to your migrations.'); throw new Doctrine_Migration_Exception('You must specify the path to your migrations.');
} }
$migration = new Doctrine_Migration($this->getMigrationsPath()); $migration = new Doctrine_Migration($this->getMigrationsPath());
$next = (string) $migration->getNextVersion(); $next = (string) $migration->getNextVersion();
$fileName = str_repeat('0', (3 - strlen($next))) . $next . '_' . Doctrine::tableize($className) . $this->_suffix; $fileName = str_repeat('0', (3 - strlen($next))) . $next . '_' . Doctrine::tableize($className) . $this->_suffix;
$class = $this->buildMigrationClass($className, $fileName, $options, $up, $down); $class = $this->buildMigrationClass($className, $fileName, $options, $up, $down);
$path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName; $path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName;
file_put_contents($path, $class); file_put_contents($path, $class);
} }
} }
...@@ -285,15 +285,15 @@ END; ...@@ -285,15 +285,15 @@ END;
public function buildMigrationClass($className, $fileName = null, $options = array(), $up = null, $down = null) public function buildMigrationClass($className, $fileName = null, $options = array(), $up = null, $down = null)
{ {
$extends = isset($options['extends']) ? $options['extends']:'Doctrine_Migration'; $extends = isset($options['extends']) ? $options['extends']:'Doctrine_Migration';
$content = '<?php' . PHP_EOL; $content = '<?php' . PHP_EOL;
$content .= sprintf(self::$_tpl, $className, $content .= sprintf(self::$_tpl, $className,
$extends, $extends,
$up, $up,
$down); $down);
return $content; return $content;
} }
} }
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment