|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Violet88\BugsnagModule; |
|
4
|
|
|
|
|
5
|
|
|
use App\Extensions\SiteConfigExtension; |
|
|
|
|
|
|
6
|
|
|
use LeKoala\CmsActions\CustomAction; |
|
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use RuntimeException; |
|
9
|
|
|
use SilverStripe\Control\Controller; |
|
10
|
|
|
use SilverStripe\Core\Environment; |
|
11
|
|
|
use SilverStripe\Core\Extension; |
|
12
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
13
|
|
|
use SilverStripe\Forms\FieldGroup; |
|
14
|
|
|
use SilverStripe\Forms\FieldList; |
|
15
|
|
|
use SilverStripe\Forms\FormAction; |
|
16
|
|
|
use SilverStripe\Forms\HeaderField; |
|
17
|
|
|
use SilverStripe\Forms\LiteralField; |
|
18
|
|
|
use SilverStripe\Forms\TextField; |
|
19
|
|
|
use SilverStripe\ORM\DataExtension; |
|
20
|
|
|
use SilverStripe\Core\Config\Config; |
|
21
|
|
|
use SilverStripe\Dev\Debug; |
|
22
|
|
|
|
|
23
|
|
|
class BugsnagSiteConfigExtension extends Extension { |
|
24
|
|
|
|
|
25
|
|
|
public function updateCMSFields(FieldList $fields) { |
|
26
|
|
|
|
|
27
|
|
|
$bugsnagState = $this->getBugsnagActiveState(); |
|
28
|
|
|
$bugsnagReleaseStage = $this->getBugsnagReleaseStage(); |
|
29
|
|
|
|
|
30
|
|
|
$fields->addFieldsToTab('Root.Bugsnag', [ |
|
31
|
|
|
HeaderField::create('Bugsnag settings'), |
|
32
|
|
|
|
|
33
|
|
|
FieldGroup::create([ |
|
34
|
|
|
TextField::create('BugsnagActiveState', 'Bugsnag active state') |
|
35
|
|
|
->setValue($bugsnagState['code']) |
|
36
|
|
|
->setAttribute('style', $bugsnagState['style']) |
|
37
|
|
|
->setReadonly(true), |
|
38
|
|
|
|
|
39
|
|
|
TextField::create('BugsnagReleaseStage', 'Bugsnag release stage') |
|
40
|
|
|
->setValue($bugsnagReleaseStage['code']) |
|
41
|
|
|
->setAttribute('style', $bugsnagReleaseStage['style']) |
|
42
|
|
|
->setReadonly(true) |
|
43
|
|
|
]), |
|
44
|
|
|
|
|
45
|
|
|
HeaderField::create('Bugsnag testing buttons'), |
|
46
|
|
|
FieldGroup::create([ |
|
47
|
|
|
FormAction::create('doForceError', 'Force error') |
|
48
|
|
|
->setAttribute('onclick', "location.href='admin/settings/bugsnag/doForceError'") |
|
49
|
|
|
->addExtraClass('btn action btn-danger'), |
|
50
|
|
|
FormAction::create('doForceWarning', 'Force warning') |
|
51
|
|
|
->setAttribute('onclick', "location.href='admin/settings/bugsnag/doForceWarning'") |
|
52
|
|
|
->addExtraClass('btn action btn-warning'), |
|
53
|
|
|
FormAction::create('doForceInfo', 'Force info') |
|
54
|
|
|
->setAttribute('onclick', "location.href='admin/settings/bugsnag/doForceInfo'") |
|
55
|
|
|
->addExtraClass('btn action btn-info') |
|
56
|
|
|
]) |
|
57
|
|
|
|
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
|
|
return $fields; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function getBugsnagActiveState() { |
|
64
|
|
|
$state = Environment::getEnv('BUGSNAG_ACTIVE'); |
|
65
|
|
|
|
|
66
|
|
|
switch($state) { |
|
67
|
|
|
case false: |
|
|
|
|
|
|
68
|
|
|
return [ |
|
69
|
|
|
"code" => "ENV variable 'BUGSNAG_ACTIVE' not set", |
|
70
|
|
|
"style" => $this->getInputStyling('bad'), |
|
71
|
|
|
]; |
|
72
|
|
|
case "": |
|
73
|
|
|
return [ |
|
74
|
|
|
"code" => "Active state not set", |
|
75
|
|
|
"style" => $this->getInputStyling('warning'), |
|
76
|
|
|
]; |
|
77
|
|
|
case "false": |
|
78
|
|
|
return [ |
|
79
|
|
|
"code" => "Bugsnag inactive", |
|
80
|
|
|
"style" => $this->getInputStyling('bad'), |
|
81
|
|
|
]; |
|
82
|
|
|
case "true": |
|
83
|
|
|
return [ |
|
84
|
|
|
"code" => "Bugsnag active", |
|
85
|
|
|
"style" => $this->getInputStyling('good'), |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
private function getBugsnagReleaseStage() { |
|
91
|
|
|
$state = Environment::getEnv('BUGSNAG_RELEASE_STAGE'); |
|
92
|
|
|
|
|
93
|
|
|
switch($state) { |
|
94
|
|
|
case false: |
|
|
|
|
|
|
95
|
|
|
return [ |
|
96
|
|
|
"code" => "ENV variable 'BUGSNAG_RELEASE_STAGE' not set, default to 'development' stage.", |
|
97
|
|
|
"style" => $this->getInputStyling('bad'), |
|
98
|
|
|
]; |
|
99
|
|
|
case "": |
|
100
|
|
|
return [ |
|
101
|
|
|
"code" => "Release stage not set, default to 'development' stage.", |
|
102
|
|
|
"style" => $this->getInputStyling('warning'), |
|
103
|
|
|
]; |
|
104
|
|
|
default: |
|
105
|
|
|
return [ |
|
106
|
|
|
"code" => $state, |
|
107
|
|
|
"style" => $this->getInputStyling('good'), |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
private function getInputStyling($type) { |
|
113
|
|
|
switch($type) { |
|
114
|
|
|
case 'good': return "background-color: #d1e7dd; color: #0f5132; border-color: #badbcc;"; |
|
115
|
|
|
case 'warning': return "background-color: #fff3cd; color: #664d03; border-color: #ffecb5;"; |
|
116
|
|
|
case 'bad': return "background-color: #f8d7da; color: #842029; border-color: #f5c2c7;"; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths