xowiki::cr_thin_out (private)

 xowiki::cr_thin_out [ -doit ] [ -delete_orphans ] \
    [ -delete_sequences ] [ -edit_interval edit_interval ] \
    [ -older_than older_than ] [ -package_id package_id ] \
    [ -item_id item_id ]

Defined in packages/xowiki/tcl/xowiki-utility-procs.tcl

Delete supposedly unimportant items and revision from the content repository.

Switches:
-doit (optional, boolean, defaults to "false")
if not true, then just write delete operation to the logfile
-delete_orphans (optional, boolean, defaults to "false")
if true, delete orphaned items
-delete_sequences (optional, boolean, defaults to "false")
if true, delete revisions from edit sequences lower than edit_interval
-edit_interval (optional, defaults to "300")
delete entries, which never become older than this interval (in seconds, default 300)
-older_than (optional, defaults to "1 month ago")
delete only entries, which were modified longer than the provided time ago
-package_id (optional)
if specified, perform operation just on the specified package
-item_id (optional)
if specified, perform operation just on the specified item

Partial Call Graph (max 5 caller/called nodes):
%3 xo::db::tcl_date xo::db::tcl_date (public) xowiki::cr_thin_out xowiki::cr_thin_out xowiki::cr_thin_out->xo::db::tcl_date

Testcases:
No testcase defined.
Source code:
    set extra_clause ""
    if {[info exists package_id]} {
      append extra_clause " and o.package_id = :package_id"
    }
    if {[info exists item_id]} {
      append extra_clause " and i.item_id = :item_id"
    }

    # only delete revisions older than this date
    set older_than [clock scan $older_than]

    if {$delete_orphans} {
      #
      # Removes orphaned items, where a user pressed "new", but never
      # saved the page. We could check as well, if the item has
      # exactly one revision.
      #
      set sql "
         select i.name, o.package_id, i.item_id, r.revision_id, o.last_modified
         from acs_objects o, xowiki_page p, cr_revisions r, cr_items i
         where p.page_id = r.revision_id and r.item_id = i.item_id and o.object_id = r.revision_id
         and i.publish_status = 'production' and i.name = r.revision_id::varchar
         $extra_clause
      "
      foreach tuple [::xo::dc list_of_lists get_revisions $sql] {
        #::xotcl::Object msg "tuple = $tuple"
        lassign $tuple name package_id item_id revision_id last_modified
        set time [clock scan [::xo::db::tcl_date $last_modified tz_var]]
        if {$time > $older_thancontinue
        ::xotcl::Object log "...will delete $name doit=$doit $last_modified"
        if {$doit} {
          ::xowiki::Package require $package_id
          ::$package_id delete -item_id $item_id -name $name
        }
      }
    }

    if {$delete_sequences} {
      #
      # The second query removes quick edits, where from a sequence of edits of the same user,
      # only the last edit is kept
      #
      set sql "
        select i.name, i.item_id, r.revision_id,  o.last_modified, o.creation_user, o.package_id
        from acs_objects o, xowiki_page p, cr_revisions r, cr_items i
        where p.page_id = r.revision_id and r.item_id = i.item_id
        and o.object_id = r.revision_id
        $extra_clause
        order by item_id, revision_id asc
      "
      set last_item ""
      set last_time 0
      set last_user ""
      set last_revision ""

      foreach tuple [::xo::dc list_of_lists get_revisions $sql] {
        #::xotcl::Object msg "tuple = $tuple"
        lassign $tuple name item_id revision_id last_modified user package_id
        set time [clock scan [::xo::db::tcl_date $last_modified tz_var]]
        if {$time > $older_thancontinue
        #::xotcl::Object msg "compare time $time with $older_than => [expr {$time < $older_than}]"
        if {$last_user eq $user && $last_item == $item_id} {
          set timediff [expr {$time-$last_time}]
          #::xotcl::Object msg "   timediff=[expr {$time-$last_time}]"
          if {$timediff < $edit_interval && $timediff >= 0} {
            ::xotcl::Object log "...will delete $name revision=$last_revision, doit=$doit $last_modified"
            if {$doit} {
              ::xowiki::Package require $package_id
              ::$package_id delete_revision -revision_id $last_revision -item_id $item_id
            }
          }
        }
        set last_user $user
        set last_time $time
        set last_item $item_id
        set last_revision $revision_id
      }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: