New Query fix
This commit is contained in:
@@ -9,8 +9,8 @@ services:
|
||||
restart: always
|
||||
volumes: ['DESTINATION_FOLDER:/var/www/html']
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: db:3306
|
||||
WORDPRESS_DB_USER: bloguser
|
||||
WORDPRESS_DB_HOST: CNT_DB_DATA
|
||||
WORDPRESS_DB_USER: CNT_DB_NAME
|
||||
WORDPRESS_DB_PASSWORD: CNT_DB_PASS
|
||||
WORDPRESS_DB_NAME: CNT_DB_NAME
|
||||
networks:
|
||||
|
||||
@@ -9,8 +9,8 @@ services:
|
||||
restart: always
|
||||
volumes: ['DESTINATION_FOLDER:/var/www/html']
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: db:3306
|
||||
WORDPRESS_DB_USER: bloguser
|
||||
WORDPRESS_DB_HOST: CNT_DB_DATA
|
||||
WORDPRESS_DB_USER: CNT_DB_NAME
|
||||
WORDPRESS_DB_PASSWORD: CNT_DB_PASS
|
||||
WORDPRESS_DB_NAME: CNT_DB_NAME
|
||||
networks:
|
||||
|
||||
@@ -9,18 +9,72 @@ class Provision extends BaseController
|
||||
|
||||
public function prepareProvision(): string
|
||||
{
|
||||
$this->allocatePortNo(); // allocte port for the conyainer use
|
||||
// $this->allocatePortNo(); // allocte port for the conyainer use
|
||||
|
||||
$this->prepareDataBase(); // allocte port for the conyainer use
|
||||
|
||||
$this->updateProvision();
|
||||
// $this->updateProvision();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function prepareDataBase():string
|
||||
{
|
||||
$servername = "172.16.4.96:3307";
|
||||
$database = "wordpress";
|
||||
$username = "root";
|
||||
$password = "may12002!";
|
||||
// Create connection
|
||||
$conn = mysqli_connect($servername, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
echo "Connected successfully";
|
||||
|
||||
$list_limit = 12;
|
||||
$mysql = "SELECT id, member_id, uid, internal_url,product_id,status,provision_port,updated
|
||||
FROM members_products
|
||||
WHERE db_status = 0 AND product_id IN ('A000004','A000003')
|
||||
ORDER BY updated ASC LIMIT ".$list_limit;
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
$provision_list = $query->getResult();
|
||||
foreach ($provision_list as $pr) {
|
||||
$memberID = $pr->member_id;
|
||||
$productId = $pr->product_id;
|
||||
$provisionUID = $pr->uid;
|
||||
$ContainerName = $productId . str_pad($pr->id, 10, "0", STR_PAD_LEFT);
|
||||
|
||||
// $allocated_port = $this->allocatePortNumber( $productId );
|
||||
// $primary_server = $this->provisionServer( $productId );
|
||||
// $mysql = "UPDATE members_products SET updated=now(), provision_port=".$allocated_port.", primary_server='".$primary_server."' WHERE uid::TEXT = '".$provisionUID."' AND provision_port = 0";
|
||||
// $query = $this->db->query($mysql);
|
||||
$dbName = $ContainerName;
|
||||
// Create database
|
||||
$sql = "CREATE DATABASE $dbName";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "Database created successfully";
|
||||
|
||||
$sql = "CREATE USER '" . $dbName . "'@'localhost' IDENTIFIED BY '" . $provisionUID . "'";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
$sql = "GRANT SELECT , INSERT , UPDATE , DELETE ON " . $dbName . " . * TO '" . $dbName . "'@'localhost' IDENTIFIED BY '" . $provisionUID . "'";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
|
||||
$mysql = "UPDATE members_products SET updated=now(), db_status = db_status + 1 WHERE uid::TEXT = '".$provisionUID."'";
|
||||
$query = $this->db->query($mysql);
|
||||
|
||||
} else {
|
||||
echo "Error creating database: " . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check connection
|
||||
|
||||
|
||||
|
||||
|
||||
mysqli_close($conn);
|
||||
|
||||
return '';
|
||||
}
|
||||
@@ -76,6 +130,7 @@ class Provision extends BaseController
|
||||
$composer_template_contents = str_replace("ALLOCATED_PORT", $allocatedPort, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("CNT_DB_NAME", $ContainerName, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("CNT_DB_PASS", $provisionUID, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("CNT_DB_DATA", '172.16.4.96:3307', $composer_template_contents);
|
||||
|
||||
//Save to the specific path
|
||||
$destination_composer_path = $ansible_folder . "/parts/" . $provisionUID . "/docker-compose.yml";
|
||||
|
||||
Reference in New Issue
Block a user