예제 #1
0
 /**
  * @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);
     }
 }
예제 #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);
 }
예제 #3
0
 /**
  * @test
  */
 public function logException()
 {
     try {
         throw new \Exception('This is a Test Exception');
     } catch (\Exception $e) {
         $this->logger->logException($e);
     }
     $this->assertLogFileContains('[CRITICAL]');
     $this->assertLogFileContains('component="Tx.PtExtbase.Logger.Logger": Uncaught exception: This is a Test Exception - See also:');
     $this->assertCount(1, Tx_PtExtbase_Utility_Files::readDirectoryRecursively($this->logExceptionsPath));
 }
예제 #4
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);
 }
 /**
  * Remove the complete directory
  */
 public function removeHasFileSystemCompletely()
 {
     Tx_PtExtbase_Utility_Files::removeDirectoryRecursively($this->rootDirectory);
 }