Created
October 23, 2008 02:27
-
-
Save fairchild/18899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Query LH for ticket, and update db cache. Allow ticket number or lh ticket object | |
def self.update_or_create_from_lighthouse(ticket, project_id) | |
lh_ticket = case ticket.class | |
when Fixnum: Ticket.retrieve_from_lh(ticket, project_id) | |
when Lighthouse::Ticket: Ticket.retrieve_from_lh(ticket.number, project_id) | |
else return false | |
end | |
if lh_ticket == 404 #delete ticket if it was deleted from LH | |
Ticket[:number=>ticket, :project_id=>project_id].destroy | |
else | |
if ticket = Ticket[:number=>lh_ticket.last['number'], :project_id=>project_id] | |
ticket.update( self.build_attributes(lh_ticket) ) | |
else | |
#TODO: add exception handling when create fails. probably just retry a few times | |
t=Ticket.new( self.build_attributes(lh_ticket) ) | |
t.save | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment