Skip to content

Commit

Permalink
improve readme, improve first log
Browse files Browse the repository at this point in the history
  • Loading branch information
keksa committed Sep 6, 2024
1 parent e4cbb60 commit 8134075
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion plugins/barcode-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This plugin generates SVG image of one or two dimensional barcode which can be i
## Templates implementation
You can add barcode image into template code e.g.:
``<img src="https://www.example.com/crm/_plugins/barcode-generator/public.php?token=USECONFIGURATIONTOKEN&code=DI{{ invoice.number }}{{ totals.totalRaw }}&type=QRCODE&width=200&height=200&color=black">``
> Server must be secured with valid certificate for https request.
> Make sure you have valid SSL certificate, otherwise the barcode won't load when used in PDF or email templates.
> In PDF templates only, you can use `http://localhost/crm/...` as an alternative.
## Required parameters
- `token` - Security token from the plugin configuration in the CRM
Expand Down
Binary file modified plugins/barcode-generator/barcode-generator.zip
Binary file not shown.
27 changes: 19 additions & 8 deletions plugins/barcode-generator/src/hook_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@

declare(strict_types=1);

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use UBarcode\Service\TokenInstaller;
use Ubnt\UcrmPluginSdk\Service\PluginConfigManager;
use Ubnt\UcrmPluginSdk\Service\PluginLogManager;
use Ubnt\UcrmPluginSdk\Service\UcrmOptionsManager;

chdir(__DIR__);

require __DIR__ . '/vendor/autoload.php';

$logger = new Logger('UBarcode');
$logger->pushHandler(new StreamHandler('data/plugin.log'));

$logManager = PluginLogManager::create();

(new TokenInstaller())->install();

$logger->info('Security token has been generated. Use it as a part of request string.');
$configManager = PluginConfigManager::create();
$config = $configManager->loadConfig();
$ucrmOptionsManager = UcrmOptionsManager::create();
$ucrmOptions = $ucrmOptionsManager->loadOptions();

$logManager = PluginLogManager::create();
$logManager->appendLog('Security token has been automatically generated. You must use it as a part of the URL.');
$logManager->appendLog('');
$logManager->appendLog('Example usage:');
$logManager->appendLog(
sprintf(
'<img src="%s_plugins/barcode-generator/public.php?token=%s&code=YOUR_CONTENTS&type=QRCODE&width=200&height=200&color=black">',
$ucrmOptions->ucrmPublicUrl,
$config['token'] ?? ''
)
);
$logManager->appendLog('');

0 comments on commit 8134075

Please sign in to comment.