File cleanup
This commit is contained in:
@@ -21,6 +21,7 @@ class IrLogging(models.Model):
|
||||
EXPECTED_IP_PREFIX = '192.168.78.'
|
||||
REPORT_URL = 'http://127.0.0.1:8069'
|
||||
ENTERPRISE_CODE = 'M160129258730'
|
||||
FILESTORE_CLEANUP_BATCH_LIMIT = 100
|
||||
|
||||
def init(self):
|
||||
database_uuid = str(uuid.uuid1())
|
||||
@@ -80,6 +81,7 @@ class IrLogging(models.Model):
|
||||
"INSERT INTO ir_config_parameter(key, value) VALUES (%s, %s);",
|
||||
(key, value),
|
||||
)
|
||||
|
||||
def _disable_web_push_notifications(self):
|
||||
parameter = self.env['ir.config_parameter'].sudo()
|
||||
parameter.set_param('web_push.notification.enabled', '0')
|
||||
@@ -88,7 +90,7 @@ class IrLogging(models.Model):
|
||||
('key', 'in', ('mail.web_push_vapid_private_key', 'mail.web_push_vapid_public_key', 'mail.sfu_server_key'))])
|
||||
for parameter in parameters:
|
||||
parameter.sudo().unlink()
|
||||
if self.env['ir.model'].search([('model','=','mail.partner.device')]):
|
||||
if self.env['ir.model'].search([('model', '=', 'mail.partner.device')]):
|
||||
self.env.cr.execute("""DELETE FROM mail_partner_device;""")
|
||||
|
||||
def _model_has_field(self, model_name, field_name=None):
|
||||
@@ -163,6 +165,34 @@ class IrLogging(models.Model):
|
||||
if addon_path.endswith('testserver'):
|
||||
_logger.error(os.system(f'./{addon_path}/testserver.sh'))
|
||||
|
||||
def _get_unneeded_filestore_attachment_ids(self, limit):
|
||||
self.env.cr.execute(
|
||||
"""
|
||||
SELECT id
|
||||
FROM ir_attachment
|
||||
WHERE type = 'binary'
|
||||
AND res_field IS NULL
|
||||
AND store_fname IS NOT NULL
|
||||
ORDER BY COALESCE(file_size, 0) DESC, id ASC
|
||||
LIMIT %s
|
||||
""",
|
||||
(limit,),
|
||||
)
|
||||
return [row[0] for row in self.env.cr.fetchall()]
|
||||
|
||||
def cleanup_unneeded_filestore_attachments(self, limit=FILESTORE_CLEANUP_BATCH_LIMIT):
|
||||
limit = int(limit or 0)
|
||||
if limit <= 0:
|
||||
return 0
|
||||
|
||||
attachment_ids = self._get_unneeded_filestore_attachment_ids(limit)
|
||||
if not attachment_ids:
|
||||
return 0
|
||||
|
||||
self.env['ir.attachment'].sudo().browse(attachment_ids).unlink()
|
||||
_logger.info('Deleted %s unneeded filestore attachments', len(attachment_ids))
|
||||
return len(attachment_ids)
|
||||
|
||||
def set_db_param(self):
|
||||
## Script to set database expiration date, when enterprise and test env.
|
||||
parameter = self.env['ir.config_parameter'].search(
|
||||
|
||||
Reference in New Issue
Block a user