timezone = $timezone; $this->request = $request; $this->driverFile = $driverFile; } public function getDates() { $days = IntegrationConstants::CLEAR_LOG_DAYS; $count = 0; $dateArr = []; $dateBefore = date('d-m-Y', strtotime($this->timezone->date()->format('d-m-Y H:i:s'))); do { $dateArr[] = [ 'date' => $dateBefore, 'selected' => ($dateBefore == $this->request->getParam('date'))? true : false ]; $dateBefore = date('d-m-Y', strtotime($dateBefore . ' -1 days')); $count++; } while ($count < $days); return $dateArr; } public function getLogs() { $logsArr = []; $logfile = ''; $date = date('d-m-Y', strtotime($this->timezone->date()->format('d-m-Y H:i:s'))); if ($this->request->getParam('date') != "") { $date = $this->request->getParam('date'); } if ($this->request->getParam('logfile') != "") { $logfile = $this->request->getParam('logfile'); } $logdir = DirectoryList::VAR_DIR.IntegrationConstants::NETSUITE_LOG_DIR; $files = Glob::glob(BP.'/'. $logdir.$date.'/'."*", GLOB_BRACE); foreach ($files as $file) { if ($this->driverFile->isFile($file)) { $logsArr[] = [ 'log' => basename($file), 'selected' => ($logfile == basename($file))? true : false ]; } } return $logsArr; } public function getDownloadLogsUrl() { $downloadUrl = ''; $logfile = ''; $date = date('d-m-Y', strtotime($this->timezone->date()->format('d-m-Y H:i:s'))); if ($this->request->getParam('date') != "") { $date = $this->request->getParam('date'); } if ($this->request->getParam('logfile') != "") { $logfile = $this->request->getParam('logfile'); } $downloadUrl = $this->getUrl('caratlane/logviewer/downloadlogs', ['date' => $date, 'logfile' => $logfile]); return $downloadUrl; } public function getClearLogsUrl() { $downloadUrl = ''; $logfile = ''; $date = date('d-m-Y', strtotime($this->timezone->date()->format('d-m-Y H:i:s'))); if ($this->request->getParam('date') != "") { $date = $this->request->getParam('date'); } if ($this->request->getParam('logfile') != "") { $logfile = $this->request->getParam('logfile'); } $downloadUrl = $this->getUrl('caratlane/logviewer/clearlogs', ['date' => $date, 'logfile' => $logfile]); return $downloadUrl; } public function getLogFileContent() { $contents = ''; $logsArr = []; $logfile = ''; $date = date('d-m-Y', strtotime($this->timezone->date()->format('d-m-Y H:i:s'))); if ($this->request->getParam('date') != "") { $date = $this->request->getParam('date'); } if ($this->request->getParam('logfile') != "") { $logfile = $this->request->getParam('logfile'); } $file = BP . '/' . DirectoryList::VAR_DIR . IntegrationConstants::NETSUITE_LOG_DIR . $date .'/'.$logfile; if ($this->driverFile->isExists($file)) { try { $contents = nl2br($this->driverFile->fileGetContents($file)); } catch (FileSystemException $e) { $contents = 'Error: '. $e->getMessage(); } } return $contents; } }