4040 */
4141class ApplicationInstallSequencer extends StepSequencer
4242{
43- /** @var \Parameters */
44- protected $ oParams ;
45- protected static $ bMetaModelStarted = false ;
43+ protected Parameters $ oParams ;
44+ protected static bool $ bMetaModelStarted = false ;
4645
4746 protected Config $ oConfig ;
4847
@@ -52,7 +51,7 @@ class ApplicationInstallSequencer extends StepSequencer
5251 * @throws \ConfigException
5352 * @throws \CoreException
5453 */
55- public function __construct ($ oParams )
54+ public function __construct (Parameters $ oParams )
5655 {
5756 $ this ->oParams = $ oParams ;
5857
@@ -100,6 +99,27 @@ protected function GetConfig()
10099 return $ oConfig ;
101100 }
102101
102+ protected function DoLogParameters ($ sPrefix = 'install- ' , $ sOperation = 'Installation ' )
103+ {
104+ // Log the parameters...
105+ $ oDoc = new DOMDocument ('1.0 ' , 'UTF-8 ' );
106+ $ oDoc ->preserveWhiteSpace = false ;
107+ $ oDoc ->formatOutput = true ;
108+ $ this ->oParams ->ToXML ($ oDoc , null , 'installation ' );
109+ $ sXML = $ oDoc ->saveXML ();
110+ $ sSafeXml = preg_replace ("|<pwd>([^<]*)</pwd>| " , "<pwd>**removed**</pwd> " , $ sXML );
111+ SetupLog::Info ("======= " .$ sOperation ." starts ======= \nParameters: \n$ sSafeXml \n" );
112+
113+ // Save the response file as a stand-alone file as well
114+ $ sFileName = $ sPrefix .date ('Y-m-d ' );
115+ $ index = 0 ;
116+ while (file_exists (APPROOT .'log/ ' .$ sFileName .'.xml ' )) {
117+ $ index ++;
118+ $ sFileName = $ sPrefix .date ('Y-m-d ' ).'- ' .$ index ;
119+ }
120+ file_put_contents (APPROOT .'log/ ' .$ sFileName .'.xml ' , $ sSafeXml );
121+ }
122+
103123 /**
104124 * Executes the next step of the installation and reports about the progress
105125 * and the next step to perform
@@ -117,32 +137,16 @@ public function ExecuteStep($sStep = '', $sInstallComment = null)
117137 $ this ->EnterReadOnlyMode ();
118138 switch ($ sStep ) {
119139 case '' :
140+
141+ $ this ->DoLogParameters ();
142+
120143 $ aResult = [
121144 'status ' => self ::OK ,
122145 'message ' => '' ,
123146 'percentage-completed ' => 0 ,
124147 'next-step ' => 'copy ' ,
125148 'next-step-label ' => 'Copying data model files ' ,
126149 ];
127-
128- // Log the parameters...
129- $ oDoc = new DOMDocument ('1.0 ' , 'UTF-8 ' );
130- $ oDoc ->preserveWhiteSpace = false ;
131- $ oDoc ->formatOutput = true ;
132- $ this ->oParams ->ToXML ($ oDoc , null , 'installation ' );
133- $ sXML = $ oDoc ->saveXML ();
134- $ sSafeXml = preg_replace ("|<pwd>([^<]*)</pwd>| " , "<pwd>**removed**</pwd> " , $ sXML );
135- SetupLog::Info ("======= Installation starts ======= \nParameters: \n$ sSafeXml \n" );
136-
137- // Save the response file as a stand-alone file as well
138- $ sFileName = 'install- ' .date ('Y-m-d ' );
139- $ index = 0 ;
140- while (file_exists (APPROOT .'log/ ' .$ sFileName .'.xml ' )) {
141- $ index ++;
142- $ sFileName = 'install- ' .date ('Y-m-d ' ).'- ' .$ index ;
143- }
144- file_put_contents (APPROOT .'log/ ' .$ sFileName .'.xml ' , $ sSafeXml );
145-
146150 break ;
147151
148152 case 'copy ' :
@@ -239,15 +243,10 @@ public function ExecuteStep($sStep = '', $sInstallComment = null)
239243
240244 case 'after-db-create ' :
241245 $ aAdminParams = $ this ->oParams ->Get ('admin_account ' );
242- $ sAdminUser = $ aAdminParams ['user ' ];
243- $ sAdminPwd = $ aAdminParams ['pwd ' ];
244- $ sAdminLanguage = $ aAdminParams ['language ' ];
245246 $ aSelectedModules = $ this ->oParams ->Get ('selected_modules ' , []);
246247
247248 $ this ->AfterDBCreate (
248- $ sAdminUser ,
249- $ sAdminPwd ,
250- $ sAdminLanguage ,
249+ $ aAdminParams ,
251250 $ aSelectedModules
252251 );
253252
@@ -261,7 +260,7 @@ public function ExecuteStep($sStep = '', $sInstallComment = null)
261260 break ;
262261
263262 case 'load-data ' :
264- $ aSelectedModules = $ this ->oParams ->Get ('selected_modules ' );
263+ $ aSelectedModules = $ this ->oParams ->Get ('selected_modules ' , [] );
265264 $ bSampleData = ($ this ->oParams ->Get ('sample_data ' , 0 ) == 1 );
266265
267266 $ this ->DoLoadFiles (
@@ -299,7 +298,6 @@ public function ExecuteStep($sStep = '', $sInstallComment = null)
299298 'next-step-label ' => 'Completed ' ,
300299 'percentage-completed ' => 100 ,
301300 ];
302- $ this ->ExitReadOnlyMode ();
303301 break ;
304302
305303 default :
@@ -312,29 +310,18 @@ public function ExecuteStep($sStep = '', $sInstallComment = null)
312310 ];
313311 break ;
314312 }
313+ $ this ->ExitReadOnlyMode ();
315314 } catch (Exception $ e ) {
316315 $ aResult = [
317316 'status ' => self ::ERROR ,
318317 'message ' => $ e ->getMessage (),
319318 'next-step ' => '' ,
320319 'next-step-label ' => '' ,
321320 'percentage-completed ' => 100 ,
321+ 'error_code ' => $ e ->getCode (),
322322 ];
323323
324- SetupLog::Error ('An exception occurred: ' .$ e ->getMessage ().' at line ' .$ e ->getLine ().' in file ' .$ e ->getFile ());
325- $ idx = 0 ;
326- // Log the call stack, but not the parameters since they may contain passwords or other sensitive data
327- SetupLog::Ok ("Call stack: " );
328- foreach ($ e ->getTrace () as $ aTrace ) {
329- $ sLine = empty ($ aTrace ['line ' ]) ? "" : $ aTrace ['line ' ];
330- $ sFile = empty ($ aTrace ['file ' ]) ? "" : $ aTrace ['file ' ];
331- $ sClass = empty ($ aTrace ['class ' ]) ? "" : $ aTrace ['class ' ];
332- $ sType = empty ($ aTrace ['type ' ]) ? "" : $ aTrace ['type ' ];
333- $ sFunction = empty ($ aTrace ['function ' ]) ? "" : $ aTrace ['function ' ];
334- $ sVerb = empty ($ sClass ) ? $ sFunction : "$ sClass {$ sType }$ sFunction " ;
335- SetupLog::Ok ("# $ idx $ sFile( $ sLine): $ sVerb(...) " );
336- $ idx ++;
337- }
324+ $ this ->ReportException ($ e );
338325 } finally {
339326 $ fDuration = round (microtime (true ) - $ fStart , 2 );
340327 SetupLog::Info ("##### STEP {$ sStep } duration: {$ fDuration }s " );
@@ -343,6 +330,24 @@ public function ExecuteStep($sStep = '', $sInstallComment = null)
343330 return $ aResult ;
344331 }
345332
333+ protected function ReportException (Exception $ e )
334+ {
335+ SetupLog::Error ('An exception occurred: ' .$ e ->getMessage ().' at line ' .$ e ->getLine ().' in file ' .$ e ->getFile ());
336+ $ idx = 0 ;
337+ // Log the call stack, but not the parameters since they may contain passwords or other sensitive data
338+ SetupLog::Ok ("Call stack: " );
339+ foreach ($ e ->getTrace () as $ aTrace ) {
340+ $ sLine = empty ($ aTrace ['line ' ]) ? "" : $ aTrace ['line ' ];
341+ $ sFile = empty ($ aTrace ['file ' ]) ? "" : $ aTrace ['file ' ];
342+ $ sClass = empty ($ aTrace ['class ' ]) ? "" : $ aTrace ['class ' ];
343+ $ sType = empty ($ aTrace ['type ' ]) ? "" : $ aTrace ['type ' ];
344+ $ sFunction = empty ($ aTrace ['function ' ]) ? "" : $ aTrace ['function ' ];
345+ $ sVerb = empty ($ sClass ) ? $ sFunction : "$ sClass {$ sType }$ sFunction " ;
346+ SetupLog::Ok ("# $ idx $ sFile( $ sLine): $ sVerb(...) " );
347+ $ idx ++;
348+ }
349+ }
350+
346351 protected function EnterReadOnlyMode ()
347352 {
348353 if ($ this ->GetTargetEnv () != 'production ' ) {
@@ -793,11 +798,14 @@ protected static function MoveColumns($sDBPrefix)
793798 }
794799
795800 protected function AfterDBCreate (
796- $ sAdminUser ,
797- $ sAdminPwd ,
798- $ sAdminLanguage ,
801+ $ aAdminParams ,
799802 $ aSelectedModules
800803 ) {
804+
805+ $ sAdminUser = $ aAdminParams ['user ' ];
806+ $ sAdminPwd = $ aAdminParams ['pwd ' ];
807+ $ sAdminLanguage = $ aAdminParams ['language ' ];
808+
801809 $ aParamValues = $ this ->oParams ->GetParamForConfigArray ();
802810 $ sTargetEnvironment = $ this ->GetTargetEnv ();
803811 $ sModulesDir = $ this ->GetTargetDir ();
0 commit comments