MediaWiki  1.28.1
sqlite.inc
Go to the documentation of this file.
1 <?php
29 class Sqlite {
30 
35  public static function isPresent() {
36  return extension_loaded( 'pdo_sqlite' );
37  }
38 
47  public static function checkSqlSyntax( $files ) {
48  if ( !Sqlite::isPresent() ) {
49  throw new MWException( "Can't check SQL syntax: SQLite not found" );
50  }
51  if ( !is_array( $files ) ) {
52  $files = [ $files ];
53  }
54 
55  $allowedTypes = array_flip( [
56  'integer',
57  'real',
58  'text',
59  'blob', // NULL type is omitted intentionally
60  ] );
61 
62  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
63  try {
64  foreach ( $files as $file ) {
65  $err = $db->sourceFile( $file );
66  if ( $err != true ) {
67  return $err;
68  }
69  }
70 
71  $tables = $db->query( "SELECT name FROM sqlite_master WHERE type='table'", __METHOD__ );
72  foreach ( $tables as $table ) {
73  if ( strpos( $table->name, 'sqlite_' ) === 0 ) {
74  continue;
75  }
76 
77  $columns = $db->query( "PRAGMA table_info({$table->name})", __METHOD__ );
78  foreach ( $columns as $col ) {
79  if ( !isset( $allowedTypes[strtolower( $col->type )] ) ) {
80  $db->close();
81 
82  return "Table {$table->name} has column {$col->name} with non-native type '{$col->type}'";
83  }
84  }
85  }
86  } catch ( DBError $e ) {
87  return $e->getMessage();
88  }
89  $db->close();
90 
91  return true;
92  }
93 }
This class contains code common to different SQLite-related maintenance scripts.
Definition: sqlite.inc:29
Database error base class.
Definition: DBError.php:26
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:2102
$files
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:1007
static newStandaloneInstance($filename, array $p=[])
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static checkSqlSyntax($files)
Checks given files for correctness of SQL syntax.
Definition: sqlite.inc:47
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static isPresent()
Checks whether PHP has SQLite support.
Definition: sqlite.inc:35