def move(self, ticket_id, author, env, delete=False): """ move a ticket to another environment env: environment to move to """ tables = {"attachment": "id", "ticket_change": "ticket"} # open the environment if it is a string if isinstance(env, basestring): base_path, _project = os.path.split(self.env.path) env = open_environment(os.path.join(base_path, env), use_cache=True) # get the old ticket old_ticket = Ticket(self.env, ticket_id) # make a new ticket from the old ticket values new_ticket = Ticket(env) new_ticket.values = old_ticket.values.copy() new_ticket.insert(when=old_ticket.time_created) # copy the changelog and attachment DBs for table, _id in tables.items(): for row in get_all_dict(self.env, "SELECT * FROM %s WHERE %s=%%s" % (table, _id), str(ticket_id)): row[_id] = new_ticket.id insert_row_from_dict(env, table, row) # copy the attachments src_attachment_dir = os.path.join(self.env.path, "attachments", "ticket", str(ticket_id)) if os.path.exists(src_attachment_dir): dest_attachment_dir = os.path.join(env.path, "attachments", "ticket") if not os.path.exists(dest_attachment_dir): os.makedirs(dest_attachment_dir) dest_attachment_dir = os.path.join(dest_attachment_dir, str(new_ticket.id)) shutil.copytree(src_attachment_dir, dest_attachment_dir) # note the previous location on the new ticket new_ticket.save_changes(author, "moved from %s" % self.env.abs_href("ticket", ticket_id)) # location of new ticket new_location = env.abs_href.ticket(new_ticket.id) if delete: old_ticket.delete() else: # close old ticket and point to new one old_ticket["status"] = u"closed" old_ticket["resolution"] = u"moved" old_ticket.save_changes(author, u"moved to %s" % new_location) if env.config["trac"].get("base_url"): return new_location else: return None
def _delete_tickets_from_milestone(self, db, milestone): tickets = get_tickets_for_milestone(self.env, db, milestone) for t in tickets: id = t['id'] ticket = Ticket(self.env, tkt_id=id, db=db) ticket.delete()
def move(self, ticket_id, author, env, delete=False): """ move a ticket to another environment env: environment to move to """ tables = {'attachment': 'id', 'ticket_change': 'ticket'} # open the environment if it is a string if isinstance(env, basestring): base_path, _project = os.path.split(self.env.path) env = open_environment(os.path.join(base_path, env), use_cache=True) # get the old ticket old_ticket = Ticket(self.env, ticket_id) # make a new ticket from the old ticket values new_ticket = Ticket(env) new_ticket.values = old_ticket.values.copy() new_ticket.insert(when=old_ticket.time_created) # copy the changelog and attachment DBs for table, _id in tables.items(): for row in get_all_dict( self.env, "SELECT * FROM %s WHERE %s=%%s" % (table, _id), str(ticket_id)): row[_id] = new_ticket.id insert_row_from_dict(env, table, row) # copy the attachments src_attachment_dir = os.path.join(self.env.path, 'attachments', 'ticket', str(ticket_id)) if os.path.exists(src_attachment_dir): dest_attachment_dir = os.path.join(env.path, 'attachments', 'ticket') if not os.path.exists(dest_attachment_dir): os.makedirs(dest_attachment_dir) dest_attachment_dir = os.path.join(dest_attachment_dir, str(new_ticket.id)) shutil.copytree(src_attachment_dir, dest_attachment_dir) # note the previous location on the new ticket new_ticket.save_changes( author, 'moved from %s' % self.env.abs_href('ticket', ticket_id)) # location of new ticket new_location = env.abs_href.ticket(new_ticket.id) if delete: old_ticket.delete() else: # close old ticket and point to new one old_ticket['status'] = u'closed' old_ticket['resolution'] = u'moved' old_ticket.save_changes(author, u'moved to %s' % new_location) if env.config['trac'].get('base_url'): return new_location else: return None
def move(self, ticket_id, author, env, delete=False): """ move a ticket to another environment env: environment to move to """ self.log.info( "Starting move of ticket %d to environment %r. delete: %r", ticket_id, env, delete) tables = {'attachment': 'id', 'ticket_change': 'ticket'} # open the environment if it is a string if isinstance(env, basestring): base_path, _project = os.path.split(self.env.path) env = open_environment(os.path.join(base_path, env), use_cache=True) PermissionCache(env, author).require('TICKET_CREATE') # get the old ticket old_ticket = Ticket(self.env, ticket_id) # make a new ticket from the old ticket values new_ticket = Ticket(env) new_ticket.values = old_ticket.values.copy() new_ticket.insert(when=old_ticket.values['time']) self.log.debug("Ticket inserted into target environment as id %s", new_ticket.id) # copy the changelog and attachment DBs for table, _id in tables.items(): for row in get_all_dict( self.env, "SELECT * FROM %s WHERE %s = %%s" % (table, _id), str(ticket_id)): row[_id] = new_ticket.id insert_row_from_dict(env, table, row) self.log.debug("Finished copying data from %r table", table) # copy the attachments src_attachment_dir = os.path.join(self.env.path, 'attachments', 'ticket', str(ticket_id)) if os.path.exists(src_attachment_dir): self.log.debug("Copying attachements from %r", src_attachment_dir) dest_attachment_dir = os.path.join(env.path, 'attachments', 'ticket') if not os.path.exists(dest_attachment_dir): os.makedirs(dest_attachment_dir) dest_attachment_dir = os.path.join(dest_attachment_dir, str(new_ticket.id)) shutil.copytree(src_attachment_dir, dest_attachment_dir) # note the previous location on the new ticket if delete: new_ticket.save_changes( author, 'moved from %s (ticket deleted)' % self.env.abs_href()) else: new_ticket.save_changes( author, 'moved from %s' % self.env.abs_href('ticket', ticket_id)) self.log.info("Finished making new ticket @ %r", env.abs_href('ticket', ticket_id)) if delete: self.log.debug("Deleting old ticket") old_ticket.delete() if env.base_url: return env.abs_href('ticket', new_ticket.id) else: self.log.debug("Marking old ticket as duplicate.") # location of new ticket if env.base_url: target_name = env.abs_href('ticket', new_ticket.id) else: target_name = "{0}:#{1}".format(env.project_name, new_ticket.id) # close old ticket and point to new one old_ticket['status'] = u'closed' old_ticket['resolution'] = u'duplicate' old_ticket.save_changes(author, u'moved to %s' % target_name)