/** * @return Collection */ protected function getLogCollection() { // Initialize the log collection if ($this->logCollection == null) { $this->logCollection = $this->logCollectionFactory->create(); } return $this->logCollection; }
/** * Clear the queue of complete and failed records */ public function clearLogs() { $this->avaTaxLogger->debug(__('Starting queue clearing')); /** @var $collection \ClassyLlama\AvaTax\Model\ResourceModel\Log\Collection */ $collection = $this->logCollectionFactory->create(); // Get configuration for record lifetime $lifetimeDays = $this->avaTaxConfig->getLogDbLifetime(); // Calculate the number of seconds to adjust the filter // 86400 seconds == 60 seconds * 60 minutes * 24 hours == 1 day $secondsBeforeNow = $lifetimeDays * 60 * 60 * 24; // Add filters $collection->addCreatedAtBeforeFilter($secondsBeforeNow); // Process each queued entity /** @var $log Log */ foreach ($collection as $log) { // Remove the queue record $log->delete(); $this->deleteCount++; } $this->avaTaxLogger->debug(__('Finished clearing log entries'), ['delete_count' => $this->deleteCount]); }