// Delete defined views from folder // /* DXL Utility to delete unwanted views WARNING: THIS CAN REALLY SCREW UP YOUR DATABASE! */ /* Modification history: Date: Who: Description: 21 April 2010 Bob Swan Initial version downloaded by KM from IBM DOORS DXL Forum 21 April 2010 Ken McNair Hard code list of NAV CANADA views to be deleted Comment out procedure "MakeMinView" Update "External Tasks" Add "Enhancements" #5-8 Change path for log file Only process modules in current folder rather than entire project Update Modification History */ //Program Summary // // For each module in folder // Compare each viewname to killlist // If viewname is in killlist delete view // //External tasks //- User is expected to have dry run this in a test copy of the project database before running it on the working database //- User has edited killlist in dxl for views to be deleted //- User must run this DXL from any module in the chosen folder //- User must be logged on as the Administrator so they can see all views (inc. "private" views) and have write access to all views // //Enhancements //1 populate killlist by offering user list of views in projects and giving keep/kill response. //2 offer option to only process current module. //3 improve efficiency by using skiplist. //4 have killlist as an include module, (makes edit safer) //5 offer option to only process current folder (hard coded in this version) //6 create new log file for each run (e.g. append date/time stamp) rather than overwriting it //7 explicitly state in log if a view does not exist //8 explicitly state in log if a view could not be deleted // ********************************************************* // Constant and Variable declarations // This array details the names of all views that are to be deleted. // This list should have been reviewed and updated before saving the module // The killlist should not include "Standard view" so that errors are not generated for trying to delete a fixed view // Empty kill list will cause this DXL to list all views in all modules in the folder without deleting any (useful in itself) string killlist[] = {//- //insert view names here with format : "name",//- "kens test view",//- "dummy list terminator" } // {for future mods} This array details the names of all views that are to be retained. // These should have been created and edited before saving the module // the list must include "Standard view" so that errors are not generated for trying to delete a fixed view string keeplist[] = {"Standard view",//- //insert view names here with format : "name",//- "kens test view2",//- "dummy list terminator" } Project currProject Item currItem Module currModule string modName string callingmodName string objViewName string s bool res Buffer msg string outputfile Stream out //==== Function Declarations //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void ReportRemainingViews(Item currItem) { //compares each view in current module with those in killlist, if a match is made the view is deleted //KM: comment seems incorrect; this procedure seems to report the remaining views in the module... Module mod1 Object obj1 int lc1 Buffer temp lc1 = 0 mod1 = current Module out << "\nRemaining views in module :-\t" name currItem " " setempty(msg) for objViewName in views mod1 do { msg += "\n\t" objViewName " " } out << msg "\n" setempty(msg) } //end reportremainingviews //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void deleteviews(void) { //compares each view in current module with those in killlist, if a match is made the view is deleted Module mod1 Object obj1 int lc1 Buffer temp bool Nameok = false lc1 = 0 mod1 = current Module //print "deleteviews: killlist size = " (sizeof (killlist)-1) "\n" load view "Standard view" //don't want to delete active view for objViewName in views mod1 do { //print "DeleteViews: Processing\t" objViewName " in " mod1."Name" "\n" Nameok = false for lc1 in 0: (sizeof (killlist)-1) do { //print "deleteviews: Processing\t entry lc1 = " lc1 "\t" "\n" if (killlist[lc1] == objViewName) { Nameok = true //wanted view matches current view //print "deleteviews: matched entry lc1 = " lc1 "\t" objViewName ",\t in " mod1."Name" "\n" break //no point continuing, name matched } } if (Nameok ) then { //print "deleting view. \n" delete (view objViewName) msg += "\tDeleted view :- \"" objViewName "\" in module " mod1."Name" "" "\n" out << msg "\n" setempty(msg) Nameok = false } } } //end deleteviews void ProcessTheItem (Item currItem) { //print "\n___________\n Processing Module " modName ",\t" msg += "\n ----------\nProcessing Module " modName "\t" // check if module is open, otherwise function "module(Item itemRef)" will return null if(open module modName) { msg += " Module Id :=" (uniqueID currItem) "\n" out << msg "\n" setempty (msg) deleteviews() } //end if open } //end processtheitem //noError() //----------------------------- /* KM: Not required by NAV CANADA void MakeMinView (Item currItem) { // construct a new view containing just the puid and main column View meDocView string viewName = "ME. Document" string attr string errData Column col int colCount = 0 // number of existing columns int i // column index // first look to see if we view already exist, if so load it // = load (view viewName) out << "Making Min View for " name currItem ", " type (currItem) bool b = isValidName(viewName) if (b) { //ack viewName " present.\n" //for debug //out<<"\nI " viewName "is valid" } else { //ack viewName " absent.\n" //for debug //out<< viewName " is invalid" } meDocView = view(viewName) //so create it b = load meDocView //load the view //remove all columns in the current display, then build the view for col in (current Module) do colCount++ // count the columns if colCount>0 then { for i in 1:colCount do delete(column 0) // delete colCount column 0s } colCount = 0 insert(column colCount) attribute(column colCount, "PUID") width(column colCount, 100) justify(column colCount, center) colCount++ insert(column colCount) main (column colCount) //attribute(column colCount, attr) width(column colCount, 400) justify(column colCount, left) refresh current // important! (last column does not appear otherwise). save view viewName }// end makeminview */ //----------------------------- //====== Main Code Body======================== // check project is open if (null current Project) { infoBox "No project is open, halting!" halt } // check folder is open if (null current Folder) { infoBox "No folder is open, halting!" halt } if (null current Module) { ack "This function must be run from an open module" halt } currProject = current Project callingmodName = fullName (current Module) currFolder = current Folder outputfile = "S:\\For Doors Admin use only\\Housekeeping\\Killviews.txt" //log of activity s ="Deletion of all defined views in current folder" s = s "\nLog file is " outputfile s = s "\n\nCurrent folder is " (name currProject) "/" (name currFolder) s = s "\nPlease Confirm if this is the correct folder." res = confirm (s, msgQuery ) if (!(res)) { ack "Incorrect Folder. \n Terminating " halt } //ok we can proceed msg = create out = write outputfile //msg += "Processing Project :- " (name currProject) "" "\n" msg += "Processing Folder :- " (name currFolder) "" "\n" //for currItem in currProject do for currItem in currFolder do { if (isDeleted currItem) {continue} if ((type(currItem) == "Formal") && (type(currItem) != "Link")) { modName = (fullName currItem) currModule = read(modName,true) ProcessTheItem (currItem) //MakeMinView (currItem) //KM: Not required by NAV CANADA ReportRemainingViews (currItem) //space for routine to delete unwanted links, usually those that have no target. //however DOORS seem to be handling that for now. if (callingmodName != modName) { close(currModule) //keep open initial module } }//end its a formal module } //end for currItem out << msg "\n_________\n" close out infoBox("Deletion of specified views in " name currProject "/" name currFolder " complete. \n")"/" name currFolder "