r77641 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77640‎ | r77641 | r77642 >
Date:11:56, 3 December 2010
Author:ialex
Status:ok
Tags:
Comment:
Convert WikiError -> MWException
Modified paths:
  • /trunk/extensions/MWSearch/MWSearchUpdater.php (modified) (history)
  • /trunk/extensions/MWSearch/luceneUpdate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MWSearch/MWSearchUpdater.php
@@ -150,7 +150,7 @@
151151 $translated = array_map( array( 'MWSearchUpdater', 'outParam' ), $param );
152152 return new XML_RPC_Value( $translated, $type );
153153 } else {
154 - return new WikiError( 'MWSearchUpdater::sendRPC given bogus parameter' );
 154+ throw new MWException( 'MWSearchUpdater::sendRPC given bogus parameter' );
155155 }
156156 }
157157
@@ -182,9 +182,9 @@
183183 }
184184
185185 if( !is_object( $result ) ) {
186 - return new WikiError( "Unknown XML-RPC error" );
 186+ throw new MWException( "Unknown XML-RPC error" );
187187 } elseif( $result->faultCode() ) {
188 - return new WikiError( $result->faultCode() . ': ' . $result->faultString() );
 188+ throw new MWException( $result->faultCode() . ': ' . $result->faultString() );
189189 } else {
190190 $value = $result->value();
191191 return $value->getval();
Index: trunk/extensions/MWSearch/luceneUpdate.php
@@ -12,31 +12,56 @@
1313 exit( -1 );
1414 }
1515
 16+$ret = true;
 17+
1618 switch( $args[0] ) {
1719 case 'stop':
18 - $ret = MWSearchUpdater::stop();
 20+ try {
 21+ MWSearchUpdater::stop();
 22+ } catch ( MWException $e ) {
 23+ $ret = $e;
 24+ }
1925 break;
2026 case 'restart':
2127 case 'flushall':
2228 case 'flush':
23 - $ret = MWSearchUpdater::flushAll();
 29+ try {
 30+ MWSearchUpdater::flushAll();
 31+ } catch ( MWException $e ) {
 32+ $ret = $e;
 33+ }
2434 break;
2535 case 'start':
26 - $ret = MWSearchUpdater::start();
 36+ try {
 37+ MWSearchUpdater::start();
 38+ } catch ( MWException $e ) {
 39+ $ret = $e;
 40+ }
2741 break;
2842 //case 'flush':
2943 // global $wgDBname;
30 -// $ret = MWSearchUpdater::flush( $wgDBname );
 44+// try {
 45+// MWSearchUpdater::flush( $wgDBname );
 46+// } catch ( MWException $e ) {
 47+// $ret = $e;
 48+// }
3149 // break;
3250 case 'status':
3351 // no-op
34 - $ret = true;
3552 break;
3653 case 'quit':
37 - $ret = MWSearchUpdater::quit();
 54+ try {
 55+ MWSearchUpdater::quit();
 56+ } catch ( MWException $e ) {
 57+ $ret = $e;
 58+ }
3859 break;
3960 case 'optimize':
40 - $ret = MWSearchUpdater::optimize();
 61+ try {
 62+ MWSearchUpdater::optimize();
 63+ } catch ( MWException $e ) {
 64+ $ret = $e;
 65+ }
4166 break;
4267 case 'update':
4368 $title = Title::newFromText( $args[1] );
@@ -44,11 +69,15 @@
4570 die( "Invalid title\n" );
4671 }
4772 $rev = Revision::newFromTitle( $title );
48 - if( $rev ) {
49 - $text = $rev->getText();
50 - $ret = MWSearchUpdater::updatePage( $wgDBname, $title, $text );
51 - } else {
52 - $ret = MWSearchUpdater::deletePage( $wgDBname, $title );
 73+ try {
 74+ if( $rev ) {
 75+ $text = $rev->getText();
 76+ $ret = MWSearchUpdater::updatePage( $wgDBname, $title, $text );
 77+ } else {
 78+ $ret = MWSearchUpdater::deletePage( $wgDBname, $title );
 79+ }
 80+ } catch ( MWException $e ) {
 81+ $ret = $e;
5382 }
5483 break;
5584 case 'rebuild':
@@ -96,18 +125,18 @@
97126 exit( -1 );
98127 }
99128
100 -if( WikiError::isError( $ret ) ) {
 129+if( $ret instanceof MWException ) {
101130 echo $ret->getMessage() . "\n";
102131 exit( -1 );
103132 }
104133
105 -$status = MWSearchUpdater::getStatus();
106 -if( WikiError::isError( $status ) ) {
107 - echo $status->getMessage() . "\n";
108 - exit( -1 );
109 -} else {
 134+try {
 135+ $status = MWSearchUpdater::getStatus();
110136 echo $status . "\n";
111137 exit( 0 );
 138+} catch ( MWException $e ) {
 139+ echo $e->getMessage() . "\n";
 140+ exit( -1 );
112141 }
113142
114143
@@ -172,9 +201,10 @@
173202 $waittime = 10;
174203
175204 while( true ) {
176 - $status = MWSearchUpdater::getStatus();
177 - if( WikiError::isError( $status ) ) {
178 - echo $status->getMessage() . "\n";
 205+ try {
 206+ $status = MWSearchUpdater::getStatus();
 207+ } catch ( MWException $e ) {
 208+ echo $e->getMessage() . "\n";
179209 sleep( $waittime );
180210 continue;
181211 }
@@ -251,11 +281,12 @@
252282 }
253283
254284 $text = $rev->getText();
255 - $hit = MWSearchUpdater::updatePage( $wgDBname, $title, $text );
256 -
257 - if( WikiError::isError( $hit ) ) {
258 - echo "ERROR: " . $hit->getMessage() . "\n";
259 - $lastError = $hit;
 285+
 286+ try {
 287+ MWSearchUpdater::updatePage( $wgDBname, $title, $text );
 288+ } catch( MWException $e ) {
 289+ echo "ERROR: " . $e->getMessage() . "\n";
 290+ $lastError = $e;
260291 $errorCount++;
261292 if( $errorCount > 20 ) {
262293 echo "Lots of errors, giving up. :(\n";
@@ -307,10 +338,11 @@
308339 foreach ( $result as $row ) {
309340 $this->progress();
310341 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
311 - $hit = MWSearchUpdater::deletePage( $wgDBname, $title );
312 - if( WikiError::isError( $hit ) ) {
313 - echo "ERROR: " . $hit->getMessage() . "\n";
314 - $lastError = $hit;
 342+ try {
 343+ MWSearchUpdater::deletePage( $wgDBname, $title );
 344+ } catch ( MWException $e ) {
 345+ echo "ERROR: " . $e->getMessage() . "\n";
 346+ $lastError = $e;
315347 }
316348 }
317349
@@ -363,10 +395,11 @@
364396 $rev = new Revision( $row );
365397 if( is_object( $rev ) ) {
366398 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
367 - $hit = MWSearchUpdater::updatePage( $wgDBname, $title, $rev->getText() );
368 - if( WikiError::isError( $hit ) ) {
369 - echo "ERROR: " . $hit->getMessage() . "\n";
370 - $lastError = $hit;
 399+ try {
 400+ MWSearchUpdater::updatePage( $wgDBname, $title, $rev->getText() );
 401+ } catch ( MWException $e ) {
 402+ echo "ERROR: " . $e->getMessage() . "\n";
 403+ $lastError = $e;
371404 }
372405 }
373406 }

Status & tagging log