/** * {@inheritdoc} */ public function load() { try { return $this->directory->readFile($this->fileName); } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \UnexpectedValueException('Unable to retrieve deployment version of static files from the file system.', 0, $e); } }
/** * Check whether generation process has already locked * * @return bool * @throws FileSystemException */ private function isProcessLocked() { if ($this->tmpDirectory->isExist($this->lockFilePath)) { $lockTime = (int) $this->tmpDirectory->readFile($this->lockFilePath); if (time() - $lockTime >= self::MAX_LOCK_TIME) { $this->tmpDirectory->delete($this->lockFilePath); return false; } return true; } return false; }
/** * Get list of IP addresses effective for maintenance mode * * @return string[] */ public function getAddressInfo() { if ($this->flagDir->isExist(self::IP_FILENAME)) { $temp = $this->flagDir->readFile(self::IP_FILENAME); return explode(',', trim($temp)); } else { return []; } }
/** * Download sample file action * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $fileName = $this->getRequest()->getParam('filename') . '.csv'; $filePath = self::SAMPLE_FILES_DIRECTORY . $fileName; if (!$this->fileDirectory->isFile($filePath)) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $this->messageManager->addError(__('There is no sample file for this entity.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/import'); return $resultRedirect; } $fileSize = isset($this->fileDirectory->stat($filePath)['size']) ? $this->fileDirectory->stat($filePath)['size'] : null; $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($this->fileDirectory->readFile($filePath)); return $resultRaw; }
/** * Check whether generation process has already locked * * @return bool */ protected function isProcessLocked() { $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE; if ($this->tmpDirectory->isExist($lockFilePath)) { $lockTime = time() - (int) $this->tmpDirectory->readFile($lockFilePath); if ($lockTime >= self::MAX_LOCK_TIME) { $this->tmpDirectory->delete($lockFilePath); return false; } return true; } return false; }
/** * Write status information to the file. * * @param string $text * @param string $filePath * @return $this * @throws \RuntimeException */ protected function writeMessageToFile($text, $filePath) { $isNewFile = !$this->varReaderWriter->isExist($filePath); if (!$isNewFile && $this->varReaderWriter->readFile($filePath)) { $text = "\n{$text}"; } try { $this->varReaderWriter->writeFile($filePath, $text, 'a+'); } catch (FileSystemException $e) { throw new \RuntimeException(sprintf('Cannot add status information to "%s"', $filePath)); } if ($isNewFile) { chmod($filePath, 0777); } return $this; }
/** * Goes to specified host/path and fetches reports from there. * Save reports to database. * * @param \Magento\Framework\Filesystem\Io\Sftp $connection * @return int Number of report rows that were fetched and saved successfully * @throws \Magento\Framework\Exception\LocalizedException */ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection) { $fetched = 0; $listing = $this->_filterReportsList($connection->rawls()); foreach ($listing as $filename => $attributes) { $localCsv = 'PayPal_STL_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.csv'; if ($connection->read($filename, $this->_tmpDirectory->getAbsolutePath($localCsv))) { if (!$this->_tmpDirectory->isWritable($localCsv)) { throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a target file for reading reports.')); } $encoded = $this->_tmpDirectory->readFile($localCsv); $csvFormat = 'new'; $fileEncoding = mb_detect_encoding($encoded); if (self::FILES_OUT_CHARSET != $fileEncoding) { $decoded = @iconv($fileEncoding, self::FILES_OUT_CHARSET . '//IGNORE', $encoded); $this->_tmpDirectory->writeFile($localCsv, $decoded); $csvFormat = 'old'; } // Set last modified date, this value will be overwritten during parsing if (isset($attributes['mtime'])) { $date = new \DateTime(); $lastModified = $date->setTimestamp($attributes['mtime']); $this->setReportLastModified($lastModified->format('Y-m-d H:i:s')); } $this->setReportDate($this->_fileNameToDate($filename))->setFilename($filename)->parseCsv($localCsv, $csvFormat); if ($this->getAccountId()) { $this->save(); } if ($this->_dataSaveAllowed) { $fetched += count($this->_rows); } // clean object and remove parsed file $this->unsetData(); $this->_tmpDirectory->delete($localCsv); } } return $fetched; }
/** * Retrieve file content from file container array * * @param array $fileData * @return string */ protected function _getFileContainerContent(array $fileData) { return $this->_directory->readFile('export/' . $fileData['value']); }
/** * Return generated varnish.vcl configuration file * * @param string $vclTemplatePath * @return string * @api */ public function getVclFile($vclTemplatePath) { $data = $this->_modulesDirectory->readFile($this->_scopeConfig->getValue($vclTemplatePath)); return strtr($data, $this->_getReplacements()); }
/** * Gets contents of the log * * @return array */ public function get() { $fileContents = explode(PHP_EOL, $this->directory->readFile($this->logFile)); return $fileContents; }
/** * Get report file output * * @param string $filename * @return string */ public function getReportOutput($filename) { return $this->varDirectory->readFile($this->getFilePath($filename)); }
/** * Return generated varnish.vcl configuration file * * @return string */ public function getVclFile() { $data = $this->_modulesDirectory->readFile($this->_scopeConfig->getValue(self::VARNISH_CONFIGURATION_PATH)); return strtr($data, $this->_getReplacements()); }