jenkins-bot has submitted this change and it was merged.

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, 63 insertions(+), 0 deletions(-)

Approvals:
  Reedy: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/getRevisionDiffs.php b/maintenance/getRevisionDiffs.php
new file mode 100644
index 0000000..86b4eab
--- /dev/null
+++ b/maintenance/getRevisionDiffs.php
@@ -0,0 +1,63 @@
+<?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;
+                       try {
+                               $diff = $repo->getDiff( $row->cr_id , '' );
+                       } catch ( MWException $mwe ) {
+                               // Suppress errors
+                               $this->output( "$id - error 
{$mwe->getMessage()}\n" );
+                               continue;
+                       }
+                       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: merged
Gerrit-Change-Id: Ia011e9cc04577544892358d1c63025575d8b0470
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CodeReview
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to