jenkins-bot has submitted this change and it was merged.
Change subject: Increase editcount for existing Flow revisions
......................................................................
Increase editcount for existing Flow revisions
Bug: T63887
Change-Id: I3fedc4aa16d94c0099091321cd5321c11e57eedd
---
A maintenance/FlowFixEditCount.php
1 file changed, 126 insertions(+), 0 deletions(-)
Approvals:
EBernhardson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/maintenance/FlowFixEditCount.php b/maintenance/FlowFixEditCount.php
new file mode 100644
index 0000000..bf51c1d
--- /dev/null
+++ b/maintenance/FlowFixEditCount.php
@@ -0,0 +1,126 @@
+<?php
+
+use Flow\Container;
+use Flow\FlowActions;
+use Flow\Model\UUID;
+
+require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
+ ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+ : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+
+/**
+ * Adjusts edit counts for all existing Flow data.
+ *
+ * @ingroup Maintenance
+ */
+class FlowFixEditCount extends LoggedUpdateMaintenance {
+ /**
+ * Array of [username => increased edit count]
+ *
+ * @var array
+ */
+ protected $updates = array();
+
+ public function __construct() {
+ parent::__construct();
+
+ $this->mDescription = 'Adjusts edit counts for all existing
Flow data';
+
+ $this->addOption( 'start', 'Timestamp to start counting
revisions at', false, true );
+ $this->addOption( 'stop', 'Timestamp to stop counting revisions
at', false, true );
+
+ $this->setBatchSize( 300 );
+ }
+
+ protected function getUpdateKey() {
+ return 'FlowFixEditCount';
+ }
+
+ protected function doDBUpdates() {
+ /** @var DatabaseBase $dbr */
+ $dbr = Container::get( 'db.factory' )->getDB( DB_SLAVE );
+ $countableActions = $this->getCountableActions();
+
+ // defaults = date of first Flow commit up until now
+ $continue = UUID::getComparisonUUID( $this->getOption( 'start',
'20130710230511' ) );
+ $stop = UUID::getComparisonUUID( $this->getOption( 'stop',
time() ) );
+ while ( $continue !== false ) {
+ $continue = $this->refreshBatch( $dbr, $continue,
$countableActions, $stop );
+
+ // wait for core (we're updating user table) slaves to
catch up
+ wfWaitForSlaves();
+ }
+
+ $this->output( "Done increasing edit counts. Increased:\n" );
+ foreach ( $this->updates as $userId => $count ) {
+ $userName = User::newFromId( $userId )->getName();
+ $this->output( " User $userId ($userName): +$count\n"
);
+ }
+
+ return true;
+ }
+
+ public function refreshBatch( DatabaseBase $dbr, UUID $continue,
$countableActions, UUID $stop ) {
+ $rows = $dbr->select(
+ 'flow_revision',
+ array( 'rev_id', 'rev_user_id' ),
+ array(
+ 'rev_id > ' . $dbr->addQuotes(
$continue->getBinary() ),
+ 'rev_id <= ' . $dbr->addQuotes(
$stop->getBinary() ),
+ 'rev_user_id > 0',
+ 'rev_user_wiki' => wfWikiID(),
+ 'rev_change_type' => $countableActions,
+ ),
+ __METHOD__,
+ array( 'ORDER BY' => 'rev_id ASC' )
+ );
+
+ // end of data
+ if ( !$rows || $rows->numRows() === 0 ) {
+ return false;
+ }
+
+ foreach ( $rows as $row ) {
+ // User::incEditCount only allows for edit count to be
increased 1
+ // at a time. It'd be better to immediately be able to
increase the
+ // edit count by the exact number it should be
increased with, but
+ // I'd rather re-use existing code, especially in a
run-once script,
+ // where performance is not the most important thing ;)
+ $user = User::newFromId( $row->rev_user_id );
+ $user->incEditCount();
+
+ // save updates so we can print them when the script is
done running
+ if ( !isset( $this->updates[$user->getId()] ) ) {
+ $this->updates[$user->getId()] = 0;
+ }
+ $this->updates[$user->getId()]++;
+
+ // set value for next batch to continue at
+ $continue = $row->rev_id;
+ }
+
+ return UUID::create( $continue );
+ }
+
+ /**
+ * Returns list of rev_change_type values that warrant an editcount
increase.
+ *
+ * @return array
+ */
+ protected function getCountableActions() {
+ $allowedActions = array();
+
+ /** @var FlowActions $actions */
+ $actions = \Flow\Container::get( 'flow_actions' );
+ foreach ( $actions->getActions() as $action ) {
+ if ( $actions->getValue( $action, 'editcount' ) ) {
+ $allowedActions[] = $action;
+ }
+ }
+
+ return $allowedActions;
+ }
+}
+
+$maintClass = 'FlowFixEditCount';
+require_once( RUN_MAINTENANCE_IF_MAIN );
--
To view, visit https://gerrit.wikimedia.org/r/189728
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3fedc4aa16d94c0099091321cd5321c11e57eedd
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits