[Legacy] Add debug feedback to AppInstallService

This commit is contained in:
Clemente Raposo 2025-01-14 10:37:44 +00:00 committed by c.raposo
parent 251cf15c56
commit 58c2cc4afc

View file

@ -111,10 +111,7 @@ class AppInstallService
if (!empty($sugar_config['installer_locked'])) { if (!empty($sugar_config['installer_locked'])) {
return [ return $this->buildResult(false, ['Installer has been disabled']);
'success' => false,
'messages' => ['Installer has been disabled'],
];
} }
//check to see if the script files need to be rebuilt, add needed variables to request array //check to see if the script files need to be rebuilt, add needed variables to request array
@ -200,8 +197,13 @@ class AppInstallService
// Add check here to see if a silent install config file exists; if so then launch silent installer // Add check here to see if a silent install config file exists; if so then launch silent installer
try {
pullSilentInstallVarsIntoSession(); pullSilentInstallVarsIntoSession();
} catch (Exception $e) {
$this->addDebug($e->getMessage());
$this->addMessage($e->getMessage());
return $this->buildResult(false);
}
$validation_errors = array(); $validation_errors = array();
@ -240,10 +242,7 @@ class AppInstallService
} }
if ($si_errors) { if ($si_errors) {
return [ return $this->buildResult(false, $validation_errors ?? []);
'success' => false,
'messages' => $validation_errors ?? [],
];
} }
//since this is a SilentInstall we still need to make sure that //since this is a SilentInstall we still need to make sure that
@ -252,16 +251,12 @@ class AppInstallService
$result = make_writable('./config.php'); $result = make_writable('./config.php');
if (!$result) { if (!$result) {
return [ return $this->buildResult(false, ['Not able to write to /public/legacy/config.php']);
'success' => false,
'messages' => ['Not able to write to /public/legacy/config.php'],
];
} }
// custom dir // custom dir
make_writable('./custom'); make_writable('./custom');
// modules dir // modules dir
recursive_make_writable('./modules'); recursive_make_writable('./modules');
@ -281,29 +276,24 @@ class AppInstallService
recursive_make_writable('./public'); recursive_make_writable('./public');
installerHook('pre_installFileRequire', ['the_file' => 'install/perform_setup.php']); installerHook('pre_installFileRequire', ['the_file' => 'install/perform_setup.php']);
$performSetupResult = [];
try { try {
$this->performSetup(); $performSetupResult = $this->performSetup();
} catch (Exception $e) { } catch (Exception $e) {
return [ return $this->buildResult(false, [$e->getMessage()]);
'success' => false,
'messages' => [$e->getMessage()],
'debug' => $this->getDebug()
];
} }
installerHook('post_installFileRequire', ['the_file' => 'install/perform_setup.php']); installerHook('post_installFileRequire', ['the_file' => 'install/perform_setup.php']);
$success = true;
if (isset($performSetupResult['success']) && $performSetupResult['success'] === false) { if (isset($performSetupResult['success']) && $performSetupResult['success'] === false) {
return $performSetupResult; $success = false;
} }
return [ return $this->buildResult($success);
'success' => true,
'messages' => []
];
} }
protected function performSetup() protected function performSetup(): array
{ {
global $mod_strings; global $mod_strings;
@ -949,6 +939,9 @@ class AppInstallService
$this->installStatus('Installation process finished'); $this->installStatus('Installation process finished');
return [
'success' => true
];
} }
protected function getSupportedInstallLanguages(): array protected function getSupportedInstallLanguages(): array
@ -1070,9 +1063,24 @@ class AppInstallService
} }
protected function addMessage(array $message): void protected function addMessage(string $message): void
{ {
$this->messages[] = $message; $this->messages[] = $message;
} }
/**
* @param bool $success
* @param array $messages
* @param array $debug
* @return array
*/
protected function buildResult(bool $success, array $messages = [], array $debug = []): array
{
return [
'success' => $success,
'messages' => array_merge($this->getMessages(), $messages),
'debug' => array_merge($this->getDebug(), $debug)
];
}
} }