This commit is contained in:
Peter Ivanov 2024-08-27 14:43:58 +03:00
parent 6c3e9cf4cc
commit 9119906f2a

View file

@ -29,19 +29,19 @@ class DomainIsCreatedListener
public function handle(DomainIsCreated $event): void
{
$findDomain = Domain::where('id', $event->model->id)->first();
if (! $findDomain) {
if (!$findDomain) {
return;
}
$findHostingSubscription = HostingSubscription::where('id', $findDomain->hosting_subscription_id)->first();
if (! $findHostingSubscription) {
if (!$findHostingSubscription) {
return;
}
$findHostingPlan = HostingPlan::where('id', $findHostingSubscription->hosting_plan_id)->first();
if (! $findHostingPlan) {
if (!$findHostingPlan) {
return;
}
if (! in_array('microweber', $findHostingPlan->additional_services)) {
if (!in_array('microweber', $findHostingPlan->additional_services)) {
return;
}
@ -56,32 +56,57 @@ class DomainIsCreatedListener
$createdDatabaseHost = null;
$createdDatabasePort = null;
try {
$databseType = 'sqlite';
$databasesAreCreated = false;
$shouldCreateMysqlDatabase = false;
$databaseUserPassword = Str::password(24);
$databaseName = $databaseUsername = 'mw'.time();
$hss = new HostingSubscriptionService($findDomain->hosting_subscription_id);
$createDatabase = $hss->createDatabase($databaseName);
if (isset($createDatabase['data']['database_name'])) {
$createdDatabaseName = $createDatabase['data']['database_name'];
}
$createDatabaseUser = $hss->createDatabaseUser($createDatabase['data']['database_id'], $databaseUsername,$databaseUserPassword);
if (isset($createDatabaseUser['data']['database_user'])) {
$createdDatabaseUsername = $createDatabaseUser['data']['database_user'];
$createdDatabaseUserPassword = $createDatabaseUser['data']['database_password'];
$createdDatabaseHost = $createDatabase['data']['database_host'];
$createdDatabasePort = $createDatabase['data']['database_port'];
}
$microweberSettingsFromPanel = setting('microweber');
$databasesAreCreated = true;
} catch (\Exception $e) {
$databasesAreCreated = false;
if (isset($microweberSettingsFromPanel['database_driver']) && $microweberSettingsFromPanel['database_driver'] == 'mysql') {
$shouldCreateMysqlDatabase = true;
}
if($shouldCreateMysqlDatabase) {
try {
$databaseUserPassword = Str::password(24);
$databaseName = $databaseUsername = 'mw' . time();
$hss = new HostingSubscriptionService($findDomain->hosting_subscription_id);
$createDatabase = $hss->createDatabase($databaseName);
if (isset($createDatabase['data']['database_name'])) {
$createdDatabaseName = $createDatabase['data']['database_name'];
}
$createDatabaseUser = $hss->createDatabaseUser($createDatabase['data']['database_id'], $databaseUsername, $databaseUserPassword);
if (isset($createDatabaseUser['data']['database_user'])) {
$createdDatabaseUsername = $createDatabaseUser['data']['database_user'];
$createdDatabaseUserPassword = $createDatabaseUser['data']['database_password'];
$createdDatabaseHost = $createDatabase['data']['database_host'];
$createdDatabasePort = $createDatabase['data']['database_port'];
}
$databasesAreCreated = true;
} catch (\Exception $e) {
$databasesAreCreated = false;
}
}
$installationType = 'symlink';
$installationLanguage = 'bg';
$installationLanguage = 'en';
$website_manager_url = 'https://microweber.com';
//$installationTemplate = 'default';
if (isset($microweberSettingsFromPanel['default_installation_type']) && $microweberSettingsFromPanel['default_installation_type'] == 'standalone') {
$installationType = 'standalone';
}
if (isset($microweberSettingsFromPanel['website_manager_url']) && $microweberSettingsFromPanel['website_manager_url']) {
$website_manager_url = $microweberSettingsFromPanel['website_manager_url'];
}
// dd(setting('microweber'));
$install = new \MicroweberPackages\SharedServerScripts\MicroweberInstaller();
$install->setChownUser($findDomain->domain_username);
@ -93,7 +118,12 @@ class DomainIsCreatedListener
$install->setLanguage($installationLanguage);
//$install->setStandaloneInstallation();
$install->setSymlinkInstallation();
if($installationType == 'symlink') {
$install->setSymlinkInstallation();
} else {
$install->setStandaloneInstallation();
}
if ($databasesAreCreated) {
$install->setDatabaseDriver('mysql');
@ -114,7 +144,7 @@ class DomainIsCreatedListener
if (isset($status['success']) && $status['success']) {
$whiteLabelSettings = [];
$whiteLabelSettings['website_manager_url'] = 'https://microweber.com';
$whiteLabelSettings['website_manager_url'] = $website_manager_url;
$whitelabel = new MicroweberWhitelabelSettingsUpdater();
$whitelabel->setPath($findDomain->domain_public);
@ -124,7 +154,7 @@ class DomainIsCreatedListener
->where('domain_id', $findDomain->id)
->first();
if (! $findInstallation) {
if (!$findInstallation) {
$findInstallation = new MicroweberInstallation();
$findInstallation->domain_id = $findDomain->id;
$findInstallation->installation_path = $findDomain->domain_public;