3 * Performs some operations specific to SQLite database backend
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @ingroup Maintenance
23 require_once( dirname(__FILE__
) . '/Maintenance.php' );
25 class SqliteMaintenance
extends Maintenance
{
26 public function __construct() {
27 parent
::__construct();
28 $this->mDescription
= "Performs some operations specific to SQLite database backend";
29 $this->addOption( 'vacuum', 'Clean up database by removing deleted pages. Decreases database file size' );
30 $this->addOption( 'integrity', 'Check database for integrity' );
33 public function execute() {
36 if ( $wgDBtype != 'sqlite' ) {
37 $this->error( "This maintenance script requires a SQLite database.\n" );
41 $this->db
= wfGetDB( DB_MASTER
);
43 if ( $this->hasOption( 'vacuum' ) )
46 if ( $this->hasOption( 'integrity' ) )
47 $this->integrityCheck();
50 private function vacuum() {
51 $prevSize = filesize( $this->db
->mDatabaseFile
);
53 $this->output( 'VACUUM: ' );
54 if ( $this->db
->query( 'VACUUM' ) ) {
56 $newSize = filesize( $this->db
->mDatabaseFile
);
57 $this->output( sprintf( "Database size was %d, now %d (%.1f%% reduction).\n",
58 $prevSize, $newSize, ( $prevSize - $newSize) * 100.0 / $prevSize ) );
60 $this->output( 'Error\n' );
64 private function integrityCheck() {
65 $this->output( "Performing database integrity checks:\n" );
66 $res = $this->db
->query( 'PRAGMA integrity_check' );
68 if ( !$res ||
$res->numRows() == 0 ) {
69 $this->error( "Error: integrity check query returned nothing.\n" );
73 foreach ( $res as $row ) {
74 $this->output( $row->integrity_check
);
79 $maintClass = "SqliteMaintenance";
80 require_once( DO_MAINTENANCE
);