bnomei / kirby3-janitor

Kirby Plugin for running commands like cleaning the cache from within the Panel, PHP code, CLI or a cronjob
https://forum.getkirby.com/t/kirby3-janitor-plugin/23573
MIT License
89 stars 8 forks source link

custom janitor button on site.yml #52

Closed bvdputte closed 2 years ago

bvdputte commented 3 years ago

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?

bnomei commented 3 years ago

the $ is my own idea to give the site object an id because $site->id() does not exist. just a way for me to use site but keep working with a route pattern that expects an id.

i will take a look why the issue you described is appearing asap.

bnomei commented 3 years ago

i can not replicate this error on my local setup. even when using the same function names that you have.

i assume you are useing the most current version of janitor. which kirby version?

using vardump in before the response will always fails since the resulting json is not valid anymore. but guess you just added that to make your issue clearer.

if debugging try using a logger or append to repsonse using 'myval' => print_r($var, true),.

bnomei commented 3 years ago
'replenishMyCache' => function (Kirby\Cms\Page $page = null, string $data = null) {
            return [
                'status' => 200,
                'label' => 'External stuff fetched',
                'data' => print_r($data, true),
            ];
        },
bnomei commented 3 years ago

@bvdputte not really sure why its not working on your setup. have you tried again since?

bvdputte commented 3 years ago

Hi @bnomei , sorry for the late reply.

I just checked again with your demo code in my site (Kirby 3.5.7.1 - janitor 2.11.0) to no avail. This is wat is returned:

{"status":"error","message":"No route found for path: \"plugin-janitor\/test\/$\" and request method: \"GET\"","code":404,"exception":"Exception","key":null,"file":"\/kirby\/src\/Http\/Router.php","line":154,"details":[],"route":null}
bvdputte commented 3 years ago

@bnomei ; I found the culprit. It interferes with my .htaccess configuration to omit trailing slashes:

# Omit trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]

When I remove this, janitor works as advertised. Any way to workaround this and keep my htaccess config working?

bnomei commented 3 years ago

nice find. i will see if thus can be solved with another route.

iskrisis commented 2 years ago

I have the same issue. It was driving me crazy what is going on. It works on default nginx config but on clients hosting with apache and default provided .htaccess i get No route found for path: "plugin-janitor/backupZip/$" and request method: "GET"

How can i solve this? @bvdputte what have you done?

bvdputte commented 2 years ago

@iskrisis I postponed the feature 🙈

iskrisis commented 2 years ago

But what really bugs me is that it works in nginx fine so what can i do to Apache to behave the same? You mention trailing slash @bvdputte but it seems to me that the url from nginx is same as in Apache. 🤷 It's wierd because i think i used button in site.yml just fine on apache in the past.

bnomei commented 2 years ago

@bvdputte @iskrisis in current release there is a route that should match the path. https://github.com/bnomei/kirby3-janitor/blob/5c8a33cc391af41c9af4ef4bc21b7f11e4fd692c/index.php#L171

does it not work?

iskrisis commented 2 years ago

I must say i didn't find why it wasn't working. It was clients shared hosting Apache so probably some unusual defaults and i am not even experienced with Apache to debug it.

I've moved the janitor button from site.yml to page and it works no problem.

bvdputte commented 2 years ago

@bvdputte @iskrisis in current release there is a route that should match the path.

https://github.com/bnomei/kirby3-janitor/blob/5c8a33cc391af41c9af4ef4bc21b7f11e4fd692c/index.php#L171

does it not work?

First, sorry for the late feedback. Second, I have just checked this again, and I can now confirm it works 👍

Thanks for this really nice plugin @bnomei ❤️