Skip to content

Commit

Permalink
Prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Apr 14, 2020
1 parent 3f1f363 commit 6de67ed
Show file tree
Hide file tree
Showing 34 changed files with 1,089 additions and 143 deletions.
1 change: 0 additions & 1 deletion .env
Expand Up @@ -6,4 +6,3 @@ DB_PORT=3306
DB_DATABASE=../db/multiflexibee.sqlite
DB_USERNAME=multiflexibee
DB_PASSWORD=multiflexibee

6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -11,6 +11,12 @@ demodata:
newphinx:
read -p "Enter CamelCase migration name : " migname ; ./vendor/bin/phinx create $$migname -c ./phinx-adapter.php

dbreset:
echo > db/multiflexibee.sqlite
chmod 666 db/multiflexibee.sqlite

demo: dbreset migration demodata


deb:
debuild -i -us -uc -b
Expand Down
2 changes: 0 additions & 2 deletions db/migrations/20180208121253_customer.php
Expand Up @@ -40,8 +40,6 @@ public function change()
->addColumn('login', 'string', ['limit' => 32])
->addColumn('DatCreate', 'datetime', [])
->addColumn('DatSave', 'datetime', ['null' => true])
->addColumn('last_modifier_id', 'integer',
['null' => true, 'signed' => false])
->addIndex(['login', 'email'], ['unique' => true])
->create();
}
Expand Down
9 changes: 4 additions & 5 deletions db/migrations/20180208122200_company.php
Expand Up @@ -28,22 +28,21 @@ class Company extends AbstractMigration
*/
public function change()
{
// Migration for table users
$table = $this->table('company');
$table
->addColumn('enabled', 'boolean', array('default' => false))
->addColumn('settings', 'text', ['null' => true])
->addColumn('logo', 'text', ['null' => true])
->addColumn('flexibee', 'integer', ['limit' => 128])
->addColumn('nazev', 'string', ['null' => true, 'limit' => 32])
->addColumn('ic', 'string', ['null' => true, 'limit' => 32])
->addColumn('company', 'string', ['comment' => 'Company Code'])
->addColumn('rw', 'boolean', ['comment' => 'Write permissions'])
->addColumn('labels', 'boolean', ['comment' => 'Labels established'])
->addColumn('setup', 'boolean', ['comment' => 'SetUP done'])
->addColumn('webhook', 'boolean', ['comment' => 'Webhook ready'])
->addColumn('DatCreate', 'datetime', [])
->addColumn('datUpdate', 'datetime', ['null' => true])
->addColumn('last_modifier_id', 'integer',
['null' => true, 'signed' => false])
->addColumn('DatUpdate', 'datetime', ['null' => true])
->addIndex(['flexibee', 'company'], ['unique' => true])
->create();
}
}
47 changes: 47 additions & 0 deletions db/migrations/20200413063021_applications.php
@@ -0,0 +1,47 @@
<?php

use Phinx\Migration\AbstractMigration;

class Applications extends AbstractMigration {

/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change() {
$table = $this->table('apps');
$table
->addColumn('enabled', 'boolean', array('default' => false))
->addColumn('image', 'text', ['null' => true])
->addColumn('nazev', 'string', ['null' => true, 'limit' => 32])
->addColumn('popis', 'string', ['comment' => 'App Description'])
->addColumn('executable', 'string', ['comment' => '/usr/bin/runme'])
->addColumn('DatCreate', 'datetime', [])
->addColumn('DatUpdate', 'datetime', ['null' => true])
->addIndex(['nazev'], ['unique' => true])
->addIndex(['executable'], ['unique' => true])
->create();
}

}
43 changes: 43 additions & 0 deletions db/migrations/20200413150836_app_to_company.php
@@ -0,0 +1,43 @@
<?php

use Phinx\Migration\AbstractMigration;

class AppToCompany extends AbstractMigration {

/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change() {
$table = $this->table('appcompany');
$table->addColumn('app_id', 'integer', array('null' => false))
->addColumn('company_id', 'integer', array('null' => false))
->addIndex(['app_id', 'company_id'], ['unique' => true])
->addForeignKey('app_id', 'apps', ['id'], ['constraint' => 'app_must_exist'])
->addForeignKey('company_id', 'company', ['id'], ['constraint' => 'company_must_exist']);

$table->save();
}

}
60 changes: 60 additions & 0 deletions db/seeds/AppSeeder.php

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions db/seeds/CompanySeeder.php
@@ -0,0 +1,48 @@
<?php

use Phinx\Seed\AbstractSeed;

class CompanySeeder extends AbstractSeed {

/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run() {

$data = [
[
'id' => 0,
'enabled' => true,
'flexibee' => 0,
'nazev' => 'Demo Firma',
'ic' => '12345678',
'company' => 'demo',
'rw' => 'true',
'setup' => false,
'webhook' => false,
'DatCreate' => date('Y-m-d H:i:s')
],
[
'id' => 1,
'enabled' => true,
'flexibee' => 0,
'nazev' => 'Ja Zivnostnik',
'ic' => '87654321',
'company' => 'demo_de',
'rw' => 'true',
'setup' => false,
'webhook' => false,
'DatCreate' => date('Y-m-d H:i:s')
]
];

$posts = $this->table('company');
$posts->insert($data)->save();
}

}
33 changes: 33 additions & 0 deletions db/seeds/CustomerSeeder.php
@@ -0,0 +1,33 @@
<?php

use Phinx\Seed\AbstractSeed;

class CustomerSeeder extends AbstractSeed {

/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run() {
$data = [
[
'id' => 0,
'enabled' => true,
'email' => 'demo@flexibee.eu',
'firstname' => 'Demo',
'lastname' => 'Demo',
'password' => '',
'login' => 'demo',
'DatCreate' => date('Y-m-d H:i:s')
]
];

$posts = $this->table('customer');
$posts->insert($data)->save();
}

}
33 changes: 33 additions & 0 deletions db/seeds/FlexiBeeSeeder.php
@@ -0,0 +1,33 @@
<?php

use Phinx\Seed\AbstractSeed;

class FlexiBeeSeeder extends AbstractSeed {

/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run() {

$data = [
[
'id' => 0,
'url' => 'https://demo.flexibee.eu:5434',
'name' => 'Demo EU',
'user' => 'winstrom',
'password' => 'winstrom',
'DatCreate' => date('Y-m-d H:i:s')
]
];

$posts = $this->table('flexibees');
$posts->insert($data)
->save();
}

}
21 changes: 10 additions & 11 deletions db/seeds/UserSeeder.php
Expand Up @@ -2,8 +2,7 @@

use Phinx\Seed\AbstractSeed;

class UserSeeder extends AbstractSeed
{
class UserSeeder extends AbstractSeed {

/**
* Run Method.
Expand All @@ -13,23 +12,23 @@ class UserSeeder extends AbstractSeed
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
public function run() {
$data = [
[
'id' => 0,
'enabled'=>true,
'email' => 'info@vitexsoftware.cz',
'login' => 'vitex',
'password' => '7254a96290b564d1b0cd85b9881b6b1a:b3',
'firstname' => 'Vítězslav',
'lastname' => 'Dvořák',
'enabled' => true,
'email' => 'demo@localhost.localhomain',
'login' => 'demo',
'password' => 'a26ac720512764602ce1c1ae537efb04:9d',
'firstname' => 'Demo',
'lastname' => 'Demo',
'DatCreate' => date('Y-m-d H:i:s')
]
];

$posts = $this->table('user');
$posts->insert($data)
->save();
->save();
}

}
22 changes: 17 additions & 5 deletions lib/executor.php
Expand Up @@ -17,7 +17,10 @@
$dotenv = Dotenv::createImmutable(dirname(__DIR__));
$dotenv->load();

$companys = (new \FlexiPeeHP\MultiSetup\Company())->listingQuery()->select('flexibees.*')->leftJoin('flexibees ON flexibees.id = company.flexibee');
define('EASE_LOGGER', 'console');

$companer = new \FlexiPeeHP\MultiSetup\Company();
$companys = $companer->listingQuery()->select('flexibees.*')->leftJoin('flexibees ON flexibees.id = company.flexibee');



Expand All @@ -36,11 +39,20 @@
];

foreach ($envNames as $envName => $sqlValue) {
echo $envName . '=' . $sqlValue . "\n";
// echo $envName . '=' . $sqlValue . "\n";
putenv($envName . '=' . $sqlValue);
}


$command = 'flexibee-client-config-checker';
system($command);
$ap2c = new AppToCompany(['company_id' => $company['id']]);
if (empty($ap2c->getData())) {
$companer->addStatusMessage(sprintf(_('No applications enabled for %s'), $company['nazev']), 'warning');
} else {
foreach ($ap2c->getData() as $servData) {
$app = new Application(intval($servData['app_id']));
$exec = $app->getDataValue('executable');
$app->addStatusMessage('begin' . $exec . '@' . $company['nazev']);
$app->addStatusMessage(shell_exec($exec), 'debug');
$app->addStatusMessage('end' . $exec . '@' . $company['nazev']);
}
}
}
33 changes: 33 additions & 0 deletions src/FlexiPeeHP/MultiSetup/AppToCompany.php
@@ -0,0 +1,33 @@
<?php

/**
* Multi FlexiBee Setup - AppToCompany class
*
* @author Vítězslav Dvořák <vitex@arachne.cz>
* @copyright 2020 Vitex Software
*/

namespace FlexiPeeHP\MultiSetup;

/**
* Description of AppToCompany
*
* @author vitex
*/
class AppToCompany extends Engine {

public function __construct($identifier = null, $options = []) {
$this->myTable = 'appcompany';
parent::__construct($identifier, $options);
}

public function setState(bool $state) {
if ($state === true) {
$result = $this->insertToSQL();
} else {
$result = $this->deleteFromSQL();
}
return $result;
}

}

0 comments on commit 6de67ed

Please sign in to comment.