28require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Performs some operations specific to SQLite database backend' );
41 'Clean up database by removing deleted pages. Decreases database file size'
43 $this->
addOption(
'integrity',
'Check database for integrity' );
44 $this->
addOption(
'backup-to',
'Backup database to the given file',
false,
true );
45 $this->
addOption(
'check-syntax',
'Check SQL file(s) for syntax errors',
false,
true );
60 if ( $this->
hasOption(
'check-syntax' ) ) {
66 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
69 $this->
error(
"This maintenance script requires a SQLite database.\n" );
89 if ( $prevSize == 0 ) {
90 $this->
fatalError(
"Can't vacuum an empty database.\n" );
93 $this->
output(
'VACUUM: ' );
94 if ( $dbw->
query(
'VACUUM', __METHOD__ ) ) {
97 $this->
output( sprintf(
"Database size was %d, now %d (%.1f%% reduction).\n",
98 $prevSize, $newSize, ( $prevSize - $newSize ) * 100.0 / $prevSize ) );
100 $this->
output(
'Error\n' );
105 $this->
output(
"Performing database integrity checks:\n" );
106 $res = $dbw->
query(
'PRAGMA integrity_check', __METHOD__ );
108 if ( !
$res ||
$res->numRows() == 0 ) {
109 $this->
error(
"Error: integrity check query returned nothing.\n" );
114 foreach (
$res as $row ) {
115 $this->
output( $row->integrity_check );
120 $this->
output(
"Backing up database:\n Locking..." );
121 $dbw->
query(
'BEGIN IMMEDIATE TRANSACTION', __METHOD__ );
123 $this->
output(
" Copying database file $ourFile to $fileName... " );
124 Wikimedia\suppressWarnings();
125 if ( !copy( $ourFile, $fileName ) ) {
126 $err = error_get_last();
127 $this->
error(
" {$err['message']}" );
129 Wikimedia\restoreWarnings();
130 $this->
output(
" Releasing lock...\n" );
131 $dbw->
query(
'COMMIT TRANSACTION', __METHOD__ );
136 $this->
error(
"Error: SQLite support not found\n" );
138 $files = [ $this->
getOption(
'check-syntax' ) ];
139 $files = array_merge( $files, $this->mArgs );
141 if ( $result ===
true ) {
142 $this->
output(
"SQL syntax check: no errors detected.\n" );
144 $this->
error(
"Error: $result\n" );
const RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
const DB_NONE
Constants for DB access type.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that performs some operations specific to SQLite database backend.
backup(DatabaseSqlite $dbw, $fileName)
execute()
Do the actual work.
__construct()
Default constructor.
vacuum(DatabaseSqlite $dbw)
getDbType()
While we use database connection, this simple lie prevents useless –dbpass and –dbuser options from a...
integrityCheck(DatabaseSqlite $dbw)
static isPresent()
Checks whether PHP has SQLite support.
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.