Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / includes / installer / OracleInstaller.php
index 9e692ea..644eec1 100644 (file)
@@ -21,6 +21,9 @@
  * @ingroup Deployment
  */
 
+use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\DBConnectionError;
+
 /**
  * Class for setting up the MediaWiki database using Oracle.
  *
  */
 class OracleInstaller extends DatabaseInstaller {
 
-       protected $globalNames = array(
+       protected $globalNames = [
                'wgDBserver',
                'wgDBname',
                'wgDBuser',
                'wgDBpassword',
                'wgDBprefix',
-       );
+       ];
 
-       protected $internalDefaults = array(
+       protected $internalDefaults = [
                '_OracleDefTS' => 'USERS',
                '_OracleTempTS' => 'TEMP',
                '_InstallUser' => 'SYSTEM',
-       );
+       ];
 
-       public $minimumVersion = '9.0.1'; // 9iR1
+       public static $minimumVersion = '9.0.1'; // 9iR1
+       protected static $notMinimumVerisonMessage = 'config-oracle-old';
 
        protected $connError = null;
 
@@ -63,17 +67,17 @@ class OracleInstaller extends DatabaseInstaller {
                return $this->getTextBox(
                        'wgDBserver',
                        'config-db-host-oracle',
-                       array(),
+                       [],
                        $this->parent->getHelpBox( 'config-db-host-oracle-help' )
                ) .
                        Html::openElement( 'fieldset' ) .
-                       Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) .
+                       Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) .
                        $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
                        $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
                        $this->getTextBox(
                                '_OracleTempTS',
                                'config-oracle-temp-ts',
-                               array(),
+                               [],
                                $this->parent->getHelpBox( 'config-db-oracle-help' )
                        ) .
                        Html::closeElement( 'fieldset' ) .
@@ -91,12 +95,12 @@ class OracleInstaller extends DatabaseInstaller {
 
        public function submitConnectForm() {
                // Get variables from the request
-               $newValues = $this->setVarsFromRequest( array(
+               $newValues = $this->setVarsFromRequest( [
                        'wgDBserver',
                        'wgDBprefix',
                        'wgDBuser',
                        'wgDBpassword'
-               ) );
+               ] );
                $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
 
                // Validate them
@@ -150,49 +154,41 @@ class OracleInstaller extends DatabaseInstaller {
                }
 
                /**
-                * @var $conn DatabaseBase
+                * @var Database $conn
                 */
                $conn = $status->value;
 
                // Check version
-               $version = $conn->getServerVersion();
-               if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
-                       return Status::newFatal( 'config-oracle-old', $this->minimumVersion, $version );
-               }
+               $status->merge( static::meetsMinimumRequirement( $conn->getServerVersion() ) );
 
                return $status;
        }
 
        public function openConnection() {
-               $status = Status::newGood();
-               try {
-                       $db = new DatabaseOracle(
-                               $this->getVar( 'wgDBserver' ),
-                               $this->getVar( '_InstallUser' ),
-                               $this->getVar( '_InstallPassword' ),
-                               $this->getVar( '_InstallDBname' ),
-                               0,
-                               $this->getVar( 'wgDBprefix' )
-                       );
-                       $status->value = $db;
-               } catch ( DBConnectionError $e ) {
-                       $this->connError = $e->db->lastErrno();
-                       $status->fatal( 'config-connection-error', $e->getMessage() );
-               }
-
-               return $status;
+               return $this->doOpenConnection();
        }
 
        public function openSYSDBAConnection() {
+               return $this->doOpenConnection( DatabaseOracle::DBO_SYSDBA );
+       }
+
+       /**
+        * @param int $flags
+        * @return Status Status with DatabaseOracle or null as the value
+        */
+       private function doOpenConnection( $flags = 0 ) {
                $status = Status::newGood();
                try {
-                       $db = new DatabaseOracle(
-                               $this->getVar( 'wgDBserver' ),
-                               $this->getVar( '_InstallUser' ),
-                               $this->getVar( '_InstallPassword' ),
-                               $this->getVar( '_InstallDBname' ),
-                               DBO_SYSDBA,
-                               $this->getVar( 'wgDBprefix' )
+                       $db = Database::factory(
+                               'oracle',
+                               [
+                                       'host' => $this->getVar( 'wgDBserver' ),
+                                       'user' => $this->getVar( '_InstallUser' ),
+                                       'password' => $this->getVar( '_InstallPassword' ),
+                                       'dbname' => $this->getVar( '_InstallDBname' ),
+                                       'tablePrefix' => $this->getVar( 'wgDBprefix' ),
+                                       'flags' => $flags
+                               ]
                        );
                        $status->value = $db;
                } catch ( DBConnectionError $e ) {
@@ -214,10 +210,10 @@ class OracleInstaller 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, 'database' );
        }
 
@@ -293,7 +289,7 @@ class OracleInstaller extends DatabaseInstaller {
        }
 
        public function getSchemaVars() {
-               $varNames = array(
+               $varNames = [
                        # These variables are used by maintenance/oracle/user.sql
                        '_OracleDefTS',
                        '_OracleTempTS',
@@ -302,8 +298,8 @@ class OracleInstaller extends DatabaseInstaller {
 
                        # These are used by tables.sql
                        'wgDBprefix',
-               );
-               $vars = array();
+               ];
+               $vars = [];
                foreach ( $varNames as $name ) {
                        $vars[$name] = $this->getVar( $name );
                }
@@ -334,11 +330,11 @@ class OracleInstaller extends DatabaseInstaller {
         * @return bool Whether the connection string is valid.
         */
        public static function checkConnectStringFormat( $connect_string ) {
-               // @@codingStandardsIgnoreStart Long lines with regular expressions.
+               // phpcs:disable Generic.Files.LineLength
                // @todo Very long regular expression. Make more readable?
                $isValid = preg_match( '/^[[:alpha:]][\w\-]*(?:\.[[:alpha:]][\w\-]*){0,2}$/', $connect_string ); // TNS name
                $isValid |= preg_match( '/^(?:\/\/)?[\w\-\.]+(?::[\d]+)?(?:\/(?:[\w\-\.]+(?::(pooled|dedicated|shared))?)?(?:\/[\w\-\.]+)?)?$/', $connect_string ); // EZConnect
-               // @@codingStandardsIgnoreEnd
+               // phpcs:enable
                return (bool)$isValid;
        }
 }