[MarkLogic Dev General] local:document-rename

Shannon Shiflett at virginia.edu
Thu Sep 2 10:18:28 PDT 2010


Thank you, Michael Blakeley, for posting your function:

declare function local:document-rename(
 $old-uri as xs:string, $new-uri as xs:string)
as empty-sequence()
{
  xdmp:document-delete($old-uri)
  ,
  let $permissions := xdmp:document-get-permissions($old-uri)
  let $collections := xdmp:document-get-collections($old-uri)
  return xdmp:document-insert(
    $new-uri, doc($old-uri),
    if ($permissions) then $permissions
    else xdmp:default-permissions(),
    if ($collections) then $collections
    else xdmp:default-collections(),
    xdmp:document-get-quality($old-uri)
  )
  ,
  let $prop-ns := namespace-uri(<prop:properties/>)
  let $properties :=
    xdmp:document-properties($old-uri)/node()
      [ namespace-uri(.) ne $prop-ns ]
  return xdmp:document-set-properties($new-uri, $properties)
};

It helped me to reclaim some lost time when I inadvertently renamed all the documents in a modules database (warning to all: in OS X Finder, if you add a WebDAV-connected folder to the sidebar, and rename the sidebar entry, you actually end up renaming the source directory, i.e., all the documents in your database!, not the shortcut/alias, which is utterly unexpected behavior; to make matters worse, it prefixed "http://" to the URIs which is an invalid WebDAV pathname, so the documents appeared to be *deleted* at first glance, which was pretty unsettling). 

So, thanks, Mike, for helping me to get my app back, and I'm curious, why is there an xdmp:document-rename?

Best regards,
Shannon



More information about the General mailing list