Index: trunk/phase3/maintenance/sqlite.php |
— | — | @@ -0,0 +1,80 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Performs some operations specific to SQLite database backend |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @ingroup Maintenance |
| 22 | + */ |
| 23 | + |
| 24 | +require_once( dirname(__FILE__) . '/Maintenance.php' ); |
| 25 | + |
| 26 | +class SqliteMaintenance extends Maintenance { |
| 27 | + public function __construct() { |
| 28 | + parent::__construct(); |
| 29 | + $this->mDescription = "Performs some operations specific to SQLite database backend"; |
| 30 | + $this->addOption( 'vacuum', 'Clean up database by removing deleted pages. Decreases database file size' ); |
| 31 | + $this->addOption( 'integrity', 'Check database for integrity' ); |
| 32 | + } |
| 33 | + |
| 34 | + public function execute() { |
| 35 | + global $wgDBtype; |
| 36 | + |
| 37 | + if ( $wgDBtype != 'sqlite' ) { |
| 38 | + $this->error( "This maintenance script requires a SQLite database.\n" ); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + $this->db = wfGetDB( DB_MASTER ); |
| 43 | + |
| 44 | + if ( $this->hasOption( 'vacuum' ) ) |
| 45 | + $this->vacuum(); |
| 46 | + |
| 47 | + if ( $this->hasOption( 'integrity' ) ) |
| 48 | + $this->integrityCheck(); |
| 49 | + } |
| 50 | + |
| 51 | + private function vacuum() { |
| 52 | + $prevSize = filesize( $this->db->mDatabaseFile ); |
| 53 | + |
| 54 | + $this->output( 'VACUUM: ' ); |
| 55 | + if ( $this->db->query( 'VACUUM' ) ) { |
| 56 | + clearstatcache(); |
| 57 | + $newSize = filesize( $this->db->mDatabaseFile ); |
| 58 | + $this->output( sprintf( "Database size was %d bytes, now %d (%.1f%% reduction).\n", |
| 59 | + $prevSize, $newSize, ( $prevSize - $newSize) / $prevSize ) ); |
| 60 | + } else { |
| 61 | + $this->output( 'Error\n' ); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + private function integrityCheck() { |
| 66 | + $this->output( "Performing database integrity checks:\n" ); |
| 67 | + $res = $this->db->query( 'PRAGMA integrity_check' ); |
| 68 | + |
| 69 | + if ( !$res || $res->numRows() == 0 ) { |
| 70 | + $this->error( "Error: integrity check query returned nothing.\n" ); |
| 71 | + return; |
| 72 | + } |
| 73 | + |
| 74 | + foreach ( $res as $row ) { |
| 75 | + $this->output( $row->integrity_check ); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +$maintClass = "SqliteMaintenance"; |
| 81 | +require_once( DO_MAINTENANCE ); |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/sqlite.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 82 | + native |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -248,6 +248,7 @@ |
249 | 249 | * (bug 21095) Tracking categories produced by the parser (expensive parser function |
250 | 250 | limit exceeded, __NOINDEX__ tracking, etc) can now be disabled by setting the |
251 | 251 | system message ([[MediaWiki:expensive-parserfunction-category]] etc) to "-". |
| 252 | +* Added maintenance script sqlite.php for SQLite-specific maintenance tasks. |
252 | 253 | |
253 | 254 | === Bug fixes in 1.16 === |
254 | 255 | |