diff --git a/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php b/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php index 4cede1e21a..41bd423dff 100644 --- a/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php +++ b/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php @@ -137,7 +137,8 @@ protected function addVersionTable() $table = $this->getTable(); $database = $table->getDatabase(); $versionTableName = $this->getParameter('version_table') ? $this->getParameter('version_table') : ($table->getOriginCommonName() . '_version'); - if (!$database->hasTable($versionTableName)) { + $this->versionTable = $database->getTable($versionTableName); + if (empty($this->versionTable)) { // create the version table $versionTable = $database->addTable([ 'name' => $versionTableName, @@ -188,8 +189,6 @@ protected function addVersionTable() $versionColumn->setNotNull(true); $versionColumn->setPrimaryKey(true); $this->versionTable = $versionTable; - } else { - $this->versionTable = $database->getTable($versionTableName); } } @@ -211,7 +210,7 @@ public function addForeignKeyVersionColumns() } foreach ($this->getVersionableReferrers() as $fk) { - $fkTableName = $fk->getTable()->getName(); + $fkTableName = $fk->getTable()->getCommonName(); $fkIdsColumnName = $fkTableName . '_ids'; if (!$versionTable->hasColumn($fkIdsColumnName)) { $versionTable->addColumn([ @@ -287,7 +286,7 @@ public function getVersionableReferrers() */ public function getReferrerIdsColumn(ForeignKey $fk) { - $fkTableName = $fk->getTable()->getName(); + $fkTableName = $fk->getTable()->getCommonName(); $fkIdsColumnName = $fkTableName . '_ids'; return $this->versionTable->getColumn($fkIdsColumnName); @@ -300,7 +299,7 @@ public function getReferrerIdsColumn(ForeignKey $fk) */ public function getReferrerVersionsColumn(ForeignKey $fk) { - $fkTableName = $fk->getTable()->getName(); + $fkTableName = $fk->getTable()->getCommonName(); $fkIdsColumnName = $fkTableName . '_versions'; return $this->versionTable->getColumn($fkIdsColumnName); diff --git a/src/Propel/Generator/Manager/AbstractManager.php b/src/Propel/Generator/Manager/AbstractManager.php index 5ce77d032f..82e884bfcc 100644 --- a/src/Propel/Generator/Manager/AbstractManager.php +++ b/src/Propel/Generator/Manager/AbstractManager.php @@ -401,6 +401,18 @@ protected function includeExternalSchemas(DOMDocument $dom, $srcDir) $externalSchema->parentNode->removeChild($externalSchema); + // when this is not readable like './some/other/schema.xml' or '../../extra/schema.xml' + if (!is_readable($include)) { + // find in the relative path + foreach ($this->getGeneratorConfig()->getConfigProperty('paths') as $path) { + if (is_readable($path . DIRECTORY_SEPARATOR . $include)) { + $include = realpath($path . DIRECTORY_SEPARATOR . $include); + + break; + } + } + } + if (!is_readable($include)) { throw new BuildException("External schema '$include' does not exist"); } diff --git a/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorTest.php index 0f596adcc6..852faae731 100644 --- a/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Versionable/VersionableBehaviorTest.php @@ -17,6 +17,9 @@ */ class VersionableBehaviorTest extends TestCase { + + const SCHEMA_NAME = 'test'; + public function basicSchemaDataProvider() { $schema = << EOF; - return [[$schema]]; + return [ + ['versionable_behavior_test_0', $schema], + [ + self::SCHEMA_NAME . '§versionable_behavior_test_0', + str_replace('setSchema($schema); $expected = << @@ -100,7 +113,7 @@ public function testModifyTableAddsVersionColumnCustomName() */ public function testModifyTableDoesNotAddVersionColumnIfExists() { - $schema = <<
@@ -151,45 +164,54 @@ public function foreignTableSchemaDataProvider() EOF; - return [[$schema]]; + return [ + ['versionable_behavior_test', $schema], + [ + self::SCHEMA_NAME . '§versionable_behavior_test', + str_replace('setSchema($schema); $expected = <<assertContains($expected, $builder->getSQL()); $expected = <<setSchema($schema); $expected = <<assertContains($expected, $builder->getSQL()); + + $column = strtr($table, [self::SCHEMA_NAME . '§' => '']); $expected = <<setSchema($schema); $expected = <<
@@ -323,12 +353,48 @@ public function testModifyTableAddsVersionTableCustomName() $this->assertContains($expected, $builder->getSQL()); } + public function testModifyTableAddsVersionTableCustomNameAndCustomSchemaName() + { + $schema = << +
+ + + + + +
+
+EOF; + $builder = new QuickBuilder(); + $builder->setSchema($schema); + $expected = <<assertContains($expected, $builder->getSQL()); + } + /** * @return void */ public function testModifyTableDoesNotAddVersionTableIfExists() { - $schema = << @@ -372,6 +438,56 @@ public function testModifyTableDoesNotAddVersionTableIfExists() UNIQUE (id) ); +EOF; + $this->assertEquals($expected, $builder->getSQL()); + } + + public function testModifyTableDoesNotAddVersionTableIfExistsCustomSchemaName() + { + $schema = << +
+ + + +
+ + + +
+ +EOF; + $builder = new QuickBuilder(); + $builder->setSchema($schema); + $expected = <<assertEquals($expected, $builder->getSQL()); } @@ -392,7 +508,13 @@ public function logSchemaDataProvider() EOF; - return [[$schema]]; + return [ + ['versionable_behavior_test_0', $schema], + [ + self::SCHEMA_NAME . '§versionable_behavior_test_0', + str_replace('setSchema($schema); $expected = <<setSchema($schema); $expected = << @@ -490,7 +612,42 @@ public function testDatabaseLevelBehavior() ON DELETE CASCADE ); EOF; - $builder = new QuickBuilder(); + $builder = new QuickBuilder(); + $builder->setSchema($schema); + $this->assertContains($expected, $builder->getSQL()); + } + + + public function testDatabaseLevelBehaviorWithSchemaName() + { + $schema = << + +
+ + +
+
+EOF; + $expected = <<setSchema($schema); $this->assertContains($expected, $builder->getSQL()); } @@ -500,7 +657,7 @@ public function testDatabaseLevelBehavior() */ public function testIndicesParameter() { - $schema = << @@ -528,7 +685,42 @@ public function testIndicesParameter() CREATE INDEX versionable_behavior_test_0_version_i_14f552 ON versionable_behavior_test_0_version (bar); EOF; - $builder = new QuickBuilder(); + $builder = new QuickBuilder(); + $builder->setSchema($schema); + $this->assertContains($expected, $builder->getSQL()); + } + + public function testIndicesParameterWithSchemaName() + { + $schema = << +
+ + + + + + + + +
+ +EOF; + $expected = <<setSchema($schema); $this->assertContains($expected, $builder->getSQL()); } @@ -566,7 +758,13 @@ public function tablePrefixSchemaDataProvider() XML; - return [[$schema]]; + return [ + ['prefix_versionable_behavior_test_0', $schema], + [ + self::SCHEMA_NAME . '§prefix_versionable_behavior_test_0', + str_replace('setSchema($schema); $expected = <<setSchema($schema); $expected = <<