Skip to content

Commit

Permalink
Signed columns fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Apr 27, 2024
1 parent 55f98bc commit 0d26bc1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 12 deletions.
4 changes: 2 additions & 2 deletions db/migrations/20200413150836_app_to_company.php
Expand Up @@ -8,8 +8,8 @@ class AppToCompany extends AbstractMigration {
*/
public function change() {
$table = $this->table('appcompany');
$table->addColumn('app_id', 'integer', ['null' => false, 'unsigned'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'unsigned'=>false])
$table->addColumn('app_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('interval','string',['length'=>1])
->addIndex(['app_id', 'company_id'])
->addForeignKey('app_id', 'apps', ['id'], ['constraint' => 'a2p-app_must_exist'])
Expand Down
6 changes: 3 additions & 3 deletions db/migrations/20200520140331_config_registry.php
Expand Up @@ -6,7 +6,7 @@ class ConfigRegistry extends AbstractMigration {

public function change() {
$customFields = $this->table('conffield');
$customFields->addColumn('app_id', 'integer', ['null' => false, 'unsigned'=>false])
$customFields->addColumn('app_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('keyname', 'string', ['length' => 64])
->addColumn('type', 'string', ['length' => 32])
->addColumn('description', 'string', ['length' => 1024])
Expand All @@ -16,8 +16,8 @@ public function change() {
$customFields->create();

$configs = $this->table('configuration');
$configs->addColumn('app_id', 'integer', ['null' => false, 'unsigned'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'unsigned'=>false])
$configs->addColumn('app_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('key', 'string', ['length' => 64])
->addColumn('value', 'string', ['length' => 1024])
->addIndex(['app_id', 'company_id', 'key'], ['unique' => true])
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/20221123091933_company_env.php
Expand Up @@ -21,7 +21,7 @@ public function change() {
$table = $this->table('companyenv');
$table->addColumn('keyword', 'string', array('null' => false))
->addColumn('value', 'string', array('null' => false))
->addColumn('company_id', 'integer', ['null' => false, 'unsigned'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'signed'=>false])
->addIndex(['keyword', 'company_id'], ['unique' => true])
->addForeignKey('company_id', 'company', ['id'], ['constraint' => 'env-company_must_exist']);
$table->save();
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/20221125095601_job.php
Expand Up @@ -22,7 +22,7 @@ public function change() {
$table->addColumn('app_id', 'integer', ['null' => false, 'unsigned' => false])
->addColumn('begin', 'datetime', ['default' => 'CURRENT_TIMESTAMP'])
->addColumn('end', 'datetime', ['null' => true])
->addColumn('company_id', 'integer', ['null' => false, 'unsigned'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('exitcode', 'integer', ['null' => true])
->addForeignKey('app_id', 'apps', ['id'], ['constraint' => 'job-app_must_exist'])
->addForeignKey('company_id', 'company', ['id'], ['constraint' => 'job-company_must_exist']);
Expand Down
4 changes: 2 additions & 2 deletions db/migrations/20231112224941_company_apps.php
Expand Up @@ -21,8 +21,8 @@ public function change(): void
{

$table = $this->table('companyapp');
$table->addColumn('app_id', 'integer', ['null' => false, 'unsigned'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'unsigned'=>false])
$table->addColumn('app_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('company_id', 'integer', ['null' => false, 'signed'=>false])
->addIndex(['app_id', 'company_id'], ['unique' => true])
->addForeignKey('app_id', 'apps', ['id'], ['constraint' => 'a2c-app_must_exist'])
->addForeignKey('company_id', 'company', ['id'], ['constraint' => 'a2c-company_must_exist']);
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/20240107205916_action_config.php
Expand Up @@ -26,7 +26,7 @@ public function change(): void
->addColumn('keyname', 'string', ['comment' => 'Configuration Key name'])
->addColumn('value', 'string', ['comment' => 'Configuration Value'])
->addColumn('mode', 'string', ['null' => true, 'length' => 10, 'default' => null, 'comment' => 'success, fail or empty'])
->addColumn('runtemplate_id', 'integer', ['null' => false, 'unsigned'=>false])
->addColumn('runtemplate_id', 'integer', ['null' => false, 'signed'=>false])
->addIndex(['module', 'keyname', 'mode', 'runtemplate_id'], ['unique' => true])
->addForeignKey('runtemplate_id', 'runtemplate', ['id'], ['constraint' => 'runtemplate_must_exist'])
->create();
Expand Down
41 changes: 40 additions & 1 deletion src/apps.php
Expand Up @@ -22,10 +22,49 @@

$allAppData = $servers->getAll();

$jobsDataRaw = (new \MultiFlexi\Job())->listingQuery()->select(['app_id','exitcode'])->fetchAll();
foreach ($jobsDataRaw as $jobData) {
$exitcodeCounts = [];
$exitcodeSuccess = [];

foreach ($jobsData as $jobData) {
$app_id = $jobData['app_id'];
$exitcode = $jobData['exitcode'];

if (!isset($exitcodeCounts[$app_id])) {
$exitcodeCounts[$app_id] = [];
$exitcodeSuccess[$app_id] = [];
}

if (!isset($exitcodeCounts[$app_id][$exitcode])) {
$exitcodeCounts[$app_id][$exitcode] = 0;
$exitcodeSuccess[$app_id][$exitcode] = 0;
}

$exitcodeCounts[$app_id][$exitcode]++;
if ($exitcode == 0) {
$exitcodeSuccess[$app_id][$exitcode]++;
}
}

$averageSuccess = [];

foreach ($exitcodeCounts as $app_id => $exitcodes) {
$averageSuccess[$app_id] = [];

foreach ($exitcodes as $exitcode => $count) {
$averageSuccess[$app_id][$exitcode] = $exitcodeSuccess[$app_id][$exitcode] / $count;
}
}
$jobsData[$jobData['app_id']] = $jobData['exitcode'];
}


$fbtable = new Table();
$fbtable->addRowHeaderColumns([_('ID'), _('Enabled'), _('Image'), _('Name'), _('Description'), _('Executable'), _('Created'), _('Modified'), _('HomePage'), _('Requirements'), _('Container Image'), _('Version'), _('Code'), _('uuid')]);
$fbtable->addRowHeaderColumns([_('Success'),_('ID'), _('Enabled'), _('Image'), _('Name'), _('Description'), _('Executable'), _('Created'), _('Modified'), _('HomePage'), _('Requirements'), _('Container Image'), _('Version'), _('Code'), _('uuid')]);

foreach ($allAppData as $appData) {
$appData['success'] = $averageSuccess[$appData['id']][0] ?? 0;
$appData['image'] = new \Ease\Html\ImgTag($appData['image'], _('Icon'), ['height' => 40]);
$appData['enabled'] = ($appData['enabled'] == 1 ? '✔' : '❌');
$executablePath = Application::findBinaryInPath($appData['executable']);
Expand Down
2 changes: 1 addition & 1 deletion src/createaccount.php
Expand Up @@ -4,7 +4,7 @@
* Multi Flexi - Company instance editor.
*
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
* @copyright 2020-2023 Vitex Software
* @copyright 2020-2024 Vitex Software
*/

namespace MultiFlexi\Ui;
Expand Down

0 comments on commit 0d26bc1

Please sign in to comment.