From 8db59acf029b1f18170e3bf42cc57e6576ad1182 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 2 Feb 2015 12:21:21 +0100 Subject: [PATCH] [FIX] don't duplicate core functionality --- attachments_to_filesystem/__openerp__.py | 8 +++-- .../models/ir_attachment.py | 35 ++----------------- 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/attachments_to_filesystem/__openerp__.py b/attachments_to_filesystem/__openerp__.py index e03784d8..2e3b25ce 100644 --- a/attachments_to_filesystem/__openerp__.py +++ b/attachments_to_filesystem/__openerp__.py @@ -39,9 +39,11 @@ root path (the odoo configuration value `root_path`) in a subdirectory called Then it will create a cron job that does the actual transfer and schedule it for 01:42 at night in the installing user's time zone. The cronjob will do a -maximum of 10000 conversions, after which it creates a new cronjob to run for -the next batch 24 hours later. The limit is configurable with the parameter -`attachments_to_filesystem.limit`. +maximum of 10000 conversions per run and is run every night. +The limit is configurable with the parameter `attachments_to_filesystem.limit`. + +After all attachments are migrated (the log will show then `moving 0 +attachments to filestore`), you can disable or delete the cronjob. If you need to run the migration synchronously during install, set the parameter `attachments_to_filesystem.move_during_init` *before* installing this diff --git a/attachments_to_filesystem/models/ir_attachment.py b/attachments_to_filesystem/models/ir_attachment.py index 109d6071..5baf75b8 100644 --- a/attachments_to_filesystem/models/ir_attachment.py +++ b/attachments_to_filesystem/models/ir_attachment.py @@ -75,6 +75,8 @@ class IrAttachment(Model): 'nextcall': next_night.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'doall': True, + 'interval_type': 'days', + 'interval_number': 1, }, context=context) @@ -110,36 +112,3 @@ class IrAttachment(Model): if not counter % (len(attachment_ids) / 100 or limit): logging.info('moving attachments: %d done', counter) counter += 1 - # see if we need to create a new cronjob for the next batch - if ir_attachment.search( - cr, uid, [('db_datas', '!=', False)], limit=1, - context=context): - module_name = __name__.split('.')[-3] - ir_cron = self.pool['ir.cron'] - last_job_id = ir_cron.search( - cr, uid, - [ - ('model', '=', 'ir.attachment'), - ('function', '=', '_attachments_to_filesystem_cron'), - ], - order='nextcall desc', - limit=1, - context=context) - if not last_job_id: - return - new_job_data = ir_cron.copy_data( - cr, uid, last_job_id[0], context=context) - new_job_data.update( - nextcall=( - datetime.strptime( - new_job_data['nextcall'], - DEFAULT_SERVER_DATETIME_FORMAT) + - relativedelta(days=1) - ).strftime(DEFAULT_SERVER_DATETIME_FORMAT), - ) - self.pool['ir.model.data']._update( - cr, uid, 'ir.cron', module_name, - new_job_data, - xml_id='config_parameter_ir_attachment_location' + str( - last_job_id[0]), - context=context)