X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=blobdiff_plain;f=includes%2Ffilebackend%2FFileBackendGroup.php;h=8b31f05c8390de26f2ed08d1d7caced59b69fcc2;hb=bb94f4964d1da0ed6a5fc3ae9f0e1b629a8cfd96;hp=a09160827b28a71b64d7e195da8b2f7d5e1e9702;hpb=500cbe99b66ddbacb57b8ade00e73ce24ad69a17;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index a09160827b..8b31f05c83 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -117,12 +117,14 @@ class FileBackendGroup { } $name = $config['name']; if ( isset( $this->backends[$name] ) ) { - throw new LogicException( "Backend with name `{$name}` already registered." ); + throw new LogicException( "Backend with name '$name' already registered." ); } elseif ( !isset( $config['class'] ) ) { - throw new InvalidArgumentException( "Backend with name `{$name}` has no class." ); + throw new InvalidArgumentException( "Backend with name '$name' has no class." ); } $class = $config['class']; + // @FIXME: ideally this would default to the DB domain (which includes the schema) + $config['domainId'] = $config['domainId'] ?? ( $config['wikiId'] ?? wfWikiID() ); $config['readOnly'] = $config['readOnly'] ?? $readOnlyReason; unset( $config['class'] ); // backend won't need this @@ -172,34 +174,40 @@ class FileBackendGroup { */ public function config( $name ) { if ( !isset( $this->backends[$name] ) ) { - throw new InvalidArgumentException( "No backend defined with the name `$name`." ); + throw new InvalidArgumentException( "No backend defined with the name '$name'." ); } - $class = $this->backends[$name]['class']; $config = $this->backends[$name]['config']; - $config['class'] = $class; - $config += [ // set defaults - // @FIXME: this does not include the domain for b/c but it ideally should - 'wikiId' => wfWikiID(), // e.g. "my_wiki-en_" - 'mimeCallback' => [ $this, 'guessMimeInternal' ], - 'obResetFunc' => 'wfResetOutputBuffers', - 'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ], - 'tmpDirectory' => wfTempDir(), - 'statusWrapper' => [ Status::class, 'wrap' ], - 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(), - 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), - 'logger' => LoggerFactory::getInstance( 'FileOperation' ), - 'profiler' => function ( $section ) { - return Profiler::instance()->scopedProfileIn( $section ); - } - ]; - $config['lockManager'] = - LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); - $config['fileJournal'] = isset( $config['fileJournal'] ) - ? FileJournal::factory( $config['fileJournal'], $name ) - : FileJournal::factory( [ 'class' => NullFileJournal::class ], $name ); - - return $config; + $services = MediaWikiServices::getInstance(); + + return array_merge( + // Default backend parameters + [ + 'mimeCallback' => [ $this, 'guessMimeInternal' ], + 'obResetFunc' => 'wfResetOutputBuffers', + 'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ], + 'tmpFileFactory' => $services->getTempFSFileFactory(), + 'statusWrapper' => [ Status::class, 'wrap' ], + 'wanCache' => $services->getMainWANObjectCache(), + 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), + 'logger' => LoggerFactory::getInstance( 'FileOperation' ), + 'profiler' => function ( $section ) { + return Profiler::instance()->scopedProfileIn( $section ); + } + ], + // Configured backend parameters + $config, + // Resolved backend parameters + [ + 'class' => $this->backends[$name]['class'], + 'lockManager' => + LockManagerGroup::singleton( $config['domainId'] ) + ->get( $config['lockManager'] ), + 'fileJournal' => isset( $config['fileJournal'] ) + ? FileJournal::factory( $config['fileJournal'], $name ) + : FileJournal::factory( [ 'class' => NullFileJournal::class ], $name ) + ] + ); } /** @@ -233,7 +241,8 @@ class FileBackendGroup { if ( !$type && $fsPath ) { $type = $magic->guessMimeType( $fsPath, false ); } elseif ( !$type && strlen( $content ) ) { - $tmpFile = TempFSFile::factory( 'mime_', '', wfTempDir() ); + $tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory() + ->newTempFSFile( 'mime_', '' ); file_put_contents( $tmpFile->getPath(), $content ); $type = $magic->guessMimeType( $tmpFile->getPath(), false ); }