Example #1
0
 /**
  * @throws CApiBaseException(Errs::Db_ExceptionError) 3001
  *
  * @return bool
  */
 public function createDatabase()
 {
     CDbCreator::ClearStatic();
     $aConnections =& CDbCreator::CreateConnector($this->oSettings);
     $oConnect = $aConnections[0];
     if ($oConnect) {
         $oConnect->ConnectNoSelect();
         $oConnect->Execute($this->oCommandCreator->createDatabase($this->oSettings->GetConf('DBName')));
     } else {
         throw new CApiBaseException(Errs::Db_ExceptionError);
     }
     return true;
 }
Example #2
0
 public function SystemDb()
 {
     if (CApi::getCsrfToken('p7admToken') === CPost::get('txtToken')) {
         if (CApi::GetConf('mailsuite', false)) {
             $this->oSettings->SetConf('Common/DBType', EDbType::MySQL);
         } else {
             $this->oSettings->SetConf('Common/DBType', EnumConvert::FromPost(CPost::get('radioSqlType'), 'EDbType'));
         }
         if (CPost::Has('txtSqlLogin')) {
             $this->oSettings->SetConf('Common/DBLogin', CPost::get('txtSqlLogin'));
         }
         if (CPost::Has('txtSqlPassword') && AP_DUMMYPASSWORD !== (string) CPost::get('txtSqlPassword')) {
             $this->oSettings->SetConf('Common/DBPassword', CPost::get('txtSqlPassword'));
         }
         if (CPost::Has('txtSqlName')) {
             $this->oSettings->SetConf('Common/DBName', CPost::get('txtSqlName'));
         }
         if (CPost::Has('txtSqlSrc')) {
             $this->oSettings->SetConf('Common/DBHost', CPost::get('txtSqlSrc'));
         }
         if (CPost::GetCheckBox('isTestConnection')) {
             CDbCreator::ClearStatic();
             $aConnections =& CDbCreator::CreateConnector($this->oSettings);
             $oConnect = $aConnections[0];
             if ($oConnect) {
                 $this->LastError = AP_LANG_CONNECTUNSUCCESSFUL;
                 try {
                     if ($oConnect->Connect()) {
                         $this->LastMessage = AP_LANG_CONNECTSUCCESSFUL;
                         $this->LastError = '';
                     }
                 } catch (CApiDbException $oException) {
                     $this->LastError .= "\r\n" . $oException->getMessage() . ' (' . (int) $oException->getCode() . ')';
                 }
             } else {
                 $this->LastError = AP_LANG_CONNECTUNSUCCESSFUL;
             }
             $this->oSettings->SaveToXml();
         } else {
             $this->saveSettingsXmlWithMessage();
         }
     }
     return '';
 }
<?php

include_once '/var/www/html/libraries/afterlogic/api.php';
if (CApi::IsValid()) {
    $settings =& CApi::GetSettings();
    if ($settings) {
        $settings->SetConf('Common/DBHost', 'localhost');
        $settings->SetConf('Common/DBName', 'afterlogic');
        $settings->SetConf('Common/DBLogin', 'root');
        $settings->SetConf('Common/DBPassword', 'webbundle');
        CDbCreator::ClearStatic();
        CDbCreator::CreateConnector($settings);
        $oApiDbManager = CApi::Manager('db');
        $oApiDbManager->SyncTables();
        $settings->SaveToXml();
    }
}
Example #4
0
 public function DoPost()
 {
     if (isset($_POST['test_btn'])) {
         $this->initDbSettings();
         $sError = $sMessage = '';
         CDbCreator::ClearStatic();
         $aConnections =& CDbCreator::CreateConnector($this->oSettings);
         $oConnect = $aConnections[0];
         if ($oConnect) {
             $sError = 'Failed to connect.';
             try {
                 if ($oConnect->Connect()) {
                     $sMessage = 'Connected successfully.';
                     $sError = '';
                 }
             } catch (CApiDbException $oException) {
                 $sError .= "\r\n" . $oException->getMessage() . ' (' . (int) $oException->getCode() . ')';
             }
         } else {
             $sError = 'Failed to connect.';
         }
         if (!empty($sError)) {
             $_SESSION['wm_install_db_test_error'] = $sError;
         } else {
             if (!empty($sMessage)) {
                 $_SESSION['wm_install_db_test_message'] = $sMessage;
             }
         }
     } else {
         if (isset($_POST['create_db_btn'])) {
             $this->initDbSettings();
             $sError = '';
             /* @var $oApiDbManager CApiDbManager */
             $oApiDbManager = CApi::Manager('db');
             if ($oApiDbManager->createDatabase($sError)) {
                 $_SESSION['wm_install_db_name_create_message'] = 'Database created successfully.';
             } else {
                 $_SESSION['wm_install_db_name_create_error'] = $sError;
             }
         } else {
             if (isset($_POST['next_btn'])) {
                 $this->initDbSettings();
                 $bResult = true;
                 if (isset($_POST['chNotCreate']) && 1 === (int) $_POST['chNotCreate']) {
                     /* @var $oApiDbManager CApiDbManager */
                     $oApiDbManager = CApi::Manager('db');
                     if ($oApiDbManager->isAUsersTableExists()) {
                         $_SESSION['wm_install_db_foot_error'] = 'The data tables already exist. To proceed, specify another prefix or delete the existing tables.';
                         $bResult = false;
                     } else {
                         $bResult = $oApiDbManager->syncTables();
                         if (!$bResult) {
                             $_SESSION['wm_install_db_foot_error'] = $oApiDbManager->GetLastErrorMessage();
                         }
                     }
                 }
                 $_SESSION['wm-install-create-db'] = true;
                 return $bResult;
             }
         }
     }
     return false;
 }