Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
DryRunLogger Class Reference

Public Member Functions

 __construct (\Magento\Framework\Filesystem\Driver\File $fileDriver, DirectoryList $directoryList)
 
 prepareToDryRun ()
 
 log ($sql)
 

Data Fields

const INPUT_KEY_DRY_RUN_MODE = 'dry-run'
 
const FILE_NAME = 'dry-run-installation.log'
 
const LINE_SEPARATOR = "\n\n"
 

Detailed Description

This class is responsible for logging dry run SQL`s By default it logs them into filesystem, but it can be extended and you can log them in CLI Current problem with logging output to CLI, is that we have redudant things in CLI output, like modules progress

Definition at line 16 of file DryRunLogger.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Filesystem\Driver\File  $fileDriver,
DirectoryList  $directoryList 
)
Parameters
\Magento\Framework\Filesystem\Driver\File$fileDriver
DirectoryList$directoryList

Definition at line 48 of file DryRunLogger.php.

51  {
52  $this->fileDriver = $fileDriver;
53  $this->directoryList = $directoryList;
54  }

Member Function Documentation

◆ log()

log (   $sql)

Do log of SQL query, 2 different SQL`s will be divided by one empty line

Parameters
string$sql
Exceptions

Definition at line 133 of file DryRunLogger.php.

134  {
135  $loggerFolder = $this->getLoggerFolder();
136  $loggerFile = $this->getLoggerFile();
137  $this->assertLogFolderExists($loggerFolder);
138  $this->assertFileExists($loggerFile);
139 
140  if ($this->fileDriver->isWritable($loggerFile)) {
141  $fd = $this->fileDriver->fileOpen($loggerFile, 'a');
142  $this->fileDriver->fileWrite($fd, $sql . self::LINE_SEPARATOR);
143  } else {
144  throw new \Exception(sprintf('Can`t write to file %s', $loggerFile));
145  }
146  }

◆ prepareToDryRun()

prepareToDryRun ( )

Make file empty from request to request

Exceptions

Definition at line 93 of file DryRunLogger.php.

94  {
95  if ($this->fileDriver->isExists($this->getLoggerFile())) {
96  if (!$this->fileDriver->isWritable($this->getLoggerFile())) {
97  throw new \Exception(sprintf('Dry run logger file is not writable'));
98  }
99 
100  $this->fileDriver->deleteFile($this->getLoggerFile());
101  $this->fileDriver->touch($this->getLoggerFile());
102  }
103  }

Field Documentation

◆ FILE_NAME

const FILE_NAME = 'dry-run-installation.log'

File name, where all dry-run SQL`s will be puted

Definition at line 26 of file DryRunLogger.php.

◆ INPUT_KEY_DRY_RUN_MODE

const INPUT_KEY_DRY_RUN_MODE = 'dry-run'

We will run installation or upgrade in Dry Run mode

Definition at line 21 of file DryRunLogger.php.

◆ LINE_SEPARATOR

const LINE_SEPARATOR = "\n\n"

Allows to separate 2 different sql statements with this separator Be default is used 2 empty lines

Definition at line 32 of file DryRunLogger.php.


The documentation for this class was generated from the following file: