11
11
12
12
namespace CachetHQ \Cachet \Composers ;
13
13
14
+ use CachetHQ \Cachet \Integrations \Core \System ;
14
15
use CachetHQ \Cachet \Models \Component ;
15
16
use CachetHQ \Cachet \Models \ComponentGroup ;
16
17
use CachetHQ \Cachet \Models \Incident ;
17
18
use Illuminate \Contracts \View \View ;
18
19
20
+ /**
21
+ * This is the status page composer.
22
+ *
23
+ * @author James Brooks <james@alt-three.com>
24
+ */
19
25
class StatusPageComposer
20
26
{
27
+ /**
28
+ * The system instance.
29
+ *
30
+ * @var \CachetHQ\Cachet\Integrations\Contracts\System
31
+ */
32
+ protected $ system ;
33
+
34
+ /**
35
+ * Create a new status page composer instance.
36
+ *
37
+ * @param \CachetHQ\Cachet\Integrations\Contracts\System $system
38
+ *
39
+ * @return void
40
+ */
41
+ public function __construct (System $ system )
42
+ {
43
+ $ this ->system = $ system ;
44
+ }
45
+
21
46
/**
22
47
* Index page view composer.
23
48
*
@@ -27,42 +52,7 @@ class StatusPageComposer
27
52
*/
28
53
public function compose (View $ view )
29
54
{
30
- $ totalComponents = Component::enabled ()->count ();
31
- $ majorOutages = Component::enabled ()->status (4 )->count ();
32
- $ isMajorOutage = $ totalComponents ? ($ majorOutages / $ totalComponents ) >= 0.5 : false ;
33
-
34
- // Default data
35
- $ withData = [
36
- 'system_status ' => 'info ' ,
37
- 'system_message ' => trans_choice ('cachet.service.bad ' , $ totalComponents ),
38
- 'favicon ' => 'favicon-high-alert ' ,
39
- ];
40
-
41
- if ($ isMajorOutage ) {
42
- $ withData = [
43
- 'system_status ' => 'danger ' ,
44
- 'system_message ' => trans_choice ('cachet.service.major ' , $ totalComponents ),
45
- 'favicon ' => 'favicon-high-alert ' ,
46
- ];
47
- } elseif (Component::enabled ()->notStatus (1 )->count () === 0 ) {
48
- // If all our components are ok, do we have any non-fixed incidents?
49
- $ incidents = Incident::notScheduled ()->orderBy ('created_at ' , 'desc ' )->get ()->filter (function ($ incident ) {
50
- return $ incident ->status > 0 ;
51
- });
52
- $ incidentCount = $ incidents ->count ();
53
-
54
- if ($ incidentCount === 0 || ($ incidentCount >= 1 && (int ) $ incidents ->first ()->status === 4 )) {
55
- $ withData = [
56
- 'system_status ' => 'success ' ,
57
- 'system_message ' => trans_choice ('cachet.service.good ' , $ totalComponents ),
58
- 'favicon ' => 'favicon ' ,
59
- ];
60
- }
61
- } else {
62
- if (Component::enabled ()->whereIn ('status ' , [2 , 3 ])->count () > 0 ) {
63
- $ withData ['favicon ' ] = 'favicon-medium-alert ' ;
64
- }
65
- }
55
+ $ status = $ this ->system ->getStatus ();
66
56
67
57
// Scheduled maintenance code.
68
58
$ scheduledMaintenance = Incident::scheduled ()->orderBy ('scheduled_at ' )->get ();
@@ -72,7 +62,7 @@ public function compose(View $view)
72
62
$ componentGroups = ComponentGroup::whereIn ('id ' , $ usedComponentGroups )->orderBy ('order ' )->get ();
73
63
$ ungroupedComponents = Component::enabled ()->where ('group_id ' , 0 )->orderBy ('order ' )->orderBy ('created_at ' )->get ();
74
64
75
- $ view ->with ($ withData )
65
+ $ view ->with ($ status )
76
66
->withComponentGroups ($ componentGroups )
77
67
->withUngroupedComponents ($ ungroupedComponents )
78
68
->withScheduledMaintenance ($ scheduledMaintenance );
0 commit comments