Completed
Push — develop ( 0a03ac...a24f25 )
by Novikov
01:58
created

LogController::fileAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace FOA\CronBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use FOA\CronBundle\Manager\CronManager;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
9
/**
10
 * Display and manage log files
11
 * @author Novikov Viktor
12
 */
13
class LogController extends Controller
14
{
15
    /**
16
     * Gets a log file
17
     *
18
     * @param $id   - the line of the cron in the cron table
19
     * @param $type - the type of file, log or error
20
     *
21
     * @return Response
22
     */
23
    public function fileAction($id, $type)
24
    {
25
        $cronManager = new CronManager();
26
        $cron = $cronManager->getById($id);
27
        $filepath = ($type == 'log') ? $cron->getLogFile() : $cron->getErrorFile();
28
        $content = file_get_contents($filepath);
29
30
        return $this->render('FOACronBundle:Dashboard:log.html.twig', [
31
            'filepath' => $filepath,
32
            'content'  => $content,
33
        ]);
34
    }
35
36
    /**
37
     * Adds a flash to the flash bag where flashes are array of messages
38
     *
39
     * @param $type
40
     * @param $message
41
     */
42
    protected function addFlash($type, $message)
43
    {
44
        if (empty($message)) {
45
            return;
46
        }
47
48
        $session = $this->get('session');
49
        $session->getFlashBag()->add($type, $message);
50
    }
51
}
52