r113859 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113858‎ | r113859 | r113860 >
Date:21:30, 14 March 2012
Author:aaron
Status:reverted
Tags:gerritmigration 
Comment:
[FileRepo]
* Added getReadOnlyReason() function to FileRepo to check read-only status. Added such checks to the File object functions that mutate files in storage. This should make read-only mode more tolerable (which is needed at least briefly when switching backends).
* Added lock()/unlock() calls to File restore() function.
* Use proper isOK() accessor for Status objects.
Modified paths:
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/file/LocalFile.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -408,6 +408,7 @@
409409 'customjsprotected',
410410 'ns-specialprotected',
411411 'titleprotected',
 412+ 'filereadonlyerror'
412413 ),
413414 'virus' => array(
414415 'virus-badscanner',
Index: trunk/phase3/includes/filerepo/file/LocalFile.php
@@ -908,9 +908,13 @@
909909 */
910910 function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null ) {
911911 global $wgContLang;
 912+
 913+ if ( $this->getRepo()->getReadOnlyReason() !== false ) {
 914+ return $this->readOnlyFatalStatus();
 915+ }
 916+
912917 // truncate nicely or the DB will do it for us
913 - // non-nicely (dangling multi-byte chars, non-truncated
914 - // version in cache).
 918+ // non-nicely (dangling multi-byte chars, non-truncated version in cache).
915919 $comment = $wgContLang->truncate( $comment, 255 );
916920 $this->lock(); // begin
917921 $status = $this->publish( $srcPath, $flags );
@@ -1175,6 +1179,10 @@
11761180 * archive name, or an empty string if it was a new file.
11771181 */
11781182 function publishTo( $srcPath, $dstRel, $flags = 0 ) {
 1183+ if ( $this->getRepo()->getReadOnlyReason() !== false ) {
 1184+ return $this->readOnlyFatalStatus();
 1185+ }
 1186+
11791187 $this->lock(); // begin
11801188
11811189 $archiveName = wfTimestamp( TS_MW ) . '!'. $this->getName();
@@ -1211,6 +1219,10 @@
12121220 * @return FileRepoStatus object.
12131221 */
12141222 function move( $target ) {
 1223+ if ( $this->getRepo()->getReadOnlyReason() !== false ) {
 1224+ return $this->readOnlyFatalStatus();
 1225+ }
 1226+
12151227 wfDebugLog( 'imagemove', "Got request to move {$this->name} to " . $target->getText() );
12161228 $this->lock(); // begin
12171229
@@ -1250,6 +1262,10 @@
12511263 * @return FileRepoStatus object.
12521264 */
12531265 function delete( $reason, $suppress = false ) {
 1266+ if ( $this->getRepo()->getReadOnlyReason() !== false ) {
 1267+ return $this->readOnlyFatalStatus();
 1268+ }
 1269+
12541270 $this->lock(); // begin
12551271
12561272 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
@@ -1266,7 +1282,7 @@
12671283 }
12681284 $status = $batch->execute();
12691285
1270 - if ( $status->ok ) {
 1286+ if ( $status->isOK() ) {
12711287 // Update site_stats
12721288 $site_stats = $dbw->tableName( 'site_stats' );
12731289 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", __METHOD__ );
@@ -1293,6 +1309,10 @@
12941310 * @return FileRepoStatus object.
12951311 */
12961312 function deleteOld( $archiveName, $reason, $suppress = false ) {
 1313+ if ( $this->getRepo()->getReadOnlyReason() !== false ) {
 1314+ return $this->readOnlyFatalStatus();
 1315+ }
 1316+
12971317 $this->lock(); // begin
12981318
12991319 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
@@ -1302,7 +1322,7 @@
13031323
13041324 $this->unlock(); // done
13051325
1306 - if ( $status->ok ) {
 1326+ if ( $status->isOK() ) {
13071327 $this->purgeDescription();
13081328 $this->purgeHistory();
13091329 }
@@ -1322,6 +1342,12 @@
13231343 * @return FileRepoStatus
13241344 */
13251345 function restore( $versions = array(), $unsuppress = false ) {
 1346+ if ( $this->getRepo()->getReadOnlyReason() !== false ) {
 1347+ return $this->readOnlyFatalStatus();
 1348+ }
 1349+
 1350+ $this->lock(); // begin
 1351+
13261352 $batch = new LocalFileRestoreBatch( $this, $unsuppress );
13271353
13281354 if ( !$versions ) {
@@ -1332,14 +1358,14 @@
13331359
13341360 $status = $batch->execute();
13351361
1336 - if ( !$status->isGood() ) {
1337 - return $status;
 1362+ if ( $status->isGood() ) {
 1363+ $cleanupStatus = $batch->cleanup();
 1364+ $cleanupStatus->successCount = 0;
 1365+ $cleanupStatus->failCount = 0;
 1366+ $status->merge( $cleanupStatus );
13381367 }
13391368
1340 - $cleanupStatus = $batch->cleanup();
1341 - $cleanupStatus->successCount = 0;
1342 - $cleanupStatus->failCount = 0;
1343 - $status->merge( $cleanupStatus );
 1369+ $this->unlock(); // done
13441370
13451371 return $status;
13461372 }
@@ -1443,6 +1469,14 @@
14441470 $dbw = $this->repo->getMasterDB();
14451471 $dbw->rollback( __METHOD__ );
14461472 }
 1473+
 1474+ /**
 1475+ * @return Status
 1476+ */
 1477+ protected function readOnlyFatalStatus() {
 1478+ return $this->getRepo()->newFatal( 'filereadonlyerror', $this->getName(),
 1479+ $this->getRepo()->getName(), $this->getRepo()->getReadOnlyReason() );
 1480+ }
14471481 } // LocalFile class
14481482
14491483 # ------------------------------------------------------------------------------
@@ -1710,7 +1744,7 @@
17111745 $this->status->merge( $status );
17121746 }
17131747
1714 - if ( !$this->status->ok ) {
 1748+ if ( !$this->status->isOK() ) {
17151749 // Critical file deletion error
17161750 // Roll back inserts, release lock and abort
17171751 // TODO: delete the defunct filearchive rows if we are using a non-transactional DB
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -120,6 +120,15 @@
121121 }
122122
123123 /**
 124+ * Get an explanatory message if this repo is read-only
 125+ *
 126+ * @return string|bool Returns false if the repo is not read-only
 127+ */
 128+ public function getReadOnlyReason() {
 129+ return $this->backend->getReadOnlyReason();
 130+ }
 131+
 132+ /**
124133 * Prepare a single zone or list of zones for usage.
125134 * See initDeletedDir() for additional setup needed for the 'deleted' zone.
126135 *
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -997,6 +997,9 @@
998998 'directorycreateerror' => 'Could not create directory "$1".',
999999 'filenotfound' => 'Could not find file "$1".',
10001000 'fileexistserror' => 'Unable to write to file "$1": File exists.',
 1001+'filereadonlyerror' => 'Unable to the modify the file "$1" because the file repository "$2" is in read-only mode.
 1002+
 1003+The administrator who locked it offered this explanation: "$3".',
10011004 'unexpected' => 'Unexpected value: "$1"="$2".',
10021005 'formerror' => 'Error: Could not submit form.',
10031006 'badarticleerror' => 'This action cannot be performed on this page.',

Follow-up revisions

RevisionCommit summaryAuthorDate
r114335Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893......catrope00:16, 21 March 2012

Status & tagging log