1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[2.0] DDC-396 - Fixed bug with RESTRICT/NO ACTION and PHP NULL not valued as the same in Schema Foreign Key Diff

This commit is contained in:
beberlei 2010-03-11 20:23:49 +00:00
parent 13ad526833
commit 2ebd2c901e
3 changed files with 49 additions and 12 deletions

View File

@ -280,19 +280,11 @@ class Comparator
return true;
}
if ($key1->hasOption('onUpdate') && $key->hasOption('onUpdate')) {
if ($key1->getOption('onUpdate') != $key2->getOption('onUpdate')) {
return true;
}
} else if ($key1->hasOption('onUpdate') != $key2->hasOption('onUpdate')) {
if ($key1->onUpdate() != $key2->onUpdate()) {
return true;
}
if ($key1->hasOption('onDelete') && $key2->hasOption('onDelete')) {
if ($key1->getOption('onDelete') != $key2->getOption('onDelete')) {
return true;
}
} else if ($key1->hasOption('onDelete') != $key2->hasOption('onDelete')) {
if ($key1->onDelete() != $key2->onDelete()) {
return true;
}

View File

@ -126,4 +126,39 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
{
return $this->_options[$name];
}
}
/**
* Foreign Key onUpdate status
*
* @return string|null
*/
public function onUpdate()
{
return $this->_onEvent('onUpdate');
}
/**
* Foreign Key onDelete status
*
* @return string|null
*/
public function onDelete()
{
return $this->_onEvent('onDelete');
}
/**
* @param string $event
* @return string|null
*/
private function _onEvent($event)
{
if (isset($this->_options[$event])) {
$onEvent = strtoupper($this->_options[$event]);
if (!in_array($onEvent, array('NO ACTION', 'RESTRICT'))) {
return $onEvent;
}
}
return false;
}
}

View File

@ -31,7 +31,8 @@ use Doctrine\DBAL\Schema\Schema,
Doctrine\DBAL\Schema\SchemaDiff,
Doctrine\DBAL\Schema\TableDiff,
Doctrine\DBAL\Schema\Comparator,
Doctrine\DBAL\Types\Type;
Doctrine\DBAL\Types\Type,
Doctrine\DBAL\Schema\ForeignKeyConstraint;
/**
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
@ -545,6 +546,15 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($tableDiff);
}
public function testCompareForeignKey_RestrictNoAction_AreTheSame()
{
$fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION'));
$fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT'));
$c = new Comparator();
$this->assertFalse($c->diffForeignKey($fk1, $fk2));
}
public function testDetectRenameColumn()
{
$tableA = new Table("foo");