| | 1 | # -*- coding: iso8859-1 -*- |
| | 2 | # |
| | 3 | # Copyright (C) 2005 Edgewall Software |
| | 4 | # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de> |
| | 5 | # All rights reserved. |
| | 6 | # |
| | 7 | # This software is licensed as described in the file COPYING, which |
| | 8 | # you should have received as part of this distribution. The terms |
| | 9 | # are also available at http://trac.edgewall.com/license.html. |
| | 10 | # |
| | 11 | # This software consists of voluntary contributions made by many |
| | 12 | # individuals. For the exact contribution history, see the revision |
| | 13 | # history and logs, available at http://projects.edgewall.com/trac/. |
| | 14 | # |
| | 15 | # Author: Manuzhai <manuzhai@gmail.com> |
| | 16 | |
| | 17 | import os |
| | 18 | |
| | 19 | from trac.core import * |
| | 20 | from webadmin.web_ui import IAdminPageProvider |
| | 21 | |
| | 22 | __all__ = [] |
| | 23 | |
| | 24 | class ResyncAdminPage(Component): |
| | 25 | |
| | 26 | implements(IAdminPageProvider) |
| | 27 | |
| | 28 | # IAdminPageProvider methods |
| | 29 | |
| | 30 | def get_admin_pages(self, req): |
| | 31 | if (req.perm.has_permission('TRAC_ADMIN') and |
| | 32 | hasattr(self.env.get_repository(), 'sync')): |
| | 33 | yield ('general', 'General', 'resync', 'Resynchronization') |
| | 34 | |
| | 35 | def do_resync(self): |
| | 36 | cnx = self.env.get_db_cnx() |
| | 37 | cursor = cnx.cursor() |
| | 38 | cursor.execute("DELETE FROM revision") |
| | 39 | cursor.execute("DELETE FROM node_change") |
| | 40 | repos = self.env.get_repository() |
| | 41 | cursor.execute("DELETE FROM system WHERE name='repository_dir'") |
| | 42 | cursor.execute("INSERT INTO system (name,value) " |
| | 43 | "VALUES ('repository_dir',%s)", (repos.name,)) |
| | 44 | repos.sync() |
| | 45 | |
| | 46 | def process_admin_request(self, req, cat, page, path_info): |
| | 47 | if req.method == 'POST': |
| | 48 | self.do_resync() |
| | 49 | req.hdf['resync.results'] = 'The environment has been synchronized.' |
| | 50 | |
| | 51 | return 'admin_resync.cs', None |