prepare release 1.7 (#1388)

This commit is contained in:
Kevin Papst
2020-01-19 21:49:04 +01:00
committed by GitHub
parent 352fac26f3
commit 9eff89963c
44 changed files with 225 additions and 57 deletions

View File

@@ -55,6 +55,29 @@ class DoctorController extends AbstractController
$this->projectDirectory = $projectDirectory;
}
/**
* @Route(path="/flush-log", name="doctor_flush_log", methods={"GET"})
* @Security("is_granted('system_configuration')")
*/
public function deleteLogfileAction(): Response
{
$logfile = $this->getLogFilename();
if (file_exists($logfile)) {
if (!is_writable($logfile)) {
$this->flashError('action.delete.error', ['%reason%' => 'Logfile cannot be written']);
} else {
if (false === file_put_contents($logfile, '')) {
$this->flashError('action.delete.error', ['%reason%' => 'Failed writing to logfile']);
} else {
$this->flashSuccess('action.delete.success');
}
}
}
return $this->redirectToRoute('doctor');
}
/**
* @Route(path="", name="doctor", methods={"GET"})
*/
@@ -62,6 +85,8 @@ class DoctorController extends AbstractController
{
$logLines = 100;
$canDeleteLogfile = $this->isGranted('system_configuration') && is_writable($this->getLogFilename());
return $this->render('doctor/index.html.twig', array_merge(
[
'modules' => get_loaded_extensions(),
@@ -70,6 +95,7 @@ class DoctorController extends AbstractController
'settings' => $this->getIniSettings(),
'extensions' => $this->getLoadedExtensions(),
'directories' => $this->getFilePermissions(),
'log_delete' => $canDeleteLogfile,
'logs' => $this->getLog(),
'logLines' => $logLines,
'logSize' => $this->getLogSize(),
@@ -106,20 +132,31 @@ class DoctorController extends AbstractController
return filesize($logfile);
}
private function getLog(int $lines = 100)
private function getLogFilename(): string
{
// why is this check here ???
if (!in_array(getenv('APP_ENV'), ['test', 'dev', 'prod'])) {
return [
'Unsupported log environment'
];
throw new \RuntimeException('Unsupported log environment');
}
$logfileName = 'var/log/' . getenv('APP_ENV') . '.log';
$logfile = $this->projectDirectory . '/' . $logfileName;
return $this->projectDirectory . '/' . $logfileName;
}
private function getLog(int $lines = 100)
{
try {
$logfile = $this->getLogFilename();
} catch (\Exception $ex) {
return [
$ex->getMessage()
];
}
if (!file_exists($logfile)) {
return [
'Could not find logfile: ' . $logfileName
'Empty or missing logfile'
];
}