Skip to content

Commit 1dee523

Browse files
committed
Provisioning ability added
1 parent 9a02ebf commit 1dee523

10 files changed

Lines changed: 147 additions & 30 deletions

File tree

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"symfony/process": "5.4.x-dev",
1515
"sensiolabs/ansi-to-html": "1.2.x-dev",
1616
"php-di/slim-bridge": "*",
17-
"slim/psr7": "dev-master",
17+
"slim/psr7": "*",
1818
"vitexsoftware/multiflexiapiserver": "*",
19-
"dyorg/slim-token-authentication": "dev-master",
20-
"tuupola/slim-basic-auth": "4.x-dev"
19+
"dyorg/slim-token-authentication": "*",
20+
"tuupola/slim-basic-auth": "*"
2121
},
2222
"license": "MIT",
2323
"authors": [
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class AppInitialSetup extends AbstractMigration
8+
{
9+
/**
10+
* Change Method.
11+
*
12+
* Write your reversible migrations using this method.
13+
*
14+
* More information on writing migrations is available here:
15+
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
16+
*
17+
* Remember to call "create()" or "update()" and NOT "save()" when working
18+
* with the Table class.
19+
*/
20+
public function change(): void
21+
{
22+
$table = $this->table('appcompany');
23+
$table
24+
->addColumn('prepared', 'boolean', ['null' => true, 'default' => null])
25+
->save();
26+
27+
}
28+
}

debian/changelog

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
multiflexi (1.2) UNRELEASED; urgency=medium
1+
multiflexi (1.3.0) UNRELEASED; urgency=medium
22

33
[ CyberVitexus ]
44
* Ability choose run interval between hour and year
@@ -20,7 +20,11 @@ multiflexi (1.2) UNRELEASED; urgency=medium
2020
[ Vitex ]
2121
* Update
2222

23-
-- Vitex <vitex@exiv> Sun, 11 Jul 2021 11:33:58 +0200
23+
[ vitex ]
24+
* executor rewrited
25+
* provisioning added
26+
27+
-- vitex <info@vitexsoftware.cz> Sat, 18 Mar 2023 11:23:01 +0100
2428

2529
multiflexi (0.1) experimental; urgency=medium
2630

debian/conf/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vitexsoftware/multiflexi",
33
"description": "Tool used to setup AbraFlexi multiinstance",
4-
"version": "1.2",
4+
"version": "1.2.1",
55
"type": "project",
66
"require": {
77
"deb/ease-bootstrap4-widgets-abraflexi": "*",

src/AbraFlexi/MultiFlexi/AppToCompany.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,39 @@ public function __construct($identifier = null, $options = []) {
2121
parent::__construct($identifier, $options);
2222
}
2323

24+
/**
25+
* Get id by App & Company
26+
*
27+
* SELECT appcompany.id, appcompany.interv, appcompany.prepared, apps.nazev AS app, company.nazev AS company FROM appcompany LEFT JOIN apps ON appcompany.app_id=apps.id LEFT JOIN company ON appcompany.company_id=company.id;
28+
*
29+
* @param int $appId
30+
* @param int $companyId
31+
*
32+
* @return int
33+
*/
34+
public function appCompanyID(int $appId, int $companyId) {
35+
return intval($this->listingQuery()->where('company_id=' . $companyId . ' AND app_id=' . $appId)->select('id', true)->fetchColumn());
36+
}
37+
38+
/**
39+
* Set APP State
40+
*
41+
* @param bool $state
42+
*
43+
* @return bool
44+
*/
2445
public function setState(bool $state) {
2546
return $state ? $this->dbsync() : $this->deleteFromSQL();
2647
}
2748

2849
public function performInit() {
29-
$this->setEnvironment();
30-
$app->runInit();
50+
$app = new Application((int) $this->getDataValue('app_id'));
51+
// $this->setEnvironment();
52+
if (empty($app->getDataValue('setup')) == false) {
53+
$this->setDataValue('prepared', 0);
54+
$this->dbsync();
55+
}
56+
// $app->runInit();
3157
}
3258

3359
/**
@@ -78,6 +104,7 @@ public function getAppEnvironment() {
78104
public function getAppInfo() {
79105
return $this->listingQuery()
80106
->select('apps.*')
107+
->select('apps.id as apps_id')
81108
->select('apps.nazev as app_name')
82109
->select('company.*')
83110
->select('abraflexis.*')
@@ -114,4 +141,15 @@ public function getAppsForCompany($companyID) {
114141
return $this->getColumnsFromSQL(['app_id', 'interv', 'id'], ['company_id' => $companyID], 'id', 'app_id');
115142
}
116143

144+
/**
145+
* Set Provision state
146+
*
147+
* @param int|null $status 0: Unprovisioned, 1: provisioned,
148+
*
149+
* @return boolean save status
150+
*/
151+
public function setProvision($status) {
152+
return $this->dbsync(['prepared' => $status]);
153+
}
154+
117155
}

src/AbraFlexi/MultiFlexi/Company.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function setEnvironment() {
350350
'EASE_EMAILTO' => $this->getDataValue('email'),
351351
'EASE_LOGGER' => empty($this->getDataValue('email')) ? 'syslog' : 'syslog|email'
352352
];
353-
$this->exportEnv($envNames);
353+
// $this->exportEnv($envNames);
354354
}
355355

356356
/**

src/AbraFlexi/MultiFlexi/Job.php

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
23
/**
3-
* Multi Flexi -
4+
* Multi Flexi - Job Eengine
45
*
56
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
6-
* @copyright 2020 Vitex Software
7+
* @copyright 2020-2023 Vitex Software
78
*/
89

910
namespace AbraFlexi\MultiFlexi;
@@ -13,44 +14,89 @@
1314
*
1415
* @author vitex
1516
*/
16-
class Job extends Engine
17-
{
17+
class Job extends Engine {
18+
1819
public $myTable = 'job';
1920

2021
/**
2122
* Begin the Job
2223
*
23-
* @param int $app_id
24+
* @param int $appId
2425
* @param int $companyId
2526
*
2627
* @return int Job ID
2728
*/
28-
public function runBegin($app_id, $companyId)
29-
{
30-
$jobId = $this->insertToSQL(['company_id' => $companyId, 'app_id' => $app_id,
29+
public function runBegin($appId, $companyId) {
30+
$jobId = $this->insertToSQL(['company_id' => $companyId, 'app_id' => $appId,
3131
'exitcode' => 255]);
3232
$this->setMyKey($jobId);
3333
$this->setObjectName();
3434
$sqlLogger = LogToSQL::singleton();
3535
$sqlLogger->setCompany($companyId);
36-
$sqlLogger->setApplication($app_id);
37-
$this->addStatusMessage('JOB: '.$jobId, 'debug');
36+
$sqlLogger->setApplication($appId);
37+
38+
$this->addStatusMessage('JOB: ' . $jobId, 'debug');
39+
if ($this->isProvisioned($appId, $companyId) == 0) {
40+
$this->addStatusMessage(_('Perform initial setup'), 'warning');
41+
$app = new Application((int) $appId);
42+
$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);
58+
}
59+
echo new \Ease\Html\DivTag(nl2br($outline));
60+
});
61+
if($result == 0){
62+
$appCompany->setProvision(1);
63+
$this->addStatusMessage('provision done', 'success');
64+
}
65+
66+
}
67+
3868
return $jobId;
3969
}
4070

4171
/**
42-
*
72+
* Action at Job run finish
73+
*
4374
* @param int $runId
4475
* @param int $statusCode
4576
*
46-
* @return type
77+
* @return int
4778
*/
48-
public function runEnd($runId, $statusCode)
49-
{
79+
public function runEnd($runId, $statusCode) {
5080
$sqlLogger = LogToSQL::singleton();
5181
$sqlLogger->setCompany(0);
5282
$sqlLogger->setApplication(0);
5383
return $this->updateToSQL(['end' => new \Envms\FluentPDO\Literal('NOW()'),
54-
'exitcode' => $statusCode], ['id' => $runId]);
84+
'exitcode' => $statusCode], ['id' => $runId]);
85+
}
86+
87+
/**
88+
* Check App Provisionning state
89+
*
90+
* @param int $appId
91+
* @param int $companyId
92+
*
93+
* @return boolean|null application with setup command provision state or setup command is not set
94+
*/
95+
public function isProvisioned($appId, $companyId) {
96+
$appCompany = new AppToCompany();
97+
$appCompany->setMyKey($appCompany->appCompanyID( $appId,$companyId));
98+
$appInfo = $appCompany->getAppInfo();
99+
return $appInfo['prepared'];
55100
}
56-
}
101+
102+
}

src/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Multi Flexi - Index page.
1111
*
1212
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
13-
* @copyright 2020-2022 Vitex Software
13+
* @copyright 2020-2023 Vitex Software
1414
*/
1515
require_once './init.php';
1616

src/launch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
/**
4-
* Multi Flexi - Customer instance editor.
4+
* Multi Flexi - Job Run.
55
*
66
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
7-
* @copyright 2017-2020 Vitex Software
7+
* @copyright 2017-2023 Vitex Software
88
*/
99

1010
namespace AbraFlexi\MultiFlexi\Ui;

src/run.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Multi Flexi - Command Runner.
55
*
66
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
7-
* @copyright 2017-2022 Vitex Software
7+
* @copyright 2017-2023 Vitex Software
88
*/
99

1010
namespace AbraFlexi\MultiFlexi;
@@ -14,6 +14,8 @@
1414

1515
require_once './init.php';
1616

17+
$oPage->onlyForLogged();
18+
1719
$appCompany = new AppToCompany($oPage->getRequestValue('id', 'int'));
1820
$appInfo = $appCompany->getAppInfo();
1921
$cmdparams = array_key_exists('cmdparams', $appInfo) ? $appInfo['cmdparams'] : '';
@@ -23,7 +25,6 @@
2325
if (strtolower(\Ease\Functions::cfg('APP_DEBUG')) == 'true') {
2426
$appCompany->addStatusMessage(sprintf(_('Setting Environment %s to %s'), $envName, $envValue), 'debug');
2527
}
26-
putenv($envName . '=' . $envValue);
2728
}
2829
$cmdparams = str_replace('{' . $envName . '}', $envValue, $cmdparams);
2930
}

0 commit comments

Comments
 (0)