Author: astaric
Date: Mon Apr 29 09:45:38 2013
New Revision: 1476944

URL: http://svn.apache.org/r1476944
Log:
Upgrade to multiproduct moves all wikis to the default product.

Modified:
    bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py
    bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py

Modified: bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py?rev=1476944&r1=1476943&r2=1476944&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py Mon Apr 29 
09:45:38 2013
@@ -225,7 +225,7 @@ class MultiProductSystem(Component):
 
                 self._insert_default_product(db)
                 self._upgrade_tickets(db, TICKET_TABLES, create_temp_table)
-                self._upgrade_wikis(db, create_temp_table, table_columns)
+                self._upgrade_wikis(db, create_temp_table)
                 self._upgrade_system_tables(db, create_temp_table)
                 self._soft_link_repositories_to_default_product(db)
                 self._upgrade_table_system(SYSTEM_TABLES, create_temp_table, 
db)
@@ -380,76 +380,31 @@ class MultiProductSystem(Component):
                    (table, cols, cols, '', temp_table_name))
             self._drop_temp_table(db, temp_table_name)
 
-    def _upgrade_wikis(self, db, create_temp_table,
-                       table_columns):
+    def _upgrade_wikis(self, db, create_temp_table):
         # migrate wiki table
         # - populate system wikis to all products + global scope
         # - update wiki attachment product to match wiki product
         table = 'wiki'
         temp_table_name, cols = create_temp_table(table)
-        self.log.info("Migrating wikis to global context")
-        db("""INSERT INTO %s (%s, product) SELECT %s, '' FROM %s""" %
-           (table, cols, cols, temp_table_name))
+        self.log.info("Migrating wikis to default product")
+        db("""INSERT INTO %(table)s (%(cols)s, product)
+                   SELECT %(cols)s, '%(default_product)s' FROM %(temp_table)s
+           """ % dict(table=table,
+                      temp_table=temp_table_name,
+                      cols=cols,
+                      default_product=DEFAULT_PRODUCT,))
         db("""UPDATE attachment
-                 SET product=''
-               WHERE attachment.type='wiki'""")
-        for wiki_name, wiki_version, wiki_product in db("""
-                        SELECT name, version, product FROM %s""" % table):
-            attachment_cols = ','.join(table_columns['attachment'])
-            if wiki_name in self.system_wiki_list:
-                for product in Product.select(self.env):
-                    db("""INSERT INTO %s (%s, product)
-                                  SELECT %s, '%s' FROM %s
-                                  WHERE name='%s' AND version=%s AND 
product='%s'""" %
-                       (table, cols, cols, product.prefix, table,
-                        wiki_name, wiki_version, wiki_product))
-                    db("""INSERT INTO attachment (%(cols)s, product)
-                                  SELECT %(cols)s, '%(new_product)s'
-                                    FROM attachment a
-                                   WHERE type='wiki'
-                                     AND id='%(wiki_name)s'
-                                     AND product='%(old_product)s'
-                                     AND NOT EXISTS(SELECT * FROM attachment
-                                                     WHERE type='wiki'
-                                                       AND id='%(wiki_name)s'
-                                                       AND 
product='%(new_product)s')
-                               """ % dict(cols=attachment_cols,
-                                          wiki_name=wiki_name,
-                                          old_product=wiki_product,
-                                          new_product=product.prefix))
-                    self._migrate_attachments(
-                        db("""SELECT type, id, filename
-                                        FROM attachment
-                                       WHERE type='wiki'
-                                         AND id='%s'
-                                         AND product='%s'
-                                   """ % (wiki_name, DEFAULT_PRODUCT)),
-                        to_product=DEFAULT_PRODUCT,
-                        copy=True
-                    )
-            else:
-                self.log.info("Moving wiki page '%s' to default product",
-                              wiki_name)
-                db("""UPDATE wiki
-                              SET product='%s'
-                              WHERE name='%s' AND version=%s AND product='%s'
-                           """ % (DEFAULT_PRODUCT,
-                                  wiki_name, wiki_version, wiki_product))
-                db("""UPDATE attachment
-                                 SET product='%s'
-                               WHERE type='wiki'
-                                 AND id='%s'
-                                 AND product='%s'
-                           """ % (DEFAULT_PRODUCT, wiki_name, wiki_product))
-                self._migrate_attachments(
-                    db("""SELECT type, id, filename
-                                    FROM attachment
-                                   WHERE type='wiki'
-                                     AND id='%s'
-                                     AND product='%s'
-                               """ % (wiki_name, DEFAULT_PRODUCT)),
-                    to_product=DEFAULT_PRODUCT,
-                )
+                 SET product='%s'
+               WHERE attachment.type='wiki'
+           """ % DEFAULT_PRODUCT)
+        self._migrate_attachments(
+            db("""SELECT type, id, filename
+                    FROM attachment
+                   WHERE type='wiki'
+                     AND product='%s'
+               """ % (DEFAULT_PRODUCT)),
+            to_product=DEFAULT_PRODUCT,
+        )
         self._drop_temp_table(db, temp_table_name)
 
     def _migrate_attachments(self, attachments, to_product=None, copy=False):

Modified: bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py?rev=1476944&r1=1476943&r2=1476944&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py Mon Apr 29 
09:45:38 2013
@@ -135,7 +135,7 @@ class EnvironmentUpgradeTestCase(unittes
                            WHERE product='@'
                              AND type='wiki'""")), 1)
 
-    def test_upgrade_duplicates_system_wikis_to_products(self):
+    def test_upgrade_moves_system_wikis_to_products(self):
         with self.env.db_direct_transaction as db:
             db("""INSERT INTO wiki (name, version) VALUES ('WikiStart', 1)""")
             db("""INSERT INTO attachment (type, id, filename)
@@ -152,11 +152,11 @@ class EnvironmentUpgradeTestCase(unittes
                            WHERE product='@'
                              AND type='wiki'""")), 1)
             self.assertEqual(
-                len(db("""SELECT * FROM wiki WHERE product=''""")), 1)
+                len(db("""SELECT * FROM wiki WHERE product=''""")), 0)
             self.assertEqual(
                 len(db("""SELECT * FROM attachment
                            WHERE product=''
-                             AND type='wiki'""")), 1)
+                             AND type='wiki'""")), 0)
 
     def test_upgrade_copies_content_of_system_tables_to_all_products(self):
         mp = MultiProductSystem(self.env)
@@ -175,7 +175,6 @@ class EnvironmentUpgradeTestCase(unittes
             db("""INSERT INTO version (name) VALUES ('foobar')""")
             db("""INSERT INTO enum (type, name) VALUES ('a', 'b')""")
             db("""INSERT INTO permission VALUES ('x', 'TICKET_VIEW')""")
-            db("""INSERT INTO wiki (name, version) VALUES ('WikiStart', 1)""")
             db("""INSERT INTO report (title) VALUES ('x')""")
 
         self._enable_multiproduct()
@@ -189,8 +188,8 @@ class EnvironmentUpgradeTestCase(unittes
                     len(rows), 6,
                     "Wrong number of lines in %s (%d instead of %d)\n%s"
                     % (table, len(rows), 6, rows))
-            for table in ('wiki', 'permission'):
-                # Permissions and wikis also hold rows for global product.
+            for table in ('permission',):
+                # Permissions also hold rows for global product.
                 rows = db("SELECT * FROM %s" % table)
                 self.assertEqual(
                     len(rows), 7,
@@ -216,22 +215,6 @@ class EnvironmentUpgradeTestCase(unittes
         for attachment in attachments:
             self.assertEqual(attachment.open().read(), 'Hello World!')
 
-    def test_upgrading_database_copies_attachments_for_system_wikis(self):
-        wiki = self.insert_wiki('WikiStart', 'content')
-        self.add_attachment(wiki.resource,
-                            self._create_file_with_content('Hello World!'))
-
-        self._enable_multiproduct()
-        self.env.upgrade()
-
-        with self.product('@'):
-            attachments = list(
-                Attachment.select(self.env, 'wiki', 'WikiStart'))
-        attachments.extend(Attachment.select(self.env, 'wiki', 'WikiStart'))
-        self.assertEqual(len(attachments), 2)
-        for attachment in attachments:
-            self.assertEqual(attachment.open().read(), 'Hello World!')
-
     def test_can_upgrade_database_with_ticket_attachment_with_text_ids(self):
         with self.env.db_direct_transaction as db:
             db("""INSERT INTO attachment (id, type, filename)


Reply via email to