LogRotate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Cron;
  7. use Magento\Framework\Exception\CouldNotDeleteException;
  8. use Vertex\Tax\Model\Config;
  9. use Vertex\Tax\Model\LogEntryRotator;
  10. use Vertex\Tax\Model\LogEntryRotatorFactory;
  11. /**
  12. * Class triggered by cron to rotate the vertex_taxrequest table
  13. */
  14. class LogRotate
  15. {
  16. /** @var Config */
  17. private $config;
  18. /** @var LogEntryRotatorFactory */
  19. private $logEntryRotatorFactory;
  20. /**
  21. * @param LogEntryRotatorFactory $logEntryRotatorFactory
  22. * @param Config $config
  23. */
  24. public function __construct(
  25. LogEntryRotatorFactory $logEntryRotatorFactory,
  26. Config $config
  27. ) {
  28. $this->logEntryRotatorFactory = $logEntryRotatorFactory;
  29. $this->config = $config;
  30. }
  31. /**
  32. * Rotate expired entries in the log entry table.
  33. *
  34. * @throws CouldNotDeleteException
  35. */
  36. public function execute()
  37. {
  38. if ($this->config->isLogRotationEnabled()) {
  39. $lifetimeSeconds = 3600 * 24 * (int)$this->config->getCronLogLifetime();
  40. try {
  41. /** @var LogEntryRotator $rotator */
  42. $rotator = $this->logEntryRotatorFactory->create();
  43. $rotator->rotate($lifetimeSeconds);
  44. } catch (\Exception $e) {
  45. throw new CouldNotDeleteException(__('Could not successfully delete record(s)'), $e);
  46. }
  47. }
  48. }
  49. }