From 2bd36677500280ad2364ffec5ede1e72b549ed34 Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Sun, 25 Nov 2007 20:30:51 +0000 Subject: [PATCH] A few fixes to Migrations and formatting/code fixes. --- lib/Doctrine.php | 2 +- lib/Doctrine/Migration.php | 2 +- lib/Doctrine/Migration/Builder.php | 30 ++++++------------------------ lib/Doctrine/Migration/Process.php | 14 +++++++------- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/lib/Doctrine.php b/lib/Doctrine.php index cd94dfe36..e1ac88efe 100644 --- a/lib/Doctrine.php +++ b/lib/Doctrine.php @@ -1114,7 +1114,7 @@ final class Doctrine */ public static function makeDirectories($path, $mode = 0777) { - if (!$path) { + if ( ! $path) { return false; } diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index dfe01a9d1..09c4698a4 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -584,4 +584,4 @@ class Doctrine_Migration $this->addChange('removed_indexes', $options); } -} +} \ No newline at end of file diff --git a/lib/Doctrine/Migration/Builder.php b/lib/Doctrine/Migration/Builder.php index 307799494..540f41dcd 100644 --- a/lib/Doctrine/Migration/Builder.php +++ b/lib/Doctrine/Migration/Builder.php @@ -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 * diff --git a/lib/Doctrine/Migration/Process.php b/lib/Doctrine/Migration/Process.php index 5cd7bdc78..55dde10e4 100644 --- a/lib/Doctrine/Migration/Process.php +++ b/lib/Doctrine/Migration/Process.php @@ -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']])))); } } }