[IMP] mail: added a cron job to delete mail attachments (lost user input or reports generated on-the-fly). They have: res_model = mail.compose.message; res_id 0; more than one day of inactivity.

bzr revid: tde@openerp.com-20130307132517-4xivu90dzn3o744a
This commit is contained in:
Thibault Delavallée 2013-03-07 14:25:17 +01:00
parent 1aac220ee2
commit fcea61b6eb
2 changed files with 33 additions and 0 deletions

View File

@ -27,6 +27,19 @@
<field name="priority">1000</field>
</record>
<record id="ir_cron_mail_garbage_collect_attachments" model="ir.cron">
<field name="name">Garbage Collect Mail Attachments</field>
<field eval="True" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">weeks</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field name="model">mail.thread</field>
<field name="function">_garbage_collect_attachments</field>
<field name="args">()</field>
</record>
<!-- Discussion subtype for messaging / Chatter -->
<record id="mt_comment" model="mail.message.subtype">
<field name="name">Discussions</field>

View File

@ -389,6 +389,26 @@ class mail_thread(osv.AbstractModel):
return [('message_unread', '=', True)]
return []
def _garbage_collect_attachments(self, cr, uid, context=None):
""" Garbage collect lost mail attachments. Those are attachments
- linked to res_model 'mail.compose.message', the composer wizard
- with res_id 0, because they were created outside of an existing
wizard (typically user input through Chatter or reports
created on-the-fly by the templates)
- unused since at least one day (create_date and write_date)
"""
limit_date = datetime.datetime.utcnow() - datetime.timedelta(days=1)
limit_date_str = datetime.datetime.strftime(limit_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
ir_attachment_obj = self.pool.get('ir.attachment')
attach_ids = ir_attachment_obj.search(cr, uid, [
('res_model', '=', 'mail.compose.message'),
('res_id', '=', 0),
('create_date', '<', limit_date_str),
('write_date', '<', limit_date_str),
], context=context)
ir_attachment_obj.unlink(cr, uid, attach_ids, context=context)
return True
#------------------------------------------------------
# Email specific
#------------------------------------------------------