Skip to content

Commit

Permalink
Merge pull request #243 from TransbankDevelopers/chore/prepare-releas…
Browse files Browse the repository at this point in the history
…e-1.9.1

chore: prepare release 1.9.1
  • Loading branch information
mastudillot authored Jun 3, 2024
2 parents ef14801 + 819ee11 commit 99c0105
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 80 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ jobs:
env:
WP_ORG_PASSWORD: ${{ secrets.WP_ORG_PASSWORD }}
TAG: ${{ github.event.release.tag_name }}
- name: Upload assets
- name: Upload transbank-webpay-plus-rest.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: |
transbank-webpay-plus-rest.zip
transbank-webpay-plus-rest-guzzle7.zip
asset_name: |
transbank-webpay-plus-rest.zip
transbank-webpay-plus-rest-guzzle7.zip
asset_path: transbank-webpay-plus-rest.zip
asset_name: transbank-webpay-plus-rest.zip
asset_content_type: application/zip
- name: Upload transbank-webpay-plus-rest-guzzle7.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: transbank-webpay-plus-rest-guzzle7.zip
asset_name: transbank-webpay-plus-rest-guzzle7.zip
asset_content_type: application/zip
12 changes: 12 additions & 0 deletions plugin/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Recibe pagos en línea con tarjetas de crédito, débito y prepago en tu WooComm
Recibe pagos en línea con tarjetas de crédito, débito y prepago en tu WooCommerce a través de Webpay Plus y Webpay Oneclick

== Changelog ==
= 1.9.1 =
* Se arregla un mensaje de warning provocado por la función maskData en PHP mayor o igual a 8.x.
* Se arregla un problema que impedía encontrar el archivo de log al migrar el sitio de un servidor a otro.
* Se arregla la zona horaria de los logs. Se usa la que este configurada en el ecommerce del comercio.
* Se arregla un problema que provocaba registros duplicados en el selector de archivos logs de la vista registros.

= 1.9.0 =
* Se agrega la opción de poder seleccionar el archivo log en la sección de registros del menú de configuración.
* Se agrega la funcionalidad para que se muestren las tarjetas registradas de Oneclick dependiendo del entorno.
Expand Down Expand Up @@ -163,6 +169,12 @@ Arreglado:
* Initial release.

== Upgrade Notice ==
= 1.9.1 =
* Se arregla un mensaje de warning provocado por la función maskData en PHP mayor o igual a 8.x.
* Se arregla un problema que impedía encontrar el archivo de log al migrar el sitio de un servidor a otro.
* Se arregla la zona horaria de los logs. Se usa la que este configurada en el ecommerce del comercio.
* Se arregla un problema que provocaba registros duplicados en el selector de archivos logs de la vista registros.

= 1.9.0 =
* Se agrega la opción de poder seleccionar el archivo log en la sección de registros del menú de configuración.
* Se agrega la funcionalidad para que se muestren las tarjetas registradas de Oneclick dependiendo del entorno.
Expand Down
87 changes: 68 additions & 19 deletions plugin/shared/Helpers/PluginLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

namespace Transbank\Plugin\Helpers;

use DateTimeZone;
use Monolog\Logger;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Formatter\LineFormatter;
use Transbank\Plugin\Model\LogConfig;

final class PluginLogger implements ILogger {
final class PluginLogger implements ILogger
{

const CACHE_LOG_NAME = 'transbank_log_file_name';

private $logger;
private $config;

Expand All @@ -18,32 +23,54 @@ final class PluginLogger implements ILogger {
* output format : "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
* @param Throwable $e
*/
public function __construct(LogConfig $config) {
public function __construct(LogConfig $config)
{
$this->config = $config;
$logDir = $this->config->getLogDir();
$cacheLogName = 'transbank_log_name';
$logFile = get_transient($cacheLogName);
if (!$logFile) {
$uniqueId = uniqid('', true);
$logFile = "{$logDir}/log_transbank_{$uniqueId}.log";
$expireTime = strtotime('tomorrow') - time();
set_transient($cacheLogName, $logFile, $expireTime);
}
$dateFormat = "Y-m-d H:i:s";

$logFilePath = $this->getLogFilePath();
$this->initializeLogger($logFilePath);
}

private function initializeLogger(string $logFilePath)
{
$ecommerceTz = new DateTimeZone(wc_timezone_string());
$dateFormat = "Y-m-d H:i:s P";
$output = "%datetime% > %level_name% > %message% %context% %extra%\n";
$formatter = new LineFormatter($output, $dateFormat);
$stream = new RotatingFileHandler($logFile,
100, Logger::DEBUG);

$stream = new RotatingFileHandler(
$logFilePath,
100,
Logger::DEBUG
);
$stream->setFormatter($formatter);

$this->logger = new Logger('transbank');
$this->logger->setTimezone($ecommerceTz);
$this->logger->pushHandler($stream);
}

public function getLogger(){
private function getLogFilePath(): string
{
$logFileName = $this->getLogFileNameFromCache();

if (!$logFileName) {
$logFileName = $this->getLogFileName();
$expireTime = strtotime('tomorrow') - time();
$this->saveLogFileNameInCache($logFileName, $expireTime);
}

$logDir = $this->getLogDir();
return $logDir . $logFileName;
}

public function getLogger()
{
return $this->logger;
}

public function getConfig(){
public function getConfig()
{
return $this->config;
}

Expand All @@ -64,7 +91,7 @@ public function logError($msg)

public function getInfo()
{
$files = glob($this->config->getLogDir().'/*.log');
$files = glob($this->config->getLogDir() . '/*.log');
if (!$files) {
return [
'dir' => $this->config->getLogDir(),
Expand All @@ -77,7 +104,7 @@ public function getInfo()
arsort($files);

$logs = [];
foreach($files as $key=>$value) {
foreach ($files as $key => $value) {
$logs[] = [
"filename" => basename($key),
"modified" => $value
Expand All @@ -97,7 +124,7 @@ public function getLogDetail($filename, $replaceNewline = false)
if ($filename == '') {
return [];
}
$fle = $this->config->getLogDir().'/'.$filename;
$fle = $this->config->getLogDir() . '/' . $filename;
$content = file_get_contents($fle);
if ($replaceNewline && $content !== false) {
$content = str_replace("\n", '#@#', $content);
Expand All @@ -122,4 +149,26 @@ private function formatBytes($path)
}
return $bytes;
}

private function getLogDir(): string
{
$logDir = $this->config->getLogDir();
return trailingslashit($logDir);
}

private function getLogFileName(): string
{
$uniqueId = uniqid('', true);
return 'log_transbank_' . $uniqueId . '.log';
}

private function getLogFileNameFromCache()
{
return get_transient(self::CACHE_LOG_NAME);
}

private function saveLogFileNameInCache(string $logFileName, int $expireTime)
{
set_transient(self::CACHE_LOG_NAME, $logFileName, $expireTime);
}
}
Loading

0 comments on commit 99c0105

Please sign in to comment.