[IMP] db_manager: better uuid management
* Always change the uuid of a duplicate database by default * Clearer message when restoring a backup
This commit is contained in:
@@ -37,6 +37,7 @@ from openerp.modules import get_resource_path
|
||||
from openerp.tools import topological_sort
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools import ustr
|
||||
from openerp.tools.misc import str2bool
|
||||
from openerp import http
|
||||
from openerp.http import request, serialize_exception as _serialize_exception
|
||||
from openerp.exceptions import AccessError
|
||||
@@ -708,7 +709,7 @@ class Database(http.Controller):
|
||||
def restore(self, master_pwd, backup_file, name, copy=False):
|
||||
try:
|
||||
data = base64.b64encode(backup_file.read())
|
||||
request.session.proxy("db").restore(master_pwd, name, data, copy)
|
||||
request.session.proxy("db").restore(master_pwd, name, data, str2bool(copy))
|
||||
return http.local_redirect('/web/database/manager')
|
||||
except Exception, e:
|
||||
error = "Database restore error: %s" % e
|
||||
|
||||
@@ -208,10 +208,19 @@
|
||||
<input id="name" type="text" name="name" class="form-control" required="required"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label for="copy">This database might have been moved or copied.</label>
|
||||
<p class="help-block">In order to avoid conflicts between databases, Odoo needs to know if this database was moved or copied.
|
||||
If you don't know, answer "This database is a copy".</p>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input name="copy" type="checkbox" class="pull-right" value="1">
|
||||
<span>Generate a new database uuid.</span>
|
||||
<input name="copy" type="radio" class="pull-right" value="true" checked="1">
|
||||
This database is a copy
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input name="copy" type="radio" class="pull-right" value="false">
|
||||
This database was moved
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -102,6 +102,11 @@ def exp_duplicate_database(db_original_name, db_name):
|
||||
_drop_conn(cr, db_original_name)
|
||||
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (db_name, db_original_name))
|
||||
|
||||
registry = openerp.modules.registry.RegistryManager.new(db_name)
|
||||
with registry.cursor() as cr:
|
||||
# if it's a copy of a database, force generation of a new dbuuid
|
||||
registry['ir.config_parameter'].init(cr, force=True)
|
||||
|
||||
from_fs = openerp.tools.config.filestore(db_original_name)
|
||||
to_fs = openerp.tools.config.filestore(db_name)
|
||||
if os.path.exists(from_fs) and not os.path.exists(to_fs):
|
||||
|
||||
@@ -566,6 +566,15 @@ def mod10r(number):
|
||||
report = codec[ (int(digit) + report) % 10 ]
|
||||
return result + str((10 - report) % 10)
|
||||
|
||||
def str2bool(s, default=None):
|
||||
s = ustr(s).lower()
|
||||
y = 'y yes 1 true t on'.split()
|
||||
n = 'n no 0 false f off'.split()
|
||||
if s not in (y + n):
|
||||
if default is None:
|
||||
raise ValueError('Use 0/1/yes/no/true/false/on/off')
|
||||
return bool(default)
|
||||
return s in y
|
||||
|
||||
def human_size(sz):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user