getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.29k stars 168 forks source link

[v4] not possible to unpublish multiple children #5396

Closed jaro-io closed 1 year ago

jaro-io commented 1 year ago

description

i am facing a weir issue when trying to unpublish multiple pages with a simple foreach loop over the children of a page. in v3.9 this works perfectly fine. however, in v4 it only unpublishes the first page from the list. all other children stay published.

i added some code to debug this and strangely with both v3.9 and v4 the output (see below) is the same. so from the dump it seems like children are being unpublished fine. but then why is this not visible afterwards when refreshing the page in the panel? i tried checking the changelog for v4 but couldn’t find anything that seems to be related to this.

expected behavior
i was expecting my code to have the same effect in both v3.9 and v4.

screenshots
v39 v4

to reproduce

add the following code to a template. open a page with this template that has multiple children.

foreach($page->children() as $child) {

    $child->unpublish();
}

your setup

kirby version
4.0.0-alpha.5

console output

Kirby\Cms\Pages Object
(
    [0] => products/t-shirt/small-red-dinosaur
    [1] => products/t-shirt/small-green-dinosaur
    [2] => products/t-shirt/small-green-cat
    [3] => products/t-shirt/medium-red-dinosaur
    [4] => products/t-shirt/large-blue-dinosaur
)
Unpublishing: products/t-shirt/small-red-dinosaur

Kirby\Cms\Pages Object
(
    [0] => products/t-shirt/small-green-dinosaur
    [1] => products/t-shirt/small-green-cat
    [2] => products/t-shirt/medium-red-dinosaur
    [3] => products/t-shirt/large-blue-dinosaur
)
Unpublishing: products/t-shirt/small-green-dinosaur

Kirby\Cms\Pages Object
(
    [0] => products/t-shirt/small-green-cat
    [1] => products/t-shirt/medium-red-dinosaur
    [2] => products/t-shirt/large-blue-dinosaur
)
Unpublishing: products/t-shirt/small-green-cat

Kirby\Cms\Pages Object
(
    [0] => products/t-shirt/medium-red-dinosaur
    [1] => products/t-shirt/large-blue-dinosaur
)
Unpublishing: products/t-shirt/medium-red-dinosaur

Kirby\Cms\Pages Object
(
    [0] => products/t-shirt/large-blue-dinosaur
)
Unpublishing: products/t-shirt/large-blue-dinosaur

Kirby\Cms\Pages Object
(
)
afbora commented 1 year ago

I can't reproduce the issue on 4.0.0-alpha.5 (notes pages). Do you have any hooks or plugins?

jaro-io commented 1 year ago

@afbora hm, yes i have both. but i just removed all plugins & hooks and the issue still persists. however, you are right.. with a clean starterkit on v4 i can’t reproduce this, too.

any other ideas where this could be coming from? it’s definitely related to v4, as it’s not happening in v3.9. but also related to my setup, as it’s not happening with the starterkit.

🤷‍♂️ ✨

afbora commented 1 year ago

Could it be due to plugins that are not compatible with v4? Can you try to narrow down the source of the issue by disabling plugins and hooks one by one?

jaro-io commented 1 year ago

@afbora like i said, i already removed all my plugins & hooks. i also emptied my config. it is still behaving the same. only one item gets unpublished. any other idea where this might be coming from?

afbora commented 1 year ago

I have no idea 🤷‍♂️ If it is in the github repository, we can test it by granting access 🤔

afbora commented 1 year ago

Closing for now. Feel free post new replicate info when you find more clues 👍

jaro-io commented 1 year ago

@afbora hm, i just tried this again with an empty starter kit. and i can easily reproduce the behaviour described above.

1. add code add the following code to the photography.php template.

foreach($page->children() as $child) {

    $child->unpublish();
}

2. open template open the /photography page in the browser. it will look as if all children have been unpublished.

template

3. check panel when checking the panel, only the last child has been unpublished.

panel
distantnative commented 1 year ago

I can reproduce it. And it did work for me fine with v3 develop branch, but not v4.

afbora commented 1 year ago

Issue summary

After the first item is unpublish, the siblings are reordered and the root paths are updated. But since the paths of the other items in the loop are still outdated, when it comes to the second item, it cannot find root and the operation fails.

Before action

content/1_photography/1_landscape
content/1_photography/2_animals
content/1_photography/3_desert

After action

content/1_photography/2_animals
content/1_photography/3_desert

Actual order

content/1_photography/1_animals
content/1_photography/2_desert