Hallo,
I'm setting a current metadata. This is a derived date, I don't need it to be in the persistent array.
I try to test it with a test request but the value is not persisted in the meta file system under the current
array and that makes me crazy.
Below is a detailed technical post.
Why, it's not persisted ?
Because in the p_set_metadata
, the metadata is set in the global value $METADATA_RENDERERS
via this condition:
if (isset($METADATA_RENDERERS[$id])) {
// set both keys individually as the renderer has references to the individual keys
$METADATA_RENDERERS[$id]['current'] = $meta['current'];
$METADATA_RENDERERS[$id]['persistent'] = $meta['persistent'];
return true;
} else {
return p_save_metadata($id, $meta);
}
I don't understand this global variable $METADATA_RENDERERS
and when it's persisted.
The code is pretty common.
- in the syntax handler / metadata renderer (the last false is for current metadata)
p_set_metadata("pageid", [ $key => $value ], false, false );
- the test code
$testRequest = new TestRequest();
$testRequest->get(["id" => "pageid"]);
$metadatas = p_read_metadata("pageid");
isset($metadatas["current"][$key]) // false
I can do a debug session and I see it all but the value is not persisted and because of the global variable $METADATA_RENDERERS
, I can't find why
Even if I set the runtime value in the renderer metadata and that I do another metadata rendering
p_save_metadata(p_render_metadata("pageid", $actualMetadatas));
I got nothing back.
Doing a visual / manual test on a DokuWiki works but yeah, I have no test.