You'll get the same error without the forward, without the debug lines and without the second function. The error is that the content of the file with menu-id=devicehelp is going to be replaced by the content of an other menu.
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){
let $raw-menu := app:open-db('en-us')/menu[@id = $menu-id]
let $menu-uri := substring-after($raw-menu/base-uri(), 'en-us/')
let $menu := $raw-menu
return (db:replace('en-us', $menu-uri, $menu),
;) ..hi France,
it may take us a while to reproduce what’s going on in your code, so..
do you think you could further simplify your example? Or, ideally,
minimize it to a simple db:replace() function?
You could check the consistency of your database via the INSPECT
> Note: If I use db:optimize('en-us', true()), I get 'unexpected error: 0'
command [1] before and after running your query.
Thanks,
Christian
[1] http://docs.basex.org/wiki/Commands#INSPECT
___________________________________
> _______________________________________________
> To replicate: you'll need a db named 'en-us' with the 3 following documents
> (file names don't matter):
>
> <menu id="devicehelp"/>
> <menu id="smbonly"/>
> <menu id="ptt-help"/>
>
> Then use these functions:
>
>
> 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),
>
> db:output(<restxq:forward>/restxq/admin/success/heading-refresh</restxq:forward>))
>
> };
>
>
> 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))
>
>
>
> RESULT:
> The result after optimize if your query for a list of the /menu/data(@id)
> should be devicehelp, smbonly, ptt-help, but it's ptt-help, smbonly,
> ptt-help.
>
> debug-ouch.xml shows the correct content (content of menu devicehelp),
> debug-uri shows the right file path (path of menu ptt-help), yet the content
> of menu with @id devicehelp gets replaced by the content of menu with
> @id=ptt-help after db:replace.
>
> Note: If I use db:optimize('en-us', true()), I get 'unexpected error: 0'
>
> --
> France Baril
> Architecte documentaire / Documentation architect
> france.baril@architextus.com
> (514) 572-0341
> BaseX-Talk mailing list
> BaseX-Talk@mailman.uni-konstanz.de
> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
>