X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Finstaller%2FMssqlInstaller.php;h=c5ec72b03f91a60957244ea48fde204a16be96c7;hb=b74e81ab6b3bdfaf67eb5d13f3f2e662d5ceb11a;hp=4d79d9665b5ad69bc6b5f112edb1c7fe440a78d3;hpb=04fdc78370dbc042116488d6826e19bf3910273b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/MssqlInstaller.php b/includes/installer/MssqlInstaller.php index 4d79d9665b..c5ec72b03f 100644 --- a/includes/installer/MssqlInstaller.php +++ b/includes/installer/MssqlInstaller.php @@ -29,7 +29,7 @@ */ class MssqlInstaller extends DatabaseInstaller { - protected $globalNames = array( + protected $globalNames = [ 'wgDBserver', 'wgDBname', 'wgDBuser', @@ -37,13 +37,13 @@ class MssqlInstaller extends DatabaseInstaller { 'wgDBmwschema', 'wgDBprefix', 'wgDBWindowsAuthentication', - ); + ]; - protected $internalDefaults = array( + protected $internalDefaults = [ '_InstallUser' => 'sa', '_InstallWindowsAuthentication' => 'sqlauth', '_WebWindowsAuthentication' => 'sqlauth', - ); + ]; // SQL Server 2005 RTM // @todo Are SQL Express version numbers different?) @@ -52,13 +52,13 @@ class MssqlInstaller extends DatabaseInstaller { // These are schema-level privs // Note: the web user will be created will full permissions if possible, this permission // list is only used if we are unable to grant full permissions. - public $webUserPrivs = array( + public $webUserPrivs = [ 'DELETE', 'INSERT', 'SELECT', 'UPDATE', 'EXECUTE', - ); + ]; /** * @return string @@ -87,48 +87,48 @@ class MssqlInstaller extends DatabaseInstaller { return $this->getTextBox( 'wgDBserver', 'config-db-host', - array(), + [], $this->parent->getHelpBox( 'config-db-host-help' ) ) . Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) . - $this->getTextBox( 'wgDBname', 'config-db-name', array( 'dir' => 'ltr' ), + Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) . + $this->getTextBox( 'wgDBname', 'config-db-name', [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-name-help' ) ) . - $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array( 'dir' => 'ltr' ), + $this->getTextBox( 'wgDBmwschema', 'config-db-schema', [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-schema-help' ) ) . - $this->getTextBox( 'wgDBprefix', 'config-db-prefix', array( 'dir' => 'ltr' ), + $this->getTextBox( 'wgDBprefix', 'config-db-prefix', [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-prefix-help' ) ) . Html::closeElement( 'fieldset' ) . Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-install-account' )->text() ) . - $this->getRadioSet( array( + Html::element( 'legend', [], wfMessage( 'config-db-install-account' )->text() ) . + $this->getRadioSet( [ 'var' => '_InstallWindowsAuthentication', 'label' => 'config-mssql-auth', 'itemLabelPrefix' => 'config-mssql-', - 'values' => array( 'sqlauth', 'windowsauth' ), - 'itemAttribs' => array( - 'sqlauth' => array( + 'values' => [ 'sqlauth', 'windowsauth' ], + 'itemAttribs' => [ + 'sqlauth' => [ 'class' => 'showHideRadio', 'rel' => 'dbCredentialBox', - ), - 'windowsauth' => array( + ], + 'windowsauth' => [ 'class' => 'hideShowRadio', 'rel' => 'dbCredentialBox', - ) - ), + ] + ], 'help' => $this->parent->getHelpBox( 'config-mssql-install-auth' ) - ) ) . - Html::openElement( 'div', array( 'id' => 'dbCredentialBox', 'style' => $displayStyle ) ) . + ] ) . + Html::openElement( 'div', [ 'id' => 'dbCredentialBox', 'style' => $displayStyle ] ) . $this->getTextBox( '_InstallUser', 'config-db-username', - array( 'dir' => 'ltr' ), + [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-install-username' ) ) . $this->getPasswordBox( '_InstallPassword', 'config-db-password', - array( 'dir' => 'ltr' ), + [ 'dir' => 'ltr' ], $this->parent->getHelpBox( 'config-db-install-password' ) ) . Html::closeElement( 'div' ) . @@ -137,12 +137,12 @@ class MssqlInstaller extends DatabaseInstaller { public function submitConnectForm() { // Get variables from the request. - $newValues = $this->setVarsFromRequest( array( + $newValues = $this->setVarsFromRequest( [ 'wgDBserver', 'wgDBname', 'wgDBmwschema', 'wgDBprefix' - ) ); + ] ); // Validate them. $status = Status::newGood(); @@ -170,11 +170,11 @@ class MssqlInstaller extends DatabaseInstaller { } // User box - $this->setVarsFromRequest( array( + $this->setVarsFromRequest( [ '_InstallUser', '_InstallPassword', '_InstallWindowsAuthentication' - ) ); + ] ); // Try to connect $status = $this->getConnection(); @@ -182,7 +182,7 @@ class MssqlInstaller extends DatabaseInstaller { return $status; } /** - * @var $conn DatabaseBase + * @var $conn Database */ $conn = $status->value; @@ -212,14 +212,14 @@ class MssqlInstaller extends DatabaseInstaller { } try { - $db = DatabaseBase::factory( 'mssql', array( + $db = Database::factory( 'mssql', [ 'host' => $this->getVar( 'wgDBserver' ), 'user' => $user, 'password' => $password, 'dbname' => false, 'flags' => 0, 'schema' => $this->getVar( 'wgDBmwschema' ), - 'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) ); + 'tablePrefix' => $this->getVar( 'wgDBprefix' ) ] ); $db->prepareStatements( false ); $db->scrollableCursor( false ); $status->value = $db; @@ -240,7 +240,7 @@ class MssqlInstaller extends DatabaseInstaller { return; } /** - * @var $conn DatabaseBase + * @var $conn Database */ $conn = $status->value; $conn->selectDB( $this->getVar( 'wgDBname' ) ); @@ -261,15 +261,15 @@ class MssqlInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return false; } - /** @var $conn DatabaseBase */ + /** @var $conn Database */ $conn = $status->value; // We need the server-level ALTER ANY LOGIN permission to create new accounts $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( NULL, 'SERVER' )" ); - $serverPrivs = array( + $serverPrivs = [ 'ALTER ANY LOGIN' => false, 'CONTROL SERVER' => false, - ); + ]; foreach ( $res as $row ) { $serverPrivs[$row->permission_name] = true; @@ -284,25 +284,25 @@ class MssqlInstaller extends DatabaseInstaller { // and just check for the permission // http://technet.microsoft.com/en-us/library/ms178569.aspx // The following array sets up which permissions imply whatever permissions we specify - $implied = array( + $implied = [ // schema database server - 'DELETE' => array( 'DELETE', 'CONTROL SERVER' ), - 'EXECUTE' => array( 'EXECUTE', 'CONTROL SERVER' ), - 'INSERT' => array( 'INSERT', 'CONTROL SERVER' ), - 'SELECT' => array( 'SELECT', 'CONTROL SERVER' ), - 'UPDATE' => array( 'UPDATE', 'CONTROL SERVER' ), - ); + 'DELETE' => [ 'DELETE', 'CONTROL SERVER' ], + 'EXECUTE' => [ 'EXECUTE', 'CONTROL SERVER' ], + 'INSERT' => [ 'INSERT', 'CONTROL SERVER' ], + 'SELECT' => [ 'SELECT', 'CONTROL SERVER' ], + 'UPDATE' => [ 'UPDATE', 'CONTROL SERVER' ], + ]; $grantOptions = array_flip( $this->webUserPrivs ); // Check for schema and db-level permissions, but only if the schema/db exists - $schemaPrivs = $dbPrivs = array( + $schemaPrivs = $dbPrivs = [ 'DELETE' => false, 'EXECUTE' => false, 'INSERT' => false, 'SELECT' => false, 'UPDATE' => false, - ); + ]; $dbPrivs['ALTER ANY USER'] = false; @@ -365,30 +365,30 @@ class MssqlInstaller extends DatabaseInstaller { ? 'display: none' : ''; $s = Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMessage( 'config-db-web-account' )->text() ) . + Html::element( 'legend', [], wfMessage( 'config-db-web-account' )->text() ) . $this->getCheckBox( '_SameAccount', 'config-db-web-account-same', - array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' ) + [ 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' ] ) . - Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ) ) . - $this->getRadioSet( array( + Html::openElement( 'div', [ 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ] ) . + $this->getRadioSet( [ 'var' => '_WebWindowsAuthentication', 'label' => 'config-mssql-auth', 'itemLabelPrefix' => 'config-mssql-', - 'values' => array( 'sqlauth', 'windowsauth' ), - 'itemAttribs' => array( - 'sqlauth' => array( + 'values' => [ 'sqlauth', 'windowsauth' ], + 'itemAttribs' => [ + 'sqlauth' => [ 'class' => 'showHideRadio', 'rel' => 'dbCredentialBox', - ), - 'windowsauth' => array( + ], + 'windowsauth' => [ 'class' => 'hideShowRadio', 'rel' => 'dbCredentialBox', - ) - ), + ] + ], 'help' => $this->parent->getHelpBox( 'config-mssql-web-auth' ) - ) ) . - Html::openElement( 'div', array( 'id' => 'dbCredentialBox', 'style' => $displayStyle ) ) . + ] ) . + Html::openElement( 'div', [ 'id' => 'dbCredentialBox', 'style' => $displayStyle ] ) . $this->getTextBox( 'wgDBuser', 'config-db-username' ) . $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) . Html::closeElement( 'div' ); @@ -408,13 +408,13 @@ class MssqlInstaller extends DatabaseInstaller { * @return Status */ public function submitSettingsForm() { - $this->setVarsFromRequest( array( + $this->setVarsFromRequest( [ 'wgDBuser', 'wgDBpassword', '_SameAccount', '_CreateDBAccount', '_WebWindowsAuthentication' - ) ); + ] ); if ( $this->getVar( '_SameAccount' ) ) { $this->setVar( '_WebWindowsAuthentication', $this->getVar( '_InstallWindowsAuthentication' ) ); @@ -457,7 +457,7 @@ class MssqlInstaller extends DatabaseInstaller { } try { - DatabaseBase::factory( 'mssql', array( + Database::factory( 'mssql', [ 'host' => $this->getVar( 'wgDBserver' ), 'user' => $user, 'password' => $password, @@ -465,7 +465,7 @@ class MssqlInstaller extends DatabaseInstaller { 'flags' => 0, 'tablePrefix' => $this->getVar( 'wgDBprefix' ), 'schema' => $this->getVar( 'wgDBmwschema' ), - ) ); + ] ); } catch ( DBConnectionError $e ) { return Status::newFatal( 'config-connection-error', $e->getMessage() ); } @@ -476,10 +476,10 @@ class MssqlInstaller extends DatabaseInstaller { public function preInstall() { # Add our user callback to installSteps, right before the tables are created. - $callback = array( + $callback = [ 'name' => 'user', - 'callback' => array( $this, 'setupUser' ), - ); + 'callback' => [ $this, 'setupUser' ], + ]; $this->parent->addInstallStep( $callback, 'tables' ); } @@ -491,7 +491,7 @@ class MssqlInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return $status; } - /** @var DatabaseBase $conn */ + /** @var Database $conn */ $conn = $status->value; $dbName = $this->getVar( 'wgDBname' ); $schemaName = $this->getVar( 'wgDBmwschema' ); @@ -500,19 +500,19 @@ class MssqlInstaller extends DatabaseInstaller { "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ ); - $conn->selectDB( $dbName ); - if ( !$this->schemaExists( $schemaName ) ) { - $conn->query( - "CREATE SCHEMA " . $conn->addIdentifierQuotes( $schemaName ), - __METHOD__ - ); - } - if ( !$this->catalogExists( $schemaName ) ) { - $conn->query( - "CREATE FULLTEXT CATALOG " . $conn->addIdentifierQuotes( $schemaName ), - __METHOD__ - ); - } + } + $conn->selectDB( $dbName ); + if ( !$this->schemaExists( $schemaName ) ) { + $conn->query( + "CREATE SCHEMA " . $conn->addIdentifierQuotes( $schemaName ), + __METHOD__ + ); + } + if ( !$this->catalogExists( $schemaName ) ) { + $conn->query( + "CREATE FULLTEXT CATALOG " . $conn->addIdentifierQuotes( $schemaName ), + __METHOD__ + ); } $this->setupSchemaVars(); @@ -554,7 +554,7 @@ class MssqlInstaller extends DatabaseInstaller { $escUser = $this->db->addIdentifierQuotes( $dbUser ); $escDb = $this->db->addIdentifierQuotes( $dbName ); $escSchema = $this->db->addIdentifierQuotes( $schemaName ); - $grantableNames = array(); + $grantableNames = []; if ( $tryToCreate ) { $escPass = $this->db->addQuotes( $password ); @@ -596,10 +596,10 @@ class MssqlInstaller extends DatabaseInstaller { foreach ( $grantableNames as $name ) { try { // First try to grant full permissions - $fullPrivArr = array( + $fullPrivArr = [ 'BACKUP DATABASE', 'BACKUP LOG', 'CREATE FUNCTION', 'CREATE PROCEDURE', 'CREATE TABLE', 'CREATE VIEW', 'CREATE FULLTEXT CATALOG', 'SHOWPLAN' - ); + ]; $fullPrivList = implode( ', ', $fullPrivArr ); $this->db->begin(); $this->db->query( "GRANT $fullPrivList ON DATABASE :: $escDb TO $escUser", __METHOD__ ); @@ -634,7 +634,7 @@ class MssqlInstaller extends DatabaseInstaller { $status = parent::createTables(); // Do last-minute stuff like fulltext indexes (since they can't be inside a transaction) - if ( $status->isOk() ) { + if ( $status->isOK() ) { $searchindex = $this->db->tableName( 'searchindex' ); $schema = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBmwschema' ) ); try { @@ -651,9 +651,9 @@ class MssqlInstaller extends DatabaseInstaller { public function getGlobalDefaults() { // The default $wgDBmwschema is null, which breaks Postgres and other DBMSes that require // the use of a schema, so we need to set it here - return array_merge( parent::getGlobalDefaults(), array( + return array_merge( parent::getGlobalDefaults(), [ 'wgDBmwschema' => 'mediawiki', - ) ); + ] ); } /** @@ -662,7 +662,7 @@ class MssqlInstaller extends DatabaseInstaller { * @return bool */ private function loginExists( $user ) { - $res = $this->db->selectField( 'sys.sql_logins', 1, array( 'name' => $user ) ); + $res = $this->db->selectField( 'sys.sql_logins', 1, [ 'name' => $user ] ); return (bool)$res; } @@ -673,7 +673,7 @@ class MssqlInstaller extends DatabaseInstaller { * @return bool */ private function userExists( $user ) { - $res = $this->db->selectField( 'sys.sysusers', 1, array( 'name' => $user ) ); + $res = $this->db->selectField( 'sys.sysusers', 1, [ 'name' => $user ] ); return (bool)$res; } @@ -683,7 +683,7 @@ class MssqlInstaller extends DatabaseInstaller { * @return bool */ private function databaseExists( $dbName ) { - $res = $this->db->selectField( 'sys.databases', 1, array( 'name' => $dbName ) ); + $res = $this->db->selectField( 'sys.databases', 1, [ 'name' => $dbName ] ); return (bool)$res; } @@ -694,7 +694,7 @@ class MssqlInstaller extends DatabaseInstaller { * @return bool */ private function schemaExists( $schemaName ) { - $res = $this->db->selectField( 'sys.schemas', 1, array( 'name' => $schemaName ) ); + $res = $this->db->selectField( 'sys.schemas', 1, [ 'name' => $schemaName ] ); return (bool)$res; } @@ -705,7 +705,7 @@ class MssqlInstaller extends DatabaseInstaller { * @return bool */ private function catalogExists( $catalogName ) { - $res = $this->db->selectField( 'sys.fulltext_catalogs', 1, array( 'name' => $catalogName ) ); + $res = $this->db->selectField( 'sys.fulltext_catalogs', 1, [ 'name' => $catalogName ] ); return (bool)$res; } @@ -715,12 +715,12 @@ class MssqlInstaller extends DatabaseInstaller { * @return array */ public function getSchemaVars() { - return array( + return [ 'wgDBname' => $this->getVar( 'wgDBname' ), 'wgDBmwschema' => $this->getVar( 'wgDBmwschema' ), 'wgDBuser' => $this->getVar( 'wgDBuser' ), 'wgDBpassword' => $this->getVar( 'wgDBpassword' ), - ); + ]; } public function getLocalSettings() {