Hello Trac devs, I am working on a plugin that indexes attachments, and I wish to handle the indexing of both Trac 0.12 Attachment models and versioned Attachments as implemented in this branch:
https://github.com/moreati/trac-gitsvn/blob/0.12-versionedattachments/trac/attachment.py#L119 I'm currently instantiating Attachment(self.env, 'ticket', 42) and testing if it has a version attribute. I'm slightly concerned that Attachment's constructor might in future check parent_realm/id exists, and break this. def _reindex_attachment(self): db = self.env.get_read_db() cursor = db.cursor() canary = Attachment(self.env, 'ticket', 42) if hasattr(canary, 'version'): # Adapted from Attachment.select() cursor.execute(""" SELECT type, id, filename, version, description, size, time, author, ipnr, status, deleted FROM attachment JOIN (SELECT type AS c_type, id AS c_id, filename AS c_filename, MAX(version) AS c_version FROM attachment WHERE deleted IS NULL GROUP BY c_type, c_id, c_filename) AS current ON type = c_type AND id = c_id AND filename = c_filename AND version = c_version ORDER BY time""") else: cursor.execute( "SELECT type,id,filename,description,size,time,author,ipnr " "FROM attachment" ) for row in cursor: parent_realm, parent_id = row[0], row[1] attachment = Attachment(self.env, parent_realm, parent_id) attachment._from_database(*row[2:]) self.attachment_added(attachment) Is there a more robust way you can think of for doing this, or is Attachment(env, 'ticket', 42) a safe operation? Assuming I don't then try to call .insert() or similar With thanks, Alex -- Alex Willmer | Developer 2 Trinity Park, Birmingham, B37 7ES | United Kingdom M: +44 7557 752744 [email protected] | www.logica.com Logica UK Ltd, registered in UK (registered number 947968) Registered Office: 250 Brook Drive, Green Park, Reading RG2 6UA, United Kingdom Think green - keep it on the screen. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. -- You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en.
