Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| MysqlSettingsForm | |
0.00% |
0 / 40 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| submit | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
56 | |||
| getMysqlInstaller | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Installer; |
| 4 | |
| 5 | use MediaWiki\MediaWikiServices; |
| 6 | use MediaWiki\Status\Status; |
| 7 | use Wikimedia\Rdbms\DBConnectionError; |
| 8 | |
| 9 | /** |
| 10 | * @internal |
| 11 | */ |
| 12 | class MysqlSettingsForm extends DatabaseSettingsForm { |
| 13 | |
| 14 | /** |
| 15 | * @return string |
| 16 | */ |
| 17 | public function getHtml() { |
| 18 | if ( $this->getMysqlInstaller()->canCreateAccounts() ) { |
| 19 | $noCreateMsg = false; |
| 20 | } else { |
| 21 | $noCreateMsg = 'config-db-web-no-create-privs'; |
| 22 | } |
| 23 | $s = $this->getWebUserBox( $noCreateMsg ); |
| 24 | |
| 25 | // Do engine selector |
| 26 | $engines = $this->getMysqlInstaller()->getEngines(); |
| 27 | // If the current default engine is not supported, use an engine that is |
| 28 | if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) { |
| 29 | $this->setVar( '_MysqlEngine', reset( $engines ) ); |
| 30 | } |
| 31 | |
| 32 | // If the current default charset is not supported, use a charset that is |
| 33 | $charsets = $this->getMysqlInstaller()->getCharsets(); |
| 34 | if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) { |
| 35 | $this->setVar( '_MysqlCharset', reset( $charsets ) ); |
| 36 | } |
| 37 | |
| 38 | return $s; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @return Status |
| 43 | */ |
| 44 | public function submit() { |
| 45 | $this->setVarsFromRequest( [ '_MysqlEngine', '_MysqlCharset' ] ); |
| 46 | $status = $this->submitWebUserBox(); |
| 47 | if ( !$status->isOK() ) { |
| 48 | return $status; |
| 49 | } |
| 50 | |
| 51 | // Validate the create checkbox |
| 52 | $canCreate = $this->getMysqlInstaller()->canCreateAccounts(); |
| 53 | if ( !$canCreate ) { |
| 54 | $this->setVar( '_CreateDBAccount', false ); |
| 55 | $create = false; |
| 56 | } else { |
| 57 | $create = $this->getVar( '_CreateDBAccount' ); |
| 58 | } |
| 59 | |
| 60 | if ( !$create ) { |
| 61 | // Test the web account |
| 62 | try { |
| 63 | MediaWikiServices::getInstance()->getDatabaseFactory()->create( 'mysql', [ |
| 64 | 'host' => $this->getVar( 'wgDBserver' ), |
| 65 | 'user' => $this->getVar( 'wgDBuser' ), |
| 66 | 'password' => $this->getVar( 'wgDBpassword' ), |
| 67 | 'ssl' => $this->getVar( 'wgDBssl' ), |
| 68 | 'dbname' => null, |
| 69 | 'flags' => 0, |
| 70 | 'tablePrefix' => $this->getVar( 'wgDBprefix' ) |
| 71 | ] ); |
| 72 | } catch ( DBConnectionError $e ) { |
| 73 | return Status::newFatal( 'config-connection-error', $e->getMessage() ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Validate engines and charsets |
| 78 | // This is done pre-submit already, so it's just for security |
| 79 | $engines = $this->getMysqlInstaller()->getEngines(); |
| 80 | if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) { |
| 81 | $this->setVar( '_MysqlEngine', reset( $engines ) ); |
| 82 | } |
| 83 | $charsets = $this->getMysqlInstaller()->getCharsets(); |
| 84 | if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) { |
| 85 | $this->setVar( '_MysqlCharset', reset( $charsets ) ); |
| 86 | } |
| 87 | |
| 88 | return Status::newGood(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Downcast the DatabaseInstaller |
| 93 | */ |
| 94 | private function getMysqlInstaller(): MysqlInstaller { |
| 95 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
| 96 | return $this->dbInstaller; |
| 97 | } |
| 98 | |
| 99 | } |