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 | public function getHtml() { |
14 | return $this->getTextBox( |
15 | 'wgSQLiteDataDir', |
16 | 'config-sqlite-dir', [], |
17 | $this->webInstaller->getHelpBox( 'config-sqlite-dir-help' ) |
18 | ) . |
19 | $this->getTextBox( |
20 | 'wgDBname', |
21 | 'config-db-name', |
22 | [], |
23 | $this->webInstaller->getHelpBox( 'config-sqlite-name-help' ) |
24 | ); |
25 | } |
26 | |
27 | /** |
28 | * @return Status |
29 | */ |
30 | public function submit() { |
31 | $this->setVarsFromRequest( [ 'wgSQLiteDataDir', 'wgDBname' ] ); |
32 | |
33 | # Try realpath() if the directory already exists |
34 | $dir = $this->realpath( $this->getVar( 'wgSQLiteDataDir' ) ); |
35 | $result = $this->getSqliteUtils()->checkDataDir( $dir ); |
36 | if ( $result->isOK() ) { |
37 | # Try expanding again in case we've just created it |
38 | $dir = $this->realpath( $dir ); |
39 | $this->setVar( 'wgSQLiteDataDir', $dir ); |
40 | } |
41 | # Table prefix is not used on SQLite, keep it empty |
42 | $this->setVar( 'wgDBprefix', '' ); |
43 | |
44 | return $result; |
45 | } |
46 | |
47 | /** |
48 | * Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path. |
49 | * |
50 | * @param string $path |
51 | * |
52 | * @return string |
53 | */ |
54 | private function realpath( $path ) { |
55 | return realpath( $path ) ?: $path; |
56 | } |
57 | |
58 | private function getSqliteUtils(): SqliteUtils { |
59 | return new SqliteUtils; |
60 | } |
61 | |
62 | } |