Kirby->update() exit cli-command

I have built a CLI command to update pages.

As soon as I call $page->update(), the call is executed, but the “out” never appears in the console.

  $cli->out('start ');
      if (count($fieldsToUpdate) > 0) {
          $updatedPage = $page->update($fieldsToUpdate);
      }
      $cli->out('end ');

A simple $cli->out($page->title()); inside the if statement works.

Could you please provide your complete code for testing?

Extracted to the minimum:

\Kirby\Cms\App::plugin('xxx/api', [
    'commands' => [
        'test' => [
            'args' => [],
            'command' => function ($cli) {

                kirby()->impersonate('kirby');
                $siteIndex = site()->index();
                $pageCount = $siteIndex->count();

                $pages = $siteIndex->offset(2)->limit(2);

                $index = 0;
                foreach ($pages as $page) {
                    $cli->out($index . '/' . $pageCount .  ' start ');
                    $updatedPage = $page->update([], null, true);
                    $cli->out($index . '/' . $pageCount .  ' end');

                    $index++;
                }
                $cli->success('done!');
            }
        ],
    ]
],
);```

Hm, getting this in console when running kirby test

0/24 start 
0/24 end
1/24 start 
1/24 end
done!

Thanks for testing, @texnixe!

My output is only:

0/866 start 

Kirby 3.9.7 and 3.9.8

Do you have any idea what I can do?

Very likely that you get an error while updating, try

foreach ($pages as $page) {
	$cli->out($index . '/' . $pageCount .  ' start ');
	$updatedPage = $page->update([], null, true); // true validates the content to update, this might cause an error
	dump($updatedPage->content()->toArray());
	$cli->out($index . '/' . $pageCount .  ' end');

	$index++;
}

Thanks for your idea!

I tried it also without validation and to dump it like this:

dump($updatedPage->content()->toArray());

and this

$cli->out( dump($updatedPage->content()->toArray()));

and i tried different pages (via offset). I can save the pages without issues in the panel. And the content itself is updated if data is provided.

And this does not output anything on the command line?

Sadly, nothing. I will run the code on a colleague’s computer for testing.

It might be worthwhile to try it with a fresh Starterkit.

Are you using the latest version of the CLI (1.1.1)?
Which PHP version?

PHP 8.1.26
Kirby CLI 1.1.1
Kirby 3.9.7 + 3.9.8

And yes plain starterkit is the next step. :pray:

you could try wrapping the foreach loop in a try-catch-clause and write any error messages to file in appending mode.

It is a bug in Kirby if no URL is defined in the config. Would be good if it appears as error in the output. You can close the ticket.

you mean that running in the cli the $_SERVER['host'] is empty and kirby can not determine urls as usual? yes that can be fixed by hardcoding the url option in the config. there has been related discussions about enviroments/config in the cli repo.