summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-03-07 14:25:17 +0100
committerThibault Delavallée <tde@openerp.com>2013-03-07 14:25:17 +0100
commitfcea61b6ebce561743bfe3876dd5a705ce6a7bad (patch)
treed7c805a2deb3281d9227cb2958a29854f01cdd4c
parent1aac220ee25b7dc45c073c76112e50c68a3c4944 (diff)
[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
-rw-r--r--addons/mail/data/mail_data.xml13
-rw-r--r--addons/mail/mail_thread.py20
2 files changed, 33 insertions, 0 deletions
diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml
index 3f517ee7858..02cfd626768 100644
--- a/addons/mail/data/mail_data.xml
+++ b/addons/mail/data/mail_data.xml
@@ -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>
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 173ec951b32..2d43b93dd9a 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -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
#------------------------------------------------------