summaryrefslogtreecommitdiff
path: root/maintenance/sqlite.php
diff options
context:
space:
mode:
Diffstat (limited to 'maintenance/sqlite.php')
-rw-r--r--maintenance/sqlite.php30
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