diff --git a/composer.json b/composer.json index 491f4ded..cc6d2ace 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "cachethq/core", + "name": "pingoo31/cachet-3-core", "description": "Cachet core package.", "license": "proprietary", "keywords": [ diff --git a/resources/lang/en/component.php b/resources/lang/en/component.php index 38058faf..e9a225e9 100644 --- a/resources/lang/en/component.php +++ b/resources/lang/en/component.php @@ -33,6 +33,7 @@ 'performance_issues' => 'Performance Issues', 'partial_outage' => 'Partial Outage', 'major_outage' => 'Major Outage', + 'under_maintenance' => 'Under maintenance', 'unknown' => 'Unknown', ], diff --git a/resources/lang/en/system_status.php b/resources/lang/en/system_status.php index feda62e9..54fa3d94 100644 --- a/resources/lang/en/system_status.php +++ b/resources/lang/en/system_status.php @@ -4,4 +4,5 @@ 'operational' => 'All systems are operational.', 'partial_outage' => 'Some systems are experiencing issues.', 'major_outage' => 'Some systems are experiencing major issues.', + 'under_maintenance' => 'Some systems are under maintenance.', ]; diff --git a/resources/lang/fr/component.php b/resources/lang/fr/component.php index 6dab49b7..1869e8d0 100644 --- a/resources/lang/fr/component.php +++ b/resources/lang/fr/component.php @@ -33,6 +33,7 @@ 'performance_issues' => 'Problèmes de performance', 'partial_outage' => 'Panne partielle', 'major_outage' => 'Panne majeure', + 'under_maintenance' => 'En maintenance', 'unknown' => 'Inconnu', ], ]; diff --git a/resources/lang/fr/system_status.php b/resources/lang/fr/system_status.php index 43f8cd74..f5c51248 100644 --- a/resources/lang/fr/system_status.php +++ b/resources/lang/fr/system_status.php @@ -4,4 +4,5 @@ 'operational' => 'Tous les systèmes sont opérationnels.', 'partial_outage' => 'Certains systèmes rencontrent des problèmes.', 'major_outage' => 'Certains systèmes rencontrent des problèmes majeurs.', + 'under_maintenance' => 'Certains systèmes sont en maintenance.', ]; diff --git a/resources/svg/component-under-maintenance.svg b/resources/svg/component-under-maintenance.svg new file mode 100644 index 00000000..ec9b1e19 --- /dev/null +++ b/resources/svg/component-under-maintenance.svg @@ -0,0 +1,36 @@ + + + + + + diff --git a/src/Enums/ComponentStatusEnum.php b/src/Enums/ComponentStatusEnum.php index 14b29061..f2c1b5fd 100644 --- a/src/Enums/ComponentStatusEnum.php +++ b/src/Enums/ComponentStatusEnum.php @@ -14,6 +14,7 @@ enum ComponentStatusEnum: int implements HasColor, HasIcon, HasLabel case partial_outage = 3; case major_outage = 4; case unknown = 5; + case under_maintenance = 6; public static function outage(): array { @@ -31,6 +32,7 @@ public function getLabel(): string self::performance_issues => __('cachet::component.status.performance_issues'), self::partial_outage => __('cachet::component.status.partial_outage'), self::major_outage => __('cachet::component.status.major_outage'), + self::under_maintenance => __('cachet::component.status.under_maintenance'), default => __('cachet::component.status.unknown'), }; } @@ -42,6 +44,7 @@ public function getIcon(): string self::performance_issues => 'cachet-component-performance-issues', self::partial_outage => 'cachet-component-partial-outage', self::major_outage => 'cachet-component-major-outage', + self::under_maintenance => 'cachet-component-under-maintenance', default => 'cachet-unknown', }; } @@ -53,6 +56,7 @@ public function getColor(): array self::performance_issues => Color::Purple, self::partial_outage => Color::Amber, self::major_outage => Color::Red, + self::under_maintenance => Color::Orange, default => Color::Blue, }; } diff --git a/src/Enums/SystemStatusEnum.php b/src/Enums/SystemStatusEnum.php index 947e137f..b1f52d80 100644 --- a/src/Enums/SystemStatusEnum.php +++ b/src/Enums/SystemStatusEnum.php @@ -12,6 +12,7 @@ enum SystemStatusEnum implements HasColor, HasIcon, HasLabel case operational; case partial_outage; case major_outage; + case under_maintenance; public function getLabel(): string { @@ -19,6 +20,7 @@ public function getLabel(): string self::operational => __('cachet::system_status.operational'), self::partial_outage => __('cachet::system_status.partial_outage'), self::major_outage => __('cachet::system_status.major_outage'), + self::under_maintenance => __('cachet::system_status.under_maintenance'), }; } @@ -28,6 +30,7 @@ public function getColor(): array self::operational => Color::Green, self::partial_outage => Color::Amber, self::major_outage => Color::Red, + self::under_maintenance => Color::Orange, }; } @@ -37,6 +40,7 @@ public function getIcon(): string self::operational => 'heroicon-m-check-circle', self::partial_outage => 'cachet-component-partial-outage', self::major_outage => 'cachet-component-major-outage', + self::under_maintenance => 'cachet-component-under-maintenance', }; } } diff --git a/src/Status.php b/src/Status.php index 9265a27f..6f71c5ff 100644 --- a/src/Status.php +++ b/src/Status.php @@ -24,6 +24,10 @@ public function current(): SystemStatusEnum { $components = $this->components(); + if ($this->underMaintenance()) { + return SystemStatusEnum::under_maintenance; + } + if ($this->majorOutage()) { return SystemStatusEnum::major_outage; } @@ -39,6 +43,18 @@ public function current(): SystemStatusEnum return SystemStatusEnum::partial_outage; } + /** + * Determine if the system is under maintenance. + */ + public function underMaintenance(): bool + { + if ((int) $this->components()->total === 0) { + return false; + } + + return (int) $this->components()->under_maintenance >= 1; + } + /** * Determine if there is a major outage. */ @@ -67,6 +83,7 @@ public function components(): object ->selectRaw('sum(case when status = ? then 1 else 0 end) as performance_issues', [ComponentStatusEnum::performance_issues]) ->selectRaw('sum(case when status = ? then 1 else 0 end) as partial_outage', [ComponentStatusEnum::partial_outage]) ->selectRaw('sum(case when status = ? then 1 else 0 end) as major_outage', [ComponentStatusEnum::major_outage]) + ->selectRaw('sum(case when status = ? then 1 else 0 end) as under_maintenance', [ComponentStatusEnum::under_maintenance]) ->first(); } diff --git a/tests/Unit/StatusTest.php b/tests/Unit/StatusTest.php index 0b71a384..f6326f72 100644 --- a/tests/Unit/StatusTest.php +++ b/tests/Unit/StatusTest.php @@ -46,6 +46,14 @@ $this->assertEquals((new Status)->current(), SystemStatusEnum::operational); }); +it('can get the current system status as under maintenance', function () { + Component::factory()->create([ + 'status' => ComponentStatusEnum::under_maintenance->value, + ]); + + $this->assertEquals((new Status)->current(), SystemStatusEnum::under_maintenance); +}); + it('can get the current system status as partial outage', function () { Component::factory()->create([ 'status' => ComponentStatusEnum::operational->value, @@ -73,16 +81,18 @@ ['status' => ComponentStatusEnum::operational->value], ['status' => ComponentStatusEnum::partial_outage->value], ['status' => ComponentStatusEnum::major_outage->value], + ['status' => ComponentStatusEnum::under_maintenance->value], ) - ->count(4) + ->count(5) ->create(); $components = (new Status)->components(); expect($components) - ->total->toBe(4) + ->total->toBe(5) ->operational->toBe(1) ->performance_issues->toBe(0) ->partial_outage->toBe(1) - ->major_outage->toBe(1); + ->major_outage->toBe(1) + ->under_maintenance->toBe(1); });