Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
abstract class AbstractLoggerCore implements PrestaShopLoggerInterface
{
public $level;
protected $level_value = [
0 => 'DEBUG',
1 => 'INFO',
2 => 'WARNING',
3 => 'ERROR',
];
public function __construct($level = self::INFO)
{
if (array_key_exists((int) $level, $this->level_value)) {
$this->level = $level;
} else {
$this->level = self::INFO;
}
}
/**
* Log the message.
*
* @param string $message
* @param int $level
*/
abstract protected function logMessage($message, $level);
/**
* Check the level and log the message if needed.
*
* @param string $message
* @param int $level
*/
public function log($message, $level = self::DEBUG)
{
if ($level >= $this->level) {
$this->logMessage($message, $level);
}
Hook::exec(
'actionLoggerLogMessage',
[
'message' => $message,
'level' => $level,
'isLogged' => $level >= $this->level,
]
);
}
/**
* Log a debug message.
*
* @param string $message
*/
public function logDebug($message)
{
$this->log($message, self::DEBUG);
}
/**
* Log an info message.
*
* @param string $message
*/
public function logInfo($message)
{
$this->log($message, self::INFO);
}
/**
* Log a warning message.
*
* @param string $message
*/
public function logWarning($message)
{
$this->log($message, self::WARNING);
}
/**
* Log an error message.
*
* @param string $message
*/
public function logError($message)
{
$this->log($message, self::ERROR);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
class FileLoggerCore extends AbstractLogger
{
/**
* @var string
*/
protected $filename = '';
/**
* Write the message in the log file.
*
* @param string $message
* @param int $level
*
* @return bool
*/
protected function logMessage($message, $level)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$formatted_message = '*' . $this->level_value[$level] . '* ' . "\tv" . _PS_VERSION_ . "\t" . date('Y/m/d - H:i:s') . ': ' . $message . "\r\n";
return (bool) file_put_contents($this->getFilename(), $formatted_message, FILE_APPEND);
}
/**
* Check if the specified filename is writable and set the filename.
*
* @param string $filename
*
* @return void
*/
public function setFilename($filename)
{
if (is_writable(dirname($filename))) {
$this->filename = $filename;
} else {
die('Directory ' . dirname($filename) . ' is not writable');
}
}
/**
* Log the message.
*
* @return string
*/
public function getFilename()
{
if (empty($this->filename)) {
throw new PrestaShopException('Filename is empty.');
}
return $this->filename;
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
declare(strict_types=1);
/**
* NullLogger is an implementation of the PrestaShop logger that logs nothing.
* It is convenient as a default value for logger instances, this way the code can be
* executed the same way even if it does nothing.
*/
class NullLogger extends AbstractLogger
{
protected function logMessage($message, $level)
{
// Null logger doesn't log anything
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
declare(strict_types=1);
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
/**
* This class is an adapter if can use PrestaShopLoggerInterface and decorate it into a PSR logger.
*/
class PSRLoggerAdapter implements LoggerInterface
{
/**
* @var PrestaShopLoggerInterface
*/
private $logger;
private bool $saveMessages = false;
/**
* @var array<string, string[]>
*/
private array $savedMessages;
public function __construct(PrestaShopLoggerInterface $logger)
{
$this->logger = $logger;
}
public function emergency($message, array $context = []): void
{
$this->logger->logError($message);
$this->saveMessage(LogLevel::EMERGENCY, $message);
}
public function alert($message, array $context = []): void
{
$this->logger->logError($message);
$this->saveMessage(LogLevel::ALERT, $message);
}
public function critical($message, array $context = []): void
{
$this->logger->logError($message);
$this->saveMessage(LogLevel::CRITICAL, $message);
}
public function error($message, array $context = []): void
{
$this->logger->logError($message);
$this->saveMessage(LogLevel::ERROR, $message);
}
public function warning($message, array $context = []): void
{
$this->logger->logWarning($message);
$this->saveMessage(LogLevel::WARNING, $message);
}
public function notice($message, array $context = []): void
{
$this->logger->logInfo($message);
$this->saveMessage(LogLevel::NOTICE, $message);
}
public function info($message, array $context = []): void
{
$this->logger->logInfo($message);
$this->saveMessage(LogLevel::INFO, $message);
}
public function debug($message, array $context = []): void
{
$this->logger->logDebug($message);
}
public function log($level, $message, array $context = []): void
{
switch ($level) {
case LogLevel::EMERGENCY:
case LogLevel::CRITICAL:
case LogLevel::ALERT:
case LogLevel::ERROR:
$legacyLevel = PrestaShopLoggerInterface::ERROR;
break;
case LogLevel::WARNING:
$legacyLevel = PrestaShopLoggerInterface::WARNING;
break;
case LogLevel::NOTICE:
case LogLevel::INFO:
$legacyLevel = PrestaShopLoggerInterface::INFO;
break;
case LogLevel::DEBUG:
default:
$legacyLevel = PrestaShopLoggerInterface::DEBUG;
break;
}
$this->logger->log($message, $legacyLevel);
if ($level == LogLevel::DEBUG) {
$this->saveMessage($level, $message);
}
}
/**
* All messages logged after this method is called are stored in a class field.
*/
public function startSavingMessages(): void
{
$this->saveMessages = true;
}
/**
* Stop saving log records and clear the saved records.
*/
public function stopSavingMessages(): void
{
$this->saveMessages = false;
$this->savedMessages = [];
}
public function getAllSavedMessages(): array
{
return $this->savedMessages;
}
public function getSavedMessages(string $level): array
{
return $this->savedMessages[$level] ?? [];
}
protected function saveMessage($level, $message): void
{
if (!$this->saveMessages) {
return;
}
$this->savedMessages[$level][] = $message;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
declare(strict_types=1);
interface PrestaShopLoggerInterface
{
public const DEBUG = 0;
public const INFO = 1;
public const WARNING = 2;
public const ERROR = 3;
/**
* @param string $message
* @param int $level
*
* @return void
*/
public function log($message, $level = self::DEBUG);
/**
* @param string $message
*
* @return void
*/
public function logDebug($message);
/**
* @param string $message
*
* @return void
*/
public function logInfo($message);
/**
* @param string $message
*
* @return void
*/
public function logWarning($message);
/**
* @param string $message
*
* @return void
*/
public function logError($message);
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
declare(strict_types=1);
use Symfony\Component\Console\Output\OutputInterface;
/**
* This logger class respects the PrestaShopLoggerInterface but is based on the Symfony console
* component. It is used as a temporary solution in legacy code until we can replace the usage of
* the legacy interface.
*/
class SymfonyConsoleLogger extends AbstractLogger
{
/**
* @var OutputInterface
*/
private $output;
public function __construct(OutputInterface $output, $level = self::INFO)
{
parent::__construct($level);
$this->output = $output;
}
protected function logMessage($message, $level)
{
$this->output->writeln($message);
}
}

14
classes/log/index.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../');
exit;