misc/migration/3.10.0_Any.py
changeset 6427 c8a5ac2d1eaa
parent 6378 5a86a0c147bd
child 6488 a512dd258ee8
--- a/misc/migration/3.10.0_Any.py	Sat Oct 09 00:05:50 2010 +0200
+++ b/misc/migration/3.10.0_Any.py	Sat Oct 09 00:05:52 2010 +0200
@@ -1,3 +1,33 @@
+from cubicweb.server.session import hooks_control
+
+for uri, cfg in config.sources().items():
+    if uri in ('system', 'admin'):
+        continue
+    repo.sources_by_uri[uri] = repo.get_source(cfg['adapter'], uri, cfg)
+
+add_entity_type('CWSource')
+add_relation_definition('CWSource', 'cw_source', 'CWSource')
+add_entity_type('CWSourceHostConfig')
+
+with hooks_control(session, session.HOOKS_ALLOW_ALL, 'cw.sources'):
+    create_entity('CWSource', type=u'native', name=u'system')
+commit()
+
+sql('INSERT INTO cw_source_relation(eid_from,eid_to) '
+    'SELECT e.eid,s.cw_eid FROM entities as e, cw_CWSource as s '
+    'WHERE s.cw_name=e.type')
+commit()
+
+for uri, cfg in config.sources().items():
+    if uri in ('system', 'admin'):
+        continue
+    repo.sources_by_uri.pop(uri)
+    config = u'\n'.join('%s=%s' % (key, value) for key, value in cfg.items()
+                        if key != 'adapter')
+    create_entity('CWSource', name=unicode(uri), type=unicode(cfg['adapter']),
+                  config=config)
+commit()
+
 # rename cwprops for boxes/contentnavigation
 for x in rql('Any X,XK WHERE X pkey XK, '
              'X pkey ~= "boxes.%s" OR '