Page update updates in dump, but not in panel

Hi,

I have a function in a plugin that updates a field on a page. I have a weird behaviour.
After I update my page in this function and I dump it, it shows that the value is at the right spot and correct, but if I have a look in the panel, the field is empty.

<?php

use Kirby\Http\Request as req;
use Kirby\Cms\Page as page;
use Kirby\Cms\Site as site;
use Kirby\Toolkit\Date as date;

function parcel($uuid){
    $order = page($uuid);
    
/*

 I do a few things here.

*/

    kirby()->impersonate('kirby');
    
    if ($order->paymentComplete()->toBool()) {
        $order = $order->update([
            'parcel_id' => 'asdfgh' //$result->parcel->id
        ], 'en');
    }

    dump($order);
    return;
}

in the dump it looks like this:


            [shippingcountry] => 
            [userid] => G5Vj6dfc
            [parcel_id] => asdfgh
            [tracking_nr] => 
 

Any Ideas? Thanks.

Would be more interesting to know if the content file is updated.

No unfortunately not.

Well, hard to tell what’s happening here from the context you provided. The code as given above should usually work.

Thank you. I put the function in a plugin and call the function


<?php

use Kirby\Http\Request as req;
use Kirby\Cms\Page as page;
use Kirby\Cms\Site as site;
use Kirby\Toolkit\Date as date;

function parcel($uuid){
    $order = page($uuid);
    
/*

 I do a few things here.

*/

    kirby()->impersonate('kirby');
    
    if ($order->paymentComplete()->toBool()) {
        $order = $order->update([
            'parcel_id' => 'asdfgh' //$result->parcel->id
        ], 'en');
    }

    dump($order);
    return;
}

Kirby::plugin('hi/sendcloud',[

]);

This is my plugin and I just call the function with parcel from the config within a hook.

Just had a look at what you posted in the other thread, and this somehow doesn’t make sense.

 kirby()->impersonate('kirby');
            if ($orderPage->paymentComplete()->toBool()) {
                $uuid = $orderPage->uuid();
                $data = parcel($uuid);
                $orderPage = $orderPage->update([
                    'parcel_id' => $data
                ]);
            }

Here, you first call the parcel method, which is supposed to update the page, just to update it again with no data at all.

Always provide all context that is needed to understand a problem!

You are right. Sorry about that.
The problem is that my hook in the config is super slow because it has probably too many functions and it has an impact on all users visiting the website in this moment of executing the hook.

So I was thinking to rewrite the function and to update from the function itself to optimise. So in my config it would only be

parcel($uuid);

This was my message in the merx plugin to see how I can optimise the hook. My own approach was to optimise my functions so I have less things within the hook.
This is the Link to the Problem:

The problem of the page update appeared after putting it in the function. That’s why I asked for help in a separate topic.

While moving the stuff into functions is generally a good idea to keep your code clean, it won’t help speeding up the process.

It would be better to execute this stuff in the background, via cron jobs that take care of all this.

But apart from this, you actually slow down things, for example, you already have an $orderPage page object in your hook, but instead of passing this object to your function, you get the UUID, pass it to the function, just to try and get a page object from the UUID again. So an unnecessary page lookup.

Also, in your hook, you update the page twice (parcel_id and user_id, if not more in your other functions), it would make more sense to collect all the data your want to update the page with and then do this only once.

Thank you. This helped and makes absolute sense.
I think I managed to get most things worked out, but I had to keep the page update function in the config hook. In the Plugin function it did not work.

Thanks for all the help, once more.