[migration] fire hooks in postcreate by default (closes #1417110)

also turn usage of hooks_control to relevent session's method

authorKatia Saurfelt <katia.saurfelt@logilab.fr>
changeset1d1cfc97f6b9
branchdefault
phasepublic
hiddenno
parent revision#517fbaad0e6e [bw compat] add compatibility for import of former VRegistry
child revision#543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
files modified by this revision
server/migractions.py
# HG changeset patch
# User Katia Saurfelt <katia.saurfelt@logilab.fr>
# Date 1328867117 -3600
# Fri Feb 10 10:45:17 2012 +0100
# Node ID 1d1cfc97f6b92e55b389a113910ad0be8f98df29
# Parent 517fbaad0e6e1c81ed5b4cc9897a3e2dbaa3d121
[migration] fire hooks in postcreate by default (closes #1417110)

also turn usage of hooks_control to relevent session's method

diff --git a/server/migractions.py b/server/migractions.py
@@ -56,11 +56,10 @@
1                               PURE_VIRTUAL_RTYPES,
2                               CubicWebRelationSchema, order_eschemas)
3  from cubicweb.cwvreg import CW_EVENT_MANAGER
4  from cubicweb.dbapi import get_repository, repo_connect
5  from cubicweb.migration import MigrationHelper, yes
6 -from cubicweb.server.session import hooks_control
7  from cubicweb.server import hook
8  try:
9      from cubicweb.server import SOURCE_TYPES, schemaserial as ss
10      from cubicweb.server.utils import manager_userpasswd
11      from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX
@@ -150,11 +149,11 @@
12              if options.backup_db is None:
13                  self.backup_database()
14              elif options.backup_db:
15                  self.backup_database(askconfirm=False)
16          # disable notification during migration
17 -        with hooks_control(self.session, self.session.HOOKS_ALLOW_ALL, 'notification'):
18 +        with self.session.allow_all_hooks_but('notification'):
19              super(ServerMigrationHelper, self).migrate(vcconf, toupgrade, options)
20 
21      def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs):
22          try:
23              return super(ServerMigrationHelper, self).cmd_process_script(
@@ -374,10 +373,13 @@
24              confirm = self.confirm
25              execscript_confirm = self.execscript_confirm
26              self.confirm = yes
27              self.execscript_confirm = yes
28              try:
29 +                if event == 'postcreate':
30 +                    with self.session.allow_all_hooks_but():
31 +                        return self.cmd_process_script(apc, funcname, *args, **kwargs)
32                  return self.cmd_process_script(apc, funcname, *args, **kwargs)
33              finally:
34                  self.confirm = confirm
35                  self.execscript_confirm = execscript_confirm
36                  if self.config.free_wheel:
@@ -696,12 +698,13 @@
37                      continue
38                  self.cmd_add_relation_definition(str(fromtype), rschema.type,
39                                                   str(totype))
40          # execute post-create files
41          for cube in reversed(newcubes):
42 -            self.cmd_exec_event_script('postcreate', cube)
43 -            self.commit()
44 +            with self.session.allow_all_hooks_but():
45 +                self.cmd_exec_event_script('postcreate', cube)
46 +                self.commit()
47 
48      def cmd_remove_cube(self, cube, removedeps=False):
49          removedcubes = super(ServerMigrationHelper, self).cmd_remove_cube(
50              cube, removedeps)
51          if not removedcubes: