Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Nov 5, 2021
2 parents 7235988 + 8e93029 commit 8dc2707
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 117 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea
assets/img
assets/app*
assets/mix-manifest.json
vendor
composer.lock
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - 2021-11-05
### Added
- PHP 7.4 and PHP 8.0 support.

### Changed
- The location of the Horizon assets has been changed. The Horizon assets are published into the plugin directory itself (`plugins/vdlp/horizon/assets`). Please note that you need to re-publish the assets when you are deploying your October CMS website or application using the `php artisan horizon:assets` command otherwise the Horizon Dashboard will not be available.
- The `horizon:assets` command can now be used to (re-)publish the Horizon Assets required for the Horizon Dashboard.
- Renamed `PushExampleJobs` to `PushExampleJobsCommand`.

### Removed
- Removed the dependency of the October CMS module (for headless applications).
- Support for PHP 7.1

## [1.0.0] - 2021-06-22

- First release of `vdlp/oc-horizon-plugin`.
62 changes: 28 additions & 34 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
use Illuminate\Notifications\NotificationServiceProvider;
use Laravel\Horizon\Horizon;
use System\Classes\PluginBase;
use Vdlp\Horizon\Console\PushExampleJobs;
use Vdlp\Horizon\Console\InstallCommand;
use Vdlp\Horizon\Console\PushExampleJobsCommand;
use Vdlp\Horizon\ServiceProviders\HorizonServiceProvider;

final class Plugin extends PluginBase
{
/**
* @var Backend
*/
private $backend;
private Backend $backend;

public function __construct($app)
{
Expand All @@ -32,7 +30,7 @@ public function pluginDetails(): array
{
return [
'name' => 'Horizon',
'description' => 'Laravel Horizon integration for OctoberCMS',
'description' => 'Laravel Horizon integration for October CMS',
'author' => 'Van der Let & Partners',
'icon' => 'icon-area-chart',
'homepage' => 'https://octobercms.com/plugin/vdlp-horizon',
Expand All @@ -43,8 +41,8 @@ public function boot(): void
{
config()->set('app.env', $this->app->environment());

Horizon::auth(static function () {
/** @var User $user */
Horizon::auth(static function (): bool {
/** @var ?User $user */
$user = AuthManager::instance()->getUser();

if ($user === null) {
Expand All @@ -60,8 +58,10 @@ public function boot(): void
$this->bootNotificationSettings();

if (config('app.debug') === true) {
$this->registerConsoleCommand(PushExampleJobs::class, PushExampleJobs::class);
$this->registerConsoleCommand(PushExampleJobsCommand::class, PushExampleJobsCommand::class);
}

$this->registerConsoleCommand(InstallCommand::class, InstallCommand::class);
}

public function register(): void
Expand All @@ -79,32 +79,26 @@ public function registerSchedule($schedule): void

public function registerPermissions(): array
{
return array_merge(
(array) parent::registerPermissions(),
[
'vdlp.horizon.access_dashboard' => [
'tab' => 'Horizon',
'label' => 'Access to the Horizon dashboard',
'roles' => ['developer'],
],
]
);
return [
'vdlp.horizon.access_dashboard' => [
'tab' => 'Horizon',
'label' => 'Access to the Horizon dashboard',
'roles' => ['developer'],
],
];
}

public function registerNavigation(): array
{
return array_merge(
(array) parent::registerNavigation(),
[
'dashboard' => [
'label' => 'Horizon',
'url' => $this->backend->url('vdlp/horizon/dashboard'),
'iconSvg' => '/plugins/vdlp/horizon/assets/icons/horizon.svg',
'permissions' => ['vdlp.horizon.access_dashboard'],
'order' => 500,
],
]
);
return [
'dashboard' => [
'label' => 'Horizon',
'url' => $this->backend->url('vdlp/horizon/dashboard'),
'iconSvg' => '/plugins/vdlp/horizon/assets/icons/horizon.svg',
'permissions' => ['vdlp.horizon.access_dashboard'],
'order' => 500,
],
];
}

public function registerMailTemplates(): array
Expand All @@ -116,20 +110,20 @@ public function registerMailTemplates(): array

private function bootNotificationSettings(): void
{
if (config('vdlp.horizon::mail_notifications_enabled', false)) {
if ((bool) config('vdlp.horizon::mail_notifications_enabled', false)) {
Horizon::routeMailNotificationsTo(
config('vdlp.horizon::mail_notifications_to')
);
}

if (config('vdlp.horizon::slack_notifications_enabled', false)) {
if ((bool) config('vdlp.horizon::slack_notifications_enabled', false)) {
Horizon::routeSlackNotificationsTo(
config('vdlp.horizon::slack_notifications_webhook_url'),
config('vdlp.horizon::slack_notifications_channel')
);
}

if (config('vdlp.horizon::sms_notifications_enabled', false)) {
if ((bool) config('vdlp.horizon::sms_notifications_enabled', false)) {
Horizon::routeSmsNotificationsTo(
config('vdlp.horizon::sms_notifications_to')
);
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Horizon is 100% open source, so you're free to dig through the source to see exa

## Requirements

* October CMS 1.0
* Due to its usage of async process signals, Horizon requires **PHP 7.1+**.
* October CMS 1.0 or higher
* PHP 7.4 or PHP 8.0+
* PHP extensions: `ext-pcntl`, `ext-posix` and `ext-redis`.
* Supervisor, see [Laravel 6.x supervisor configuration](https://laravel.com/docs/6.x/queues#supervisor-configuration).

Expand Down Expand Up @@ -53,22 +53,22 @@ You should add the `dont-discover` option to your projects `composer.json` file
> IMPORTANT: Make sure the `composer.json` is deployed to your hosting site. This will be parsed by te framework to determine which service providers should be ignored.
## Assets

* Run the command to publish assets for the Horizon dashboard:
## Assets & Configuration

```
php artisan vendor:publish --tag horizon-assets --force
php artisan horizon:install
```

## Configuration
## Update Horizon Assets

* Run the command to publish configuration file `config/horizon.php`:
To update the Horizon Assets you can use the following command:

```
php artisan vendor:publish --tag horizon-config --force
php artisan horizon:assets
```

> IMPORTANT: Add the above command to your deployment logic. This way the assets will always be up to date on your staging or production environment.
* Configure Laravel Horizon settings file at `config/horizon.php`, please make sure `use` contains `horizon` (see the configuration snippet below).

```
Expand Down
51 changes: 22 additions & 29 deletions classes/PathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,24 @@

namespace Vdlp\Horizon\Classes;

use Cms\Classes\Theme;
use Cms\Facades\Cms;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Filesystem\Filesystem;
use Throwable;

final class PathHelper
{
/**
* @var Theme|null
*/
private $theme;
private UrlGenerator $urlGenerator;
private Filesystem $filesystem;

public function __construct()
public function __construct(UrlGenerator $urlGenerator, Filesystem $filesystem)
{
$this->theme = Theme::getActiveTheme();
}

private function hasActiveTheme(): bool
{
return $this->theme !== null;
$this->urlGenerator = $urlGenerator;
$this->filesystem = $filesystem;
}

public function getAssetsPath(?string $path = null): string
{
if (!$this->hasActiveTheme()) {
return (string) $path;
}

$assetsPath = $this->theme->getPath(
$this->theme->getDirName()
. DIRECTORY_SEPARATOR
. 'assets'
. DIRECTORY_SEPARATOR
. 'horizon'
);
$assetsPath = plugins_path('vdlp/horizon/assets');

if ($path !== null) {
$assetsPath .= DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
Expand All @@ -47,16 +32,24 @@ public function getAssetsPath(?string $path = null): string

public function getAssetsUrlPath(?string $path = null): string
{
if (!$this->hasActiveTheme()) {
return (string) $path;
}

$assetsUrlPath = Cms::url('/themes/' . $this->theme->getDirName() . '/assets/horizon');
$assetsUrlPath = $this->urlGenerator->asset('plugins/vdlp/horizon/assets');

if ($path !== null) {
$assetsUrlPath .= '/' . ltrim($path, '/');
}

return $assetsUrlPath;
}

public function assetsAreCurrent(): bool
{
$publishedPath = $this->getAssetsPath('mix-manifest.json');
$vendorPath = base_path('vendor/laravel/horizon/public/mix-manifest.json');

try {
return $this->filesystem->get($publishedPath) === $this->filesystem->get($vendorPath);
} catch (Throwable $exception) {
return false;
}
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
],
"license": "GPL-2.0-only",
"require": {
"php": ">=7.1",
"php": "^7.4 || ^8.0",
"ext-pcntl": "*",
"ext-posix": "*",
"ext-redis": "*",
"laravel/horizon": "^3.0",
"composer/installers": "^1.0"

},
"archive": {
"exclude": [
Expand Down
29 changes: 29 additions & 0 deletions console/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Vdlp\Horizon\Console;

use Illuminate\Console\Command;

final class InstallCommand extends Command
{
public function __construct()
{
$this->signature = 'horizon:install';
$this->description = 'Install all of the Horizon resources';

parent::__construct();
}

public function handle(): void
{
$this->comment('Publishing Horizon Assets...');
$this->callSilent('vendor:publish', ['--tag' => 'horizon-assets']);

$this->comment('Publishing Horizon Configuration...');
$this->callSilent('vendor:publish', ['--tag' => 'horizon-config']);

$this->info('Horizon scaffolding installed successfully.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use October\Rain\Support\Str;
use Vdlp\Horizon\Jobs\Example;

final class PushExampleJobs extends Command
final class PushExampleJobsCommand extends Command
{
public function __construct()
{
Expand Down
7 changes: 4 additions & 3 deletions jobs/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

final class Example implements ShouldQueue
{
use Dispatchable, Queueable;
private $fooBar;
use Dispatchable;
use Queueable;

private string $fooBar;

public function __construct(string $fooBar)
{
$this->fooBar = $fooBar;
}

/**
* @param LoggerInterface $log
* @throws Exception
*/
public function handle(LoggerInterface $log): void
Expand Down
24 changes: 10 additions & 14 deletions listeners/SendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@

final class SendNotification
{
/**
* @var Horizon\Lock
*/
private $lock;

/**
* @var Mailer
*/
private $mailer;
private Horizon\Lock $lock;
private Mailer $mailer;

public function __construct(Horizon\Lock $lock, Mailer $mailer)
{
Expand All @@ -46,11 +39,14 @@ public function handle(Horizon\Events\LongWaitDetected $event): void
'seconds' => $notification->seconds,
];

$this->mailer->send('vdlp.horizon::mail.long-wait-detected', $data, static function (Message $message) {
$message
->to(Horizon\Horizon::$email)
->subject(config('app.name') . ': Long Queue Wait Detected');
});
$this->mailer->send(
'vdlp.horizon::mail.long-wait-detected',
$data,
static function (Message $message): void {
$message
->to(Horizon\Horizon::$email)
->subject(config('app.name') . ': Long Queue Wait Detected');
});
}
}
}
4 changes: 2 additions & 2 deletions models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
final class Settings extends Model
{
public $implement = ['System.Behaviors.SettingsModel'];
public $settingsCode = 'vdlp_horizon_settings';
public $settingsFields = 'fields.yaml';
public string $settingsCode = 'vdlp_horizon_settings';
public string $settingsFields = 'fields.yaml';

public function isMailNotificationEnabled(): bool
{
Expand Down
Loading

0 comments on commit 8dc2707

Please sign in to comment.