Hi, I am having issues with updating functions in BaseX 7.5 (official release).
When I update a document, its content is updated with the content of another document.
I even perform the db:optimized in a separate function after a forward to ensure that the db:replace is in fact completed before indexes are optimized.
declare %rest:path("/admin/refresh-menu-headings")
%rest:GET
%rest:query-param("menu-id", "{$menu-id}", "devicehelp")
updating function admin:refresh-menu-headings($menu-id as xs:string){
(:Get the content:)
let $raw-menu := app:open-db('en-us')/menu[@id = $menu-id]
(:Get the file location:)
let $menu-uri := substring-after($raw-menu/base-uri(), 'en-us/')
(:Copy the content:)
let $menu := $raw-menu
(:Output the content in a file to ensure you have the right one:)
let $debug := file:write('debug-ouch.xml', document{$menu})
(:Output the file uri to ensure you have the right one:)
let $debug-uri := file:write('debug-uri.xml', $menu-uri)
(:Replace the content of the file with the same content that was outputted in debug-ouch:)
return (db:replace('en-us', $menu-uri, $menu),
declare %rest:path('/admin/success/heading-refresh')
updating function admin:success-heading-refresh(){
let $result := <html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Add headings to menu topicrefs</title></head>
<body>
<h2>Add headings to menu topicrefs</h2>
<ul>
<li style="color:green">Menus were updated successfully.</li>
</ul>
</body>
</html>
return (db:optimize('en-us'), db:output($result))