Adicion de test para DATABASE CONNECTIONS
This commit is contained in:
@@ -180,43 +180,69 @@ class DataBaseConnection
|
|||||||
$oContent->removeContent( 'DBS_DESCRIPTION', "", $dbConnecionUid );
|
$oContent->removeContent( 'DBS_DESCRIPTION', "", $dbConnecionUid );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConnection($dataCon, $returnArray = false)
|
||||||
public function testConnection($dataCon)
|
|
||||||
{
|
{
|
||||||
$resp = array();
|
$resp = array();
|
||||||
|
$respTest = array();
|
||||||
$resp['resp'] = false;
|
$resp['resp'] = false;
|
||||||
|
|
||||||
|
$dataCon = array_change_key_case($dataCon, CASE_UPPER);
|
||||||
|
|
||||||
G::LoadClass( 'net' );
|
G::LoadClass( 'net' );
|
||||||
$Server = new \NET($dataCon['DBS_SERVER']);
|
$Server = new \NET($dataCon['DBS_SERVER']);
|
||||||
|
|
||||||
// STEP 1 : Resolving Host Name
|
// STEP 1 : Resolving Host Name
|
||||||
|
$respTest['0'] = array();
|
||||||
|
$respTest['0']['test'] = 'Resolving Host Name ' . $dataCon['DBS_SERVER'];
|
||||||
if ($Server->getErrno() != 0) {
|
if ($Server->getErrno() != 0) {
|
||||||
$resp['message'] = "Error Testting Connection: Resolving Host Name FAILED : " . $Server->error;
|
if ($returnArray) {
|
||||||
return $resp;
|
$respTest['0']['error'] = "Error Testting Connection: Resolving Host Name FAILED : " . $Server->error;
|
||||||
|
} else {
|
||||||
|
$resp['message'] = "Error Testting Connection: Resolving Host Name FAILED : " . $Server->error;
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2 : Checking port
|
// STEP 2 : Checking port
|
||||||
|
$respTest['1'] = array();
|
||||||
|
$respTest['1']['test'] = 'Checking port ' . $dataCon['DBS_PORT'];
|
||||||
$Server->scannPort($dataCon['DBS_PORT']);
|
$Server->scannPort($dataCon['DBS_PORT']);
|
||||||
if ($Server->getErrno() != 0) {
|
if ($Server->getErrno() != 0) {
|
||||||
$resp['message'] = "Error Testting Connection: Checking port FAILED : " . $Server->error;
|
if ($returnArray) {
|
||||||
return $resp;
|
$respTest['1']['error'] = "Error Testting Connection: Checking port FAILED : " . $Server->error;
|
||||||
|
} else {
|
||||||
|
$resp['message'] = "Error Testting Connection: Checking port FAILED : " . $Server->error;
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 3 : Trying to connect to host
|
// STEP 3 : Trying to connect to host
|
||||||
|
$respTest['2'] = array();
|
||||||
|
$respTest['2']['test'] = 'Trying to connect to host ' . $dataCon['DBS_SERVER'] . (($dataCon['DBS_PORT'] != '') ? ':'.$dataCon['DBS_PORT'] : '');
|
||||||
$Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
|
$Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
|
||||||
$Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
|
$Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
|
||||||
if ($Server->errno == 0) {
|
if ($Server->errno == 0) {
|
||||||
$response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
|
$response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
|
||||||
if ($response->status != 'SUCCESS') {
|
if ($response->status != 'SUCCESS') {
|
||||||
|
if ($returnArray) {
|
||||||
|
$respTest['2']['error'] = "Error Testting Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||||
|
} else {
|
||||||
|
$resp['message'] = "Error Testting Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($returnArray) {
|
||||||
|
$respTest['2']['error'] = "Error Testting Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||||
|
} else {
|
||||||
$resp['message'] = "Error Testting Connection: Trying to connect to host FAILED : " . $Server->error;
|
$resp['message'] = "Error Testting Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$resp['message'] = "Error Testting Connection: Trying to connect to host FAILED : " . $Server->error;
|
|
||||||
return $resp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 4 : Trying to open database
|
// STEP 4 : Trying to open database
|
||||||
|
$respTest['3'] = array();
|
||||||
|
$respTest['3']['test'] = 'Trying to open database [' . $dataCon['DBS_DATABASE_NAME'] . ']';
|
||||||
$Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
|
$Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
|
||||||
$Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
|
$Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
|
||||||
if ($Server->errno == 0) {
|
if ($Server->errno == 0) {
|
||||||
@@ -224,21 +250,37 @@ class DataBaseConnection
|
|||||||
if ($response->status == 'SUCCESS') {
|
if ($response->status == 'SUCCESS') {
|
||||||
$response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']);
|
$response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']);
|
||||||
if ($response->status != 'SUCCESS') {
|
if ($response->status != 'SUCCESS') {
|
||||||
|
if ($returnArray) {
|
||||||
|
$respTest['3']['error'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
||||||
|
} else {
|
||||||
|
$resp['message'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($returnArray) {
|
||||||
|
$respTest['3']['error'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
||||||
|
} else {
|
||||||
$resp['message'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
$resp['message'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($returnArray) {
|
||||||
|
$respTest['3']['error'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
||||||
} else {
|
} else {
|
||||||
$resp['message'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
$resp['message'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$resp['message'] = "Error Testting Connection: Trying to open database FAILED : " . $Server->error;
|
|
||||||
return $resp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CORRECT CONNECTION
|
if ($returnArray) {
|
||||||
$resp['resp'] = true;
|
return $respTest;
|
||||||
return $resp;
|
} else {
|
||||||
|
// CORRECT CONNECTION
|
||||||
|
$resp['resp'] = true;
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,47 @@ class DataBaseConnection extends Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $projectUid {@min 1} {@max 32}
|
||||||
|
* @param array $request_data
|
||||||
|
*
|
||||||
|
* @param string $dbs_type {@from body}
|
||||||
|
* @param string $dbs_server {@from body}
|
||||||
|
* @param string $dbs_database_name {@from body}
|
||||||
|
* @param string $dbs_username {@from body}
|
||||||
|
* @param string $dbs_port {@from body}
|
||||||
|
* @param string $dbs_encode {@from body}
|
||||||
|
* @param string $dbs_password {@from body}
|
||||||
|
* @param string $dbs_description {@from body}
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||||
|
* @copyright Colosa - Bolivia
|
||||||
|
*
|
||||||
|
* @url POST /:projectUid/database-connection/test
|
||||||
|
*/
|
||||||
|
public function doPostTestDataBaseConnection(
|
||||||
|
$projectUid,
|
||||||
|
$request_data,
|
||||||
|
$dbs_type,
|
||||||
|
$dbs_server,
|
||||||
|
$dbs_database_name,
|
||||||
|
$dbs_username,
|
||||||
|
$dbs_port,
|
||||||
|
$dbs_encode,
|
||||||
|
$dbs_password = '',
|
||||||
|
$dbs_description = ''
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
$oDBConnection = new \BusinessModel\DataBaseConnection();
|
||||||
|
$request_data['pro_uid'] = $projectUid;
|
||||||
|
$response = $oDBConnection->testConnection($request_data, true);
|
||||||
|
return $response;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $projectUid {@min 1} {@max 32}
|
* @param string $projectUid {@min 1} {@max 32}
|
||||||
* @param array $request_data
|
* @param array $request_data
|
||||||
|
|||||||
Reference in New Issue
Block a user