Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/65812


Change subject: Hooked up EntityRemover to lower level components
......................................................................

Hooked up EntityRemover to lower level components

Change-Id: I97f44b88051c5e3dd65e0d84b8233056ed775e72
---
D QueryEngine/includes/SQLStore/ClaimStore/ClaimRemover.php
M QueryEngine/includes/SQLStore/ClaimStore/ClaimsTable.php
M QueryEngine/includes/SQLStore/EntityRemover.php
D QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimRemoverTest.php
M QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimsTableTest.php
M QueryEngine/tests/phpunit/SQLStore/EntityRemoverTest.php
6 files changed, 53 insertions(+), 225 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/12/65812/1

diff --git a/QueryEngine/includes/SQLStore/ClaimStore/ClaimRemover.php 
b/QueryEngine/includes/SQLStore/ClaimStore/ClaimRemover.php
deleted file mode 100644
index 7d2ef43..0000000
--- a/QueryEngine/includes/SQLStore/ClaimStore/ClaimRemover.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-namespace Wikibase\QueryEngine\SQLStore\ClaimStore;
-
-use Wikibase\Claim;
-
-/**
- * Use case for removing snaks from the store.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @since 0.1
- *
- * @file
- * @ingroup WikibaseSQLStore
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class ClaimRemover {
-
-//     protected $claimsTable;
-//     protected $snakInserter;
-//     protected $claimRowBuilder;
-//
-//     public function __construct( ClaimsTable $claimsTable, SnakInserter 
$snakInserter, ClaimRowBuilder $claimRowBuilder ) {
-//             $this->claimsTable = $claimsTable;
-//             $this->snakInserter = $snakInserter;
-//             $this->claimRowBuilder = $claimRowBuilder;
-//     }
-
-       /**
-        * @param Claim $claim
-        * @param int $internalSubjectId
-        */
-       public function removeClaim( Claim $claim, $internalSubjectId ) {
-//             $internalClaimId = $this->insertIntoClaimsTable( $claim, 
$internalSubjectId );
-//             $this->insertSnaks( $claim, $internalClaimId, 
$internalSubjectId );
-       }
-
-//     protected function insertIntoClaimsTable( Claim $claim, 
$internalSubjectId ) {
-//             $claimRow = $this->claimRowBuilder->newClaimRow( $claim, 
$internalSubjectId );
-//             return $this->claimsTable->insertClaimRow( $claimRow );
-//     }
-//
-//     protected function insertSnaks( Claim $claim, $internalClaimId, 
$internalSubjectId ) {
-//             $this->insertSnak( $claim->getMainSnak(), SnakRole::MAIN_SNAK, 
$internalClaimId, $internalSubjectId );
-//
-//             foreach ( $claim->getQualifiers() as $qualifier ) {
-//                     $this->insertSnak( $qualifier, SnakRole::QUALIFIER, 
$internalClaimId, $internalSubjectId );
-//             }
-//     }
-//
-//     protected function insertSnak( Snak $snak, $snakRole, $internalClaimId, 
$internalSubjectId ) {
-//             $this->snakInserter->insertSnak( $snak, $snakRole, 
$internalClaimId, $internalSubjectId );
-//     }
-
-}
diff --git a/QueryEngine/includes/SQLStore/ClaimStore/ClaimsTable.php 
b/QueryEngine/includes/SQLStore/ClaimStore/ClaimsTable.php
index 970cacf..b312789 100644
--- a/QueryEngine/includes/SQLStore/ClaimStore/ClaimsTable.php
+++ b/QueryEngine/includes/SQLStore/ClaimStore/ClaimsTable.php
@@ -71,4 +71,13 @@
                );
        }
 
+       public function removeClaimsOfSubject( $internalSubjectId ) {
+               $this->queryInterface->delete(
+                       $this->tableName,
+                       array(
+                               'subject_id' => $internalSubjectId
+                       )
+               );
+       }
+
 }
diff --git a/QueryEngine/includes/SQLStore/EntityRemover.php 
b/QueryEngine/includes/SQLStore/EntityRemover.php
index 260e63d..6d4363c 100644
--- a/QueryEngine/includes/SQLStore/EntityRemover.php
+++ b/QueryEngine/includes/SQLStore/EntityRemover.php
@@ -5,6 +5,8 @@
 use Wikibase\Entity;
 use Wikibase\EntityId;
 use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRemover;
+use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimsTable;
+use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover;
 
 /**
  * Use case for removing entities from the store.
@@ -34,18 +36,21 @@
  */
 class EntityRemover {
 
-       private $claimRemover;
+       private $claimsTable;
        private $idFinder;
+       private $snakRemover;
 
        /**
         * @since 0.1
         *
-        * @param ClaimRemover $claimRemover
+        * @param ClaimsTable $claimsTable
+        * @param SnakRemover $snakRemover
         * @param InternalEntityIdFinder $idFinder
         */
-       public function __construct( ClaimRemover $claimRemover, 
InternalEntityIdFinder $idFinder ) {
-               $this->claimRemover = $claimRemover;
+       public function __construct( ClaimsTable $claimsTable, SnakRemover 
$snakRemover, InternalEntityIdFinder $idFinder ) {
+               $this->claimsTable = $claimsTable;
                $this->idFinder = $idFinder;
+               $this->snakRemover = $snakRemover;
        }
 
        /**
@@ -56,12 +61,8 @@
        public function removeEntity( Entity $entity ) {
                $internalSubjectId = $this->getInternalId( $entity->getId() );
 
-               foreach ( $entity->getClaims() as $claim ) {
-                       $this->claimRemover->removeClaim(
-                               $claim,
-                               $internalSubjectId
-                       );
-               }
+               $this->claimsTable->removeClaimsOfSubject( $internalSubjectId );
+               $this->snakRemover->removeSnaksOfSubject( $internalSubjectId );
 
                // TODO: obtain and remove virtual claims
        }
diff --git a/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimRemoverTest.php 
b/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimRemoverTest.php
deleted file mode 100644
index c1c0d91..0000000
--- a/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimRemoverTest.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-
-namespace Wikibase\QueryEngine\Tests\SQLStore\ClaimStore;
-
-use DataValues\StringValue;
-use Wikibase\Claim;
-use Wikibase\EntityId;
-use Wikibase\PropertyNoValueSnak;
-use Wikibase\PropertyValueSnak;
-use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimInserter;
-use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRowBuilder;
-use Wikibase\Reference;
-use Wikibase\ReferenceList;
-use Wikibase\SnakList;
-use Wikibase\Statement;
-
-/**
- * @covers Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRemover
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @since 0.1
- *
- * @ingroup WikibaseQueryEngineTest
- *
- * @group Wikibase
- * @group WikibaseQueryEngine
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class ClaimRemoverTest extends \PHPUnit_Framework_TestCase {
-
-       /**
-        * @dataProvider claimProvider
-        */
-       public function testRemoveClaim( Claim $claim ) {
-               $this->assertTrue( true ); // TODO
-//             $claimTable = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimsTable' )
-//                     ->disableOriginalConstructor()->getMock();
-//
-//             $claimTable->expects( $this->once() )->method( 'insertClaimRow' 
);
-//
-//             $snakInserter = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\SnakStore\SnakInserter' )
-//                     ->disableOriginalConstructor()->getMock();
-//
-//             $snakInserter->expects( $this->exactly( $this->countClaimSnaks( 
$claim ) ) )->method( 'insertSnak' );
-//
-//             $idFinder = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' );
-//             $idFinder->expects( $this->any() )
-//                     ->method( 'getInternalIdForEntity' )
-//                     ->will( $this->returnValue( 42 ) );
-//
-//             $claimRowBuilder = new ClaimRowBuilder( $idFinder );
-//
-//             $claimInserter = new ClaimInserter( $claimTable, $snakInserter, 
$claimRowBuilder );
-//
-//             $claimInserter->insertClaim( $claim, new EntityId( 'item', 1 ) 
);
-       }
-
-       public function claimProvider() {
-               /**
-                * @var Claim[] $claims
-                */
-               $claims = array();
-
-               $claims[] = new Claim(
-                       new PropertyValueSnak( 42, new StringValue( 'NyanData' 
) )
-               );
-
-               $claims[] = new Claim(
-                       new PropertyNoValueSnak( 23 ),
-                       new SnakList( array(
-                               new PropertyValueSnak( 1337, new StringValue( 
'NyanData' ) ),
-                               new PropertyNoValueSnak( 9001 )
-                       ) )
-               );
-
-               $claims[] = new Statement(
-                       new PropertyNoValueSnak( 1 ),
-                       new SnakList( array(
-                               new PropertyValueSnak( 2, new StringValue( 
'NyanData' ) ),
-                               new PropertyNoValueSnak( 3 )
-                       ) ),
-                       new ReferenceList( array(
-                               new Reference( new SnakList( array(
-                                       new PropertyValueSnak( 3, new 
StringValue( 'NyanData' ) ),
-                               ) ) ),
-                               new Reference( new SnakList( array(
-                                       new PropertyValueSnak( 4, new 
StringValue( 'NyanData' ) ),
-                                       new PropertyValueSnak( 5, new 
StringValue( 'NyanData' ) ),
-                               ) ) )
-                       ) )
-               );
-
-               $argLists = array();
-
-               foreach ( $claims as $claim ) {
-                       $claim->setGuid( 'some-claim-guid' );
-                       $argLists[] = array( $claim );
-               }
-
-               return $argLists;
-       }
-
-       private function countClaimSnaks( Claim $claim ) {
-               $snakCount = 1;
-
-               $snakCount += $claim->getQualifiers()->count();
-
-               // References are ignored as these are not inserted into the 
store at this point.
-
-               return $snakCount;
-       }
-
-}
diff --git a/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimsTableTest.php 
b/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimsTableTest.php
index 883403e..296ce9b 100644
--- a/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimsTableTest.php
+++ b/QueryEngine/tests/phpunit/SQLStore/ClaimStore/ClaimsTableTest.php
@@ -104,4 +104,21 @@
                $table->insertClaimRow( $claimRow );
        }
 
+       public function testRemoveClaimsOfSubject() {
+               $tableName = 'test_claims';
+               $subjectId = 1234;
+
+               $queryInterface = $this->getMock( 
'Wikibase\Database\QueryInterface' );
+               $queryInterface->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with(
+                               $this->equalTo( $tableName ),
+                               $this->equalTo( array( 'subject_id' => 
$subjectId ) )
+                       );
+
+               $table = new ClaimsTable( $queryInterface, $tableName );
+
+               $table->removeClaimsOfSubject( $subjectId );
+       }
+
 }
diff --git a/QueryEngine/tests/phpunit/SQLStore/EntityRemoverTest.php 
b/QueryEngine/tests/phpunit/SQLStore/EntityRemoverTest.php
index bd6d42a..d4bb629 100644
--- a/QueryEngine/tests/phpunit/SQLStore/EntityRemoverTest.php
+++ b/QueryEngine/tests/phpunit/SQLStore/EntityRemoverTest.php
@@ -47,22 +47,24 @@
         * @dataProvider entityProvider
         */
        public function testRemoveEntity( Entity $entity ) {
-               $claimRemover = $this
-                       ->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRemover' )
+               $internalSubjectId = 9001;
+
+               $claimTable = $this
+                       ->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimsTable' )
                        ->disableOriginalConstructor()
                        ->getMock();
 
-               $invocationMocker = $claimRemover->expects( $this->exactly( 
count( $entity->getClaims() ) ) )
-                       ->method( 'removeClaim' );
+               $claimTable->expects( $this->once() )
+                       ->method( 'removeClaimsOfSubject' )
+                       ->with( $this->equalTo( $internalSubjectId ) );
 
-               // The 'with' constraints fail if the method is not invoked,
-               // so we can only add them when there are claims.
-               if ( count( $entity->getClaims() ) > 0 ) {
-                       $invocationMocker->with(
-                               $this->anything(),
-                               $this->equalTo( 1234 )
-                       );
-               }
+               $snakRemover = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $snakRemover->expects( $this->once() )
+                       ->method( 'removeSnaksOfSubject' )
+                       ->with( $this->equalTo( $internalSubjectId ) );
 
                $idFinder = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' );
 
@@ -71,9 +73,9 @@
                        ->with(
                                $entity->getId()
                        )
-                       ->will( $this->returnValue( 1234 ) );
+                       ->will( $this->returnValue( $internalSubjectId ) );
 
-               $remover = new EntityRemover( $claimRemover, $idFinder );
+               $remover = new EntityRemover( $claimTable, $snakRemover, 
$idFinder );
 
                $remover->removeEntity( $entity );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/65812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97f44b88051c5e3dd65e0d84b8233056ed775e72
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to