bnomei/kirby3-janitor

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

1.0.3 2018-12-09 00:25 UTC

README

GitHub release License Kirby Version

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

TIP 1: The Janitor plugin can also perform other jobs than the build-in cache jobs.

TIP 2: It can also create logs of what it did.

Commerical Usage

This plugin is free but if you use it in a commercial project please consider to

Screenshots

clean & loot

Usage Examples

PHP code

$success = janitor('clean'); // boolean
// or
$json = janitor('clean', true); // array

Panel Field will create a clickable button

  janitor:
    type: janitor
    label: Clean Cache
    progress: Cleaning Cache...
    job: clean
  heist:
    type: janitor
    label: Enter Bank
    progress: Performing Heist...
    job: heist

Kirby API (post Authentification)

let janitor = fetch('https://devkit.bnomei.com/api/plugin-janitor/clean')
  .then(response => response.json())
  .then(json => {
      console.log(json);
  });

Kirby Vue

this.$api.get('plugin-janitor/clean')
  .then(response => {
    console.log(response)
  })

Cronjob

Set a secret in your config.php file and call the janitor api with secret in a crobjob like this. This way you do not need the Kirby API to authentificate.

wget https://devkit.bnomei.com/plugin-janitor/clean/e9fe51f94eadabf54dbf2fbbd57188b9abee436e --delete-after
// or
curl -s https://devkit.bnomei.com/plugin-janitor/clean/e9fe51f94eadabf54dbf2fbbd57188b9abee436e > /dev/null

Custom Jobs

Go build your own jobs. Trigger APIs, create ZIPs, rename Files, ...

site/config.php

<?php
    return [
        'bnomei.janitor.jobs' => [
            'heist' => function() {
                \Bnomei\Janitor::log('heist.mask '.time());
                $grand = \Bnomei\Janitor::lootTheSafe();
                // or trigger a snippet like this:
                // snippet('call-police');
                \Bnomei\Janitor::log('heist.exit '.time());
                return [
                    'status' => $grand > 0 ? 200 : 404,
                    'label' => $grand . ' Grand looted!'
                ];
            }
        ],
        // ... other configs
    ];

Predefined Jobs

  • tend removes cache-files that have expired from all but excluded cache-folders.
  • clean removes cache-files from all but excluded cache-folders.
  • flush calls flush() on all cache-folders. Dangerous!
  • repair creates the root cache folder if it is missing.

Settings

All settings must be prefixed with bnomei.janitor..

jobs

  • default: [] array of keys => callbacks:bool|array

jobs.extends

  • default: [] array of names to other keys => callbacks:bool|array options
  • example: ['bvdputte.kirbyqueue.queues']

label.cooldown

  • default: 2000ms. the field allow you to override this as well.

exclude

  • default: ['bnomei/autoid', 'bnomei/fingerprint'] array of foldernames to exclude.

secret

  • default: null, any string

log.enabled

simulate

  • default: false, will not remove any files if enabled. You could check this option in your customs jobs as well if you want to support simulating the job.

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.

Credits

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.