public function testGetDatabaseInfoFromConnectionString()
 {
     $dsn = 'mysql:host=localhost;port=3306;dbname=zurmo';
     // Not Coding Standard
     $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString($dsn);
     $compareData = array('databaseType' => 'mysql', 'databaseHost' => 'localhost', 'databasePort' => '3306', 'databaseName' => 'zurmo');
     $this->assertEquals($compareData, $databaseConnectionInfo);
     $dsn = 'mysql:host=127.0.0.1;dbname=zurmo';
     // Not Coding Standard
     $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString($dsn);
     $compareData = array('databaseType' => 'mysql', 'databaseHost' => '127.0.0.1', 'databasePort' => '3306', 'databaseName' => 'zurmo');
     $this->assertEquals($compareData, $databaseConnectionInfo);
     $dsn = 'mysql:host=localhost;dbname=zurmo;port=3306;';
     // Not Coding Standard
     $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString($dsn);
     $compareData = array('databaseType' => 'mysql', 'databaseHost' => 'localhost', 'databasePort' => '3306', 'databaseName' => 'zurmo');
     $this->assertEquals($compareData, $databaseConnectionInfo);
     $dsn = 'mysql:host=localhost;';
     // Not Coding Standard
     try {
         $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString($dsn);
         $this->fail();
     } catch (NotSupportedException $e) {
     }
 }
 public function __construct()
 {
     parent::__construct();
     list(, $this->temporaryDatabaseHostname, $this->temporaryDatabasePort, $this->temporaryDatabaseName) = array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->tempDb->connectionString));
     $this->temporaryDatabaseUsername = Yii::app()->tempDb->username;
     $this->temporaryDatabasePassword = Yii::app()->tempDb->password;
     $this->superUserPassword = '******';
 }
 public function __construct()
 {
     parent::__construct();
     list(, $this->temporaryDatabaseHostname, $this->temporaryDatabasePort, $this->temporaryDatabaseName) = array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->tempDb->connectionString));
     $this->temporaryDatabaseUsername = Yii::app()->tempDb->username;
     $this->temporaryDatabasePassword = Yii::app()->tempDb->password;
     $this->superUserPassword = '******';
     $this->databaseBackupTestFile = INSTANCE_ROOT . '/protected/runtime/databaseBackupTest.sql';
 }
 public function setUp()
 {
     parent::setUp();
     list(, $this->databaseHostname, $this->databasePort, $this->databaseName) = array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString));
     $this->databaseUsername = Yii::app()->db->username;
     $this->databasePassword = Yii::app()->db->password;
     $this->superUserPassword = '******';
     $this->instanceRoot = INSTANCE_ROOT;
     $this->perInstanceFile = "{$this->instanceRoot}/protected/config/perInstanceTest.php";
     $this->debugFile = "{$this->instanceRoot}/protected/config/debugTest.php";
     if (is_file($this->perInstanceFile)) {
         $this->perInstanceConfigContents = file_get_contents($this->perInstanceFile);
         unlink($this->perInstanceFile);
     }
     if (is_file($this->debugFile)) {
         $this->debugConfigContents = file_get_contents($this->debugFile);
         unlink($this->debugFile);
     }
     Yii::app()->gameHelper->muteScoringModelsOnSave();
 }
Exemple #5
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     set_time_limit('3600');
     if (!isset($args[0])) {
         $this->usageError('You must specify an action.');
     } else {
         $action = $args[0];
     }
     if (!isset($args[1])) {
         $this->usageError('You must specify a path to the file.');
     } else {
         $filePath = $args[1];
     }
     if (count($args) != 2 && count($args) != 8) {
         $this->usageError('Invalid number of arguments.');
     }
     if (count($args) == 8) {
         $databaseType = $args[2];
         $databaseHost = $args[3];
         $databaseName = $args[4];
         $databasePort = $args[5];
         $databaseUsername = $args[6];
         $databasePassword = $args[7];
     } else {
         $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString);
         $databaseType = $databaseConnectionInfo['databaseType'];
         $databaseHost = $databaseConnectionInfo['databaseHost'];
         $databaseName = $databaseConnectionInfo['databaseName'];
         $databasePort = $databaseConnectionInfo['databasePort'];
         $databaseUsername = Yii::app()->db->username;
         $databasePassword = Yii::app()->db->password;
     }
     if (!Yii::app()->isApplicationInMaintenanceMode()) {
         $this->usageError('Please set $maintenanceMode = true in the perInstance.php config file.');
     }
     if (!function_exists('exec')) {
         $this->usageError('exec() command is not available in PHP environment.');
     }
     try {
         $template = "{message}\n";
         $messageStreamer = new MessageStreamer($template);
         $messageStreamer->setExtraRenderBytes(0);
         $messageStreamer->add(' ');
         if ($action == 'backup') {
             $this->backupDatabase($filePath, $messageStreamer, $databaseType, $databaseHost, $databaseName, $databasePort, $databaseUsername, $databasePassword);
         } elseif ($action == 'restore') {
             $this->restoreDatabase($filePath, $messageStreamer, $databaseType, $databaseHost, $databaseName, $databasePort, $databaseUsername, $databasePassword);
         } else {
             $this->usageError('Invalid action. Valid values are "backup" and "restore".');
         }
     } catch (Exception $e) {
         $messageStreamer->add(Zurmo::t('Commands', 'An error occur during database backup/restore: {message}', array('{message}' => $e->getMessage())));
     }
 }
 public static function checkServicesAfterInstallationAndGetResultsDataForDisplay()
 {
     $servicesToCheck = self::getServicesToCheckAfterInstallation();
     $form = new InstallSettingsForm();
     list(, $form->databaseHostname, $form->databasePort, $form->databaseName) = array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString));
     $form->databaseUsername = Yii::app()->db->username;
     $form->databasePassword = Yii::app()->db->password;
     return static::processServicesAndGetResultsData($servicesToCheck, $form);
 }
 /**
  * Check whether db supports load local infile or not.
  * public due to usage in benchmarks
  * @return bool
  */
 public static function databaseSupportsLoadLocalInFile()
 {
     list($databaseType, $databaseHostname, $databasePort) = array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString));
     return InstallUtil::checkDatabaseLoadLocalInFile($databaseType, $databaseHostname, Yii::app()->db->username, Yii::app()->db->password, $databasePort);
 }