@@ -28,7 +28,7 @@ class Job extends Engine {
2828 */
2929 public function runBegin ($ appId , $ companyId ) {
3030 $ jobId = $ this ->insertToSQL (['company_id ' => $ companyId , 'app_id ' => $ appId ,
31- 'exitcode ' => 255 ]);
31+ 'exitcode ' => - 1 , ' launched_by ' => \ Ease \Shared:: user ()-> getMyKey () ]);
3232 $ this ->setMyKey ($ jobId );
3333 $ this ->setObjectName ();
3434 $ sqlLogger = LogToSQL::singleton ();
@@ -40,29 +40,30 @@ public function runBegin($appId, $companyId) {
4040 $ this ->addStatusMessage (_ ('Perform initial setup ' ), 'warning ' );
4141 $ app = new Application ((int ) $ appId );
4242 $ setupCommand = $ app ->getDataValue ('setup ' );
43-
44- $ appCompany = new AppToCompany ();
45- $ appCompany ->setMyKey ($ appCompany ->appCompanyID ( $ appId ,$ companyId ));
46- $ appInfo = $ appCompany ->getAppInfo ();
47- $ appEnvironment = $ appCompany ->getAppEnvironment ();
48- $ process = new \Symfony \Component \Process \Process (explode (' ' , $ setupCommand ), null , $ appEnvironment , null , 32767 );
49-
50- $ result = $ process ->run (function ($ type , $ buffer ) {
51- $ logger = new Runner ();
52- if (\Symfony \Component \Process \Process::ERR === $ type ) {
53- $ outline = (new \SensioLabs \AnsiConverter \AnsiToHtmlConverter ())->convert ($ buffer );
54- $ logger ->addStatusMessage ($ buffer , 'error ' );
55- } else {
56- $ logger ->addStatusMessage ($ buffer , 'success ' );
57- $ outline = (new \SensioLabs \AnsiConverter \AnsiToHtmlConverter ())->convert ($ buffer );
43+ if (!empty (trim ($ setupCommand ))) {
44+ $ app ->addStatusMessage (_ ('Setup command ' ) . ': ' . $ setupCommand , 'debug ' );
45+ $ appCompany = new AppToCompany ();
46+ $ appCompany ->setMyKey ($ appCompany ->appCompanyID ($ appId , $ companyId ));
47+ $ appInfo = $ appCompany ->getAppInfo ();
48+ $ appEnvironment = $ appCompany ->getAppEnvironment ();
49+ $ process = new \Symfony \Component \Process \Process (explode (' ' , $ setupCommand ), null , $ appEnvironment , null , 32767 );
50+
51+ $ result = $ process ->run (function ($ type , $ buffer ) {
52+ $ logger = new Runner ();
53+ if (\Symfony \Component \Process \Process::ERR === $ type ) {
54+ $ outline = (new \SensioLabs \AnsiConverter \AnsiToHtmlConverter ())->convert ($ buffer );
55+ $ logger ->addStatusMessage ($ buffer , 'error ' );
56+ } else {
57+ $ logger ->addStatusMessage ($ buffer , 'success ' );
58+ $ outline = (new \SensioLabs \AnsiConverter \AnsiToHtmlConverter ())->convert ($ buffer );
59+ }
60+ echo new \Ease \Html \DivTag (nl2br ($ outline ));
61+ });
62+ if ($ result == 0 ) {
63+ $ appCompany ->setProvision (1 );
64+ $ this ->addStatusMessage ('provision done ' , 'success ' );
5865 }
59- echo new \Ease \Html \DivTag (nl2br ($ outline ));
60- });
61- if ($ result == 0 ){
62- $ appCompany ->setProvision (1 );
63- $ this ->addStatusMessage ('provision done ' , 'success ' );
6466 }
65-
6667 }
6768
6869 return $ jobId ;
@@ -76,11 +77,13 @@ public function runBegin($appId, $companyId) {
7677 *
7778 * @return int
7879 */
79- public function runEnd ($ runId , $ statusCode ) {
80+ public function runEnd ($ runId , $ statusCode, $ stdout , $ stderr ) {
8081 $ sqlLogger = LogToSQL::singleton ();
8182 $ sqlLogger ->setCompany (0 );
8283 $ sqlLogger ->setApplication (0 );
8384 return $ this ->updateToSQL (['end ' => new \Envms \FluentPDO \Literal ('NOW() ' ),
85+ 'stdout ' => $ stdout ,
86+ 'stderr ' => $ stderr ,
8487 'exitcode ' => $ statusCode ], ['id ' => $ runId ]);
8588 }
8689
@@ -94,7 +97,7 @@ public function runEnd($runId, $statusCode) {
9497 */
9598 public function isProvisioned ($ appId , $ companyId ) {
9699 $ appCompany = new AppToCompany ();
97- $ appCompany ->setMyKey ($ appCompany ->appCompanyID ( $ appId ,$ companyId ));
100+ $ appCompany ->setMyKey ($ appCompany ->appCompanyID ($ appId , $ companyId ));
98101 $ appInfo = $ appCompany ->getAppInfo ();
99102 return $ appInfo ['prepared ' ];
100103 }
0 commit comments