![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Soon/AdminLogger/Model/ |
<?php /** * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @author Hervé Guétin <[email protected]> <@herveguetin> * @copyright Copyright (c) 2018 Kaliop Digital Commerce (http://digitalcommerce.kaliop.com) */ namespace Soon\AdminLogger\Model; class Log extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface { const CACHE_TAG = 'soon_adminlogger_log'; const LOG_FILE_NAME = 'soon_adminlogger.csv'; /** * @var \Magento\Framework\App\Filesystem\DirectoryList */ private $directoryList; /** * @var \Magento\Framework\Filesystem\Driver\File */ private $file; /** * @var \Magento\Framework\File\Csv */ private $csv; public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Soon\AdminLogger\Model\ResourceModel\Log $resource = null, \Soon\AdminLogger\Model\ResourceModel\Log\Collection $resourceCollection = null, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem\Driver\File $file, \Magento\Framework\File\Csv $csv, array $data = [] ) { parent::__construct($context, $registry, $resource, $resourceCollection, $data); $this->directoryList = $directoryList; $this->file = $file; $this->csv = $csv; } protected function _construct() { $this->_init('Soon\AdminLogger\Model\ResourceModel\Log'); } /** * @return array * @throws \Magento\Framework\Exception\FileSystemException */ public function getLoggedData() { return $this->csv->getData($this->getLogFilePath()); } /** * @return string * @throws \Magento\Framework\Exception\FileSystemException */ private function getLogFilePath() { return $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::LOG) . \DIRECTORY_SEPARATOR . self::LOG_FILE_NAME; } public function getIdentities() { return [self::CACHE_TAG . '_' . $this->getId()]; } /** * @param array $data * @throws \Magento\Framework\Exception\FileSystemException */ public function saveData(array $data) { $fh = fopen($this->getLogFilePath(), 'a'); $this->file->filePutCsv($fh, $data); fclose($fh); } }