I am creating posts for my plugins to make it easier to find them using the forum search and not just the docs search.
Kirby 3 Plugin for running jobs.
It is a Panel Button!
It has jobs build-in for cleaning the cache, sessions, create zip-backup, pre-generate thumbs, open URLs, refresh the current Panel page, download a file, copy to clipboard and more.
You can define your own jobs (call API hooks, play a game, hack a server, …)
It can be triggered in your frontend code and with CRON.
It can also be used as a CLI with fancy output.
It can also create logs of what it did.
register and define a job as callback aka closure
site/config/config.php
'bnomei.janitor.jobs' => [
'aweSomeItCouldBe' => function (Kirby\Cms\Page $page = null, string $data = null) {
// $page => page object where the button as pressed
// $data => 'my custom data'
return [
'status' => 200,
'label' => $page->title() . ' ' . $data,
];
},
'query' => function (Kirby\Cms\Page $page = null, string $data = null) {
return [
'status' => 200,
'label' => $data, // this is the current panel users email
];
},
]
I thought cleaning the cache would clean the whole website’s cache – ideally it’d be a button/section in the main panel navigation, like I saw other plugins do. It’s not really tied to a page. But I think the owner of the website wouldn’t mind if it would be a button just when editing a certain page, that’s fine.
I tried adding the YAML above it to all 3 blueprints that are actually used on this website and none of the forms changed when trying to edit the pages.
First I wasn’t putting it under the fields entry, second I didn’t even realise about the site/blueprints/site.yml. While upgrading from Kirby 2 to 3 I put all blueprints into blueprints/pages and site.yml wasn’t at all respected, so I thought it was an old unused blueprint. I added it to site.yml fields and the button is there, thanks so much!
But now that I have added it, the previous dashboard where new pages could be added is gone – how could I allow both site.yml fields and editing pages too?
version 3 released today. I refactored Janitor plugin to work with kirbys new cli commands. You can define and trigger your own command easily but you can keep using callbacks if you prefer that (see janitor:job).
test_ping:
type: janitor
command: 'ping' # see tests/site/commands/ping.php
label: Ping
progress: ....
success: Pong
error: BAMM
janitor_open:
type: janitor
command: 'janitor:open --data {{ user.panel.url }}'
intab: true
label: Open current user URL in new tab
icon: open
# the open command will forward the `data` arg to `open` and open that URL
janitor_clipboarddata:
type: janitor
command: 'janitor:clipboard --data {{ page.title }}'
label: 'Copy "{{ page.title }}" to Clipboard'
progress: Copied!
icon: copy
# the clipboard command will forward the `data` arg to `clipboard` and copy that
janitor_download:
type: janitor
command: 'janitor:download --data {{ site.index.files.first.url }}'
label: Download File Example
icon: download
# the download command will forward the `data` arg to `download` and start downloading that
janitor_backupzip:
type: janitor
command: 'janitor:backupzip'
cooldown: 5000
label: Generate Backup ZIP
icon: archive
janitor_render:
type: janitor
command: 'janitor:render'
label: Render pages to create missing thumb jobs
janitor_thumbssite:
type: janitor
command: 'janitor:thumbs --site'
label: Generate thumbs from existing thumb jobs (full site)
janitor v3 needs the kirby cli installed. while you can run some core cli commands with the —quiet option others might fail due to the cli being optimized to run in terminal only. i created an issue but got no response yet.
in my commands i combine all calls to the cli output with a defined('STDOUT') && which essentially prevents that issue from happening.
@bnomei I also have the STDOUT problem with my first implementation of the new janitor.
Not to test I created a fully new and empty plainkit project and followed your readme for the example command and even there I get the STDOUT Kirby CLI is installed btw…
Cheers @bnomei ! In regards to the other problem I’m having with the DuplicatePage exception… (I’ll keep it on the forum because i’m not sure if it’s a bug yet… I’m having a hard time to get my head around it)
I’ve tracked it down that this piece is causing it:
If I remove the $this->model()->uuid()->toString() references then everything works as excepted. If I keep them I get the DuplicatePage exception as mentioned in my screenshot above.
I wonder if it’s somewhat related to “a-call-to-uuid-causes-a-write-on-a-virtual-page” but I’m really flabbergasted on what’s happening here… Can’t really seem to replicate it in plainkit either.
Delaying query resolution - if you want to send JSON etc
janitor_smart:
label: 'Resolve Arg smart/lazy using {( instead of {{'
type: janitor
command: 'janitor:pipe --data {( model.text.kirbytext )} --to message'
# pipe will show lazy/smart resolved data on button (aka the message)
colors from blueprint and api
janitor_color:
label: Janitor buttons can now be colorful
type: janitor
command: 'janitor:job --key random.colors'
color: 'var(--color-blue-600)'
backgroundColor: 'var(--color-blue-200)'
calling methods on a model
if you do not want to create a command file or job definition in config for everything.
janitor_callNoData:
label: Call method on current model
type: janitor
command: 'janitor:call --method whoAmI'
janitor_callWithData:
label: Call method on current model with Data
type: janitor
command: 'janitor:call --method repeatAfterMe --data {{ user.id }}'
Create a Backup of pages (and subpages) easily with undertaker()-helper
site/config/config.php or in a plugin
<?php
return [
'hooks' => [
'page.delete:before' => function (\Kirby\Cms\Page $page, bool $force) {
// do something before a page gets deleted
undertaker($page);
// will create a file with filename DATETIME-ID-USERID.zip
// site/graveyard/202303231729-myparent+my-slug-HYE7dsx.zip
},
],
// ... other options
];
Create Backup ZIP of content and accounts folder
If you do not just need to archive a few pages on change but want to archive the full content and/or user accounts then Janitor also has solution for that. You can adjust which folders to archive.