diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
commit | 9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch) | |
tree | 46d1a0dee7febef5c2d57a9f7b972be16a163b3d /maintenance/sqlite.php | |
parent | 78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff) |
update to MediaWiki 1.17.0
Diffstat (limited to 'maintenance/sqlite.php')
-rw-r--r-- | maintenance/sqlite.php | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/maintenance/sqlite.php b/maintenance/sqlite.php index 8886fe74..13d136d8 100644 --- a/maintenance/sqlite.php +++ b/maintenance/sqlite.php @@ -20,7 +20,7 @@ * @ingroup Maintenance */ -require_once( dirname(__FILE__) . '/Maintenance.php' ); +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); class SqliteMaintenance extends Maintenance { public function __construct() { @@ -29,6 +29,7 @@ class SqliteMaintenance extends Maintenance { $this->addOption( 'vacuum', 'Clean up database by removing deleted pages. Decreases database file size' ); $this->addOption( 'integrity', 'Check database for integrity' ); $this->addOption( 'backup-to', 'Backup database to the given file', false, true ); + $this->addOption( 'check-syntax', 'Check SQL file(s) for syntax errors', false, true ); } /** @@ -41,7 +42,12 @@ class SqliteMaintenance extends Maintenance { public function execute() { global $wgDBtype; - + + // Should work even if we use a non-SQLite database + if ( $this->hasOption( 'check-syntax' ) ) { + $this->checkSyntax(); + } + if ( $wgDBtype != 'sqlite' ) { $this->error( "This maintenance script requires a SQLite database.\n" ); return; @@ -66,14 +72,14 @@ class SqliteMaintenance extends Maintenance { $prevSize = filesize( $this->db->mDatabaseFile ); if ( $prevSize == 0 ) { $this->error( "Can't vacuum an empty database.\n", true ); - } + } $this->output( 'VACUUM: ' ); if ( $this->db->query( 'VACUUM' ) ) { clearstatcache(); $newSize = filesize( $this->db->mDatabaseFile ); $this->output( sprintf( "Database size was %d, now %d (%.1f%% reduction).\n", - $prevSize, $newSize, ( $prevSize - $newSize) * 100.0 / $prevSize ) ); + $prevSize, $newSize, ( $prevSize - $newSize ) * 100.0 / $prevSize ) ); } else { $this->output( 'Error\n' ); } @@ -107,7 +113,21 @@ class SqliteMaintenance extends Maintenance { $this->output( " Releasing lock...\n" ); $this->db->query( 'COMMIT TRANSACTION', __METHOD__ ); } + + private function checkSyntax() { + if ( !Sqlite::IsPresent() ) { + $this->error( "Error: SQLite support not found\n" ); + } + $files = array( $this->getOption( 'check-syntax' ) ); + $files += $this->mArgs; + $result = Sqlite::checkSqlSyntax( $files ); + if ( $result === true ) { + $this->output( "SQL syntax check: no errors detected.\n" ); + } else { + $this->error( "Error: $result\n" ); + } + } } $maintClass = "SqliteMaintenance"; -require_once( DO_MAINTENANCE );
\ No newline at end of file +require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file |