Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Report.php
Go to the documentation of this file.
1 <?php
8 
11 
19 {
23  protected $timeZone;
24 
28  protected $varDirectory;
29 
37  public function __construct(
38  \Magento\Framework\App\Helper\Context $context,
39  \Magento\Framework\Stdlib\DateTime\Timezone $timeZone,
40  \Magento\Framework\Filesystem $filesystem
41  ) {
42  $this->timeZone = $timeZone;
43  $this->varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
44  parent::__construct($context);
45  }
46 
53  public function getExecutionTime($time)
54  {
55  $reportTime = $this->timeZone->date($time);
56  $timeDiff = $reportTime->diff($this->timeZone->date());
57  return $timeDiff->format('%H:%I:%S');
58  }
59 
66  public function getSummaryStats(\Magento\ImportExport\Model\Import $import)
67  {
68  $message = __(
69  'Created: %1, Updated: %2, Deleted: %3',
70  $import->getCreatedItemsCount(),
71  $import->getUpdatedItemsCount(),
72  $import->getDeletedItemsCount()
73  );
74  return $message;
75  }
76 
83  public function importFileExists($filename)
84  {
85  return $this->varDirectory->isFile($this->getFilePath($filename));
86  }
87 
94  public function getReportOutput($filename)
95  {
96  return $this->varDirectory->readFile($this->getFilePath($filename));
97  }
98 
106  {
107  return $this->varDirectory->getAbsolutePath(Import::IMPORT_HISTORY_DIR . $fileName);
108  }
109 
116  public function getReportSize($filename)
117  {
118  return $this->varDirectory->stat($this->getFilePath($filename))['size'];
119  }
120 
128  protected function getFilePath($filename)
129  {
130  if (preg_match('/\.\.(\\\|\/)/', $filename)) {
131  throw new \InvalidArgumentException('Filename has not permitted symbols in it');
132  }
133 
134  return $this->varDirectory->getRelativePath(Import::IMPORT_HISTORY_DIR . $filename);
135  }
136 
143  public function getDelimiter()
144  {
145  return $this->_request->getParam(Import::FIELD_FIELD_SEPARATOR, ',');
146  }
147 }
getSummaryStats(\Magento\ImportExport\Model\Import $import)
Definition: Report.php:66
__()
Definition: __.php:13
$message
$fileName
Definition: translate.phtml:15
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Stdlib\DateTime\Timezone $timeZone, \Magento\Framework\Filesystem $filesystem)
Definition: Report.php:37
$filesystem