// Undelete links from history /* Re-create links from link deletion history. Pekka Mäkinen / SoftQA Oy / 2011-02-09 */ // MODIFY THESE VALUES BEFORE RUNNING THIS SCRIPT AS ADMINISTRATOR //------------------------------------------------------------------------------------------ // The date one before we will re-create the links, no deleted links before this // will be restored Date CheckUpDate = "20/01/2008" // If OptionaLinkModule is not empty, then that specific link module will be used for // creating links instead of the one defined in history string OptionalLinkModule = "/EasyStart/Requirements/DOORS Links" // If DeletedFromLinkModule is not empty, then only that specific link module // will be used for finding deleted links - no other links will be restored string DeletedFromLinkModule = "/EasyStart/Requirements/DOORS Links" //------------------------------------------------------------------------------------------ // DO NOT MODIFY ANYTHING AFTER THIS LINE Object o = null Module currMod = current Module trgMod = null string TargetModule = "" string LinkModule = "" int TargetAbs = 0 Object TargetObject = null History h = null HistoryType ht = null User currUser = null UserClass currUserClass Link l = null int NumLinksRestored = 0 // GetLinkHistory void GetLinkHistory(History h) { LinkModule = h.linkInitialName //requires Admin Rights, gets the full name //to the link module of the deleted link TargetAbs = h.targetAbsNo //doesn't need Admin Rights, gets the deleted //target's Absolute Number TargetModule = h.targetInitialName //requires Admin Rights, gets the full name //to the target module of the deleted links target } // Main program currUser = find() currUserClass = currUser.class if (stringOf(currUserClass) != "Administrator") { ack "Only the Administrator user can run this script" halt } if ((null currMod) || (!isEdit currMod)) { ack "Please run this script from a module in exlusive edit mode" halt } for o in currMod do { for h in o do { ht = h.type if ((ht==deleteLink) && (h.date > CheckUpDate)) { GetLinkHistory(h) if (DeletedFromLinkModule > "") { if (DeletedFromLinkModule != LinkModule) continue } // Use the original link module, but if the optional has some content, then use it if (OptionalLinkModule > "") { LinkModule = OptionalLinkModule } if ((exists module LinkModule) && (!isDeleted module LinkModule) && (exists module TargetModule) && (!isDeleted module TargetModule)) { trgMod = read(TargetModule, false) if (!null trgMod) { current = trgMod filtering off sorting off outlining off level 0 current = currMod TargetObject = object(TargetAbs, trgMod) if (!null TargetObject) { l = o -> LinkModule -> TargetObject if (!null l) { NumLinksRestored++ } else { print "Could not create link from " o."Absolute Number" " to " TargetModule " object " TargetAbs "\n" } } else { print "Null target object " TargetAbs " in module " TargetModule "\n" } } } } } } // Save the module save currMod // Close all the modules, except current one for trgMod in database do { if ((!null trgMod) && (trgMod != currMod)) { close trgMod } } infoBox "Done! " NumLinksRestored " links were re-created from history back to " CheckUpDate ""rom history