Skip to content

Commit 158354d

Browse files
committed
✨ maintenance mode check callback and 503 https status
closes #103 Signed-off-by: bnomei <[email protected]>
1 parent e2f3364 commit 158354d

23 files changed

+280
-252
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,37 @@ in your cron scheduler add the following command
358358
cd /path/to/my/kirby/project/root && vendor/bin/kirby janitor:backupzip
359359
```
360360

361+
## Maintenance Mode
362+
363+
You can toggle maintenance mode with a janitor button like this:
364+
365+
```yml
366+
janitor_maintenance:
367+
type: janitor
368+
command: 'janitor:maintenance --user {{ user.uuid }}'
369+
cooldown: 5000
370+
label: 'Maintenance: {{ site.isUnderMaintenance.ecco("DOWN","UP") }}'
371+
icon: '{{ site.isUnderMaintenance.ecco("cancel","circle") }}'
372+
```
373+
374+
If you need to add a custom check when maintenance mode is enforced you can do this by providing a callback for the `bnomei.janitor.maintenance.check` option.
375+
376+
**site/config/config.php**
377+
```php
378+
<?php
379+
380+
return [
381+
// return `true` for maintenance and `false` to skip maintenance
382+
'bnomei.janitor.maintenance.check' => function(): bool {
383+
// example: block unless it is a logged-in user and it has the admin role
384+
return kirby()->users()->current()?->role()->isAdmin() !== true;
385+
},
386+
// other options...
387+
];
388+
```
389+
390+
You can also overwrite the maintenance snippet if you create your own and store it as `site/snippets/maintenance.php`.
391+
361392
## Dependencies
362393

363394
- [Kirby CLI](https://github.com/getkirby/cli)

classes/Janitor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,13 @@ public static function requestBlockedByMaintenance(): bool
179179
return false;
180180
}
181181
}
182-
return true;
182+
183+
$isBlocked = option('bnomei.janitor.maintenance.check', true);
184+
if ($isBlocked && !is_string($isBlocked) && is_callable($isBlocked)) {
185+
$isBlocked = $isBlocked();
186+
}
187+
188+
return boolval($isBlocked);
183189
}
184190

185191
public static function resolveModel(string $uuid): mixed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "bnomei/kirby3-janitor",
33
"type": "kirby-plugin",
4-
"version": "3.4.3",
4+
"version": "3.4.5",
55
"license": "MIT",
6+
"homepage": "https://github.com/bnomei/kirby3-janitor",
67
"description": "Kirby 3 Plugin for running commands like cleaning the cache from within the Panel, PHP code or a cronjob",
78
"authors": [
89
{

0 commit comments

Comments
 (0)