17 Commits

Author SHA1 Message Date
Simon Hiller
078fd9a746 feat: implement settings config 2026-02-25 12:45:04 +01:00
Davide Iadeluca
4f261dbee4 chore: adjust workflows
[skip ci]
2025-11-30 11:51:35 +01:00
IanM
d59ebfa684 fix: extend not called (#5)
* fix: extend not called

* chore: phpstan
2025-11-18 22:01:50 +00:00
IanM
b03ca35d54 Extend Redis functionality with new method 2025-11-18 20:44:52 +00:00
flarum-bot
4c7a5d377d Bundled output for commit 6545bfdffc
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2025-10-10 09:51:12 +00:00
IanM
6545bfdffc chore: migrate to fof/redis, repo maintenance (#4)
* chore: migrate to fof/redis, repo maintenance

* chore: newline

* chore: use new fof horizon initializer

* chore: revert initializer  change

Only changed for 2.x ..

* chore: remove unused secrets

Shouldn't have been added in the first place

---------

Co-authored-by: Davide Iadeluca <146922689+DavideIadeluca@users.noreply.github.com>
Co-authored-by: Davide Iadeluca <davide.iadeluca@glowingblue.com>
2025-10-10 10:50:31 +01:00
Davide Iadeluca
2f2cce1abe chore: remove sync workflow 2024-01-31 11:21:07 +01:00
flarum-bot
78082dc842 Bundled output for commit e02001333b
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2024-01-31 09:45:51 +00:00
Davide Iadeluca
e02001333b Merge pull request #2 from glowingblue/di/update-deps
chore(deps): update dependencies
2024-01-31 10:45:12 +01:00
Davide Iadeluca
44fa68c278 chore: add custom repository 2024-01-31 10:37:20 +01:00
Davide Iadeluca
139d687e1b ci: update workflows 2024-01-31 10:25:04 +01:00
Davide Iadeluca
9061552db9 chore(deps): update dependencies 2024-01-30 13:59:01 +01:00
Rafael Horvat
eab24f9adc fix build workflow 2023-08-09 17:05:25 +02:00
Rafael Horvat
94049c5183 Refactoring and made some methods public static(to be able to reuse them) 2023-08-09 17:04:59 +02:00
Rafael Horvat
96af9b58f6 Added and/or updated config files 2023-01-25 14:50:01 +01:00
flarum-bot
69c73e2397 Bundled output for commit c2ddd30cd7
Includes transpiled JS/TS.

[skip ci]
2022-04-26 11:23:43 +00:00
Rafael Horvat
c2ddd30cd7 Infra updates & require flarum 1.2 2022-04-26 13:22:18 +02:00
19 changed files with 1540 additions and 3328 deletions

11
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@@ -0,0 +1,11 @@
**Resolves**
<!-- include a link to the issue -->
**Changes proposed in this pull request:**
<!-- mention the pages and/or components which have been impacted -->
**Reviewers should focus on:**
<!-- ask for feedback on specific changes you are unsure about -->
**Screenshot**
<!-- include an image of the most relevant user-facing change, if any -->

13
.github/workflows/backend.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
name: GB Redis Setup PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
with:
enable_backend_testing: false
enable_phpstan: true
php_versions: '["8.1", "8.2", "8.3", "8.4"]'
backend_directory: .

23
.github/workflows/frontend.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: GB Redis Setup JS
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: 1.x
git_actor_name: ${{ vars.GIT_ACTOR_NAME }}
git_actor_email: ${{ vars.GIT_ACTOR_EMAIL }}
secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
git_actor_token: ${{ secrets.GIT_ACTOR_TOKEN }}

View File

@@ -1,91 +0,0 @@
name: JS
on: [workflow_dispatch, push, pull_request]
env:
NODE_VERSION: 16
jobs:
prettier:
name: Prettier
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
cache-dependency-path: js/yarn.lock
- name: Install JS dependencies
run: yarn install --immutable
working-directory: ./js
- name: Check JS formatting
run: yarn run format-check
working-directory: ./js
build-prod:
name: Build and commit
runs-on: ubuntu-latest
needs: [prettier]
# Only commit JS on push to master branch
# Remember to change in `build-test` job too
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
cache-dependency-path: js/yarn.lock
# Our action will install node, npm and yarn, cd into `./js`, run `yarn run build` (and
# `yarn run build-typings` if desired), then commit and upload any changes
- name: Build production JS
uses: flarum/action-build@2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
build_script: build
package_manager: yarn
# typings_script: build-typings
build-test:
name: Test build
runs-on: ubuntu-latest
needs: [prettier]
# Inverse check of `build-prod`
# Remember to change in `build-prod` job too
if: github.ref != 'refs/heads/master' || github.event_name != 'push'
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
cache-dependency-path: js/yarn.lock
# Our action will install node, npm and yarn, cd into `./js`, run `yarn run build` (and
# `yarn run build-typings` if desired). It will NOT commit and upload.
- name: Build production JS
uses: flarum/action-build@2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
build_script: build
package_manager: yarn
# typings_script: build-typings
do_not_commit: true

View File

@@ -65,6 +65,7 @@
"bmewburn.vscode-intelephense-client",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"felixfbecker.php-debug"
"xdebug.php-debug",
"firefox-devtools.vscode-firefox-debug"
]
}

View File

@@ -18,8 +18,9 @@
},
"homepage": "https://glowingblue.com",
"require": {
"flarum/core": "^1.0.4",
"blomstra/flarum-redis": "^0.4.0"
"php": "^8.1",
"flarum/core": "^1.8.5",
"fof/redis": "^1.0"
},
"authors": [
{
@@ -52,11 +53,22 @@
"color": "#fff"
},
"optional-dependencies": [
"blomstra/horizon"
"fof/horizon"
]
},
"extiverse": {
"discuss": "https://discuss.flarum.org/d/27455"
}
},
"require-dev": {
"flarum/phpstan": "*",
"fof/horizon": "^1.0"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
}
}

2
js/dist/admin.js vendored
View File

@@ -1,2 +1,2 @@
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t){e.exports=flarum.core.compat["admin/app"]},function(e,t){e.exports=flarum.core.compat["common/extend"]},function(e,t){e.exports=flarum.core.compat["admin/components/StatusWidget"]},function(e,t,r){"use strict";r.r(t);var n=r(0),o=r.n(n),a=r(1),i=r(2),l=r.n(i),u="glowingblue-redis-setup";function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return c(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var f=o.a.translator.trans.bind(o.a.translator),d=u+".admin.settings";o.a.initializers.add(u,(function(){o.a.extensionData.for(u).registerSetting({setting:"glowingblue-redis.enableCache",type:"boolean",label:f(d+".enable_cache")}).registerSetting({setting:"glowingblue-redis.redisSessions",type:"boolean",label:f(d+".enable_redis_sessions")}).registerSetting({setting:"glowingblue-redis.enableQueue",type:"boolean",label:f(d+".enable_queue")}),o.a.initializers.has("blomstra/horizon")&&o.a.extensionData.for(u).registerSetting({setting:"glowingblue-redis.horizonConfig",type:"textarea",label:f(d+".horizon_config"),help:f(d+".horizon_help_text")}),Object(a.extend)(l.a.prototype,"items",(function(e){var t=o.a.data.blomstraQueuesLoad;if(void 0!==t)for(var r,n=s(o.a.data.blomstraQueuesSeen);!(r=n()).done;){var a=r.value,i=t[a]||null;e.add("blomstra-queue-size-"+a,[m("strong",null,"Queue ",a),m("br",null),i||"0"])}}))}))}]);
(()=>{var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};(()=>{"use strict";e.r(t);const r=flarum.core.compat["admin/app"];var n=e.n(r);const o=flarum.core.compat["common/extend"],a=flarum.core.compat["admin/components/StatusWidget"];var i=e.n(a),l="glowingblue-redis-setup";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var u=n().translator.trans.bind(n().translator),d=l+".admin.settings";n().initializers.add(l,(function(){n().extensionData.for(l).registerSetting({setting:"glowingblue-redis.enableCache",type:"boolean",label:u(d+".enable_cache")}).registerSetting({setting:"glowingblue-redis.redisSessions",type:"boolean",label:u(d+".enable_redis_sessions")}).registerSetting({setting:"glowingblue-redis.enableQueue",type:"boolean",label:u(d+".enable_queue")}),n().initializers.has("fof/horizon")&&n().extensionData.for(l).registerSetting({setting:"glowingblue-redis.horizonConfig",type:"textarea",label:u(d+".horizon_config"),help:u(d+".horizon_help_text")}),(0,o.extend)(i().prototype,"items",(function(e){var t=n().data.fofQueuesLoad;if(void 0!==t)for(var r,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(n().data.fofQueuesSeen);!(r=o()).done;){var a=r.value,i=t[a]||null;e.add("fof-queue-size-"+a,[m("strong",null,"Queue ",a),m("br",null),i||"0"])}}))}))})(),module.exports=t})();
//# sourceMappingURL=admin.js.map

File diff suppressed because one or more lines are too long

View File

@@ -4,13 +4,13 @@
"private": true,
"prettier": "@glowingblue-dev/prettier-config",
"dependencies": {
"flarum-webpack-config": "^1.0.0",
"webpack": "^4.26.0",
"webpack-cli": "^4.9.2"
"flarum-webpack-config": "^2.0.0",
"webpack": "^5.72.0",
"webpack-cli": "^5.0"
},
"devDependencies": {
"@glowingblue-dev/prettier-config": "^1.0.0",
"prettier": "^2.6.1"
"prettier": "^3.5.1"
},
"scripts": {
"dev": "webpack --mode development --watch",

View File

@@ -36,7 +36,7 @@ app.initializers.add(slug, () => {
label: t(`${prfx}.enable_queue`),
});
if (app.initializers.has('blomstra/horizon')) {
if (app.initializers.has('fof/horizon')) {
app.extensionData.for(slug).registerSetting({
setting: 'glowingblue-redis.horizonConfig',
type: 'textarea',
@@ -46,15 +46,16 @@ app.initializers.add(slug, () => {
}
extend(StatusWidget.prototype, 'items', (items) => {
const loads = app.data.blomstraQueuesLoad;
const loads = app.data.fofQueuesLoad;
if (loads === undefined) {
return;
}
for (let queue of app.data.blomstraQueuesSeen) {
// @ts-ignore
for (let queue of app.data.fofQueuesSeen) {
const load = loads[queue] || null;
items.add('blomstra-queue-size-' + queue, [
items.add('fof-queue-size-' + queue, [
<strong>Queue {queue}</strong>,
<br />,
load || '0',

17
js/tsconfig.json Normal file
View File

@@ -0,0 +1,17 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
}
}
}

File diff suppressed because it is too large Load Diff

13
phpstan.neon Normal file
View File

@@ -0,0 +1,13 @@
includes:
- vendor/flarum/phpstan/extension.neon
parameters:
# The level will be increased in Flarum 2.0
level: 5
paths:
- extend.php
- src
excludePaths:
- *.blade.php
checkMissingIterableValueType: false
databaseMigrationsPath: ['migrations']

View File

@@ -6,4 +6,4 @@ glowingblue-redis-setup:
Enable Redis sessions (all users will be logged out after changing this setting)
enable_queue: Enable Redis queue
horizon_config: "Horizon config (format: JSON)."
horizon_help_text: This will be passed to <code>(new \Blomstra\Horizon\Extend\Horizon)->config(...))</code>
horizon_help_text: This will be passed to <code>(new \FoF\Horizon\Extend\Horizon)->config(...))</code>

View File

@@ -12,7 +12,7 @@
namespace GlowingBlue\RedisSetup\Extend;
use Blomstra\Horizon\Extend\Horizon;
use FoF\Horizon\Extend\Horizon;
use Flarum\Extend\ExtenderInterface;
use Flarum\Extension\Extension;
use Flarum\Extension\ExtensionManager;
@@ -25,7 +25,7 @@ class ConfigureHorizon implements ExtenderInterface
{
$extensions = resolve(ExtensionManager::class);
if (!$extensions->isEnabled('blomstra-horizon') || !class_exists(Horizon::class)) {
if (!$extensions->isEnabled('fof-horizon') || !class_exists(Horizon::class)) {
return;
}

View File

@@ -3,7 +3,7 @@
/*
* This file is part of glowingblue/redis-setup.
*
* Copyright (c) 2022 Glowing Blue AG.
* Copyright (c) 2023 Glowing Blue AG.
* Authors: Ian Morland, iPurpl3x, Rafael Horvat.
*
* For the full copyright and license information, please view the LICENSE.md
@@ -12,7 +12,7 @@
namespace GlowingBlue\RedisSetup\Extend;
use Blomstra\Redis\Extend\Redis;
use FoF\Redis\Extend\Redis;
use Flarum\Extend\ExtenderInterface;
use Flarum\Extension\Extension;
use Flarum\Settings\SettingsRepositoryInterface;
@@ -24,14 +24,17 @@ class EnableRedis implements ExtenderInterface
const CACHE_KEY = 'connections.cache';
const QUEUE_KEY = 'connections.queue';
const SESSION_KEY = 'connections.session';
const SETTINGS_KEY = 'connections.settings';
public function extend(Container $container, Extension $extension = null)
{
$config = $this->buildConfig();
(new Redis($config))
->disable($this->getDisabledServices())
->extend($container, $extension);
/** @var Redis $redis */
$redis = (new Redis($config))
->disable($this->getDisabledServices());
$redis->extend($container, $extension);
}
private function getDisabledServices(): array
@@ -43,6 +46,7 @@ class EnableRedis implements ExtenderInterface
if (!(bool) $settings->get('glowingblue-redis.enableCache', false)) {
$disabled[] = 'cache';
$disabled[] = 'settings';
}
if (!(bool) $settings->get('glowingblue-redis.enableQueue', false)) {
@@ -58,68 +62,68 @@ class EnableRedis implements ExtenderInterface
private function buildConfig($config = []): array
{
$cache = [
$base = [
'host' => $this->getHost(),
'password' => $this->getPassword(),
'port' => $this->getPort(),
'database' => $this->getCacheDatabase(),
'prefix' => $this->getPrefix(),
];
$queue = [
'host' => $this->getHost(),
'password' => $this->getPassword(),
'port' => $this->getPort(),
'database' => $this->getQueueDatabase(),
'prefix' => $this->getPrefix(),
$cache = $base + [
'database' => static::getCacheDatabase(),
];
$session = [
'host' => $this->getHost(),
'password' => $this->getPassword(),
'port' => $this->getPort(),
'database' => $this->getSessionDatabase(),
'prefix' => $this->getPrefix(),
$queue = $base + [
'database' => static::getQueueDatabase(),
];
$session = $base + [
'database' => static::getSessionDatabase(),
];
$settings = $base + [
'database' => static::getSessionDatabase(),
];
$config = Arr::add($config, self::CACHE_KEY, $cache);
$config = Arr::add($config, self::QUEUE_KEY, $queue);
$config = Arr::add($config, self::SESSION_KEY, $session);
$config = Arr::add($config, self::SETTINGS_KEY, $settings);
return $config;
}
private function getHost(): string
public static function getHost(): string
{
return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : '127.0.0.1';
}
private function getPassword(): ?string
public static function getPassword(): ?string
{
return getenv('REDIS_PASSWORD') ? getenv('REDIS_PASSWORD') : null;
}
private function getPort(): string
public static function getPort(): string
{
return getenv('REDIS_PORT') ? getenv('REDIS_PORT') : '6379';
}
private function getCacheDatabase(): int
public static function getCacheDatabase(): int
{
return (int) getenv('REDIS_DATABASE_CACHE') ? getenv('REDIS_DATABASE_CACHE') : 1;
}
private function getQueueDatabase(): int
public static function getQueueDatabase(): int
{
return (int) getenv('REDIS_DATABASE_QUEUE') ? getenv('REDIS_DATABASE_QUEUE') : 2;
}
private function getSessionDatabase(): int
public static function getSessionDatabase(): int
{
return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
}
private function getPrefix(): string
public static function getPrefix(): string
{
return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
}

View File

@@ -55,7 +55,7 @@ class QueueProvider extends AbstractServiceProvider
/** @var QueueContract $queue */
$queue = resolve(QueueContract::class);
$queues = $cache->get('blomstra.queue.queues-seen') ?? [];
$queues = $cache->get('fof.queue.queues-seen') ?? [];
if ($queue instanceof RedisQueue) {
$load = [];
@@ -67,8 +67,8 @@ class QueueProvider extends AbstractServiceProvider
}
}
$document->payload['blomstraQueuesSeen'] = $queues;
$document->payload['blomstraQueuesLoad'] = $load ?? null;
$document->payload['fofQueuesSeen'] = $queues;
$document->payload['fofQueuesLoad'] = $load ?? null;
}
public function trackQueues(Looping $event)
@@ -76,8 +76,8 @@ class QueueProvider extends AbstractServiceProvider
/** @var Store $cache */
$cache = resolve('cache.store');
$queues = $cache->get('blomstra.queue.queues-seen') ?? [];
$queues = $cache->get('fof.queue.queues-seen') ?? [];
$queues = array_merge($queues, (array) explode(',', $event->queue));
$cache->put('blomstra.queue.queues-seen', array_unique($queues), 60);
$cache->put('fof.queue.queues-seen', array_unique($queues), 60);
}
}