Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / installer / SqliteDatabaseCreator.php
blob298dad63c75f806a008c0a9b5ca5211fa1a905c5
1 <?php
3 namespace MediaWiki\Installer;
5 use MediaWiki\Installer\Task\ITaskContext;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\Status\Status;
8 use Wikimedia\Rdbms\DatabaseSqlite;
9 use Wikimedia\Rdbms\ILoadBalancer;
11 class SqliteDatabaseCreator extends DatabaseCreator {
12 /** @var string */
13 private $dataDir;
15 protected function __construct( ITaskContext $context ) {
16 parent::__construct( $context );
17 $this->dataDir = $context->getConfigVar( MainConfigNames::SQLiteDataDir );
20 public function existsLocally( $database ) {
21 $file = DatabaseSqlite::generateFileName( $this->dataDir, $database );
22 return file_exists( $file );
25 public function existsInLoadBalancer( ILoadBalancer $loadBalancer, $database ) {
26 return $this->existsLocally( $database );
29 public function createLocally( $database ): Status {
30 return $this->makeStubDBFile( $database );
33 public function createInLoadBalancer( ILoadBalancer $loadBalancer, $database ): Status {
34 return $this->createLocally( $database );
37 private function makeStubDBFile( $db ) {
38 $file = DatabaseSqlite::generateFileName( $this->dataDir, $db );
40 if ( file_exists( $file ) ) {
41 if ( !is_writable( $file ) ) {
42 return Status::newFatal( 'config-sqlite-readonly', $file );
44 return Status::newGood();
47 $oldMask = umask( 0177 );
48 if ( file_put_contents( $file, '' ) === false ) {
49 umask( $oldMask );
50 return Status::newFatal( 'config-sqlite-cant-create-db', $file );
52 umask( $oldMask );
54 return Status::newGood();