Files
MermsProvision/app/Controllers/Home.php
T
2025-01-19 19:01:37 -05:00

48 lines
1.3 KiB
PHP

<?php
namespace App\Controllers;
class Home extends BaseController
{
public function index(): string
{
return view('welcome_message');
}
public function provision(): string
{
$public_path = FCPATH;
$ansible_folder = str_replace("public/", "ANSIBLE", $public_path);
$mysql = "SELECT id, internal_url,product_id,status FROM members_products";
$query = $this->db->query($mysql);
// $num = $query->num_rows();
$provision_list= $query->getResult();
//$provision_list =[];
foreach ($provision_list as $pr){
$productId = $pr->product_id;
$prov_name = str_replace(".", "_", $pr->internal_url).".yml";
$template_file = $ansible_folder ."/templates/".$pr->product_id.".yml";
// GET THE TEMPLATE FOR THIS PROVISIONING
$template_content = file_get_contents($template_file);
$template_content_processed = str_replace("WHAT_HOST_IN_USE", $productId."_SERVER", $template_content);;
// CREATE PROVISOINING FILE
$myfile = fopen( $ansible_folder ."/".$prov_name, "w") or die("Unable to open file!");
fwrite($myfile, $template_content_processed);
fclose($myfile);
}
// echo (__dir__);
return view('welcome_message');
}
}