Exemplo n.º 1
0
 /**
  * Just check that the database configuration is okay.
  * @param $databaseConfig
  * @param $dbName
  */
 public function checkdatabase($databaseConfig, $dbName)
 {
     if ($this->requireFunction('mysqli_connect', array(ts("PHP Configuration"), ts("MySQL support"), ts("MySQL support not included in PHP.")))) {
         $this->requireMySQLServer($databaseConfig['server'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Does the server exist?"), ts("Can't find the a MySQL server on '%1'.", array(1 => $databaseConfig['server'])), $databaseConfig['server']));
         if ($this->requireMysqlConnection($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Are the access credentials correct?"), ts("That username/password doesn't work")))) {
             @$this->requireMySQLVersion("5.1", array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("MySQL version at least %1", array(1 => '5.1')), ts("MySQL version %1 or higher is required, you are running MySQL %2.", array(1 => '5.1', 2 => mysqli_get_server_info($this->conn))), ts("MySQL %1", array(1 => mysqli_get_server_info($this->conn)))));
             $this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Is auto_increment_increment set to 1"), ts("An auto_increment_increment value greater than 1 is not currently supported. Please see issue CRM-7923 for further details and potential workaround.")));
             $testDetails = array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Is the provided database name valid?"), ts("The database name provided is not valid. Please use only 0-9, a-z, A-Z, _ and - as characters in the name."));
             if (!CRM_Core_DAO::requireSafeDBName($databaseConfig['database'])) {
                 $this->error($testDetails);
                 return FALSE;
             } else {
                 $this->testing($testDetails);
             }
             $this->requireMySQLThreadStack($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], self::MINIMUM_THREAD_STACK, array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Does MySQL thread_stack meet minimum (%1k)", array(1 => self::MINIMUM_THREAD_STACK)), ""));
         }
         $onlyRequire = $dbName == 'Drupal' || $dbName == 'Backdrop' ? TRUE : FALSE;
         $this->requireDatabaseOrCreatePermissions($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Can I access/create the database?"), ts("I can't create new databases and the database '%1' doesn't exist.", array(1 => $databaseConfig['database']))), $onlyRequire);
         if ($dbName != 'Drupal' && $dbName != 'Backdrop') {
             $this->requireMySQLInnoDB($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts("Can I access/create InnoDB tables in the database?"), ts("Unable to create InnoDB tables. MySQL InnoDB support is required for CiviCRM but is either not available or not enabled in this MySQL database server.")));
             $this->requireMySQLTempTables($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts('Can I create temporary tables in the database?'), ts('Unable to create temporary tables. This MySQL user is missing the CREATE TEMPORARY TABLES privilege.')));
             $this->requireMySQLLockTables($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts('Can I create lock tables in the database?'), ts('Unable to lock tables. This MySQL user is missing the LOCK TABLES privilege.')));
             $this->requireMySQLTrigger($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], array(ts("MySQL %1 Configuration", array(1 => $dbName)), ts('Can I create triggers in the database?'), ts('Unable to create triggers. This MySQL user is missing the CREATE TRIGGERS  privilege.')));
         }
     }
 }
Exemplo n.º 2
0
 /**
  * requireSafeDBName() method (to check valid database name)
  */
 public function testRequireSafeDBName()
 {
     $databases = array('testdb' => TRUE, 'test_db' => TRUE, 'TEST_db' => TRUE, '123testdb' => TRUE, 'test12db34' => TRUE, 'test_12_db34' => TRUE, 'test-db' => TRUE, 'test;db' => FALSE, 'test*&db' => FALSE, 'testdb;Delete test' => FALSE, '123456' => FALSE, 'test#$%^&*' => FALSE);
     $testDetails = array();
     foreach ($databases as $database => $val) {
         $this->assertEquals(CRM_Core_DAO::requireSafeDBName($database), $val);
     }
 }