removed debug log

This commit is contained in:
O K
2025-06-05 20:11:21 +03:00
parent bab4d43a44
commit a35c8aa098
3 changed files with 172 additions and 5 deletions

View File

@@ -36,7 +36,8 @@ class Hutko extends PaymentModule
'HUTKO_NEW_ORDER_STATUS_ID',
'HUTKO_SUCCESS_STATUS_ID',
'HUTKO_SHOW_CARDS_LOGO',
'HUTKO_SAVE_LOGS'
'HUTKO_SAVE_LOGS',
'HUTKO_INCLUDE_DISCOUNT_TO_TOTAL'
];
public $postErrors = [];
@@ -98,6 +99,7 @@ class Hutko extends PaymentModule
return true;
}
/**
* Load the configuration form
@@ -119,7 +121,7 @@ class Hutko extends PaymentModule
}
}
return $err . $this->renderForm();
return $err . $this->renderForm() . $this->context->smarty->fetch('module:hutko/views/templates/admin/help.tpl').$this->displayLastDayLog();
}
/**
@@ -260,6 +262,24 @@ class Hutko extends PaymentModule
)
),
),
array(
'type' => 'radio',
'label' => $this->trans('Include fixed amount discounts to Payment amount calculation', array(), 'Modules.Hutko.Admin'),
'name' => 'HUTKO_INCLUDE_DISCOUNT_TO_TOTAL',
'is_bool' => true,
'values' => array(
array(
'id' => 'include_discount_to_total',
'value' => 1,
'label' => $this->trans('Yes', array(), 'Modules.Hutko.Admin')
),
array(
'id' => 'discard_discount_to_total',
'value' => 0,
'label' => $this->trans('No', array(), 'Modules.Hutko.Admin')
)
),
),
array(
'type' => 'radio',
'label' => $this->trans('Save Logs', array(), 'Modules.Hutko.Admin'),
@@ -426,6 +446,11 @@ class Hutko extends PaymentModule
$amount = $order->total_products_wt;
}
}
if (Configuration::get('HUTKO_INCLUDE_DISCOUNT_TO_TOTAL')) {
$amount -= $order->total_discounts_tax_incl;
}
$amountInt = round($amount * 100);
// 5. Get the currency ISO code of the current cart.
@@ -1221,7 +1246,72 @@ class Hutko extends PaymentModule
$logger->setFilename($logdirectory . 'dayly.log');
$logger->logInfo($data);
}
public function displayLastDayLog()
{
$baseLogDir = _PS_ROOT_DIR_ . '/var/modules/' . $this->name . '/logs/';
$daysToCheck = 300; // How many recent days to check for logs
$latestLogFile = false;
$logDate = null;
// Find the latest log file by iterating backward from today
for ($i = 0; $i < $daysToCheck; $i++) {
// Use \DateTime for clarity as we might be in a different namespace
$date = new \DateTime("-$i days");
$year = $date->format("Y");
$month = $date->format("m");
$day = $date->format("d");
$potentialDir = $baseLogDir . $year . '/' . $month . '/' . $day . '/';
$potentialFile = $potentialDir . 'dayly.log';
if (is_dir($potentialDir) && file_exists($potentialFile)) {
$latestLogFile = $potentialFile;
$logDate = $date; // Store the date of the found log
break; // Found the latest one, stop searching
}
}
// Prepare HTML output
$html = '<div class="panel">';
// Use translation function for the heading
$html .= '<div class="panel-heading"><i class="icon-align-left"></i> ' . $this->trans('Hutko Module Logs', [], 'Modules.Hutko.Admin') . '</div>';
$html .= '<div class="panel-body">';
if ($latestLogFile) {
// Add a heading indicating the date of the log file
$html .= '<h4>' . sprintf($this->trans('Log file for %s', [], 'Modules.Hutko.Admin'), $logDate->format("Y-m-d")) . '</h4>';
// Read the file line by line into an array
// FILE_IGNORE_NEW_LINES: removes the trailing newline character from each element
// FILE_SKIP_EMPTY_LINES: skips empty lines
$lines = file($latestLogFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines !== false) { // Check if file() succeeded
if (empty($lines)) {
$html .= '<p>' . $this->trans('The log file is empty.', [], 'Modules.Hutko.Admin') . '</p>';
} else {
// Output each line wrapped in a <p> tag
foreach ($lines as $line) {
// Use htmlspecialchars to prevent HTML injection and display characters correctly
// Add word-wrap style for long lines
$html .= '<p style="word-wrap: break-word;">' . htmlspecialchars($line, ENT_QUOTES, 'UTF-8') . '</p>';
}
}
} else {
// Error reading the file
$html .= '<div class="alert alert-warning">' . $this->trans('Could not read the log file:', [], 'Modules.Hutko.Admin') . ' ' . $latestLogFile . '</div>';
}
} else {
// No log file found in the specified range
$html .= '<div class="alert alert-info">' . sprintf($this->trans('No log file found in the last %d days.', [], 'Modules.Hutko.Admin'), $daysToCheck) . '</div>';
}
$html .= '</div>'; // End panel-body
$html .= '</div>'; // End panel
return $html;
}
/**
* URL-safe encodes a string using a Base64-like approach.