Kirby 3 Plugin for running jobs like cleaning the cache from within the Panel, PHP code, CLI or a cronjob

Overview

Kirby 3 Janitor

Release Downloads Build Status Coverage Status Maintainability Twitter

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 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.

Install

Using composer:

composer require bnomei/kirby3-janitor

Using git submodules:

git submodule add https://github.com/bnomei/kirby3-janitor.git site/plugins/kirby3-janitor

Using download & copy: download the latest release and copy to site/plugins

Commerical Usage


Support open source!

This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?

Be kind. Share a little. Thanks.

‐ Bruno
 
M O N E Y
Github sponsor Patreon Buy Me a Coffee Paypal dontation Hire me

Wiki

Continue to the Janitor Wiki to read more on how to install, setup and use this plugin.

Dependencies

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

Comments
  • custom janitor button on site.yml

    custom janitor button on site.yml

    Is it expected that my custom janitor job button doesn't work from site.yml blueprint without adding a data (which I don't need) property to it?

    This is my site.yml:

    janitor:
      type: janitor
      label: Replenish my custom cache
      progress: Replenishing (can take a few secs)...
      cooldown: 5000
      job: replenishMyCache
      data: blablabla
    

    and this is the job defined in my config.php:

    'bnomei.janitor.jobs' => [
        'replenishMyCache' => function (Kirby\Cms\Page $page = null, string $data = null) {
            var_dump($page);
            var_dump($data);
            die;
            return [
                'status' => 200,
                'label' => 'External stuff fetched',
            ];
        },
    ]
    

    When I remove data: blablabla from the blueprint, the button doesn't work and I get a 404 in the panel for the call: http://mywebsite.test/api/plugin-janitor/replenishMyCache/$ -> I notice a $ is appended? Is this expected? FYI: when data: blablabla is in the blueprint, the url that is fetched looks like this: http://mywebsite.test/api/plugin-janitor/replenishMyCache/%24/mlkqsjdf

    Am I doing something wrong?


    When I test this on a page blueprint, I don't need to add the data property. It just works as expected then?

    bug 
    opened by bvdputte 13
  • How to avoid php max_execution_time timeout

    How to avoid php max_execution_time timeout

    First of all thanks for this great plugin!

    I build a panel-button and corresponding custom job to import data from json and copying external image-files to create new pages out of that. Because it´s a larger data-set I run into an php max_execution_time timeout. Is there any mechanism inside janitor to avoid that?

    Thanks for any help in advance!

    opened by tideg 9
  • Error in panel

    Error in panel

    With version 1.4.0 installed through Composer on a Kirby 3.2 instance, I get the following error in the panel:

    Error: Cannot find module 'function () {var a={name:"Janitor",props:{label:String,progress:String,job:String,cooldown:Number,status:String,data:String,pageURI:String},methods:{janitor:function(){var t=this.job;t=t+"/"+encodeURIComponent(this.pageURI),null!=this.data&&(t=t+"/"+encodeURIComponent(this.data)),this.getRequest(t)},getRequest:function(t){var s=this,e=this.label;this.label=this.progress.length>0?this.progress:this.label+"...",this.status="doing-job",this.$api.get(t).then(function(t){void 0!==t.label&&(s.label=t.label),void 0!==t.status?s.status=200==t.status?"is-success":"has-error":s.status="has-response",setTimeout(function(){s.label=e,s.status=""},s.cooldown)})}}};if(typeof a==="function"){a=a.options}Object.assign(a,function(){var render=function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c("k-button",{staticClass:"janitor",class:_vm.status,attrs:{"job":_vm.job},on:{"click":function($event){return _vm.janitor()}}},[_vm._v(_vm._s(_vm.label))])};var staticRenderFns=[];return{render:render,staticRenderFns:staticRenderFns,_compiled:true,_scopeId:null,functional:undefined}}());panel.plugin("bnomei/janitor",{fields:{janitor:a}});}'
    

    From the file media/plugins/index.js line 37

    It breaks all my custom fields for some reason. If I disable the plugin everything works fine again.

    The blueprint looks like this:

    janitor:
      type: janitor
      label: Vider le cache
      progress: Nettoyage en cours…
      job: clean
    

    In the panel, where the button is supposed to show up, Kirby throws:

     The field type "janitor" does not exist
    

    Let me know what extra info would help you debug this issue.

    Edit: with Kirby 3.1.x everything works fine.

    wontfix 
    opened by LeBenLeBen 8
  • Dialogue boxes

    Dialogue boxes

    Follow up from Discord:

    Are you thinking what I'm thinking, like: I'm telling janitor what fields I need and upon pressing a button, I'm prompted for those fields, and then I can use the entered information inside a job? That would be AWESOME!

    enhancement help wanted 
    opened by S1SYPHOS 6
  • working with draft pages

    working with draft pages

    hey there 🌻 ✨ i was just trying to get a draft page by using data: '{{ page.id }}'. first of all, the basic solution ->findById() from the wiki page has been deprecated. so i was trying with ->findPageOrDraft() first. but looks like this only works for direct children. so i just thought i’d post this here in case anyone else struggles with it.

    $page = site()->findPageOrDraft($data);   //not working
    $page = site()->index(true)->find($data); //working
    $page = kirby()->page($data, null, true); //working
    

    to get a more performant solution, i also tried with the auto id plugin. but so far the suggested solution from the wiki page doesn’t seem to work. there is even an info in the auto id wiki that says the autoid() helper function "will not find drafts". so i am confused now. any thoughts @bnomei?

    thank youuu! ♥️

    opened by jaro-io 5
  • Render fails with

    Render fails with "Invalid page objects" on stock starterkit setup

    I've set up a brand new starterkit on Laravel Valet, installed the plugin and ran php janitor -v render. This is the output I get. Any idea why this happens?

    ➜  kirby3-janitor git:(master) php janitor -v render
    ATTENTION! Janitor created this file to load the Kirby instance: /Users/username/ubilabs/starterkit/janitor-b9767f1d0d2be1a0598bcd40b6d7dbec98952a66.php
    Using Kirby instance from: /Users/username/ubilabs/starterkit/janitor-b9767f1d0d2be1a0598bcd40b6d7dbec98952a66.php
    Pages: 20
    Languages: 0
    Rendering...
    ======================================================================> 100%
    Found images with media/pages/* : 0
    Render failed: 20
    3_about: Invalid page object
    home: preg_match_all(): Compilation failed: invalid range in character class at offset 20
    1_photography: Invalid page object
    1_photography/desert: Invalid page object
    1_photography/mountains: Invalid page object
    1_photography/landscape: Invalid page object
    1_photography/plants: Invalid page object
    1_photography/sky: Invalid page object
    1_photography/trees: Invalid page object
    1_photography/ocean: Invalid page object
    1_photography/waterfall: Invalid page object
    sandbox: preg_match_all(): Compilation failed: invalid range in character class at offset 20
    2_notes: Invalid page object
    2_notes/through-the-desert: Invalid page object
    2_notes/a-night-in-the-forest: Invalid page object
    2_notes/chasing-waterfalls: Invalid page object
    2_notes/across-the-ocean: Invalid page object
    2_notes/exploring-the-universe: Invalid page object
    2_notes/himalaya-and-back: Invalid page object
    error: preg_match_all(): Compilation failed: invalid range in character class at offset 20
    200
    
    help wanted question 
    opened by pReya 5
  • Enhancement suggestion: be able to query data property for user

    Enhancement suggestion: be able to query data property for user

    In the current version of janitor, the data property only works for page and file models. It could be nice to be able to query data property for user too.

    My use case: I need a janitor button in a user blueprint to trigger a user field update. For this, I need to get the user id in the Janitor jobs by the data property to update the right fields.

    /blueprints/users/journalist.yml

    journalistUpdate:
      type: janitor
      label: Confirm this update
      job: updateJournalistValidated
      data: '{{ user.id }}'
    

    config.php

    'updateJournalistValidated' => function (Kirby\Cms\Page $page = null, string $data = null ) {
                $kirby = kirby();
                $kirby->impersonate();
                $journalist = $kirby->user( $data );
                if ( !empty( $journalist ) ) :
                    $journalist->update([
                        'journalistState'  => '',
                        'updateJournalistValidatedInfo' => '',
                    ]);
                endif;
                return [
                    'status'    => 200,
                    'reload'    => true,
                ];
            },
    
    enhancement 
    opened by vauvarin 4
  • Installation trough composer doesn’t install the actual repo

    Installation trough composer doesn’t install the actual repo

    The title says it all; I was getting multiple 404 errors from API calls while testing some of the plugin functions; search for backupzip classes and didn’t find anything ’bout it in the plugin directory.. because there’s anything about it.

    opened by jesuismaxime 4
  • CLI 8.0

    CLI 8.0

    I am getting

    TypeError: array_merge(): Argument #2 must be of type array, null given in file /.../site/plugins/kirby3-janitor/classes/Janitor.php on line 37
    

    when trying to use the CLI. Both my machine and server are PHP8.0. It's line

    $extends = array_merge($this->options['jobs-defaults'], $this->options['jobs-extends']);
    

    but when i get $this->options after defaults merge

    array:6 [[▼]()
      "debug" => null
      "log" => null
      "jobs" => null
      "jobs-defaults" => array:1 [[▶]()]
      "jobs-extends" => null
      "secret" => null
    ]
    

    So i am not loading the generated index. Surprisingly what fixes it is if i do

    php site/plugins/kirby3-janitor/janitor --kirby .
    

    now what i don't understand is that . should be same as pwd and if i put the absolute path from pwd it doesn't work.

    Also this is happening on both linux and mac. Kind of wierd that . fixes it for me?

    bug 
    opened by iskrisis 3
  • How to call an API via blueprint

    How to call an API via blueprint

    Hey, I’m using this plugin: https://github.com/thathoff/kirby-git-content which creates an endpoint like /git-content/push and I’d like to add a button in site.yml that calls that endpoint.

    This example https://github.com/bnomei/kirby3-janitor/wiki/Example:-Trigger-jons-with-JS-and-Panel-Vue shows how to call endpoints but I am not sure where would I place this code. Can you advice?

    Thanks!

    opened by gryzzly 3
  • Note down that Clipboard API is available only in SecureContext

    Note down that Clipboard API is available only in SecureContext

    Navigator.clipboard is available only in secure context - i.e. HTTPS active or localhost (not local domain, actual localhost).

    • https://github.com/bnomei/kirby3-janitor/wiki/Panel-Field:-Copy-to-Clipboard
    • https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#interfaces
    opened by adamkiss 3
  • ⬆️ Bump json5 from 2.2.0 to 2.2.3

    ⬆️ Bump json5 from 2.2.0 to 2.2.3

    Bumps json5 from 2.2.0 to 2.2.3.

    Release notes

    Sourced from json5's releases.

    v2.2.3

    v2.2.2

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)
    Changelog

    Sourced from json5's changelog.

    v2.2.3 [code, diff]

    v2.2.2 [code, diff]

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1 [code, diff]

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)
    Commits
    • c3a7524 2.2.3
    • 94fd06d docs: update CHANGELOG for v2.2.3
    • 3b8cebf docs(security): use GitHub security advisories
    • f0fd9e1 docs: publish a security policy
    • 6a91a05 docs(template): bug -> bug report
    • 14f8cb1 2.2.2
    • 10cc7ca docs: update CHANGELOG for v2.2.2
    • 7774c10 fix: add proto to objects and arrays
    • edde30a Readme: slight tweak to intro
    • 97286f8 Improve example in readme
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies javascript 
    opened by dependabot[bot] 0
  • Translateable labels for janitor fields

    Translateable labels for janitor fields

    Janitor field doesn't support multi-lang labels in blueprints.

    Blueprint

                  downloadContent:
                    label:
                      de: Content herunterladen (.zip)
                      en: Download content (.zip)
                    type: janitor
                    command: 'download-content'
    

    Error:

    CleanShot 2022-12-18 at 17 02 54@2x

    Expected behavior

    Button text would be "Content herunterladen (.zip)" if logged in with a German account, but "Download content (.zip)" if logged in with an English account.

    opened by tobimori 0
  • Disabling uuid generation in kirby config crashes janitor

    Disabling uuid generation in kirby config crashes janitor

    Hello :)

    When I disable UUID generation in the config, the janitor field crashes with this message:

    Call to a member function toString() on null in file: /var/www/site/plugins/kirby3-janitor/index.php line: 52

    This is because $model->uuid() returns null when uuids are disabled, you are however calling the toString() method on it. Since you already are providing fallback values via a null coalescing operator, a simple fix would be to use optional chaining:

                        // append model
                        if ($this->model() instanceof \Kirby\Cms\Page) {
                            $command .= ' --page ' . $this->model()->uuid()?->toString() ?? $this->model()->id();
                        } elseif ($this->model() instanceof \Kirby\Cms\File) {
                            $command .= ' --file ' . $this->model()->uuid()?->toString() ?? $this->model()->id();
                        } elseif ($this->model() instanceof \Kirby\Cms\User) {
                            $command .= ' --user ' . $this->model()->uuid()?->toString() ?? $this->model()->id();
                        } elseif ($this->model() instanceof \Kirby\Cms\Site) {
                            $command .= ' --site'; // boolean argument
                        }
                        $command .= ' --model '. $this->model()->uuid()?->toString() ??
                            ($this->model() instanceof \Kirby\Cms\Site ? 'site://' : $this->model()->id());
                        return $command;
    

    Optional chaining is supported since PHP 8.

    opened by rasteiner 0
  • What about `info`

    What about `info`

    Hello Bruno :)

    what are your thoughts about adding an info prop? Something like: image

    The above screenshot was done by adding 2 lines: under the button:

        <k-text v-if="help" theme="help" class="k-field-help" :html="help" />
    

    and in the props:

        help: String,
    
    opened by rasteiner 0
  • ⬆️ Bump minimatch from 3.0.4 to 3.1.2

    ⬆️ Bump minimatch from 3.0.4 to 3.1.2

    Bumps minimatch from 3.0.4 to 3.1.2.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies javascript 
    opened by dependabot[bot] 0
Releases(v3.2.2)
Owner
Bruno Meilick
Bachelor in Interaction Design ZHdK, Freelance Webdeveloper
Bruno Meilick
Do you want CronJob to follow the solar date?You need this package to solve this problem.

Shamsic Maybe it happened to you that you wanted to use CronJob in your project and you realized that you cannot manage the exact dates that are in th

Amin Ghaninia 5 Jul 19, 2022
Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files

toKirby Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files. You can easily install and test it in a few steps.

R. Banus 4 Jan 15, 2022
html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users

html-sanitizer html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users (who you cannot trust), allowing yo

Titouan Galopin 381 Dec 12, 2022
Rah cache minify - HTML compressor module for rah cache Textpattern CMS plugin

Minify module for rah_cache This is a minify module for rah_cache, a full-page caching solution for Textpattern CMS. Rah_cache_minify will minify HTML

Jukka Svahn 1 Feb 13, 2014
Etc cache - Cache plugin for Textpattern CMS

etc_cache Download | Packagist This Textpattern plugin provides an events-driven cache solution for Textpattern CMS. Textpattern is fast, but when you

null 3 Aug 30, 2020
A Magento 1.x module which facilitates automatic purging of static assets from HTTP caches such as browser cache, CDN, Varnish, etc using best practices outlined within the HTML5 boilerplate community.

Magento Cachebuster Cachebuster is a Magento module which facilitates automatic purging of static assets from HTTP caches such as browser cache, CDN,

Gordon Knoppe 129 Apr 1, 2022
A quick,easy and safe way of accessing Mysql-like databases from within a PHP program

Mysqli-Safe A simple, easy-to-use and secure way of accessing a Mysql database from within your PHP programs Mysqli-safe is a wrapper around the mysql

Anthony Maina Njoroge 2 Oct 9, 2022
Rah cache - Cache Textpattern's dynamic pages as flat files

rah_cache Packagist | Issues Rah_cache is a simple, experimental full-page caching plugin for Textpattern CMS. It caches Texpattern’s dynamic pages as

Jukka Svahn 2 Apr 24, 2022
The Cache component provides an extended PSR-6 implementation for adding cache to your applications.

Symfony PSR-6 implementation for caching The Cache component provides an extended PSR-6 implementation for adding cache to your applications. It is de

Symfony 3.8k Jan 3, 2023
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
This repository contains the codebase PHP bridge using RoadRunner Jobs plugin.

RoadRunner Jobs Plugin This repository contains the codebase PHP bridge using RoadRunner Jobs plugin. Installation To install application server and J

Spiral Scout 15 Nov 9, 2022
Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Stef Dawson 8 Oct 3, 2020
This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.

Kirby 3 Many To Many Field This plugin allows you to create many-to-many relationships between pages in Kirby.

Jonas Holfeld 41 Nov 19, 2022
Helper to automatically load various Kirby extensions in a plugin

Autoloader for Kirby Helper to automatically load various Kirby extensions in a plugin Commerical Usage This package is free but if you use it in a co

Bruno Meilick 13 Nov 9, 2022
Plugin for Kirby that allows you to load assets generated by Vite.

Kirby Vite Plugin Plugin for Kirby that allows you to load assets generated by Vite. In development mode, assets are loaded from Vite's development se

Oblik Studio 10 Nov 20, 2022
Kirby plugin to visually show hidden characters in all kind of input fields and their previews.

Kirby Hidden Characters Kirby plugin to visually show hidden characters in all kind of input fields and their previews. This includes white spaces and

Jakob Grommas 21 Oct 17, 2022
provides a nested object property based user interface for accessing this configuration data within application code

laminas-config This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steeri

Laminas Project 43 Dec 26, 2022
KodExplorer is a file manager for web. It is also a web code editor, which allows you to develop websites directly within the web browser.

KodExplorer is a file manager for web. It is also a web code editor, which allows you to develop websites directly within the web browser.

warlee 5.5k Feb 10, 2022
Opens an interactive PHP console for running and testing PHP code.

wp-cli/shell-command Opens an interactive PHP console for running and testing PHP code. Quick links: Using | Installing | Contributing | Support Using

WP-CLI 20 Nov 4, 2022