From e90d1a09185f2ab8d2b4533ba0d03b5dab15149d Mon Sep 17 00:00:00 2001 From: jeroendedauw Date: Thu, 6 Dec 2012 23:34:23 +0100 Subject: [PATCH] (bug 42226) failure in sites tests MediaWikiSiteTest::testRemove got a duplicate key error. Change-Id: I7a40fe50b757e4162b7ccf1655d872cbd2c51f5d --- includes/db/ORMRow.php | 4 ++-- includes/site/SiteObject.php | 23 +++++++++++++++++++++-- tests/phpunit/includes/db/ORMRowTest.php | 10 +--------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/includes/db/ORMRow.php b/includes/db/ORMRow.php index affd65f99a..d64530f34a 100644 --- a/includes/db/ORMRow.php +++ b/includes/db/ORMRow.php @@ -453,8 +453,8 @@ abstract class ORMRow implements IORMRow { } /** - * Gets called after successfull removal. - * Can be overriden to get rid of linked data. + * Gets called after successful removal. + * Can be overridden to get rid of linked data. * * @since 1.20 */ diff --git a/includes/site/SiteObject.php b/includes/site/SiteObject.php index 0c6aeb39b8..78c942b60b 100644 --- a/includes/site/SiteObject.php +++ b/includes/site/SiteObject.php @@ -439,7 +439,7 @@ class SiteObject extends ORMRow implements Site { } /** - * @see ORMRow::save + * @see IORMRow::save * @see Site::save * * @since 1.21 @@ -449,7 +449,7 @@ class SiteObject extends ORMRow implements Site { * @return boolean Success indicator */ public function save( $functionName = null ) { - $dbw = wfGetDB( DB_MASTER ); + $dbw = $this->table->getWriteDbConnection(); $trx = $dbw->trxLevel(); @@ -495,6 +495,25 @@ class SiteObject extends ORMRow implements Site { return $success; } + /** + * @since 1.21 + * + * @see ORMRow::onRemoved + */ + protected function onRemoved() { + $dbw = $this->table->getWriteDbConnection(); + + $dbw->delete( + 'site_identifiers', + array( + 'si_site' => $this->getId() + ), + __METHOD__ + ); + + parent::onRemoved(); + } + /** * @see Site::setPath * diff --git a/tests/phpunit/includes/db/ORMRowTest.php b/tests/phpunit/includes/db/ORMRowTest.php index b46ce2e27b..8516241458 100644 --- a/tests/phpunit/includes/db/ORMRowTest.php +++ b/tests/phpunit/includes/db/ORMRowTest.php @@ -136,7 +136,7 @@ abstract class ORMRowTest extends \MediaWikiTestCase { /** * @dataProvider constructorTestProvider */ - public function testSave( array $data, $loadDefaults ) { + public function testSaveAndRemove( array $data, $loadDefaults ) { $item = $this->getRowInstance( $data, $loadDefaults ); $this->assertTrue( $item->save() ); @@ -151,14 +151,6 @@ abstract class ORMRowTest extends \MediaWikiTestCase { $this->assertEquals( $id, $item->getId() ); $this->verifyFields( $item, $data ); - } - - /** - * @dataProvider constructorTestProvider - * @depends testSave - */ - public function testRemove( array $data, $loadDefaults ) { - $item = $this->getRowInstance( $data, $loadDefaults ); $this->assertTrue( $item->remove() ); -- 2.20.1