EBernhardson has uploaded a new change for review.

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

Change subject: Bug: Cant update old revision rows
......................................................................

Bug: Cant update old revision rows

The storage class was performing its update query with the alphadecimal
id, and as such was only updating the cache and not the actual database.
We likely didn't notice this because nothing currently updates historical
revisions, but i'm working on a followup patch that adds a database row
and needs this update method to work.

This patch adds a test case to assert update uses the binary primary key
and fixes the broken line of code.

Change-Id: I103b9907bbc40e01eb2aabf638bc91567d0dc34a
---
M includes/Data/Storage/RevisionStorage.php
A tests/phpunit/Data/Storage/RevisionStorageTest.php
2 files changed, 54 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/81/165681/1

diff --git a/includes/Data/Storage/RevisionStorage.php 
b/includes/Data/Storage/RevisionStorage.php
index 404936d..7d5a142 100644
--- a/includes/Data/Storage/RevisionStorage.php
+++ b/includes/Data/Storage/RevisionStorage.php
@@ -452,7 +452,7 @@
                        $res = $dbw->update(
                                'flow_revision',
                                $this->preprocessSqlArray( $rev ),
-                               array( 'rev_id' => $old['rev_id'] ),
+                               $this->preprocessSqlArray( array( 'rev_id' => 
$old['rev_id'] ) ),
                                __METHOD__
                        );
                        if ( !( $res && $dbw->affectedRows() ) ) {
diff --git a/tests/phpunit/Data/Storage/RevisionStorageTest.php 
b/tests/phpunit/Data/Storage/RevisionStorageTest.php
new file mode 100644
index 0000000..effae6c
--- /dev/null
+++ b/tests/phpunit/Data/Storage/RevisionStorageTest.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Flow\Tests\Data\Storage;
+
+use Flow\Data\Storage\HeaderRevisionStorage;
+use Flow\Model\UUID;
+
+class RevisionStorageTest extends \MediaWikiTestCase {
+
+       public function testUpdateConvertsPrimaryKeyToBinary() {
+               $dbw = $this->getMockBuilder( 'DatabaseMysql' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $factory = $this->getMockBuilder( 'Flow\DbFactory' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $factory->expects( $this->any() )
+                       ->method( 'getDB' )
+                       ->will( $this->returnValue( $dbw ) );
+
+               $id = UUID::create();
+               $dbw->expects( $this->once() )
+                       ->method( 'update' )
+                       ->with(
+                               $this->equalTo( 'flow_revision' ),
+                               $this->equalTo( array(
+                                       'rev_mod_user_id' => 42,
+                               ) ),
+                               $this->equalTo( array(
+                                       'rev_id' => $id->getBinary(),
+                               ) )
+                       )
+                       ->will( $this->returnValue( true ) );
+               $dbw->expects( $this->any() )
+                       ->method( 'affectedRows' )
+                       ->will( $this->returnValue( 1 ) );
+
+               // Header is bare bones implementation, sufficient for testing
+               // the parent class.
+               $storage = new HeaderRevisionStorage( $factory, /* 
$externalStore = */false );
+               $storage->update(
+                       array(
+                               'rev_id' => $id->getAlphadecimal(),
+                               'rev_mod_user_id' => 0,
+                       ),
+                       array(
+                               'rev_id' => $id->getAlphadecimal(),
+                               'rev_mod_user_id' => 42,
+                       )
+               );
+
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I103b9907bbc40e01eb2aabf638bc91567d0dc34a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to