ReportFileCleaner (optional)

https://github.com/magesuite/magesuite-report-file-cleaner

The module was created in order to avoid cases when hundreds of thousands of files were placed in var/report which slowed down file operations and the deployment process. The module allows periodic cleaning of files.

 

Installation

This module is optional.

composer require "creativestyle/magesuite-report-file-cleaner" ^1.0.0

Admin settings

Admin setting can be found under Stores -> Configuration -> Advanced -> System in the Report File Cleaner tab.

The module is disabled by default when installed.

Settings:

Field

Options

Comment

Field

Options

Comment

Enabled

Yes/No 

 

Period of storing files in days

 

 

Cleaning files cron schedule expression

Default: 0 0 15 * *

 

Cleaning files patterns

Default: report/*

The base directory is var/
All patterns should be paths inside var/ directory.

Currently stored files amount:

/var/www/projects/creativeshop/var/report/*: 34

 

Backend

Documentation is in progress

Cron

vendor/creativestyle/magesuite-report-file-cleaner/Cron/CleanFiles.php:33
class CleanFiles { public function execute() { ..... $this->logFilesCleaner->cleanFiles(); return true; } }

 

Command

system:clean_report_files

vendor/creativestyle/magesuite-report-file-cleaner/Console/Command/CleanFiles.php:38
class CleanFiles extends \Symfony\Component\Console\Command\Command { protected function execute( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) { ..... $logFilesCleaner = $this->logFilesCleanerFactory->create(); $logFilesCleaner->cleanFiles(); return true; } }

 

Service for removing files

class LogFilesCleaner { public function cleanFiles() { $period = $this->configuration->getStoringFilesPeriodInDays(); $searchPatterns = $this->configuration->getSearchPatterns(); foreach ($searchPatterns as $searchPattern) { $this->cleanFilesForPattern($searchPattern, $period); } } public function cleanFilesForPattern(string $searchPattern, ?int $period) { $pattern = sprintf('%s/%s', $this->directory->getDirectoryAbsolutePath(\Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR), ltrim($searchPattern, '/')); $filesPaths = $this->directory->getItemsForPattern($pattern); $this->removeFiles($filesPaths, $period); } }

 

Frontend

There is no frontend functionality in this module.