BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
Maintenance Class Reference

Inherited by AllTrans, AlterSharedConstraints, AttachLatest, BackfillUnreadWikis, BackupDumper, BackupReader, BatchedQueryRunner, Benchmarker, BenchmarkParse, BSMaintenance, CachePendingRevs, ChangePassword, ChangeSMWOffsetNamespaceIds, CheckBadRedirects, CheckComposerLockUpToDate, CheckImages, CheckLess, CheckSyntax, CheckUsernames, CleanupAncientTables, CleanupArchiveUserText, CleanupBlocks, CleanupPreferences, CleanupRemovedModules, CleanupSpam, ClearInterwikiCache, CLIParser, CommandLineInc, CommandLineInstaller, CompareParserCache, CompressOld, ConfirmUserEMail, ConvertExtensionToRegistration, ConvertLinks, ConvertUserOptions, CopyFileBackend, CopyJobQueue, CreateAndPromote, CreateAvatarHTML, DatabaseLag, DateFormats, DeleteArchivedFiles, DeleteArchivedRevisions, DeleteBatch, DeleteDefaultMessages, DeleteEqualMessages, DeleteOldRevisions, DeleteOrphanedRevisions, DeleteRevision, DeleteSelfExternals, Digit2Html, DumpIterator, DumpLinks, DumpMessages, DumpRenderer, DumpRev, EditCLI, EraseArchivedFile, ExpireAll, ExportSites, FakeMaintenance, FetchText, FindDeprecated, FindHooks, FindMissingFiles, FindOrphanedFiles, FixBug20757, FixBug28348, FixDoubleRedirects, FixOldImage, FixTimestamps, FixUserRegistration, FlagProtectToSemiProtect, GenerateCollationData, GenerateCommonPassword, GenerateJqueryMsgData, GenerateNormalizerDataAr, GenerateNormalizerDataMl, GenerateRandomImages, GenerateSampleNotifications, GenerateSitemap, GetConfiguration, GetLagTimes, GetSlaveServer, GetTextMaint, HitCounters\UpdateHitCounter, ImageBuilder, ImportSites, ImportSiteScripts, ImportTextFiles, InitEditCount, InitSiteStats, JSParseHelper, LangMemUsage, ListVariants, LoggedUpdateMaintenance, MaintenanceFixup, MaintenanceFormatInstallDoc, MakeTestEdits, McTest, MergeMessageFileList, MigrateFileRepoLayout, MigrateSemanticFormsToPageForms, MigrateUserGroup, MinifyScript, ModifyExportXML, MoveBatch, MWDocGen, MwSql, NamespaceConflictChecker, NukeNS, NukePage, Orphans, OrphanStats, PageExists, PatchSql, PHPUnitMaintClass, PopulateCategory, PopulateContentModel, PopulateFRRevTimestamp, ProcessBsEchoEmailBatch, ProcessEchoEmailBatch, Protect, PruneFileCache, PruneFRIncludeData, PurgeChangedFiles, PurgeChangedPages, PurgeList, PurgeOldText, PurgeParserCache, PurgeReviewablePages, RatedCommentsArchiveRatingsAShoutsInRCNs, ReassignEdits, RebuildAll, RebuildFileCache, RebuildLocalisationCache, RebuildMessages, RebuildRecentchanges, RebuildSitesCache, RebuildTextIndex, RebuildTitleKeys, RefreshFileHeaders, RefreshImageMetadata, RefreshLinks, RelocalizeWiki, RemoveInvalidEmails, RemoveInvalidNotification, RemoveInvalidTargetPage, RemoveUnusedAccounts, RenameAndMergeUserToStrLower, RenameDbPrefix, RenameUserCleanup, ReplaceText, ResetUserEmail, ResetUserImages, ResetUserTokens, ReviewAllPages, RollbackEdits, RunJobs, RunNotifications, SearchDeleteIndex, ShowJobs, ShowSiteStats, SMW\Maintenance\DumpRdf, SMW\Maintenance\RebuildConceptCache, SMW\Maintenance\RebuildData, SMW\Maintenance\RebuildPropertyStatistics, SMW\Maintenance\SetupStore, SqliteMaintenance, StorageTypeStats, SyncFileBackend, TableCleanup, TestDiscussionParser, TestFileOpPerformance, TidyUpBug37714, Undelete, UpdateArticleCount, UpdateCollation, UpdateCSS, UpdateDoubleWidthSearch, UpdateEchoSchemaForSuppression, UpdateFlaggedRevsQueryCache, UpdateFlaggedRevsStats, UpdateFRAutoPromote, UpdateFRTracking, UpdateLanguageList, UpdateMediaWiki, UpdateRestrictions, UpdateSearchIndex, UpdateSpecialPages, UploadDumper, UploadStashCleanup, ValidateRegistrationFile, and WrapOldPasswords.

Public Member Functions

 __construct ()
 
 execute ()
 
 getName ()
 
 isQuiet ()
 
 cleanupChanneled ()
 
 outputChanneled ($msg, $channel=null)
 
 getDbType ()
 
 getConfig ()
 
 setConfig (Config $config)
 
 setup ()
 
 memoryLimit ()
 
 clearParamsAndArgs ()
 
 loadWithArgv ($argv)
 
 loadParamsAndArgs ($self=null, $opts=null, $args=null)
 
 globals ()
 
 loadSettings ()
 
 purgeRedundantText ($delete=true)
 
 setDB (IDatabase $db)
 
 updateSearchIndex ($maxLockTime, $callback, $dbw, $results)
 
 updateSearchIndexForPage ($dbw, $pageId)
 

Static Public Member Functions

static shouldExecute ()
 
static posix_isatty ($fd)
 
static readconsole ($prompt= '> ')
 

Public Attributes

const DB_NONE = 0
 
const DB_STD = 1
 
const DB_ADMIN = 2
 
const STDIN_ALL = 'all'
 
 $mDbPass
 
 $fileHandle
 
 $orderedOptions = []
 

Protected Member Functions

 addOption ($name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
 
 hasOption ($name)
 
 getOption ($name, $default=null)
 
 addArg ($arg, $description, $required=true)
 
 deleteOption ($name)
 
 addDescription ($text)
 
 hasArg ($argId=0)
 
 getArg ($argId=0, $default=null)
 
 setBatchSize ($s=0)
 
 getStdin ($len=null)
 
 output ($out, $channel=null)
 
 error ($err, $die=0)
 
 addDefaultParams ()
 
 adjustMemoryLimit ()
 
 activateProfiler ()
 
 validateParamsAndArgs ()
 
 loadSpecialVars ()
 
 maybeHelp ($force=false)
 
 afterFinalSetup ()
 
 getDir ()
 
 getDB ($db, $groups=[], $wiki=false)
 
 beginTransaction (IDatabase $dbw, $fname)
 
 commitTransaction (IDatabase $dbw, $fname)
 
 rollbackTransaction (IDatabase $dbw, $fname)
 

Protected Attributes

 $mParams = []
 
 $mShortParamsMap = []
 
 $mArgList = []
 
 $mOptions = []
 
 $mArgs = []
 
 $mSelf
 
 $mQuiet = false
 
 $mDbUser
 
 $mDescription = ''
 
 $mInputLoaded = false
 
 $mBatchSize = null
 

Detailed Description

Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effort. All that must be defined is the execute() method. See docs/maintenance.txt for more info and a quick demo of how to use it.

Author
Chad Horohoe chad@.nosp@m.anyo.nosp@m.necan.nosp@m.edit.nosp@m..org
Since
1.16

Constructor & Destructor Documentation

Maintenance::__construct ( )

Default constructor. Children should call this first if implementing their own constructors

Member Function Documentation

Maintenance::activateProfiler ( )
protected

Activate the profiler (assuming $wgProfiler is set)

Maintenance::addArg (   $arg,
  $description,
  $required = true 
)
protected

Add some args that are needed

Parameters
string$argName of the arg, like 'start'
string$descriptionShort description of the arg
bool$requiredIs this required?
Maintenance::addDefaultParams ( )
protected

Add the default parameters to the scripts

Maintenance::addDescription (   $text)
protected

Set the description text.

Parameters
string$textThe text of the description
Maintenance::addOption (   $name,
  $description,
  $required = false,
  $withArg = false,
  $shortName = false,
  $multiOccurrence = false 
)
protected

Add a parameter to the script. Will be displayed on –help with the associated description

Parameters
string$nameThe name of the param (help, version, etc)
string$descriptionThe description of the param to show on –help
bool$requiredIs the param required?
bool$withArgIs an argument required with this option?
string$shortNameCharacter to use as short name
bool$multiOccurrenceCan this option be passed multiple times?
Maintenance::adjustMemoryLimit ( )
protected

Adjusts PHP's memory limit to better suit our needs, if needed.

Maintenance::afterFinalSetup ( )
protected

Execute a callback function at the end of initialisation

Maintenance::beginTransaction ( IDatabase  $dbw,
  $fname 
)
protected

Begin a transcation on a DB

This method makes it clear that begin() is called from a maintenance script, which has outermost scope. This is safe, unlike $dbw->begin() called in other places.

Parameters
IDatabase$dbw
string$fnameCaller name
Since
1.27
Maintenance::cleanupChanneled ( )

Clean up channeled output. Output a newline if necessary.

Maintenance::clearParamsAndArgs ( )

Clear all params and arguments.

Maintenance::commitTransaction ( IDatabase  $dbw,
  $fname 
)
protected

Commit the transcation on a DB handle and wait for slaves to catch up

This method makes it clear that commit() is called from a maintenance script, which has outermost scope. This is safe, unlike $dbw->commit() called in other places.

Parameters
IDatabase$dbw
string$fnameCaller name
Returns
bool Whether the slave wait succeeded
Since
1.27
Maintenance::deleteOption (   $name)
protected

Remove an option. Useful for removing options that won't be used in your script.

Parameters
string$nameThe option to remove.
Maintenance::error (   $err,
  $die = 0 
)
protected

Throw an error to the user. Doesn't respect –quiet, so don't use this for non-error output

Parameters
string$errThe error to display
int$dieIf > 0, go ahead and die out using this int as the code
Maintenance::execute ( )
abstract

Do the actual work. All child classes will need to implement this

Maintenance::getArg (   $argId = 0,
  $default = null 
)
protected

Get an argument.

Parameters
int$argIdThe integer value (from zero) for the arg
mixed$defaultThe default if it doesn't exist
Returns
mixed
Maintenance::getConfig ( )
Since
1.24
Returns
Config
Maintenance::getDB (   $db,
  $groups = [],
  $wiki = false 
)
protected

Returns a database to be used by current maintenance script. It can be set by setDB(). If not set, wfGetDB() will be used. This function has the same parameters as wfGetDB()

Parameters
integer$dbDB index (DB_SLAVE/DB_MASTER)
array$groups,;default: empty array
string | bool$wiki,;default: current wiki
Returns
IDatabase
Maintenance::getDbType ( )

Does the script need different DB access? By default, we give Maintenance scripts normal rights to the DB. Sometimes, a script needs admin rights access for a reason and sometimes they want no access. Subclasses should override and return one of the following values, as needed: Maintenance::DB_NONE - For no DB access at all Maintenance::DB_STD - For normal DB access, default Maintenance::DB_ADMIN - For admin DB access

Returns
int
Maintenance::getDir ( )
protected

Get the maintenance directory.

Returns
string
Maintenance::getName ( )

Get the script's name

Returns
string
Maintenance::getOption (   $name,
  $default = null 
)
protected

Get an option, or return the default.

If the option was added to support multiple occurrences, this will return an array.

Parameters
string$nameThe name of the param
mixed$defaultAnything you want, default null
Returns
mixed
Maintenance::getStdin (   $len = null)
protected

Return input from stdin.

Parameters
int$lenThe number of bytes to read. If null, just return the handle. Maintenance::STDIN_ALL returns the full length
Returns
mixed
Maintenance::globals ( )

Potentially debug globals. Originally a feature only for refreshLinks

Maintenance::hasArg (   $argId = 0)
protected

Does a given argument exist?

Parameters
int$argIdThe integer value (from zero) for the arg
Returns
bool
Maintenance::hasOption (   $name)
protected

Checks to see if a particular param exists.

Parameters
string$nameThe name of the param
Returns
bool
Maintenance::isQuiet ( )
Returns
bool
Maintenance::loadParamsAndArgs (   $self = null,
  $opts = null,
  $args = null 
)

Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs becomes a zero-based array containing the non-option arguments

Parameters
string$selfThe name of the script, if any
array$optsAn array of options, in form of key=>value
array$argsAn array of command line arguments
Maintenance::loadSettings ( )

Generic setup for most installs. Returns the location of LocalSettings

Returns
string
Maintenance::loadSpecialVars ( )
protected

Handle the special variables that are global to all scripts

Maintenance::loadWithArgv (   $argv)

Load params and arguments from a given array of command-line arguments

Since
1.27
Parameters
array$argv
Maintenance::maybeHelp (   $force = false)
protected

Maybe show the help.

Parameters
bool$forceWhether to force the help to show, default false
Maintenance::memoryLimit ( )

Normally we disable the memory_limit when running admin scripts. Some scripts may wish to actually set a limit, however, to avoid blowing up unexpectedly. We also support a –memory-limit option, to allow sysadmins to explicitly set one if they'd prefer to override defaults (or for people using Suhosin which yells at you for trying to disable the limits)

Returns
string
Maintenance::output (   $out,
  $channel = null 
)
protected

Throw some output to the user. Scripts can call this with no fears, as we handle all –quiet stuff here

Parameters
string$outThe text to show to the user
mixed$channelUnique identifier for the channel. See function outputChanneled.
Maintenance::outputChanneled (   $msg,
  $channel = null 
)

Message outputter with channeled message support. Messages on the same channel are concatenated, but any intervening messages in another channel start a new line.

Parameters
string$msgThe message without trailing newline
string$channelChannel identifier or null for no channel. Channel comparison uses ===.
static Maintenance::posix_isatty (   $fd)
static

Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but treating stout as not a tty to avoid color codes

Parameters
mixed$fdFile descriptor
Returns
bool
Maintenance::purgeRedundantText (   $delete = true)

Support function for cleaning up redundant text records

Parameters
bool$deleteWhether or not to actually delete the records
Author
Rob Church robch.nosp@m.ur@g.nosp@m.mail..nosp@m.com
static Maintenance::readconsole (   $prompt = ',
 
)
static

Prompt the console for input

Parameters
string$promptWhat to begin the line with, like '> '
Returns
string Response
Maintenance::rollbackTransaction ( IDatabase  $dbw,
  $fname 
)
protected

Rollback the transcation on a DB handle

This method makes it clear that rollback() is called from a maintenance script, which has outermost scope. This is safe, unlike $dbw->rollback() called in other places.

Parameters
IDatabase$dbw
string$fnameCaller name
Since
1.27
Maintenance::setBatchSize (   $s = 0)
protected

Set the batch size.

Parameters
int$sThe number of operations to do in a batch
Maintenance::setConfig ( Config  $config)
Since
1.24
Parameters
Config$config
Maintenance::setDB ( IDatabase  $db)

Sets database object to be returned by getDB().

Parameters
IDatabase$dbDatabase object to be used
Maintenance::setup ( )

Do some sanity checking and basic setup

static Maintenance::shouldExecute ( )
static

Should we execute the maintenance script, or just allow it to be included as a standalone class? It checks that the call stack only includes this function and "requires" (meaning was called from the file scope)

Returns
bool
Maintenance::updateSearchIndex (   $maxLockTime,
  $callback,
  $dbw,
  $results 
)

Perform a search index update with locking

Parameters
int$maxLockTimeThe maximum time to keep the search index locked.
string$callbackThe function that will update the function.
DatabaseBase$dbw
array$results
Maintenance::updateSearchIndexForPage (   $dbw,
  $pageId 
)

Update the searchindex table for a given pageid

Parameters
DatabaseBase$dbwA database write handle
int$pageIdThe page ID to update.
Returns
null|string
Maintenance::validateParamsAndArgs ( )
protected

Run some validation checks on the params, etc

Member Data Documentation

const Maintenance::DB_NONE = 0

Constants for DB access type

See Also
Maintenance::getDbType()

The documentation for this class was generated from the following file: