Skip to content

Commit

Permalink
Extract SystemMessages class from Util,
Browse files Browse the repository at this point in the history
Improve messages on cloud provisioning
  • Loading branch information
jorikfon committed Apr 10, 2024
1 parent bfd7fd5 commit a560587
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
13 changes: 6 additions & 7 deletions src/AdminCabinet/Controllers/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ class SessionController extends BaseController
*/
public function indexAction(): void
{
$this->view->NameFromSettings
= PbxSettings::getValueByKey(PbxSettingsConstants::PBX_NAME);
$this->view->DescriptionFromSettings
= PbxSettings::getValueByKey(PbxSettingsConstants::PBX_DESCRIPTION);
if ($this->view->DescriptionFromSettings==='auth_DefaultCloudPasswordInstructions'){
$this->view->DescriptionFromSettings=$this->translation->_($this->view->DescriptionFromSettings);
$this->view->setVar('NameFromSettings', PbxSettings::getValueByKey(PbxSettingsConstants::PBX_NAME));
$description = PbxSettings::getValueByKey(PbxSettingsConstants::PBX_DESCRIPTION);
if ($description===PbxSettingsConstants::DEFAULT_CLOUD_PASSWORD_DESCRIPTION){
$description=$this->translation->_($description);
}
$this->view->form = new LoginForm();
$this->view->setVar('DescriptionFromSettings', $description);
$this->view->setVar('form', new LoginForm());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Common/Models/PbxSettingsConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ abstract class PbxSettingsConstants
const PBX_LICENSE = 'PBXLicense';


// Other
const DEFAULT_CLOUD_PASSWORD_DESCRIPTION = 'auth_DefaultCloudPasswordInstructions';
}
24 changes: 12 additions & 12 deletions src/Core/System/CloudProvisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CloudProvisioning
*/
public static function start(): void
{
if (self::checkItNeedToStartProvisioning()===false){
if (self::checkItNeedToStartProvisioning() === false) {
$message = " |- Provisioning was already completed.";
SystemMessages::echoToTeletype($message);
SystemMessages::teletypeEchoResult($message, SystemMessages::RESULT_SKIPPED);
Expand Down Expand Up @@ -70,6 +70,17 @@ public static function start(): void
}
}

/**
* Checks if provisioning is needed.
*/
private static function checkItNeedToStartProvisioning(): bool
{
if (PbxSettings::findFirst('key="' . PbxSettingsConstants::CLOUD_PROVISIONING . '"') === null) {
return true; // Need provision
}
return false; // Provisioning is already completed
}

/**
* After provisioning, perform the following actions:
* @param $provider mixed The provider object.
Expand All @@ -87,15 +98,4 @@ public static function afterProvisioning($provider, string $cloudName): void
$provider->updatePbxSettings(PbxSettingsConstants::VIRTUAL_HARDWARE_TYPE, $cloudName);

}

/**
* Checks if provisioning is needed.
*/
private static function checkItNeedToStartProvisioning(): bool
{
if (PbxSettings::findFirst('key="' . PbxSettingsConstants::CLOUD_PROVISIONING . '"') === null) {
return true; // Need provision
}
return false; // Provisioning is already completed
}
}
1 change: 1 addition & 0 deletions src/Core/System/CloudProvisioning/CloudProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ protected function updateWebPassword(string $webPassword): void
}
$this->updatePbxSettings(PbxSettingsConstants::WEB_ADMIN_PASSWORD, $webPassword);
$this->updatePbxSettings(PbxSettingsConstants::CLOUD_INSTANCE_ID, $webPassword);
$this->updatePbxSettings(PbxSettingsConstants::PBX_DESCRIPTION, PbxSettingsConstants::DEFAULT_CLOUD_PASSWORD_DESCRIPTION);
}

}
8 changes: 2 additions & 6 deletions src/Core/System/RootFS/etc/rc/bootup
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@
*/

namespace MikoPBX\Core\RootFS\etc\rc;
use MikoPBX\Core\System\{Processes, SystemMessages, Util, SystemLoader};
use MikoPBX\Core\System\{Processes, Util, SystemLoader};

require_once('Globals.php');

// Echo message with syslog
SystemMessages::echoWithSyslog(' - Start /etc/rc/bootup ...'.PHP_EOL);

// Sleep if /tmp/ejectcd file exists
if(file_exists('/tmp/ejectcd')){
sleep(15);
}

// Create instance of SystemLoader and start the system
// Create an instance of SystemLoader and start the system
$mikoPBX = new SystemLoader();
SystemMessages::echoWithSyslog(' - Start SystemLoader\startSystem...'.PHP_EOL);
$result = $mikoPBX->startSystem();

// Run /etc/rc/bootup_pbx in background if system start is successful
Expand Down
5 changes: 1 addition & 4 deletions src/Core/System/RootFS/etc/rc/bootup_pbx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@

namespace MikoPBX\Core\RootFS\etc\rc;

use MikoPBX\Core\System\{SystemMessages, SystemLoader};
use MikoPBX\Core\System\SystemLoader;
require_once('Globals.php');

SystemMessages::echoWithSyslog(' - Start /etc/rc/bootup_pbx ...'.PHP_EOL);
SystemMessages::echoWithSyslog(' - Start SystemLoader ...'.PHP_EOL);

// Create instance of SystemLoader and start MikoPBX
$mikoPBX = new SystemLoader();
$mikoPBX->startMikoPBX();
5 changes: 2 additions & 3 deletions src/Core/System/SystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ public function startSystem(): bool

// Start cloud provisioning
if (!$this->isDocker) {
$this->echoStartMsg(' - Cloud provisioning...'."\n");
$this->echoStartMsg(' - Cloud provisioning...'.PHP_EOL);
CloudProvisioning::start();
$this->echoResultMsg();

// Connect storage in a cloud if needed
$this->echoStartMsg(' - Auto connect storage for a cloud ..."\n"');
$this->echoStartMsg(' - Auto connect storage for a cloud ...'.PHP_EOL);
$connectResult = Storage::connectStorageInCloud();
$this->echoResultMsg($connectResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

class ReloadCloudDescriptionAction implements ReloadActionInterface
{
public const DEFAULT_PASSWORD_DESCRIPTION = 'auth_DefaultCloudPasswordInstructions';

/**
* Reset default cloud password instructions
*
Expand All @@ -21,11 +19,12 @@ public function execute(array $parameters = []): void
$description = PbxSettings::getValueByKey(PbxSettingsConstants::PBX_DESCRIPTION);
$cloudInstanceId = PbxSettings::getValueByKey(PbxSettingsConstants::CLOUD_INSTANCE_ID);
$webAdminPassword = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_ADMIN_PASSWORD);
$defaultDescription = PbxSettingsConstants::DEFAULT_CLOUD_PASSWORD_DESCRIPTION;

if ($cloudInstanceId === $webAdminPassword && $description!==self::DEFAULT_PASSWORD_DESCRIPTION){
if ($cloudInstanceId === $webAdminPassword && $description!==$defaultDescription){
$config = new MikoPBXConfig();
$config->setGeneralSettings(PbxSettingsConstants::PBX_DESCRIPTION, self::DEFAULT_PASSWORD_DESCRIPTION);
} elseIf ($description === self::DEFAULT_PASSWORD_DESCRIPTION) {
$config->setGeneralSettings(PbxSettingsConstants::PBX_DESCRIPTION, $defaultDescription);
} elseIf ($description === $defaultDescription) {
$config = new MikoPBXConfig();
$config->resetGeneralSettings(PbxSettingsConstants::PBX_DESCRIPTION);
}
Expand Down

0 comments on commit a560587

Please sign in to comment.