-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlugin.php
123 lines (103 loc) · 3.66 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
declare(strict_types=1);
namespace Vdlp\Horizon;
use Backend\Classes\AuthManager;
use Backend\Helpers\Backend;
use Backend\Models\User;
use Illuminate\Notifications\NotificationServiceProvider;
use Laravel\Horizon\Horizon;
use System\Classes\PluginBase;
use Vdlp\Horizon\Console\ClearQueuesCommand;
use Vdlp\Horizon\Console\InstallCommand;
use Vdlp\Horizon\Console\PushExampleJobsCommand;
use Vdlp\Horizon\ServiceProviders\HorizonServiceProvider;
final class Plugin extends PluginBase
{
public function pluginDetails(): array
{
return [
'name' => 'Horizon',
'description' => 'Laravel Horizon integration for October CMS',
'author' => 'Van der Let & Partners',
'icon' => 'icon-area-chart',
'homepage' => 'https://octobercms.com/plugin/vdlp-horizon',
];
}
public function boot(): void
{
config()->set('app.env', $this->app->environment());
Horizon::auth(static function (): bool {
/** @var ?User $user */
$user = AuthManager::instance()->getUser();
if ($user === null) {
return false;
}
return $user->hasPermission('vdlp.horizon.access_dashboard')
|| $user->isSuperUser();
});
$this->bootNotificationSettings();
if (config('app.debug') === true) {
$this->registerConsoleCommand(PushExampleJobsCommand::class, PushExampleJobsCommand::class);
}
$this->registerConsoleCommand(ClearQueuesCommand::class, ClearQueuesCommand::class);
$this->registerConsoleCommand(InstallCommand::class, InstallCommand::class);
}
public function register(): void
{
$this->app->register(HorizonServiceProvider::class);
$this->app->register(NotificationServiceProvider::class);
}
public function registerSchedule($schedule): void
{
$schedule->command('horizon:snapshot')->everyFiveMinutes();
}
public function registerPermissions(): array
{
return [
'vdlp.horizon.access_dashboard' => [
'tab' => 'Horizon',
'label' => 'Access to the Horizon dashboard',
'roles' => ['developer'],
],
];
}
public function registerNavigation(): array
{
/** @var Backend $backend */
$backend = $this->app->make(Backend::class);
return [
'dashboard' => [
'label' => 'Horizon',
'url' => $backend->url('vdlp/horizon/dashboard'),
'iconSvg' => '/plugins/vdlp/horizon/assets/icons/horizon.svg',
'permissions' => ['vdlp.horizon.access_dashboard'],
'order' => 500,
],
];
}
public function registerMailTemplates(): array
{
return [
'vdlp.horizon::mail.long-wait-detected',
];
}
private function bootNotificationSettings(): void
{
if (config('vdlp.horizon::mail_notifications_enabled', false) === true) {
Horizon::routeMailNotificationsTo(
config('vdlp.horizon::mail_notifications_to')
);
}
if (config('vdlp.horizon::slack_notifications_enabled', false) === true) {
Horizon::routeSlackNotificationsTo(
config('vdlp.horizon::slack_notifications_webhook_url'),
config('vdlp.horizon::slack_notifications_channel')
);
}
if (config('vdlp.horizon::sms_notifications_enabled', false) === true) {
Horizon::routeSmsNotificationsTo(
config('vdlp.horizon::sms_notifications_to')
);
}
}
}