Hello, Kirby community!
I’m trying to do a bulk file update, but I’ve encountered an unexpected problem. When calling the $file->update() method, the metadata files are deleted. This only happens when I try to update multilingual files.
Here’s the Blueprint file:
title: Image
accept:
type: image
columns:
- width: 1/2
sections:
content:
type: fields
fields:
caption:
label: Caption
type: textarea
size: medium
- width: 1/2
sections:
meta:
type: fields
fields:
published:
label: Published Date
type: date
display: DD.MM.YYYY
time: true
default: now
alt:
label: Alternative Text
type: text
photographer:
label: Photographer
type: text
width: 2/3
license:
label: License
type: select
width: 1/3
options:
- Unsplash
- CC BY 4.0
- CC BY-SA 4.0
- CC BY-NC 4.0
- CC BY-ND 4.0
link:
label: Link
type: url
And this is the plugin that updates the files (I found an example here: Update file metadata | Kirby CMS ):
<?php
Kirby::plugin("cookbook/update-metadata", [
"filesMethods" => [
"update_published" => function (array $data) {
$messages = [];
$kirby = kirby();
foreach ($this as $file) {
try {
if ($kirby->multilang() === true) {
$languages = $kirby->languages();
foreach ($languages as $language) {
$newFile = $file->update($data, $language->code());
}
} else {
$newFile = $file->update($data);
}
} catch (Exception $e) {
$messages[] = $file->filename() . " could not be updated (" . $e->getMessage() . ")";
}
}
return $messages;
},
],
'routes' => [
[
'pattern' => 'ex/update-files',
'action' => function() {
$kirby = kirby();
$folder = 'photography';
$page = $kirby->page($folder);
// update all files of all subpages of the current page
$result = $kirby->impersonate('kirby', function () use ($page) {
$files = $page->index()->files()->filterBy("template", "in", ['image']);
return $files->update_published([
'published' => '2025-11-11 01:02:03',
// more metadata if required
]);
});
dump($result);
die('end');
}
],
]
]);
Config file:
<?php
return [
'debug' => true,
'panel' =>[
'install' => true,
],
'languages' => true,
'languages.detect' => true,
'yaml.handler' => 'symfony',
];
Files before the update:
Running the script:
Files after the update:
When I run the script, only the JPG files remain in the directory, while the TXT files with metadata are deleted. What could be the cause, and what am I doing wrong?


