I’m having an issue when $file->update() is run multiple times, only the last one seems to work.
I’m writing a plugin that pulls in data from an external API and whenever a file is updated. Below is a stripped down version of the plugin that illustrates the issue. When this plugin/hook runs, the only field added is Field2: value2
.
Thanks in advance!
// plugins/myplugin/index.php
<?php
function fileUpdate($file, $field, $value){
// in the actual plugin, an api call is made here
// and multiple fields are updated
try {
$file->update([ $field => $value ]);
} catch(Exception $e) {
throw $e;
}
}
Kirby::plugin('violet/fieldtest', [
'hooks' => [
'file.update:after' => function ($file) {
fileUpdate($file, 'field1', 'value1');
fileUpdate($file, 'field2', 'value2');
}
]
]);