jenkins-bot has submitted this change and it was merged.
Change subject: Bug: prod db contains rows with both *_user_id and *_user_ip set
......................................................................
Bug: prod db contains rows with both *_user_id and *_user_ip set
Bug: 71858
Bug: 73153
Change-Id: I3d78cbeb7313769c3c10c67f68fdbd52531d8f8f
---
A maintenance/FlowFixUserIp.php
1 file changed, 154 insertions(+), 0 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/maintenance/FlowFixUserIp.php b/maintenance/FlowFixUserIp.php
new file mode 100644
index 0000000..c1a0a1b
--- /dev/null
+++ b/maintenance/FlowFixUserIp.php
@@ -0,0 +1,154 @@
+<?php
+
+use Flow\Container;
+use Flow\Data\ManagerGroup;
+use Flow\Model\UUID;
+
+require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
+ ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+ : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+
+/**
+ * Sets *_user_ip to null when *_user_id is > 0
+ *
+ * @ingroup Maintenance
+ */
+class FlowFixUserIp extends LoggedUpdateMaintenance {
+ /**
+ * The number of entries completed
+ *
+ * @var int
+ */
+ private $completeCount = 0;
+
+ /**
+ * @var ManagerGroup
+ */
+ protected $storage;
+
+ static private $types = array(
+ 'post' => 'Flow\Model\PostRevision',
+ 'header' => 'Flow\Model\Header',
+ 'post-summary' => 'Flow\Model\PostSummary',
+ );
+
+ protected function doDBUpdates() {
+ $this->storage = $storage = Container::get( 'storage' );
+ $dbf = Container::get( 'db.factory' );
+ $dbw = $dbf->getDB( DB_MASTER );
+ $hasRun = false;
+
+ $runUpdate = function( $callback ) use ( $dbf, $dbw, $storage )
{
+ $hasRun = true;
+ $continue = "\0";
+ do {
+ $dbw->begin();
+ $continue = call_user_func( $callback, $dbw,
$continue );
+ $dbw->commit();
+ $dbf->waitForSlaves();
+ $storage->clear();
+ } while ( $continue !== null );
+ };
+
+ $runUpdate( array( $this, 'updateTreeRevision' ) );
+ $self = $this;
+ foreach ( array( 'rev_user', 'rev_mod_user', 'rev_edit_user' )
as $prefix ){
+ $runUpdate( function( $dbw, $continue ) use ( $self,
$prefix ) {
+ return $self->updateRevision( $prefix, $dbw,
$continue );
+ } );
+ }
+
+ return true;
+ }
+
+ public function updateTreeRevision( DatabaseBase $dbw, $continue = null
) {
+ $rows = $dbw->select(
+ /* table */'flow_tree_revision',
+ /* select */array( 'tree_rev_id' ),
+ array(
+ 'tree_rev_id > ' . $dbw->addQuotes( $continue ),
+ 'tree_orig_user_ip IS NOT NULL',
+ 'tree_orig_user_id > 0',
+ ),
+ __METHOD__,
+ /* options */array( 'LIMIT' => $this->mBatchSize,
'ORDER BY' => 'tree_rev_id' )
+ );
+
+ $om = Container::get( 'storage' )->getStorage( 'PostRevision' );
+ $objs = $ids = array();
+ foreach ( $rows as $row ) {
+ $ids[] = $row->tree_rev_id;
+ $objs[] = $om->get( UUID::create( $row->tree_rev_id ) );
+ }
+ if ( !$ids ) {
+ return null;
+ }
+ $dbw->update(
+ /* table */'flow_tree_revision',
+ /* update */array( 'tree_orig_user_ip' => null ),
+ /* conditions */array( 'tree_rev_id' => $ids ),
+ __METHOD__
+ );
+ foreach ( $objs as $obj ) {
+ $om->cachePurge( $obj );
+ }
+
+ $this->completeCount += count( $ids );
+
+ return end( $ids );
+ }
+
+ public function updateRevision( $columnPrefix, DatabaseBase $dbw,
$continue = null ) {
+ $rows = $dbw->select(
+ /* table */'flow_revision',
+ /* select */array( 'rev_id', 'rev_type' ),
+ /* conditions */ array(
+ 'rev_id > ' . $dbw->addQuotes( $continue ),
+ "{$columnPrefix}_id > 0",
+ "{$columnPrefix}_ip IS NOT NULL",
+ ),
+ __METHOD__,
+ /* options */array( 'LIMIT' => $this->mBatchSize,
'ORDER BY' => 'rev_id' )
+ );
+
+ $ids = $objs = array();
+ foreach ( $rows as $row ) {
+ $ids[] = $row->rev_id;
+
+ $storage = $this->storage->getStorage(
self::$types[$row->rev_type] );
+ $obj = $storage->get( UUID::create( $row->rev_id ) );
+ $storage->merge( $obj );
+ $objs[] = $obj;
+ }
+ if ( !$ids ) {
+ return null;
+ }
+
+ $dbw->update(
+ /* table */ 'flow_revision',
+ /* update */ array( "{$columnPrefix}_ip" => null ),
+ /* conditions */ array( 'rev_id' => $ids ),
+ __METHOD__
+ );
+
+ foreach ( $objs as $obj ) {
+ $this->storage->cachePurge( $obj );
+ }
+
+ $this->completeCount += count( $ids );
+
+ return end( $ids );
+ }
+
+ /**
+ * Get the update key name to go in the update log table
+ *
+ * @return string
+ */
+ protected function getUpdateKey() {
+ return 'FlowFixUserIp';
+ }
+}
+
+$maintClass = 'FlowFixUserIp'; // Tells it to run the class
+require_once( RUN_MAINTENANCE_IF_MAIN );
--
To view, visit https://gerrit.wikimedia.org/r/171466
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3d78cbeb7313769c3c10c67f68fdbd52531d8f8f
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits