MediaWiki
master
Toggle main menu visibility
LoggedUpdateMaintenance.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\Maintenance
;
8
14
abstract
class
LoggedUpdateMaintenance
extends
Maintenance
{
15
16
public
function
__construct
() {
17
parent::__construct();
18
$this->
addOption
(
'force'
,
'Run the update even if it was completed already'
);
19
$this->
setBatchSize
( 200 );
20
}
21
23
public
function
execute
() {
24
if
( !$this->
hasOption
(
'force'
) && $this->
isAlreadyCompleted
() ) {
25
$this->
output
(
"..."
. $this->
updateSkippedMessage
() .
" Use --force to run it again.\n"
);
26
return
true
;
27
}
28
29
$result = $this->
doDBUpdates
();
30
31
if
( is_bool( $result ) ) {
32
// NOTE: returning a boolean value from doDBUpdates() is deprecated
33
// since 1.46, but a lot of subclasses still do.
34
// TODO: make this emit a deprecation warning.
35
$result = $result ? LoggedUpdateOutcome::COMPLETE : LoggedUpdateOutcome::FAILED;
36
}
37
38
if
( $result === LoggedUpdateOutcome::FAILED ) {
39
return
false
;
40
}
41
42
if
( $result !==
LoggedUpdateOutcome::SIMULATED
) {
43
$db = $this->
getPrimaryDB
();
44
$db->newInsertQueryBuilder()
45
->insertInto(
'updatelog'
)
46
->ignore()
47
->row( [
'ul_key'
=> $this->
getUpdateKey
() ] )
48
->caller( __METHOD__ )->execute();
49
}
50
51
return
true
;
52
}
53
54
public
function
isAlreadyCompleted
(): bool {
55
$db = $this->
getPrimaryDB
();
56
return
(
bool
)$db->newSelectQueryBuilder()
57
->select(
'1'
)
58
->from(
'updatelog'
)
59
->where( [
'ul_key'
=> $this->getUpdateKey() ] )
60
->caller( __METHOD__ )
61
->fetchRow();
62
}
63
68
public
function
setForce
( $forced =
true
) {
69
$this->
setOption
(
'force'
, $forced );
70
}
71
76
public
function
updateSkippedMessage
() {
77
$key = $this->
getUpdateKey
();
78
79
return
"Update '{$key}' already logged as completed."
;
80
}
81
91
abstract
protected
function
doDBUpdates
();
92
97
abstract
protected
function
getUpdateKey
();
98
}
99
101
class_alias( LoggedUpdateMaintenance::class,
'LoggedUpdateMaintenance'
);
MediaWiki\Maintenance\LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition
LoggedUpdateMaintenance.php:14
MediaWiki\Maintenance\LoggedUpdateMaintenance\__construct
__construct()
Default constructor.
Definition
LoggedUpdateMaintenance.php:16
MediaWiki\Maintenance\LoggedUpdateMaintenance\execute
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...
Definition
LoggedUpdateMaintenance.php:23
MediaWiki\Maintenance\LoggedUpdateMaintenance\setForce
setForce( $forced=true)
Sets whether a run of this maintenance script has the force parameter set.
Definition
LoggedUpdateMaintenance.php:68
MediaWiki\Maintenance\LoggedUpdateMaintenance\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition
LoggedUpdateMaintenance.php:76
MediaWiki\Maintenance\LoggedUpdateMaintenance\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
MediaWiki\Maintenance\LoggedUpdateMaintenance\isAlreadyCompleted
isAlreadyCompleted()
Definition
LoggedUpdateMaintenance.php:54
MediaWiki\Maintenance\LoggedUpdateMaintenance\doDBUpdates
doDBUpdates()
Do the actual work.
MediaWiki\Maintenance\Maintenance\setBatchSize
setBatchSize( $s=0)
Definition
Maintenance.php:425
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:485
MediaWiki\Maintenance\Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition
Maintenance.php:265
MediaWiki\Maintenance\Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option was set.
Definition
Maintenance.php:284
MediaWiki\Maintenance\Maintenance\setOption
setOption(string $name, $value)
Programmatically set the value of the given option.
Definition
Maintenance.php:394
MediaWiki\Maintenance\Maintenance\getPrimaryDB
getPrimaryDB(string|false $virtualDomain=false)
Definition
Maintenance.php:1143
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
MediaWiki\Maintenance\SIMULATED
@ SIMULATED
Return value for doDBUpdates() indicating that the update was completed and does not need to be run a...
Definition
LoggedUpdateOutcome.php:30
maintenance
includes
LoggedUpdateMaintenance.php
Generated on
for MediaWiki by
1.18.0