Changeset 601


Ignore:
Timestamp:
10/17/08 12:56:13 (5 years ago)
Author:
cbalan
Message:

WikiTools?: - Added tags support & updated debug messages.

Location:
trunk/plugins/wikitoolsplugin
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/wikitoolsplugin/setup.py

    r583 r601  
    2020            'tracwikitools.relation.wiki = tracwikitools.relation.wiki', 
    2121            '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' 
    2325            ]} 
    2426) 
  • trunk/plugins/wikitoolsplugin/tracwikitools/rename/__init__.py

    r576 r601  
    11from tracwikitools.rename.api import * 
    22from tracwikitools.rename.wiki import * 
     3from tracwikitools.rename.properties import * 
     4from tracwikitools.rename.tags import * 
  • trunk/plugins/wikitoolsplugin/tracwikitools/rename/api.py

    r585 r601  
    99import urllib 
    1010import re 
     11import traceback 
    1112 
    1213from trac.core import * 
     
    6566         
    6667            # 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)) 
    6869            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) 
    6970         
    7071            # 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)) 
    7273            cursor.execute('UPDATE wiki SET name=%s WHERE name=%s', (new_name,old_name)) 
    7374         
    7475            # 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)) 
    7677            cursor.execute('UPDATE attachment SET id=%s WHERE type=%s AND id=%s', (new_name,'wiki',old_name)) 
    7778         
    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)) 
    7980            if cursor.rowcount > 0: 
    8081                # 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)) 
    8283                from_path = os.path.join(self.env.path, 'attachments', 'wiki', urllib.quote(old_name)) 
    8384                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)) 
    8586                os.renames(from_path, to_path) 
    8687         
    8788            # 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             
    8991            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)) 
    9193            cursor.execute(sql, ('%[wiki:'+old_name+'%',)) 
    9294         
    9395            # Rewrite all links to the old page, such as to point to the new page 
    9496            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])) 
    9698                newtext = re.sub('\[wiki:%s'%old_name,'[wiki:%s'%new_name,row[2]) 
    9799                cursor.execute('UPDATE wiki SET text=%s WHERE name=%s AND version=%s', (newtext,row[1],row[0])) 
     
    107109                db.rollback() 
    108110            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 properties 
    122         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 related 
    127         cursor.execute("UPDATE resource_custom" 
    128                        " SET value=%s " 
    129                        " WHERE value=%s", (page.name, old_name)) 
    130          
    131         # update related by  
    132         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.