X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2FLocalRepo.php;h=18529126e0ab6d22be35c8e85da0fbd9fd9e8195;hb=0ea03a7f56070956838ab360a5dccc2a506fc4ff;hp=800a230de9ddb2d277b5aa571e959cc2a6e28bd8;hpb=399ba814a09dd48ae188c1cf93e6c13b7d56a12f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 800a230de9..18529126e0 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -29,6 +29,9 @@ * @ingroup FileRepo */ class LocalRepo extends FileRepo { + /** @var bool */ + protected $hasSha1Storage = false; + /** @var array */ protected $fileFactory = array( 'LocalFile', 'newFromTitle' ); @@ -47,6 +50,20 @@ class LocalRepo extends FileRepo { /** @var array */ protected $oldFileFactoryKey = array( 'OldLocalFile', 'newFromKey' ); + function __construct( array $info = null ) { + parent::__construct( $info ); + + $this->hasSha1Storage = isset( $info['storageLayout'] ) && $info['storageLayout'] === 'sha1'; + + if ( $this->hasSha1Storage() ) { + $this->backend = new FileBackendDBRepoWrapper( array( + 'backend' => $this->backend, + 'repoName' => $this->name, + 'dbHandleFactory' => $this->getDBFactory() + ) ); + } + } + /** * @throws MWException * @param stdClass $row @@ -82,6 +99,11 @@ class LocalRepo extends FileRepo { * @return FileRepoStatus */ function cleanupDeletedBatch( array $storageKeys ) { + if ( $this->hasSha1Storage() ) { + wfDebug( __METHOD__ . ": skipped because storage uses sha1 paths\n" ); + return Status::newGood(); + } + $backend = $this->backend; // convenience $root = $this->getZonePath( 'deleted' ); $dbw = $this->getMasterDB(); @@ -469,6 +491,16 @@ class LocalRepo extends FileRepo { return wfGetDB( DB_MASTER ); } + /** + * Get a callback to get a DB handle given an index (DB_SLAVE/DB_MASTER) + * @return Closure + */ + protected function getDBFactory() { + return function( $index ) { + return wfGetDB( $index ); + }; + } + /** * Get a key on the primary cache for this repository. * Returns false if the repository's cache is not accessible at this site. @@ -514,4 +546,56 @@ class LocalRepo extends FileRepo { 'favicon' => wfExpandUrl( $wgFavicon ), ) ); } + + public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + public function storeBatch( array $triplets, $flags = 0 ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + public function cleanupBatch( array $files, $flags = 0 ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + public function publish( + $srcPath, + $dstRel, + $archiveRel, + $flags = 0, + array $options = array() + ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + public function publishBatch( array $ntuples, $flags = 0 ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + public function delete( $srcRel, $archiveRel ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + public function deleteBatch( array $sourceDestPairs ) { + return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() ); + } + + /** + * Skips the write operation if storage is sha1-based, executes it normally otherwise + * + * @param string $function + * @param array $args + * @return FileRepoStatus + */ + protected function skipWriteOperationIfSha1( $function, array $args ) { + $this->assertWritableRepo(); // fail out if read-only + + if ( $this->hasSha1Storage() ) { + wfDebug( __METHOD__ . ": skipped because storage uses sha1 paths\n" ); + return Status::newGood(); + } else { + return call_user_func_array('parent::' . $function, $args ); + } + } }