Ladsgroup has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373040 )

Change subject: Use replica with fallback only if the request got POST'ed
......................................................................

Use replica with fallback only if the request got POST'ed

We assume attemptSave is POST'ed so only use master

Bug: T154555
Change-Id: I1f4f8de5438f1028265b09982514c834e5d85f77
---
M repo/includes/EditEntity.php
M repo/includes/Specials/SpecialModifyEntity.php
M repo/tests/phpunit/includes/EditEntityTest.php
3 files changed, 19 insertions(+), 5 deletions(-)


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

diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index c79edfe..ef4bcc1 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -315,10 +315,13 @@
         * the constructor, this returns the latest revision. If the entity 
does not exist
         * yet, this returns null.
         *
+        * @param string $mode LATEST_FROM_REPLICA, 
LATEST_FROM_REPLICA_WITH_FALLBACK or
+        *        LATEST_FROM_MASTER.
+        *
         * @return EntityRevision|null
         * @throws MWException
         */
-       public function getBaseRevision() {
+       public function getBaseRevision( $mode ) {
                if ( $this->baseRev === null ) {
                        $baseRevId = $this->getBaseRevisionId();
 
@@ -329,7 +332,7 @@
                                $this->baseRev = 
$this->entityRevisionLookup->getEntityRevision(
                                        $id,
                                        $baseRevId,
-                                       
EntityRevisionLookup::LATEST_FROM_REPLICA_WITH_FALLBACK
+                                       $mode
                                );
 
                                if ( $this->baseRev === null ) {
@@ -411,7 +414,7 @@
         * @return null|EntityDocument The patched Entity, or null if patching 
failed.
         */
        private function fixEditConflict( EntityDocument $newEntity ) {
-               $baseRev = $this->getBaseRevision();
+               $baseRev = $this->getBaseRevision( 
EntityRevisionLookup::LATEST_FROM_MASTER );
                $latestRev = $this->getLatestRevision();
 
                if ( !$latestRev ) {
diff --git a/repo/includes/Specials/SpecialModifyEntity.php 
b/repo/includes/Specials/SpecialModifyEntity.php
index c26a165..c281ddf 100644
--- a/repo/includes/Specials/SpecialModifyEntity.php
+++ b/repo/includes/Specials/SpecialModifyEntity.php
@@ -7,6 +7,7 @@
 use MWException;
 use Status;
 use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Repo\ChangeOp\ChangeOp;
 use Wikibase\Repo\ChangeOp\ChangeOpException;
 use Wikibase\Repo\ChangeOp\ChangeOpValidationException;
@@ -91,8 +92,15 @@
         */
        protected function getBaseRevision() {
                $id = $this->getEntityId();
+
+               if ( $this->getRequest()->wasPosted() ) {
+                       $mode = 
EntityRevisionLookup::LATEST_FROM_REPLICA_WITH_FALLBACK;
+               } else {
+                       $mode = EntityRevisionLookup::LATEST_FROM_REPLICA;
+               }
+
                try {
-                       $baseRev = $this->getEditEntity()->getBaseRevision();
+                       $baseRev = $this->getEditEntity()->getBaseRevision( 
$mode );
 
                        if ( $baseRev === null ) {
                                throw new UserInputException(
diff --git a/repo/tests/phpunit/includes/EditEntityTest.php 
b/repo/tests/phpunit/includes/EditEntityTest.php
index 31c7864..cb3a6aa 100644
--- a/repo/tests/phpunit/includes/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/EditEntityTest.php
@@ -16,6 +16,7 @@
 use Wikibase\DataModel\Services\Diff\EntityPatcher;
 use Wikibase\DataModel\Term\Fingerprint;
 use Wikibase\EditEntity;
+use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Repo\Store\EntityTitleStoreLookup;
 use Wikibase\Lib\Tests\MockRepository;
 use Wikibase\Repo\Hooks\EditFilterHookRunner;
@@ -320,7 +321,9 @@
                $editEntity = $this->makeEditEntity( $repo, $item->getId(), 
$titleLookup, $user, $baseRevisionId );
 
                if ( $baseRevisionId > 0 ) {
-                       $baseRevision = $editEntity->getBaseRevision();
+                       $baseRevision = $editEntity->getBaseRevision(
+                               EntityRevisionLookup::LATEST_FROM_REPLICA
+                       );
                        $this->assertSame( $baseRevisionId, 
$baseRevision->getRevisionId() );
                        $this->assertEquals( $entityId, 
$baseRevision->getEntity()->getId() );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f4f8de5438f1028265b09982514c834e5d85f77
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>

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

Reply via email to