. */ /* */ /*************************************************************************************/ /** * Created by Franck Allimant, CQFDev * Date: 11/01/2016 11:57 */ namespace Paypal\Hook; use Paypal\Classes\API\PaypalApiLogManager; use Paypal\Paypal; use Thelia\Core\Event\Hook\HookRenderEvent; use Thelia\Core\Hook\BaseHook; use Thelia\Model\ModuleConfig; use Thelia\Model\ModuleConfigQuery; class HookManager extends BaseHook { const MAX_TRACE_SIZE_IN_BYTES = 40000; public function onModuleConfigure(HookRenderEvent $event) { $logFilePath = PaypalApiLogManager::getLogFilePath(); $traces = @file_get_contents($logFilePath); if (false === $traces) { $traces = $this->translator->trans("The log file doesn't exists yet.", [], Paypal::DOMAIN); } elseif (empty($traces)) { $traces = $this->translator->trans("The log file is empty.", [], Paypal::DOMAIN); } else { // Limiter la taille des traces à 1MO if (strlen($traces) > self::MAX_TRACE_SIZE_IN_BYTES) { $traces = substr($traces, strlen($traces) - self::MAX_TRACE_SIZE_IN_BYTES); // Cut a first line break; if (false !== $lineBreakPos = strpos($traces, "\n")) { $traces = substr($traces, $lineBreakPos+1); } $traces = $this->translator->trans( "(Previous log is in %file file.)\n", [ '%file' => sprintf("log".DS."%s.log", Paypal::DOMAIN) ], Paypal::DOMAIN ) . $traces; } } $vars = ['trace_content' => nl2br($traces) ]; if (null !== $params = ModuleConfigQuery::create()->findByModuleId(Paypal::getModuleId())) { /** @var ModuleConfig $param */ foreach ($params as $param) { $vars[ $param->getName() ] = $param->getValue(); } } $event->add( $this->render('paypal/module-configuration.html', $vars) ); } }