1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Drush Cerbere command line tools. |
5
|
|
|
* Copyright (C) 2015 - Sebastien Malot <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along |
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Cerbere\Event; |
23
|
|
|
|
24
|
|
|
use Cerbere\Model\Hacked\HackedProject; |
25
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class CerbereHackedListener |
29
|
|
|
* |
30
|
|
|
* @package Cerbere\Event |
31
|
|
|
*/ |
32
|
|
|
class CerbereHackedListener implements EventSubscriberInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
*/ |
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns an array of event names this subscriber wants to listen to. |
42
|
|
|
* |
43
|
|
|
* The array keys are event names and the value can be: |
44
|
|
|
* |
45
|
|
|
* * The method name to call (priority defaults to 0) |
46
|
|
|
* * An array composed of the method name to call and the priority |
47
|
|
|
* * An array of arrays composed of the method names to call and respective |
48
|
|
|
* priorities, or 0 if unset |
49
|
|
|
* |
50
|
|
|
* For instance: |
51
|
|
|
* |
52
|
|
|
* * array('eventName' => 'methodName') |
53
|
|
|
* * array('eventName' => array('methodName', $priority)) |
54
|
|
|
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')) |
55
|
|
|
* |
56
|
|
|
* @return array The event names to listen to |
57
|
|
|
*/ |
58
|
|
|
public static function getSubscribedEvents() |
59
|
|
|
{ |
60
|
|
|
return array( |
61
|
|
|
CerbereEvents::CERBERE_REPORT_ACTION => array('onReportAction', 0), |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param CerbereReportActionEvent $event |
67
|
|
|
*/ |
68
|
|
|
public function onReportAction(CerbereReportActionEvent $event) |
69
|
|
|
{ |
70
|
|
|
$current_dir = getcwd(); |
71
|
|
|
// Change current directory to the module directory. |
72
|
|
|
chdir(dirname($event->getProject()->getFilename())); |
73
|
|
|
|
74
|
|
|
$hacked = new HackedProject($event->getProject()); |
75
|
|
|
$result = $hacked->computeReport(); |
76
|
|
|
|
77
|
|
|
// Restore previous directory. |
78
|
|
|
chdir($current_dir); |
79
|
|
|
|
80
|
|
|
$report = $event->getReport(); |
81
|
|
|
$options = $event->getOptions(); |
82
|
|
|
|
83
|
|
|
// Alter report. |
84
|
|
|
if (!empty($options['flat'])) { |
85
|
|
|
$report['hacked_status'] = $result['status']; |
86
|
|
|
$report['hacked_label'] = HackedProject::getStatusLabel($result['status']); |
87
|
|
|
} else { |
88
|
|
|
$report['hacked'] = array( |
89
|
|
|
'status' => $result['status'], |
90
|
|
|
'status_label' => HackedProject::getStatusLabel($result['status']), |
91
|
|
|
'counts' => $result['counts'], |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$event->setReport($report); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|