Saving files via script (like using the panel)

Hi,
I need your help, please.

I would like to save all all pages in the content folder using a PHP script.
Reason: I have built a website on my test server and treansferred it to a live server.
For some pages I use the gallery block field.
Unfortunately all paths were saved as follows:

// actual: 
Gallery: [{"content":{"images":["path1\/path2\/filename.jpg" ... }]

//target: 
Gallery: [{"content":{"images":["filename.jpg" ... }]

Fortunately, if I resave the page with the panel on live server, the “paths” are automatically “corrected” (only the filename without the path).

Unfortunately I am not able to do this with a script that saves all files (automatically) and then also changes the paths in the gallery blocks.

I have tried it with the following code:

<?php 
require __DIR__ . '/kirby/bootstrap.php';

$kirby = new Kirby;
$kirby->impersonate('kirby');
$collection = $kirby->site()->index();

foreach($collection as $item) {
   //$item->update();
   $item->save();
}

Thank you
Robert

Have you tried to use these methods with the data as argument?

foreach($collection as $item) {
   //$item->update($item->content()->toArray());
   $item->save($item->content()->toArray());
}

Not tested.

Hi texnixe,
thanks for your answer.

Unfortunately, that didn’t work. The paths are still included…
I have tried it with save($item->content()->toArray()) and update($item->content()->toArray())

Strange that the paths are included here at all … :thinking:
Local/Test server: Laragon under Windows 11

What else could I do to remove the paths from the galleries of the content files?

Unfortunately, there are a lot of files (pages). :sleepy:

Robert

Yes, indeed. Which Kirby version are you using? And did you use a host domain or something like http://localhost/some-path?

I installed the latest Kirby version and used “http://localhost/some-path” locally …

Texnixe, you’ve put me on to something.

I stored the page for filling the content at my hosting provider in a subfolder protected with .htpasswd. I have moved (updated) the content folder to my local server from time to time.

I will ask them if they have any ideas.

Nevertheless, I still have the problem that I now have the wrong file paths everywhere. Search and replace in the editor is only possible to a limited extent, as the paths vary greatly in the project… :expressionless: