Reedy has uploaded a new change for review.

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


Change subject: Add maintenance script to populate revision diffs in database
......................................................................

Add maintenance script to populate revision diffs in database

Change-Id: Ia011e9cc04577544892358d1c63025575d8b0470
---
A maintenance/getRevisionDiffs.php
1 file changed, 48 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeReview 
refs/changes/97/78497/1

diff --git a/maintenance/getRevisionDiffs.php b/maintenance/getRevisionDiffs.php
new file mode 100644
index 0000000..1727cbe
--- /dev/null
+++ b/maintenance/getRevisionDiffs.php
@@ -0,0 +1,48 @@
+<?php
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+
+if ( $IP === false ) {
+       $IP = dirname( __FILE__ ) . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" ); class GetRevisionDiffs 
extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Populates the cr_diff column (where 
possible) for all rows in a repo";
+               $this->addArg( 'repo', 'The name of the repo. Cannot be all.' );
+       }
+       public function execute() {
+               $repoName = $this->getArg( 0 );
+               if ( $repoName == "all" ) {
+                       $this->error( "Cannot use the 'all' repo", true );
+               }
+               $repo = CodeRepository::newFromName( $repoName );
+               if ( !$repo ) {
+                       $this->error( "Repo '{$repoName}' is not a valid 
Repository", true );
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       'code_rev',
+                       'cr_id',
+                       array( 'cr_repo_id' => $repo->getId(), 'cr_diff IS 
null', ),
+                       __METHOD__
+               );
+               $count = 0;
+               foreach ( $res as $row ) {
+                       $id = $row->cr_id;
+                       $diff = $repo->getDiff( $row->cr_id , '' );
+                       if ( is_int( $diff ) ) {
+                               $error = CodeRepository::getDiffErrorMessage( 
$diff );
+                               $this->output( "$id - $error\n" );
+                       } else {
+                               $this->output( "$id\n" );
+                       }
+
+                       if ( ++$count % 100 == 0 ) {
+                               wfWaitForSlaves();
+                       }
+               }
+               $this->output( "Done!\n" );
+       }
+}
+$maintClass = "GetRevisionDiffs"; require_once( DO_MAINTENANCE );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia011e9cc04577544892358d1c63025575d8b0470
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeReview
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>

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

Reply via email to