本文整理汇总了PHP中FileBackendGroup类的典型用法代码示例。如果您正苦于以下问题:PHP FileBackendGroup类的具体用法?PHP FileBackendGroup怎么用?PHP FileBackendGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileBackendGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpForeignRepo
private function setUpForeignRepo()
{
global $wgUploadDirectory;
$this->setMwGlobals('wgForeignFileRepos', [['class' => 'ForeignAPIRepo', 'name' => 'wikimediacommons', 'backend' => 'wikimediacommons-backend', 'apibase' => 'https://commons.wikimedia.org/w/api.php', 'hashLevels' => 2, 'fetchDescription' => true, 'descriptionCacheExpiry' => 43200, 'apiThumbCacheExpiry' => 86400, 'directory' => $wgUploadDirectory]]);
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
}
示例2: execute
public function execute()
{
$backend = FileBackendGroup::singleton()->get($this->getOption('b1'));
$this->doPerfTest($backend);
if ($this->getOption('b2')) {
$backend = FileBackendGroup::singleton()->get($this->getOption('b2'));
$this->doPerfTest($backend);
}
}
示例3: tearDown
protected function tearDown()
{
foreach ($this->savedGlobals as $var => $val) {
$GLOBALS[$var] = $val;
}
// Restore backends
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
parent::tearDown();
}
示例4: tearDown
public function tearDown()
{
foreach ($this->savedGlobals as $var => $val) {
$GLOBALS[$var] = $val;
}
// Restore backends
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
$this->teardownUploadDir($this->uploadDir);
}
示例5: execute
public function execute()
{
$backend = FileBackendGroup::singleton()->get($this->getOption('b1'));
$this->doPerfTest($backend);
if ($this->getOption('b2')) {
$backend = FileBackendGroup::singleton()->get($this->getOption('b2'));
$this->doPerfTest($backend);
}
$profiler = Profiler::instance();
$profiler->setTemplated(true);
//NOTE: as of MW1.21, $profiler->logData() is called implicitly by doMaintenance.php.
}
示例6: execute
public function execute()
{
$backend = FileBackendGroup::singleton()->get($this->getOption('b1'));
$this->doPerfTest($backend);
if ($this->getOption('b2')) {
$backend = FileBackendGroup::singleton()->get($this->getOption('b2'));
$this->doPerfTest($backend);
}
$profiler = Profiler::instance();
$profiler->setTemplated(true);
$profiler->logData();
// prints
}
示例7: getBackend
/**
* @return FileBackend
*/
public function getBackend()
{
global $wgCaptchaFileBackend, $wgCaptchaDirectory;
if ($wgCaptchaFileBackend) {
return FileBackendGroup::singleton()->get($wgCaptchaFileBackend);
} else {
static $backend = null;
if (!$backend) {
$backend = new FSFileBackend(array('name' => 'captcha-backend', 'wikiId' => wfWikiId(), 'lockManager' => new NullLockManager(array()), 'containerPaths' => array('captcha-render' => $wgCaptchaDirectory), 'fileMode' => 777));
}
return $backend;
}
}
示例8: __construct
/**
* @param $info array|null
* @throws MWException
*/
public function __construct(array $info = null)
{
// Verify required settings presence
if ($info === null || !array_key_exists('name', $info) || !array_key_exists('backend', $info)) {
throw new MWException(__CLASS__ . " requires an array of options having both 'name' and 'backend' keys.\n");
}
// Required settings
$this->name = $info['name'];
if ($info['backend'] instanceof FileBackend) {
$this->backend = $info['backend'];
// useful for testing
} else {
$this->backend = FileBackendGroup::singleton()->get($info['backend']);
}
// Optional settings that can have no value
$optionalSettings = array('descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', 'thumbScriptUrl', 'pathDisclosureProtection', 'descriptionCacheExpiry', 'scriptExtension');
foreach ($optionalSettings as $var) {
if (isset($info[$var])) {
$this->{$var} = $info[$var];
}
}
// Optional settings that have a default
$this->initialCapital = isset($info['initialCapital']) ? $info['initialCapital'] : MWNamespace::isCapitalized(NS_FILE);
$this->url = isset($info['url']) ? $info['url'] : false;
// a subclass may set the URL (e.g. ForeignAPIRepo)
if (isset($info['thumbUrl'])) {
$this->thumbUrl = $info['thumbUrl'];
} else {
$this->thumbUrl = $this->url ? "{$this->url}/thumb" : false;
}
$this->hashLevels = isset($info['hashLevels']) ? $info['hashLevels'] : 2;
$this->deletedHashLevels = isset($info['deletedHashLevels']) ? $info['deletedHashLevels'] : $this->hashLevels;
$this->transformVia404 = !empty($info['transformVia404']);
$this->abbrvThreshold = isset($info['abbrvThreshold']) ? $info['abbrvThreshold'] : 255;
$this->isPrivate = !empty($info['isPrivate']);
// Give defaults for the basic zones...
$this->zones = isset($info['zones']) ? $info['zones'] : array();
foreach (array('public', 'thumb', 'transcoded', 'temp', 'deleted') as $zone) {
if (!isset($this->zones[$zone]['container'])) {
$this->zones[$zone]['container'] = "{$this->name}-{$zone}";
}
if (!isset($this->zones[$zone]['directory'])) {
$this->zones[$zone]['directory'] = '';
}
if (!isset($this->zones[$zone]['urlsByExt'])) {
$this->zones[$zone]['urlsByExt'] = array();
}
}
}
示例9: execute
public function execute()
{
$src = FileBackendGroup::singleton()->get($this->getOption('src'));
$dst = FileBackendGroup::singleton()->get($this->getOption('dst'));
$posDir = $this->getOption('posdir');
$posFile = $posDir ? $posDir . '/' . wfWikiID() : false;
$start = $this->getOption('start', 0);
if (!$start && $posFile && is_dir($posDir)) {
$start = is_file($posFile) ? (int) trim(file_get_contents($posFile)) : 0;
++$start;
// we already did this ID, start with the next one
$startFromPosFile = true;
} else {
$startFromPosFile = false;
}
$end = $this->getOption('end', INF);
$this->output("Synchronizing backend '{$dst->getName()}' to '{$src->getName()}'...\n");
$this->output("Starting journal position is {$start}.\n");
if (is_finite($end)) {
$this->output("Ending journal position is {$end}.\n");
}
// Actually sync the dest backend with the reference backend
$lastOKPos = $this->syncBackends($src, $dst, $start, $end);
// Update the sync position file
if ($startFromPosFile && $lastOKPos >= $start) {
// successfully advanced
if (file_put_contents($posFile, $lastOKPos, LOCK_EX) !== false) {
$this->output("Updated journal position file.\n");
} else {
$this->output("Could not update journal position file.\n");
}
}
if ($lastOKPos === false) {
if (!$start) {
$this->output("No journal entries found.\n");
} else {
$this->output("No new journal entries found.\n");
}
} else {
$this->output("Stopped synchronization at journal position {$lastOKPos}.\n");
}
if ($this->isQuiet()) {
print $lastOKPos;
// give a single machine-readable number
}
}
示例10: store
/**
* @see ExternalStoreMedium::store()
*/
public function store($backend, $data)
{
$be = FileBackendGroup::singleton()->get($backend);
if ($be instanceof FileBackend) {
// Get three random base 36 characters to act as shard directories
$rand = wfBaseConvert(mt_rand(0, 46655), 10, 36, 3);
// Make sure ID is roughly lexicographically increasing for performance
$id = str_pad(UIDGenerator::newTimestampedUID128(32), 26, '0', STR_PAD_LEFT);
// Segregate items by wiki ID for the sake of bookkeeping
$wiki = isset($this->params['wiki']) ? $this->params['wiki'] : wfWikiID();
$url = $be->getContainerStoragePath('data') . '/' . rawurlencode($wiki) . "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}";
$be->prepare(array('dir' => dirname($url), 'noAccess' => 1, 'noListing' => 1));
if ($be->create(array('dst' => $url, 'content' => $data))->isOK()) {
return $url;
}
}
return false;
}
示例11: onBeforeRenderTimeline
/**
* Modify timeline extension to use Swift storage (BAC-893)
*
* @param FileBackend $backend
* @param string $fname mwstore abstract path
* @param string $hash file hash
* @return bool true - it's a hook
*/
static function onBeforeRenderTimeline(&$backend, &$fname, $hash)
{
global $wgEnableSwiftFileBackend, $wgFSSwiftContainer;
if (!empty($wgEnableSwiftFileBackend)) {
$backend = FileBackendGroup::singleton()->get('swift-backend');
$fname = 'mwstore://' . $backend->getName() . "/{$wgFSSwiftContainer}/images/timeline/{$hash}";
}
return true;
}
示例12: __construct
/**
* Construct a proxy backend that consists of several internal backends.
* Locking, journaling, and read-only checks are handled by the proxy backend.
*
* Additional $config params include:
* - backends : Array of backend config and multi-backend settings.
* Each value is the config used in the constructor of a
* FileBackendStore class, but with these additional settings:
* - class : The name of the backend class
* - isMultiMaster : This must be set for one backend.
* - template: : If given a backend name, this will use
* the config of that backend as a template.
* Values specified here take precedence.
* - syncChecks : Integer bitfield of internal backend sync checks to perform.
* Possible bits include the FileBackendMultiWrite::CHECK_* constants.
* There are constants for SIZE, TIME, and SHA1.
* The checks are done before allowing any file operations.
* - autoResync : Automatically resync the clone backends to the master backend
* when pre-operation sync checks fail. This should only be used
* if the master backend is stable and not missing any files.
* Use "conservative" to limit resyncing to copying newer master
* backend files over older (or non-existing) clone backend files.
* Cases that cannot be handled will result in operation abortion.
* - noPushQuickOps : (hack) Only apply doQuickOperations() to the master backend.
* - noPushDirConts : (hack) Only apply directory functions to the master backend.
*
* @param Array $config
* @throws MWException
*/
public function __construct( array $config ) {
parent::__construct( $config );
$this->syncChecks = isset( $config['syncChecks'] )
? $config['syncChecks']
: self::CHECK_SIZE;
$this->autoResync = isset( $config['autoResync'] )
? $config['autoResync']
: false;
$this->noPushQuickOps = isset( $config['noPushQuickOps'] )
? $config['noPushQuickOps']
: false;
$this->noPushDirConts = isset( $config['noPushDirConts'] )
? $config['noPushDirConts']
: array();
// Construct backends here rather than via registration
// to keep these backends hidden from outside the proxy.
$namesUsed = array();
foreach ( $config['backends'] as $index => $config ) {
if ( isset( $config['template'] ) ) {
// Config is just a modified version of a registered backend's.
// This should only be used when that config is used only by this backend.
$config = $config + FileBackendGroup::singleton()->config( $config['template'] );
}
$name = $config['name'];
if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
throw new MWException( "Two or more backends defined with the name $name." );
}
$namesUsed[$name] = 1;
// Alter certain sub-backend settings for sanity
unset( $config['readOnly'] ); // use proxy backend setting
unset( $config['fileJournal'] ); // use proxy backend journal
$config['wikiId'] = $this->wikiId; // use the proxy backend wiki ID
$config['lockManager'] = 'nullLockManager'; // lock under proxy backend
if ( !empty( $config['isMultiMaster'] ) ) {
if ( $this->masterIndex >= 0 ) {
throw new MWException( 'More than one master backend defined.' );
}
$this->masterIndex = $index; // this is the "master"
$config['fileJournal'] = $this->fileJournal; // log under proxy backend
}
// Create sub-backend object
if ( !isset( $config['class'] ) ) {
throw new MWException( 'No class given for a backend config.' );
}
$class = $config['class'];
$this->backends[$index] = new $class( $config );
}
if ( $this->masterIndex < 0 ) { // need backends and must have a master
throw new MWException( 'No master backend defined.' );
}
}
示例13: prepareEnvironment
protected function prepareEnvironment()
{
global $wgMemc;
// Don't share DB, storage, or memcached connections
MediaWikiServices::resetChildProcessServices();
FileBackendGroup::destroySingleton();
LockManagerGroup::destroySingletons();
JobQueueGroup::destroySingletons();
ObjectCache::clear();
RedisConnectionPool::destroySingletons();
$wgMemc = null;
}
示例14: execute
public function execute() {
$src = FileBackendGroup::singleton()->get( $this->getOption( 'src' ) );
$dst = FileBackendGroup::singleton()->get( $this->getOption( 'dst' ) );
$containers = explode( '|', $this->getOption( 'containers' ) );
$subDir = rtrim( $this->getOption( 'subdir', '' ), '/' );
$rateFile = $this->getOption( 'ratefile' );
if ( $this->hasOption( 'utf8only' ) && !extension_loaded( 'mbstring' ) ) {
$this->error( "Cannot check for UTF-8, mbstring extension missing.", 1 ); // die
}
foreach ( $containers as $container ) {
if ( $subDir != '' ) {
$backendRel = "$container/$subDir";
$this->output( "Doing container '$container', directory '$subDir'...\n" );
} else {
$backendRel = $container;
$this->output( "Doing container '$container'...\n" );
}
if ( $this->hasOption( 'missingonly' ) ) {
$this->output( "\tBuilding list of missing files..." );
$srcPathsRel = $this->getListingDiffRel( $src, $dst, $backendRel );
$this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" );
} else {
$srcPathsRel = $src->getFileList( array(
'dir' => $src->getRootStoragePath() . "/$backendRel",
'adviseStat' => true // avoid HEADs
) );
if ( $srcPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
}
if ( $this->getOption( 'prestat' ) && !$this->hasOption( 'missingonly' ) ) {
// Build the stat cache for the destination files
$this->output( "\tBuilding destination stat cache..." );
$dstPathsRel = $dst->getFileList( array(
'dir' => $dst->getRootStoragePath() . "/$backendRel",
'adviseStat' => true // avoid HEADs
) );
if ( $dstPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
$this->statCache = array(); // clear
foreach ( $dstPathsRel as $dstPathRel ) {
$path = $dst->getRootStoragePath() . "/$backendRel/$dstPathRel";
$this->statCache[sha1( $path )] = $dst->getFileStat( array( 'src' => $path ) );
}
$this->output( "done [" . count( $this->statCache ) . " file(s)]\n" );
}
$this->output( "\tCopying file(s)...\n" );
$count = 0;
$batchPaths = array();
foreach ( $srcPathsRel as $srcPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
$this->mBatchSize = max( 1, (int)file_get_contents( $rateFile ) );
$this->output( "\tBatch size is now {$this->mBatchSize}.\n" );
}
$batchPaths[$srcPathRel] = 1; // remove duplicates
if ( count( $batchPaths ) >= $this->mBatchSize ) {
$this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );
$batchPaths = array(); // done
}
++$count;
}
if ( count( $batchPaths ) ) { // left-overs
$this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );
$batchPaths = array(); // done
}
$this->output( "\tCopied $count file(s).\n" );
if ( $this->hasOption( 'syncviadelete' ) ) {
$this->output( "\tBuilding list of excess destination files..." );
$delPathsRel = $this->getListingDiffRel( $dst, $src, $backendRel );
$this->output( count( $delPathsRel ) . " file(s) need to be deleted.\n" );
$this->output( "\tDeleting file(s)...\n" );
$count = 0;
$batchPaths = array();
foreach ( $delPathsRel as $delPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
$this->mBatchSize = max( 1, (int)file_get_contents( $rateFile ) );
$this->output( "\tBatch size is now {$this->mBatchSize}.\n" );
}
$batchPaths[$delPathRel] = 1; // remove duplicates
if ( count( $batchPaths ) >= $this->mBatchSize ) {
$this->delFileBatch( array_keys( $batchPaths ), $backendRel, $dst );
$batchPaths = array(); // done
}
++$count;
}
if ( count( $batchPaths ) ) { // left-overs
$this->delFileBatch( array_keys( $batchPaths ), $backendRel, $dst );
$batchPaths = array(); // done
}
//.........这里部分代码省略.........
示例15: provider_testGetContentType
public static function provider_testGetContentType()
{
return [[null, false], [[FileBackendGroup::singleton(), 'guessMimeInternal'], true]];
}