diff --git a/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php b/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php index 0d262b8c94..1a47faff08 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php @@ -178,35 +178,31 @@ class TaskManagerController extends Controller public function getSchedulerLog(Request $request) { - file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export(null, true)), FILE_APPEND); /** @var LogFileFactory $factory */ $factory = $this->app['task-manager.log-file.factory']; $logFile = $factory->forManager(); - if ($request->query->get('clr')) { + if ($request->query->get('clr') && $request->query->get('version') !== null) { $logFile->clear($request->query->get('version')); } return $this->render('admin/task-manager/log_scheduler.html.twig', [ 'logfile' => $logFile, - 'version' => $request->query->get('version'), - 'logname' => 'Scheduler', + 'version' => $request->query->get('version') ]); } public function getTaskLog(Request $request, Task $task) { - file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export(null, true)), FILE_APPEND); /** @var LogFileFactory $factory */ $factory = $this->app['task-manager.log-file.factory']; $logFile = $factory->forTask($task); - if ($request->query->get('clr')) { + if ($request->query->get('clr') && $request->query->get('version') !== null) { $logFile->clear($request->query->get('version')); } return $this->render('admin/task-manager/log_task.html.twig', [ 'logfile' => $logFile, - 'version' => $request->query->get('version'), - 'logname' => sprintf('%s (task id %d)', $task->getName(), $task->getId()), + 'version' => $request->query->get('version') ]); } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php b/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php index e0c33941b9..40468483a6 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/AbstractLogFile.php @@ -66,6 +66,15 @@ abstract class AbstractLogFile implements LogFileInterface */ public function clear($version) { - file_put_contents($this->getPath($version), ''); + file_put_contents($this->getPath($version), sprintf("File cleared %s\n", date('r'))); } + + /** + * {@inheritdoc} + */ + public function versionExists($version) + { + return file_exists($this->getPath($version)); + } + } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php b/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php index fab254bc4d..be33b80393 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/LogFileInterface.php @@ -54,4 +54,13 @@ interface LogFileInterface * @param string $version */ public function clear($version); + + /** + * Returns true if the logfile exists + * + * @param $version + * @return bool + */ + public function versionExists($version); + } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php b/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php index 5aeec9ee7b..e9b3b0bdf2 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/ManagerLogFile.php @@ -11,6 +11,9 @@ namespace Alchemy\Phrasea\TaskManager\Log; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; + class ManagerLogFile extends AbstractLogFile implements LogFileInterface { /** @@ -18,7 +21,17 @@ class ManagerLogFile extends AbstractLogFile implements LogFileInterface */ public function getVersions() { - return array(''); + $x = '/^scheduler(|(-.*))\.log$/'; + $f = new Finder(); + $versions = []; + /** @var \SplFileInfo $file */ + foreach($f->files()->in($this->root) as $file) { + $matches = []; + if(preg_match($x, $file->getBasename(), $matches)) { + $versions[] = $matches[1]; + } + } + return $versions; } /** @@ -26,6 +39,6 @@ class ManagerLogFile extends AbstractLogFile implements LogFileInterface */ public function getPath($version) { - return sprintf('%s/scheduler%s.log', $this->root, $version ? ('-'.$version) : '' ); + return sprintf('%s/scheduler%s.log', $this->root, $version); } } diff --git a/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php b/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php index da8f5d590f..515a93e09e 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php +++ b/lib/Alchemy/Phrasea/TaskManager/Log/TaskLogFile.php @@ -12,6 +12,8 @@ namespace Alchemy\Phrasea\TaskManager\Log; use Alchemy\Phrasea\Model\Entities\Task; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; class TaskLogFile extends AbstractLogFile implements LogFileInterface { @@ -29,7 +31,17 @@ class TaskLogFile extends AbstractLogFile implements LogFileInterface */ public function getVersions() { - return array('', '2015-12-21'); + $x = sprintf('/^task_%d(|(-.*))\.log$/', $this->task->getId()); + $f = new Finder(); + $versions = []; + /** @var \SplFileInfo $file */ + foreach($f->files()->in($this->root) as $file) { + $matches = []; + if(preg_match($x, $file->getBasename(), $matches)) { + $versions[] = $matches[1]; + } + } + return $versions; } /** @@ -47,8 +59,7 @@ class TaskLogFile extends AbstractLogFile implements LogFileInterface */ public function getPath($version) { - $path = sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version ? ('-'.$version) : ''); - file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($path, true)), FILE_APPEND); - return sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version ? ('-'.$version) : ''); + return sprintf('%s/task_%d%s.log', $this->root, $this->task->getId(), $version); } + } diff --git a/templates/web/admin/task-manager/log_scheduler.html.twig b/templates/web/admin/task-manager/log_scheduler.html.twig index fda8767441..3bda38f075 100644 --- a/templates/web/admin/task-manager/log_scheduler.html.twig +++ b/templates/web/admin/task-manager/log_scheduler.html.twig @@ -1,17 +1,22 @@ - - < {{ 'Return' | trans }} - -
- {{ logfile.getContent(version) }} -+{% if version is not null %} +
{{ logfile.getContent(version) }}+ + {{ 'Clear' | trans }} + {% endif %} diff --git a/templates/web/admin/task-manager/log_task.html.twig b/templates/web/admin/task-manager/log_task.html.twig index c48ffefdf5..2a5ad8e909 100644 --- a/templates/web/admin/task-manager/log_task.html.twig +++ b/templates/web/admin/task-manager/log_task.html.twig @@ -1,7 +1,7 @@ +{% if version is null and logfile.versionExists('') %} + {% set version = '' %} +{% endif %} - - < {{ 'Return' | trans }} -
- {{ logfile.getContent(version) }} -- +
{{ logfile.getContent(version) }}+ {{ 'Clear' | trans }} {% endif %}