Commit 2bd36677 authored by Jonathan.Wage's avatar Jonathan.Wage

A few fixes to Migrations and formatting/code fixes.

parent 3829b0f2
......@@ -1114,7 +1114,7 @@ final class Doctrine
*/
public static function makeDirectories($path, $mode = 0777)
{
if (!$path) {
if ( ! $path) {
return false;
}
......
......@@ -584,4 +584,4 @@ class Doctrine_Migration
$this->addChange('removed_indexes', $options);
}
}
}
\ No newline at end of file
......@@ -82,9 +82,7 @@ class Doctrine_Migration_Builder
*/
public function setMigrationsPath($path)
{
if ( ! file_exists($path)) {
mkdir($path, 0777);
}
Doctrine::makeDirectories($path);
$this->migrationsPath = $path;
}
......@@ -138,7 +136,7 @@ END;
*/
public function generateMigrationsFromDb()
{
$directory = '/tmp/tmp_doctrine_models';
$directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
Doctrine::generateModelsFromDb($directory);
......@@ -173,7 +171,7 @@ END;
$up = $this->buildCreateTable($export);
$down = $this->buildDropTable($export);
$className = 'Add'.Doctrine::classify($export['tableName']);
$className = 'Add' . Doctrine::classify($export['tableName']);
$this->generateMigrationClass($className, array(), $up, $down);
}
......@@ -207,7 +205,7 @@ END;
*/
public function buildCreateForeignKey($tableName, $definition)
{
return "\t\t\$this->createForeignKey('" . $tableName . "', " . $this->dataToPhpCode($definition) . ");";
return "\t\t\$this->createForeignKey('" . $tableName . "', " . var_export($definition, true) . ");";
}
/**
......@@ -232,9 +230,9 @@ END;
{
$code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', ";
$code .= $this->dataToPhpCode($tableData['columns']) . ", ";
$code .= var_export($tableData['columns'], true) . ", ";
$code .= $this->dataToPhpCode(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']));
$code .= var_export(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']), true);
$code .= ");";
......@@ -252,22 +250,6 @@ END;
return "\t\t\$this->dropTable('" . $tableData['tableName'] . "');";
}
/**
* dataToPhpCode
*
* @param string $data
* @return string
*/
public function dataToPhpCode($data)
{
ob_start();
var_export($data);
$results = ob_get_contents();
ob_end_clean();
return $results;
}
/**
* generateMigrationClass
*
......
......@@ -116,13 +116,13 @@ class Doctrine_Migration_Process
public function processRenamedColumns($columns)
{
foreach ($columns as $column) {
$conn = $this->getConnection($column['tableName']);
$columnList = $conn->import->listTableColumns($column['tableName']);
if (isset($columnList[$column['oldColumnName']])) {
$conn->export->alterTable($column['tableName'],
array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName'],
'definition'=>$columnList[$column['oldColumnName']]))));
$conn = $this->getConnection($column['tableName']);
$columnList = $conn->import->listTableColumns($column['tableName']);
if (isset($columnList[$column['oldColumnName']])) {
$conn->export->alterTable($column['tableName'],
array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName'],
'definition'=>$columnList[$column['oldColumnName']]))));
}
}
}
......
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