def ticket_created(self, ticket): """Called when a ticket is created. This basically takes the ticket data and parses it for references to requirements and then creates a relationship map between requirements and this ticket. Note: There should be no need to check for duplicates or deletions because this is when a ticket is just being created. """ searchfields = ['summary', 'description', 'keywords'] for field in searchfields: refs = RequirementCacheSystem( \ self.env).parse_data_for_req_references(ticket[field]) if refs: for (component, fp, object) in refs: req_ticket_cache = RequirementTicketCache(self.env, ticket.id, component, fp, object) if not (req_ticket_cache.exists): req_ticket_cache.insert()
def ticket_deleted(self, ticket): """Called when a ticket is deleted. This basically takes the ticket that was deleted and removes all relationships from the database mapping requirements to the the ticket. """ req_ticket_cache = RequirementTicketCache(self.env, ticket.id) if (req_ticket_cache.ticket_in_table): req_ticket_cache.delete()
def ticket_changed(self, ticket, comment, author, old_values): """Called when a ticket is modified. The method takes the ticket, deletes the old relationships mapping requirements to the ticket and creates new ones. """ # delete all old information related to this ticket: req_ticket_cache = RequirementTicketCache(self.env, ticket.id) if (req_ticket_cache.ticket_in_table): req_ticket_cache.delete() # insert current information: searchfields = ['summary', 'description', 'keywords'] for field in searchfields: refs = RequirementCacheSystem( \ self.env).parse_data_for_req_references(ticket[field]) if refs: for (component, fp, object) in refs: req_ticket_cache = RequirementTicketCache(self.env, ticket.id, component, fp, object) if not (req_ticket_cache.exists): req_ticket_cache.insert() # insert information gleaned from the comment history: comments = self._get_comments(ticket.id) if comments: for comment in comments: refs = RequirementCacheSystem( \ self.env).parse_data_for_req_references(comment) if refs: for (component, fp, object) in refs: req_ticket_cache = RequirementTicketCache(self.env, ticket.id, component, fp, object) if not (req_ticket_cache.exists): req_ticket_cache.insert()
def index_tickets(self, db=None): """Index all requirement references found in tickets. Iterate through all the ticket descriptions, their recorded changes, and their associated comments in the database parsing them for references to requirements. If new references are found then they are added appropriately to the database cache tables. """ if not db: db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute("SELECT id, description FROM ticket") for id, description in cursor: # parse the description refs = self.parse_data_for_req_references(description) if refs: for (component, fp, object) in refs: req_ticket_cache = RequirementTicketCache(self.env, id, component, fp, object) if not (req_ticket_cache.exists): req_ticket_cache.insert(db=db) cursor.execute("SELECT ticket, newvalue FROM ticket_change WHERE field = 'description' or field = 'comment'") for id, textdata in cursor: # parse the description modification or comment refs = self.parse_data_for_req_references(textdata) if refs: for (component, fp, object) in refs: req_ticket_cache = RequirementTicketCache(self.env, id, component, fp, object) if not (req_ticket_cache.exists): req_ticket_cache.insert(db=db)