diff --git a/document_reindex/README.rst b/document_reindex/README.rst new file mode 100644 index 00000000..f7dbf8f7 --- /dev/null +++ b/document_reindex/README.rst @@ -0,0 +1,33 @@ +Reindex documents +================= + +This module allows you to reindex documents in case they were uploaded when the right configuration for indexation was missing. + +Usage +===== + +To reindex a single document, open its form and click the `Reindex document` button. + +To reindex all documents, go to Settings / Configuration / Knowledge, check the box `Reindex all documents` or `Reindex all unindexed documents` and click apply. Those are done in the background, so watch your logs for the process to finish. + +Credits +======= + +Contributors +------------ + +* Holger Brunn +* Icon courtesy of http://www.picol.org (refresh.svg) and https://github.com/odoo/odoo/blob/8.0/addons/knowledge/static/description/icon.png + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/document_reindex/__init__.py b/document_reindex/__init__.py new file mode 100644 index 00000000..48f5a694 --- /dev/null +++ b/document_reindex/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import models diff --git a/document_reindex/__openerp__.py b/document_reindex/__openerp__.py new file mode 100644 index 00000000..c69c5ba5 --- /dev/null +++ b/document_reindex/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Reindex documents", + "version": "1.0", + "author": "Therp BV", + "license": "AGPL-3", + "category": "Knowledge Management", + "summary": "Reindex your already uploaded documents", + "depends": [ + 'document', + ], + "data": [ + "views/knowledge_config_settings.xml", + "views/ir_attachment.xml", + ], + "auto_install": False, + "installable": True, + "application": False, + "external_dependencies": { + 'python': [], + }, +} diff --git a/document_reindex/models/__init__.py b/document_reindex/models/__init__.py new file mode 100644 index 00000000..a9c96dea --- /dev/null +++ b/document_reindex/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import ir_attachment +from . import knowledge_config_settings diff --git a/document_reindex/models/ir_attachment.py b/document_reindex/models/ir_attachment.py new file mode 100644 index 00000000..5666f6a2 --- /dev/null +++ b/document_reindex/models/ir_attachment.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models, fields, api + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + @api.multi + def document_reindex(self): + for this in self: + if not this.datas: + continue + mimetype, indexed_content = this._index( + this.datas.decode('base64'), this.datas_fname, this.file_type) + this.write({ + 'file_type': mimetype, + 'index_content': indexed_content, + }) + + @api.model + def document_reindex_all(self): + self.search([('datas', '!=', False)]).document_reindex() + + @api.model + def document_reindex_unindexed(self): + self.search([ + ('datas', '!=', False), + '|', + ('index_content', '=', False), + ('index_content', '=', ''), + ]).document_reindex() diff --git a/document_reindex/models/knowledge_config_settings.py b/document_reindex/models/knowledge_config_settings.py new file mode 100644 index 00000000..b24b10f6 --- /dev/null +++ b/document_reindex/models/knowledge_config_settings.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models, fields, api + + +class KnowledgeConfigSettings(models.TransientModel): + _inherit = 'knowledge.config.settings' + + document_reindex_all = fields.Boolean('Reindex all documents') + document_reindex_unindexed = fields.Boolean('Reindex unindexed documents') + + @api.one + def set_document_reindex(self): + if self.document_reindex_all: + self.document_reindex_create_cronjob('document_reindex_all') + if self.document_reindex_unindexed: + self.document_reindex_create_cronjob('document_reindex_unindexed') + + @api.multi + def document_reindex_create_cronjob(self, function): + self.env['ir.cron'].create({ + 'name': function, + 'model': 'ir.attachment', + 'function': function, + }) diff --git a/document_reindex/static/description/icon.png b/document_reindex/static/description/icon.png new file mode 100644 index 00000000..e106e973 Binary files /dev/null and b/document_reindex/static/description/icon.png differ diff --git a/document_reindex/views/ir_attachment.xml b/document_reindex/views/ir_attachment.xml new file mode 100644 index 00000000..af842f21 --- /dev/null +++ b/document_reindex/views/ir_attachment.xml @@ -0,0 +1,16 @@ + + + + + ir.attachment + + + +
+
+
+
+
+
+
diff --git a/document_reindex/views/knowledge_config_settings.xml b/document_reindex/views/knowledge_config_settings.xml new file mode 100644 index 00000000..2d91a7bf --- /dev/null +++ b/document_reindex/views/knowledge_config_settings.xml @@ -0,0 +1,21 @@ + + + + + knowledge.config.settings + + + +
+ +
+
+ +
+
+
+
+
+