Created
February 4, 2016 13:28
-
-
Save ableasdale/600010599fb6c5c4907f to your computer and use it in GitHub Desktop.
Batch Change Permissions - Second Cut...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xquery version "1.0-ml"; | |
| declare variable $chunk as xs:integer := 1000; | |
| declare variable $count as xs:unsignedLong := xdmp:eager(fn:count( cts:uris( (), (), (), (), () ))); | |
| declare variable $loop as xs:unsignedLong := xs:integer(fn:ceiling ( $count ) div $chunk) + 1; | |
| declare variable $option as element() := | |
| <options xmlns="xdmp:eval"> | |
| <transaction-mode>update-auto-commit</transaction-mode> | |
| </options>; | |
| declare function local:doWork($start as xs:integer, $end as xs:integer, $uris as xs:string*) { | |
| for $i in $uris return xdmp:document-set-permissions($i,xdmp:permission("read-only","read")), | |
| xdmp:log(fn:concat("Processing: ", " start:", $start, " end:", $end, " finished:", xdmp:eval("fn:current-time()"), " Elapsed:", xdmp:elapsed-time() )) | |
| }; | |
| xdmp:log(text { "Starting processing: ", $count, " documents. Script started at: ", fn:current-time() }), | |
| for $i in 1400 to $loop | |
| let $pos := ($i -1) * $chunk + 1 | |
| let $end := $pos + $chunk - 1 | |
| return xdmp:spawn-function ( | |
| function() {local:doWork($pos, $end, subsequence( cts:values(cts:uri-reference(), "/", (), (), (), ()), $pos, $chunk))}, | |
| $option | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment