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

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

Closed pReya closed 2 years ago

pReya commented 3 years ago

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
bnomei commented 3 years ago

hi @pReya i am on parental leave right now so i do not have the time to debug this right now. can you help me out a little bit.

1) does it work if not using the -v option 2) verbose mode in janitor triggers a check using regex looking for images https://github.com/bnomei/kirby3-janitor/blob/60cd6ed5750cf496266c96b7155d854d16d2ecc9/classes/RenderJob.php#L158 maybe you can see what causes the issue? like dump and die content of first verbose check?

thanks

maxackerman commented 2 years ago

I'm running into the same issue testing out Janitor on local dev site.

Testing with Plainkit:

When using the fresh plainkit, janitor render is working. In this instance there are only two items in the /content folder: site.txt and home.

Changing content/home to content/1_home, causes the bug to happen.

Adding a new listed page e.g content/1_example-page/default.txt also causes the bug to happen.

bnomei commented 2 years ago

thanks @maxackerman that makes it easier to replicate. i will try to fix this asap.

grommas commented 2 years ago

I ran into the same problem and just had a look on classes/RenderJob.php. I’m not quite sure, but it seems to be a problem with the regex on line 141:

140  if (strpos($id, '_drafts') === false) {
141    $ids[] = preg_replace('/\/\d+_/', '/', $id);
142  }

Since the relative pathname is not preceded with a slash (at least for me on valet), we could conditionally check for either the beginning of the string or the slash:

140  if (strpos($id, '_drafts') === false) {
141    $ids[] = preg_replace('/(^|\/)\d+_/', '/', $id);
142  }

Is this the best way for you, @bnomei? Should I add a pull request? (I’m not that much into GitHub stuff, but would be happy to help.) Thanks for your great work!

bnomei commented 2 years ago

i have not had the time to take a look myself yet. thanks for your input. you dont need to do a PR for that since i would need to test it anyways.