MediaWiki  master
TableCleanup Class Reference

Generic class to cleanup a database table. More...

Inheritance diagram for TableCleanup:
Collaboration diagram for TableCleanup:

Public Member Functions

 __construct ()
 Default constructor. More...
 
 execute ()
 Do the actual work. More...
 
 runTable ( $params)
 
- Public Member Functions inherited from Maintenance
 checkRequiredExtensions ()
 Verify that the required extensions are installed. More...
 
 cleanupChanneled ()
 Clean up channeled output. More...
 
 clearParamsAndArgs ()
 Clear all params and arguments. More...
 
 finalSetup (SettingsBuilder $settingsBuilder=null)
 Handle some last-minute setup here. More...
 
 getConfig ()
 
 getDbType ()
 Does the script need different DB access? By default, we give Maintenance scripts normal rights to the DB. More...
 
 getName ()
 Get the script's name. More...
 
 getParameters ()
 
 globals ()
 Potentially debug globals. More...
 
 isQuiet ()
 
 loadParamsAndArgs ( $self=null, $opts=null, $args=null)
 Process command line arguments. More...
 
 loadSettings ()
 
 loadWithArgv ( $argv)
 Load params and arguments from a given array of command-line arguments. More...
 
 memoryLimit ()
 Normally we disable the memory_limit when running admin scripts. More...
 
 outputChanneled ( $msg, $channel=null)
 Message outputter with channeled message support. More...
 
 purgeRedundantText ( $delete=true)
 Support function for cleaning up redundant text records. More...
 
 runChild ( $maintClass, $classFile=null)
 Run a child maintenance script. More...
 
 setAgentAndTriggers ()
 This method used to be for internal use by doMaintenance.php to apply some optional global state to LBFactory for debugging purposes. More...
 
 setConfig (Config $config)
 
 setDB (IMaintainableDatabase $db)
 Sets database object to be returned by getDB(). More...
 
 setup ()
 Do some checking and basic setup. More...
 
 shutdown ()
 Call before exiting CLI process for the last DB commit, and flush any remaining buffers and other deferred work. More...
 
 validateParamsAndArgs ()
 Run some validation checks on the params, etc. More...
 

Public Attributes

 $count
 
 $startTime
 
 $table
 
 $updated
 
- Public Attributes inherited from Maintenance
resource null $fileHandle
 Used when creating separate schema files. More...
 
 $mDbPass
 
array $orderedOptions = []
 Used to read the options in the order they were passed. More...
 
const DB_ADMIN = 2
 
const DB_NONE = 0
 Constants for DB access type. More...
 
const DB_STD = 1
 
const GENERIC_MAINTENANCE_PARAMETERS = 'Generic maintenance parameters'
 
const SCRIPT_DEPENDENT_PARAMETERS = 'Script dependent parameters'
 
const STDIN_ALL = -1
 

Protected Member Functions

 hexChar ( $matches)
 
 init ( $count, $table)
 
 progress ( $updated)
 
- Protected Member Functions inherited from Maintenance
 addArg ( $arg, $description, $required=true)
 Add some args that are needed. More...
 
 addDefaultParams ()
 Add the default parameters to the scripts. More...
 
 addDescription ( $text)
 Set the description text. More...
 
 addOption ( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
 Add a parameter to the script. More...
 
 adjustMemoryLimit ()
 Adjusts PHP's memory limit to better suit our needs, if needed. More...
 
 afterFinalSetup ()
 Override to perform any required operation at the end of initialisation. More...
 
 beginTransaction (IDatabase $dbw, $fname)
 Begin a transaction on a DB. More...
 
 commitTransaction (IDatabase $dbw, $fname)
 Commit the transaction on a DB handle and wait for replica DBs to catch up. More...
 
 countDown ( $seconds)
 Count down from $seconds to zero on the terminal, with a one-second pause between showing each number. More...
 
 deleteOption ( $name)
 Remove an option. More...
 
 error ( $err, $die=0)
 Throw an error to the user. More...
 
 fatalError ( $msg, $exitCode=1)
 Output a message and terminate the current script. More...
 
 getArg ( $argId=0, $default=null)
 Get an argument. More...
 
 getBatchSize ()
 Returns batch size. More...
 
 getDB ( $db, $groups=[], $dbDomain=false)
 Returns a database to be used by current maintenance script. More...
 
 getDir ()
 Get the maintenance directory. More...
 
 getHookContainer ()
 Get a HookContainer, for running extension hooks or for hook metadata. More...
 
 getHookRunner ()
 Get a HookRunner for running core hooks. More...
 
 getOption ( $name, $default=null)
 Get an option, or return the default. More...
 
 getStdin ( $len=null)
 Return input from stdin. More...
 
 hasArg ( $argId=0)
 Does a given argument exist? More...
 
 hasOption ( $name)
 Checks to see if a particular option was set. More...
 
 loadSpecialVars ()
 Handle the special variables that are global to all scripts. More...
 
 maybeHelp ( $force=false)
 Maybe show the help. More...
 
 output ( $out, $channel=null)
 Throw some output to the user. More...
 
 parseIntList ( $text)
 Utility function to parse a string (perhaps from a command line option) into a list of integers (perhaps some kind of numeric IDs). More...
 
 requireExtension ( $name)
 Indicate that the specified extension must be loaded before the script can run. More...
 
 rollbackTransaction (IDatabase $dbw, $fname)
 Rollback the transaction on a DB handle. More...
 
 setAllowUnregisteredOptions ( $allow)
 Sets whether to allow unregistered options, which are options passed to a script that do not match an expected parameter. More...
 
 setBatchSize ( $s=0)
 
 showHelp ()
 Definitely show the help. More...
 
 supportsOption ( $name)
 Checks to see if a particular option in supported. More...
 
 validateUserOption ( $errorMsg)
 
 waitForReplication ()
 Wait for replica DBs to catch up. More...
 

Protected Attributes

 $defaultParams
 
 $dryrun = false
 
 $processed
 
 $reportInterval = 100
 
- Protected Attributes inherited from Maintenance
array $mArgList = []
 Empty. More...
 
array $mArgs = []
 This is the list of arguments that were actually passed. More...
 
int null $mBatchSize = null
 Batch size. More...
 
 $mDbUser
 
string $mDescription = ''
 A description of the script, children should change this via addDescription() More...
 
bool $mInputLoaded = false
 Have we already loaded our user input? More...
 
array $mOptions = []
 This is the list of options that were actually passed. More...
 
array[] $mParams = []
 Empty. More...
 
bool $mQuiet = false
 Special vars for params that are always used. More...
 
string null $mSelf
 Name of the script currently running. More...
 
MaintenanceParameters $parameters
 

Additional Inherited Members

- Static Public Member Functions inherited from Maintenance
static getTermSize ()
 Get the terminal size as a two-element array where the first element is the width (number of columns) and the second element is the height (number of rows). More...
 
static posix_isatty ( $fd)
 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. More...
 
static readconsole ( $prompt='> ')
 Prompt the console for input. More...
 
static requireTestsAutoloader ()
 Call this to set up the autoloader to allow classes to be used from the tests directory. More...
 
static shouldExecute ()
 

Detailed Description

Generic class to cleanup a database table.

Already subclasses Maintenance.

Definition at line 31 of file TableCleanup.php.

Constructor & Destructor Documentation

◆ __construct()

TableCleanup::__construct ( )

Default constructor.

Children should call this first if implementing their own constructors

Stability: stable
to call

Reimplemented from Maintenance.

Reimplemented in CleanupWatchlist, TitleCleanup, CleanupImages, and CleanupCaps.

Definition at line 44 of file TableCleanup.php.

References Maintenance\addOption(), and Maintenance\setBatchSize().

Member Function Documentation

◆ execute()

TableCleanup::execute ( )

Do the actual work.

All child classes will need to implement this

Returns
bool|null|void True for success, false for failure. Not returning a value, or returning null, is also interpreted as success. Returning false for failure will cause doMaintenance.php to exit the process with a non-zero exit status.

Reimplemented from Maintenance.

Reimplemented in CleanupWatchlist, and CleanupCaps.

Definition at line 51 of file TableCleanup.php.

References Maintenance\getOption(), Maintenance\hasOption(), Maintenance\output(), and runTable().

◆ hexChar()

TableCleanup::hexChar (   $matches)
protected
Parameters
string[]$matches
Returns
string

Definition at line 174 of file TableCleanup.php.

References $matches.

◆ init()

TableCleanup::init (   $count,
  $table 
)
protected

Definition at line 65 of file TableCleanup.php.

References $count, and $table.

Referenced by runTable().

◆ progress()

◆ runTable()

TableCleanup::runTable (   $params)
Parameters
array$params
Exceptions
MWException

Definition at line 110 of file TableCleanup.php.

References $count, $dbr, $res, $table, DB_REPLICA, Maintenance\getBatchSize(), Maintenance\getDB(), init(), and Maintenance\output().

Referenced by CleanupCaps\execute(), and execute().

Member Data Documentation

◆ $count

TableCleanup::$count

Definition at line 42 of file TableCleanup.php.

Referenced by init(), progress(), and runTable().

◆ $defaultParams

TableCleanup::$defaultParams
protected
Initial value:
= [
'table' => 'page',
'conds' => [],
'index' => 'page_id',
'callback' => 'processRow',
]

Definition at line 32 of file TableCleanup.php.

◆ $dryrun

TableCleanup::$dryrun = false
protected

Definition at line 39 of file TableCleanup.php.

◆ $processed

TableCleanup::$processed
protected

Definition at line 42 of file TableCleanup.php.

Referenced by progress().

◆ $reportInterval

TableCleanup::$reportInterval = 100
protected

Definition at line 40 of file TableCleanup.php.

◆ $startTime

TableCleanup::$startTime

Definition at line 42 of file TableCleanup.php.

Referenced by progress().

◆ $table

TableCleanup::$table

Definition at line 42 of file TableCleanup.php.

Referenced by init(), and runTable().

◆ $updated

TableCleanup::$updated

Definition at line 42 of file TableCleanup.php.

Referenced by CleanupWatchlist\processRow(), and progress().


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