Browse Source

Recognise company

main
Vítězslav Dvořák 4 months ago
parent
commit
d65f80376a
  1. 2
      README.md
  2. 1
      debian/abraflexi-webhook-acceptor-mysql.debhelper.log
  3. 1
      debian/abraflexi-webhook-acceptor-pgsql.debhelper.log
  4. 1
      debian/abraflexi-webhook-acceptor-sqlite.debhelper.log
  5. 10
      src/AbraFlexi/Acceptor/HookReciever.php
  6. 3
      src/AbraFlexi/Acceptor/Hooker.php
  7. 2
      src/AbraFlexi/Acceptor/Saver/PdoSQL.php
  8. 32
      src/installer.php
  9. 19
      src/webhook.php

2
README.md

@ -19,7 +19,7 @@ Installation
```shell
sudo apt install lsb-release wget
echo "deb http://repo.vitexsoftware.cz $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vitexsoftware.list
echo "deb http://repo.vitexsoftware.com $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vitexsoftware.list
sudo wget -O /etc/apt/trusted.gpg.d/vitexsoftware.gpg http://repo.vitexsoftware.cz/keyring.gpg
sudo apt update
sudo apt install multiflexi-DATABASE

1
debian/abraflexi-webhook-acceptor-mysql.debhelper.log vendored

@ -0,0 +1 @@
dh_install

1
debian/abraflexi-webhook-acceptor-pgsql.debhelper.log vendored

@ -0,0 +1 @@
dh_install

1
debian/abraflexi-webhook-acceptor-sqlite.debhelper.log vendored

@ -0,0 +1 @@
dh_install

10
src/AbraFlexi/Acceptor/HookReciever.php

@ -119,7 +119,7 @@ class HookReciever extends \AbraFlexi\Changes {
*
* @return array list IDS processed
*/
function processFlexiBeeChanges(array $changes) {
function processAbraFlexiChanges(array $changes) {
$changepos = 0;
$doneIDd = [];
foreach ($changes as $change) {
@ -175,6 +175,7 @@ class HookReciever extends \AbraFlexi\Changes {
*
* @link https://www.abraflexi.eu/api/dokumentace/ref/changes-api/ Changes API
* @param array $changes pole změn
*
* @return int Globální verze poslední změny
*/
public function takeChanges($changes) {
@ -198,10 +199,11 @@ class HookReciever extends \AbraFlexi\Changes {
* @param int $version
*/
public function saveLastProcessedVersion($version) {
$source = \Ease\Functions::cfg('ABRAFLEXI_URL').'/c/'.\Ease\Functions::cfg('ABRAFLEXI_COMPANY');
$this->lastProcessedVersion = $version;
$this->myCreateColumn = null;
$this->sqlEngine->deleteFromSQL(['serverurl' => \Ease\Functions::cfg('ABRAFLEXI_URL')]);
if (is_null($this->sqlEngine->insertToSQL(['serverurl' => \Ease\Functions::cfg('ABRAFLEXI_URL'), 'changeid' => $version]))) {
$this->sqlEngine->deleteFromSQL(['serverurl' => $source]);
if (is_null($this->sqlEngine->insertToSQL(['serverurl' => $source, 'changeid' => $version]))) {
$this->sqlEngine->addStatusMessage(_("Last Processed Change ID Saving Failed"), 'error');
} else {
if ($this->debug === true) {
@ -218,7 +220,7 @@ class HookReciever extends \AbraFlexi\Changes {
public function getLastSavedVersion() {
$lastProcessedVersion = null;
foreach ($this->saver as $saver) {
$lastProcessedVersion = $saver->lastProcessedVersion;
$lastProcessedVersion = $saver->getLastProcessedVersion();
}
if (is_null($lastProcessedVersion)) {
$this->addStatusMessage(_("Last Processed Change ID Loading Failed"),

3
src/AbraFlexi/Acceptor/Hooker.php

@ -27,9 +27,10 @@ class Hooker extends \AbraFlexi\Hooks {
$baseUrl = \Ease\Document::phpSelf();
$urlInfo = parse_url($baseUrl);
$curFile = basename($urlInfo['path']);
$webHookUrl = str_replace($curFile,
'webhook.php?instanceid=' . $instanceId, $baseUrl);
return $webHookUrl;
return \Ease\Functions::addUrlParams($webHookUrl,['company' => \Ease\Functions::cfg('ABRAFLEXI_COMPANY')]);
}
}

2
src/AbraFlexi/Acceptor/Saver/PdoSQL.php

@ -57,7 +57,7 @@ class PdoSQL extends \Ease\SQL\Engine implements AcceptorSaver {
if ($version) {
$this->setmyTable('changesapi');
$this->setKeyColumn('serverurl');
$apich = ['changeid' => $version, 'serverurl' => \Ease\Functions::cfg('ABRAFLEXI_URL')];
$apich = ['changeid' => $version, 'serverurl' => \Ease\Functions::cfg('ABRAFLEXI_URL').'/c/'.\Ease\Functions::cfg('ABRAFLEXI_COMPANY')];
if ($this->lastProcessedVersion ? $this->updateToSQL($apich) : $this->insertToSQL($apich)) {
$this->lastProcessedVersion = $version;
} else {

32
src/installer.php

@ -6,7 +6,7 @@ namespace AbraFlexi\Acceptor;
* System.Spoje.Net - WebHook Acceptor & Saver to SQL Cache.
*
* @author Vítězslav Dvořák <vitex@arachne.cz>
* @copyright 2017-2020 Spoje.Net
* @copyright 2017-2020 Spoje.Net, 2021-2022 VitexSoftware
*/
define('APP_NAME', 'WebHookInstaller');
define('EASE_LOGGER', 'syslog');
@ -25,17 +25,21 @@ if ($hooker->debug) {
$endpoint = Hooker::webHookUrl(strval(time()));
try {
$hooker->register($endpoint);
$hooker->addStatusMessage(sprintf(_('Registering %s in AbraFlexi'), $endpoint), 'success');
} catch (\AbraFlexi\Exception $ex) {
$hooker->addStatusMessage(sprintf(_('Registering %s in AbraFlexi') . ' ' . _('Failed'), $endpoint), 'error');
if (empty($endpoint)) {
$hooker->addStatusMessage(_('No endpoint ? - check your webserver configuration'), 'warning');
} else {
try {
$hooker->addStatusMessage(sprintf(_('Registering %s in AbraFlexi'), $endpoint), $hooker->register($endpoint) ? 'success' : 'error');
echo $hooker->getDataValue('url') . ' -> ' . $hooker->getApiURL();
try {
$reciever = new HookReciever(['throwException' => false]);
$reciever->addStatusMessage(_('Last Processed version set to 0'), $reciever->saveLastProcessedVersion(0) ? 'success' : 'warning' );
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
} catch (\AbraFlexi\Exception $ex) {
$hooker->addStatusMessage(sprintf(_('Registering %s in AbraFlexi') . ' ' . _('Failed'), $endpoint), 'error');
}
}
try {
$reciever = new HookReciever(['throwException' => false]);
$reciever->addStatusMessage(_('Last Processed version set to 0'), $reciever->saveLastProcessedVersion(0) ? 'success' : 'warning' );
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}

19
src/webhook.php

@ -12,6 +12,10 @@ define('APP_NAME', 'WebHookAcceptor');
define('EASE_LOGGER', 'syslog');
require_once __DIR__ . '/../vendor/autoload.php';
if (array_key_exists('company', $_REQUEST)) {
define('ABRAFLEXI_COMPANY', $_REQUEST['company']);
}
$cfg = '../.env';
if (file_exists($cfg)) {
\Ease\Shared::singleton()->loadConfig($cfg, true);
@ -19,6 +23,15 @@ if (file_exists($cfg)) {
try {
$hooker = new HookReciever();
$hooker->debug = true;
$apiResponseRaw = $hooker->listen();
if (!empty($apiResponseRaw) && $hooker->takeChanges($apiResponseRaw)) {
$hooker->saveWebhookData($hooker->onlyFreshHooks($hooker->changes));
} else {
echo 'No changes';
}
} catch (\AbraFlexi\Exception $exc) {
echo $exc->getMessage();
echo new \Ease\Html\ATag('installer.php', _('Run the installer'));
@ -26,9 +39,3 @@ try {
exit;
}
//$hooker->debug = true;
$apiResponseRaw = $hooker->listen();
if (!empty($apiResponseRaw) && $hooker->takeApiChanges($apiResponseRaw)) {
$hooker->saveWebhookData($hooker->onlyFreshHooks($hooker->changes));
}

Loading…
Cancel
Save