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.

*
*

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.ba...@architextus.com
(514) 572-0341
_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

Reply via email to