Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| SqliteConnectForm | |
0.00% |
0 / 21 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| submit | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| realpath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| getSqliteUtils | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Installer; |
| 4 | |
| 5 | use MediaWiki\Installer\Task\SqliteUtils; |
| 6 | use MediaWiki\Status\Status; |
| 7 | |
| 8 | /** |
| 9 | * @internal |
| 10 | */ |
| 11 | class SqliteConnectForm extends DatabaseConnectForm { |
| 12 | |
| 13 | /** @inheritDoc */ |
| 14 | public function getHtml() { |
| 15 | return $this->getTextBox( |
| 16 | 'wgSQLiteDataDir', |
| 17 | 'config-sqlite-dir', [], |
| 18 | $this->webInstaller->getHelpBox( 'config-sqlite-dir-help' ) |
| 19 | ) . |
| 20 | $this->getTextBox( |
| 21 | 'wgDBname', |
| 22 | 'config-db-name', |
| 23 | [], |
| 24 | $this->webInstaller->getHelpBox( 'config-sqlite-name-help' ) |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return Status |
| 30 | */ |
| 31 | public function submit() { |
| 32 | $this->setVarsFromRequest( [ 'wgSQLiteDataDir', 'wgDBname' ] ); |
| 33 | |
| 34 | # Try realpath() if the directory already exists |
| 35 | $dir = $this->realpath( $this->getVar( 'wgSQLiteDataDir' ) ); |
| 36 | $result = $this->getSqliteUtils()->checkDataDir( $dir ); |
| 37 | if ( $result->isOK() ) { |
| 38 | # Try expanding again in case we've just created it |
| 39 | $dir = $this->realpath( $dir ); |
| 40 | $this->setVar( 'wgSQLiteDataDir', $dir ); |
| 41 | } |
| 42 | # Table prefix is not used on SQLite, keep it empty |
| 43 | $this->setVar( 'wgDBprefix', '' ); |
| 44 | |
| 45 | return $result; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path. |
| 50 | * |
| 51 | * @param string $path |
| 52 | * |
| 53 | * @return string |
| 54 | */ |
| 55 | private function realpath( $path ) { |
| 56 | return realpath( $path ) ?: $path; |
| 57 | } |
| 58 | |
| 59 | private function getSqliteUtils(): SqliteUtils { |
| 60 | return new SqliteUtils; |
| 61 | } |
| 62 | |
| 63 | } |