[MERGE] forward port of branch saas-3 up to bdc4dd4
authorChristophe Simonis <chs@odoo.com>
Fri, 27 Jun 2014 14:06:37 +0000 (16:06 +0200)
committerChristophe Simonis <chs@odoo.com>
Fri, 27 Jun 2014 14:06:37 +0000 (16:06 +0200)
1  2 
addons/web/static/src/js/view_list.js
addons/web/static/src/js/views.js
addons/website/models/ir_http.py
addons/website/views/website_templates.xml
openerp/modules/loading.py
openerp/service/db.py

Simple merge
Simple merge
Simple merge
Simple merge
@@@ -148,10 -140,28 +148,28 @@@ def exp_get_progress(id)
              self_actions.pop(id)
              return 1.0, users
          else:
 -            e = self_actions[id]['exception'] # TODO this seems wrong: actions[id]['traceback'] is set, but not 'exception'.
 -            self_actions.pop(id)
 -            raise Exception, e
 +            a = self_actions.pop(id)
 +            exc, tb = a['exception'], a['traceback']
 +            raise Exception, exc, tb
  
+ def _drop_conn(cr, db_name):
+     # Try to terminate all other connections that might prevent
+     # dropping the database
+     try:
+         # PostgreSQL 9.2 renamed pg_stat_activity.procpid to pid:
+         # http://www.postgresql.org/docs/9.2/static/release-9-2.html#AEN110389
+         pid_col = 'pid' if cr._cnx.server_version >= 90200 else 'procpid'
+         cr.execute("""SELECT pg_terminate_backend(%(pid_col)s)
+                       FROM pg_stat_activity
+                       WHERE datname = %%s AND
+                             %(pid_col)s != pg_backend_pid()""" % {'pid_col': pid_col},
+                    (db_name,))
+     except Exception:
+         pass
  def exp_drop(db_name):
      if db_name not in exp_list(True):
          return False
@@@ -330,10 -277,10 +335,11 @@@ def exp_rename(old_name, new_name)
  
      db = openerp.sql_db.db_connect('postgres')
      with closing(db.cursor()) as cr:
 -        cr.autocommit(True) # avoid transaction block
 +        cr.autocommit(True)     # avoid transaction block
+         _drop_conn(cr, old_name)
          try:
              cr.execute('ALTER DATABASE "%s" RENAME TO "%s"' % (old_name, new_name))
 +            _logger.info('RENAME DB: %s -> %s', old_name, new_name)
          except Exception, e:
              _logger.error('RENAME DB: %s -> %s failed:\n%s', old_name, new_name, e)
              raise Exception("Couldn't rename database %s to %s: %s" % (old_name, new_name, e))