	/*  
	
	clean.sql - In views that identify corrupted items in a collaboration area, "clean up" those items.
	Copyright 2005 IBM Corporation
	Version 2, August 3, 2005


	Instructions for using this script:

	1. Run the SQL command "select coa_name, coa_id, coa_src_container_id, coa_dst_container_id from coa order by coa_id;"
		in your WPC DB Admin, or sqlplus, window, 
		to see a list of collab areas and their ids, src_container_ids, and dst_container_ids.

	2. Find (the name of) the collab area you want to clean up.
		 and write down its id, src_container_id, and dst_container_id
		 (i.e. the values of its "coa_id", "coa_src_container_id", and "coa_dst_container_id" fields).

	3. Now do the following:

		a. Run the drop_views.sql script.

		b. Text edit the create_views.sql script, to substitute the desired collaboration area's id, 
		for each of the seven occurrences of the default id value of "clnCoaId" in that script.

		c. Run the edited create_views.sql script.

		d. Run the procs.sql procedure to define two PL/SQL procedures.

		d. Edit this clean.sql script, substituting the actual src_container_id value for the default value of "clnSrcCtgId" below,
			and substituting the actual dst_container_id for the default value of "clnCoaCtgId" below.

		e. Create the backup tables, if you haven't already done so.   I.e. run 
			the drop_backup_tables.sh and create_backup_tables.sh scripts.
			In general, you should only need to create the backup tables once, and should never need to drop them.
			Each time you run this clean.sql for a particular collab area, it automatically flushes all prior
			data for that collab area (and only that collab area) from the backup tables.  
			Thus care is needed - you cannot, or rather should not, re-run this cleanup.sh for a collab area
			which still has data in the backup tables that you wish to keep or potentially restore from.
			If you have such still-interesting backup data from a previous cleanup run (for this collab area), 
			you must copy it elsewhere first before re-running cleanup.

		e. Run this clean.sql script.  This will alter the database, populate the backup tables, and
			produce a certain report of items cleaned up.

		f. Run the drop_views.sql script.


	4. Capture the text outputs of all the runs of clean.sql, and send those output files to IBM,
		together with the output of the "select from coa" command.

	END OF Instructions.

	WARNING:  Do not run this script on any collaboration area where an item checked out to it,
		might also be simultaneously checked out to other collaboration areas, unless you are
		willing to have those checkouts undonee (i.e. reverted).   The reason for this warning is 
		that if this script decides to undo the checkout of an item to the collaboration area
		you want cleaned up, it will also undo that item's checkouts to any other
		collaboration areas.

	*/


set serveroutput on size 1000000;
set echo off;
set linesize 120
set heading off
set line 10000
set wrap off
set newpage NONE
BEGIN 
  DBMS_OUTPUT.enable(1000000);

  CLEAN_AND_BACKUP_DATABASE_ROWS(clnCoaId);

END; 
/
