Changeset 601
- Timestamp:
- 10/17/08 12:56:13 (5 years ago)
- Location:
- trunk/plugins/wikitoolsplugin
- Files:
-
- 2 added
- 3 edited
-
setup.py (modified) (1 diff)
-
tracwikitools/rename/__init__.py (modified) (1 diff)
-
tracwikitools/rename/api.py (modified) (3 diffs)
-
tracwikitools/rename/properties.py (added)
-
tracwikitools/rename/tags.py (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/wikitoolsplugin/setup.py
r583 r601 20 20 'tracwikitools.relation.wiki = tracwikitools.relation.wiki', 21 21 'tracwikitools.rename.api = tracwikitools.rename.api', 22 'tracwikitools.rename.wiki = tracwikitools.rename.wiki' 22 'tracwikitools.rename.wiki = tracwikitools.rename.wiki', 23 'tracwikitools.rename.properties = tracwikitools.rename.properties', 24 'tracwikitools.rename.tags = tracwikitools.rename.tags' 23 25 ]} 24 26 ) -
trunk/plugins/wikitoolsplugin/tracwikitools/rename/__init__.py
r576 r601 1 1 from tracwikitools.rename.api import * 2 2 from tracwikitools.rename.wiki import * 3 from tracwikitools.rename.properties import * 4 from tracwikitools.rename.tags import * -
trunk/plugins/wikitoolsplugin/tracwikitools/rename/api.py
r585 r601 9 9 import urllib 10 10 import re 11 import traceback 11 12 12 13 from trac.core import * … … 65 66 66 67 # Create a new page with the needed comment 67 self.log.debug( 'Inserting new page %r', new_wiki_page)68 self.log.debug("Wiki rename %s -> %s: - inserting new page."%(old_name, new_name)) 68 69 cursor.execute('INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)', new_wiki_page) 69 70 70 71 # Move all the old versions of the page 71 self.log.debug(" Moving all old versions of page")72 self.log.debug("Wiki rename %s -> %s: - moving all old versions of page."%(old_name, new_name)) 72 73 cursor.execute('UPDATE wiki SET name=%s WHERE name=%s', (new_name,old_name)) 73 74 74 75 # Move any attachments that are on the page 75 self.log.debug(" Moving all attachments in database")76 self.log.debug("Wiki rename %s -> %s: - moving all attachments in database."%(old_name, new_name)) 76 77 cursor.execute('UPDATE attachment SET id=%s WHERE type=%s AND id=%s', (new_name,'wiki',old_name)) 77 78 78 self.log.debug(" Found %s attachments on that page", cursor.rowcount)79 self.log.debug("Wiki rename %s -> %s: - found %s attachments on that page."%(old_name, new_name, cursor.rowcount)) 79 80 if cursor.rowcount > 0: 80 81 # Change the directory where the attachments are stored, if there were any 81 self.log.debug( 'Moving all attachments on file system')82 self.log.debug("Wiki rename %s -> %s: - moving all attachments on file system."%(old_name, new_name)) 82 83 from_path = os.path.join(self.env.path, 'attachments', 'wiki', urllib.quote(old_name)) 83 84 to_path = os.path.join(self.env.path, 'attachments', 'wiki', urllib.quote(new_name)) 84 self.log.debug( 'Moving from %r to %r', from_path, to_path)85 self.log.debug("Wiki rename %s -> %s: - moving from %r to %r'."%(old_name, new_name, from_path, to_path)) 85 86 os.renames(from_path, to_path) 86 87 87 88 # Get a list of all wiki pages containing links to the old page 88 self.log.debug("Trying to fix links") 89 self.log.debug("Wiki rename %s -> %s: - trying to fix links."%(old_name, new_name)) 90 89 91 sql = 'SELECT w1.version,w1.name,w1.text' + sqlbase + 'AND w1.text like %s' 90 self.log.debug( 'Running query %r', sql)92 self.log.debug("Wiki rename %s -> %s: - running query '%r'."%(old_name, new_name, sql)) 91 93 cursor.execute(sql, ('%[wiki:'+old_name+'%',)) 92 94 93 95 # Rewrite all links to the old page, such as to point to the new page 94 96 for row in list(cursor): 95 self.log.debug(" Found a page with a backlink in it: %s (v%s)", row[1], row[0])97 self.log.debug("Wiki rename %s -> %s: - found a page with a backlink in it: %s (v%s)."%(old_name, new_name, row[1], row[0])) 96 98 newtext = re.sub('\[wiki:%s'%old_name,'[wiki:%s'%new_name,row[2]) 97 99 cursor.execute('UPDATE wiki SET text=%s WHERE name=%s AND version=%s', (newtext,row[1],row[0])) … … 107 109 db.rollback() 108 110 raise 109 110 class ResourcePropertiesWikiRenameListener(Component):111 """Straightforward resource property mover.112 113 @todo: Revisit update queries.114 """115 116 implements(IWikiRenameListener)117 118 def wiki_page_renamed(self, page, old_name, db):119 cursor = db.cursor()120 121 # update properties122 cursor.execute("UPDATE resource_custom"123 " SET resource_id=%s "124 " WHERE resource_id=%s AND resource_realm='wiki'", (page.name, old_name))125 126 # update related127 cursor.execute("UPDATE resource_custom"128 " SET value=%s "129 " WHERE value=%s", (page.name, old_name))130 131 # update related by132 cursor.execute("UPDATE resource_custom"133 " SET value=%s "134 " WHERE value=%s", ('wiki:'+page.name, 'wiki:'+old_name))135 cursor.close()
Note: See TracChangeset
for help on using the changeset viewer.
