/**
  * @return void
  */
 protected function evaluateExceptionDirectory()
 {
     if (!$this->exceptionDirectory) {
         $path_parts = pathinfo($this->logFilePath);
         $this->exceptionDirectory = \Tx_PtExtbase_Utility_Files::concatenatePaths(array(realpath($path_parts['dirname']), 'Exceptions'));
         \Tx_PtExtbase_Utility_Files::createDirectoryRecursively($this->exceptionDirectory);
     }
 }
Example #2
0
 /**
  * Writes information about the given exception into the log.
  *
  * @param \Exception $exception The exception to log
  * @param null $logComponent
  * @param array $additionalData Additional data to log
  * @return void
  * @api
  */
 public function logException(\Exception $exception, $logComponent = null, array $additionalData = array())
 {
     $backTrace = $exception->getTrace();
     $message = $this->getExceptionLogMessage($exception);
     if ($exception->getPrevious() !== null) {
         $additionalData['previousException'] = $this->getExceptionLogMessage($exception->getPrevious());
     }
     if (!file_exists($this->exceptionDirectory)) {
         mkdir($this->exceptionDirectory);
     }
     if (file_exists($this->exceptionDirectory) && is_dir($this->exceptionDirectory) && is_writable($this->exceptionDirectory)) {
         $referenceCode = ($exception->getCode() > 0 ? $exception->getCode() . '.' : '') . date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6);
         $exceptionDumpPathAndFilename = Tx_PtExtbase_Utility_Files::concatenatePaths(array($this->exceptionDirectory, $referenceCode . '.txt'));
         file_put_contents($exceptionDumpPathAndFilename, $message . PHP_EOL . PHP_EOL . $this->getBacktraceCode($backTrace, 1));
         $message .= ' - See also: ' . basename($exceptionDumpPathAndFilename);
     } else {
         $this->warning(sprintf('Could not write exception backtrace into %s because the directory could not be created or is not writable.', $this->exceptionDirectory), $logComponent, array());
     }
     $this->critical($message, $logComponent, $additionalData);
 }
Example #3
0
 /**
  * @return array
  */
 public function checkDirAndCreateIfMissingDataProvider()
 {
     $this->testDirectory = Tx_PtExtbase_Utility_Files::concatenatePaths(array(__DIR__, 'workspace'));
     return array('alreadyExisting' => array('directoryToCreate' => $this->testDirectory), 'notExisting' => array('directoryToCreate' => Tx_PtExtbase_Utility_Files::concatenatePaths(array($this->testDirectory, 'test1'))), 'notExistingDeep' => array('directoryToCreate' => Tx_PtExtbase_Utility_Files::concatenatePaths(array($this->testDirectory, 'test1', 'test2'))));
 }
 /**
  * @test
  */
 public function removeFile()
 {
     $expectedFileLocation = $this->hashFileSystemService->getHashPath(1234) . '/test.pdf';
     $this->assertFileNotExists($expectedFileLocation);
     $testFile = Tx_PtExtbase_Utility_Files::concatenatePaths(array(PATH_site, 'typo3temp', 'test.pdf'));
     touch($testFile);
     $this->hashFileSystemService->storeFile(1234, $testFile);
     $this->assertFileExists($expectedFileLocation);
     $this->hashFileSystemService->removeFile(1234, 'test.pdf');
     $this->assertFileNotExists($expectedFileLocation);
 }
 /**
  * @param $identifier
  * @param $fileName
  * @return bool
  */
 public function fileExists($identifier, $fileName)
 {
     return file_exists(Tx_PtExtbase_Utility_Files::concatenatePaths(array($this->getHashPath($identifier), $fileName)));
 }
 /**
  * @param $astId
  * @param bool $createDirectory
  * @throws \InvalidArgumentException
  * @return string
  */
 public function getHashPath($astId, $createDirectory = false)
 {
     $astId = (int) $astId;
     if ($astId == 0) {
         throw new \InvalidArgumentException('The AstId must be an integer > 0', 1369816965);
     }
     $level1 = $astId % 10;
     $level2 = $astId % 100;
     $hashPath = Tx_PtExtbase_Utility_Files::concatenatePaths(array($this->rootDirectory, $level1, $level2, $astId));
     if ($createDirectory) {
         Tx_PtExtbase_Utility_Files::createDirectoryRecursively($hashPath);
     }
     return $hashPath;
 }