Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.6 #1049

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

1.6 #1049

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

[![Build Status](https://secure.travis-ci.org/propelorm/Propel.png?branch=master)](http://travis-ci.org/propelorm/Propel)
[![Build
Status](https://travis-ci.org/propelorm/Propel.png?branch=1.6)](https://travis-ci.org/propelorm/Propel)

## A quick tour of the features ##

Expand Down
3 changes: 2 additions & 1 deletion generator/lib/behavior/i18n/I18nBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class I18nBehavior extends Behavior
'i18n_columns' => '',
'i18n_pk_name' => null,
'locale_column' => 'locale',
'locale_length' => 5,
'default_locale' => null,
'locale_alias' => '',
);
Expand Down Expand Up @@ -128,7 +129,7 @@ protected function addLocaleColumnToI18n()
$this->i18nTable->addColumn(array(
'name' => $localeColumnName,
'type' => PropelTypes::VARCHAR,
'size' => 5,
'size' => $this->getParameter('locale_length') ? (int) $this->getParameter('locale_length') : 5,
'default' => $this->getDefaultLocale(),
'primaryKey' => 'true',
));
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/model/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public function addExtraIndices()
foreach ($this->getReferrers() as $foreignKey) {
$referencedColumns = $foreignKey->getForeignColumnObjects();
$referencedColumnsHash = $this->getColumnList($referencedColumns);
if (!empty($localColumnsHash) && !array_key_exists($referencedColumnsHash, $_indices)) {
if (!empty($referencedColumns) && !array_key_exists($referencedColumnsHash, $_indices)) {
// no matching index defined in the schema, so we have to create one

$name = sprintf('I_referenced_%s_%s', $foreignKey->getName(), ++$counter);
Expand Down
16 changes: 16 additions & 0 deletions generator/lib/util/PropelMigrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,37 @@ public function getMigrationClassBody($migrationsUp, $migrationsDown, $timestamp
class $migrationClassName
{

/**
* @param PropelMigrationManager \$manager
*
* @return bool|void
*/
public function preUp(\$manager)
{
// add the pre-migration code here
}

/**
* @param PropelMigrationManager \$manager
*/
public function postUp(\$manager)
{
// add the post-migration code here
}

/**
* @param PropelMigrationManager \$manager
*
* @return bool|void
*/
public function preDown(\$manager)
{
// add the pre-migration code here
}

/**
* @param PropelMigrationManager \$manager
*/
public function postDown(\$manager)
{
// add the post-migration code here
Expand Down
30 changes: 30 additions & 0 deletions test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,37 @@ public function testModifyTableUseCustomPkName()
$this->assertContains($expected, $builder->getSQL());
}

public function testModiFyTableUsesCustomI18nLocaleLength()
{
$schema = <<<EOF
<database name="i18n_behavior_test_0">
<table name="i18n_behavior_test_0">
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<behavior name="i18n">
<parameter name="locale_length" value="6" />
</behavior>
</table>
</database>
EOF;
$builder = new PropelQuickBuilder();
$builder->setSchema($schema);
$expected = <<<EOF
-----------------------------------------------------------------------
-- i18n_behavior_test_0_i18n
-----------------------------------------------------------------------

DROP TABLE IF EXISTS [i18n_behavior_test_0_i18n];

CREATE TABLE [i18n_behavior_test_0_i18n]
(
[id] INTEGER NOT NULL,
[locale] VARCHAR(6) DEFAULT 'en_US' NOT NULL,
PRIMARY KEY ([id],[locale])
);
EOF;
$this->assertContains($expected, $builder->getSQL());
}

public function testTableWithPrefix()
{
$schema = <<<EOF
Expand Down
129 changes: 129 additions & 0 deletions test/testsuite/misc/Issue651Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

class Issue651Test extends PHPUnit_Framework_TestCase
{

public function testIndex()
{
$updatedSchema = '
<database>
<table name="notification">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="target_user_id" required="true" type="INTEGER" />
<column name="notification_type_unique_name" required="true" size="255" type="VARCHAR" />
<column name="group_id" type="INTEGER" />
<column name="date" required="true" type="TIMESTAMP" />
<column name="objects" type="LONGVARCHAR" />
<column name="is_new" defaultValue="1" required="true" type="BOOLEAN" />
<foreign-key foreignTable="notification_type" name="FK_NOTIFICATION_TYPENOTIFICATION0">
<reference foreign="unique_name" local="notification_type_unique_name" />
</foreign-key>
<index name="FK_NOTIFICATION_TARGET_USER">
<index-column name="target_user_id" />
</index>
<index name="FK_NOTIFICATION_TYPENOTIFICATION">
<index-column name="notification_type_unique_name" />
</index>
</table>
<table name="notification_type">
<column name="module_unique_name" primaryKey="true" required="true" size="255" type="VARCHAR" />
<column name="unique_name" primaryKey="true" required="true" size="255" type="VARCHAR" />
<column name="is_correction" defaultValue="0" required="true" type="BOOLEAN" />
<column name="disabled_engine" size="255" type="VARCHAR" />
<foreign-key foreignTable="module" name="FK_TYPENOTIFICATION_MODULE0" onDelete="CASCADE" onUpdate="CASCADE">
<reference foreign="unique_name" local="module_unique_name" />
</foreign-key>
<index name="FK_TYPENOTIFICATION_MODULE">
<index-column name="module_unique_name" />
</index>
</table>
<table name="module">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="unique_name" required="true" size="255" type="VARCHAR" />
<column name="label" primaryString="true" required="true" size="255" type="VARCHAR" />
<column name="description" required="true" size="255" type="VARCHAR" />
</table>
</database>
';

$actual = "
# This is a fix for InnoDB in MySQL >= 4.1.x
# It \"suspends judgement\" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

-- ---------------------------------------------------------------------
-- notification
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `notification`;

CREATE TABLE `notification`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`target_user_id` INTEGER NOT NULL,
`notification_type_unique_name` VARCHAR(255) NOT NULL,
`group_id` INTEGER,
`date` DATETIME NOT NULL,
`objects` TEXT,
`is_new` TINYINT(1) DEFAULT 1 NOT NULL,
PRIMARY KEY (`id`),
INDEX `FK_NOTIFICATION_TARGET_USER` (`target_user_id`),
INDEX `FK_NOTIFICATION_TYPENOTIFICATION` (`notification_type_unique_name`),
CONSTRAINT `FK_NOTIFICATION_TYPENOTIFICATION0`
FOREIGN KEY (`notification_type_unique_name`)
REFERENCES `notification_type` (`unique_name`)
) ENGINE=InnoDb;

-- ---------------------------------------------------------------------
-- notification_type
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `notification_type`;

CREATE TABLE `notification_type`
(
`module_unique_name` VARCHAR(255) NOT NULL,
`unique_name` VARCHAR(255) NOT NULL,
`is_correction` TINYINT(1) DEFAULT 0 NOT NULL,
`disabled_engine` VARCHAR(255),
PRIMARY KEY (`module_unique_name`,`unique_name`),
INDEX `FK_TYPENOTIFICATION_MODULE` (`module_unique_name`),
INDEX `I_referenced_FK_NOTIFICATION_TYPENOTIFICATION0_1` (`unique_name`),
CONSTRAINT `FK_TYPENOTIFICATION_MODULE0`
FOREIGN KEY (`module_unique_name`)
REFERENCES `module` (`unique_name`)
ON UPDATE CASCADE
ON DELETE CASCADE
) ENGINE=InnoDb;

-- ---------------------------------------------------------------------
-- module
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `module`;

CREATE TABLE `module`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`unique_name` VARCHAR(255) NOT NULL,
`label` VARCHAR(255) NOT NULL,
`description` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDb;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
";


$platform = new MysqlPlatform();
$platform->setDefaultTableEngine('InnoDb');
$updatedBuilder = new PropelQuickBuilder();
$updatedBuilder->setPlatform($platform);
$updatedBuilder->setSchema($updatedSchema);

$sql = $updatedBuilder->getSQL();
$this->assertEquals($actual, $sql);
}

}