fixed a bug that cause restore fail if 1 user have access to more then 1 database

This commit is contained in:
Usman Nasir 2021-07-17 13:24:05 +05:00
parent 7b5bdb650c
commit ed9a5e27c1
1 changed files with 10 additions and 4 deletions

View File

@ -625,8 +625,10 @@ class backupUtilities:
for databaseUser in databaseUsers:
dbUser = databaseUser.find('dbUser').text
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, 'cyberpanel') == 0:
raise BaseException
res = mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, 'cyberpanel')
if res == 0:
logging.CyberCPLogFileWriter.writeToFile(
'Failed to restore database %s. But it can be false positive, moving on..' % (dbName))
newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
newDB.save()
@ -903,10 +905,14 @@ class backupUtilities:
logging.CyberCPLogFileWriter.writeToFile('Database host: %s' % (dbHost))
logging.CyberCPLogFileWriter.writeToFile('Database password: %s' % (password))
## Future ref, this logic can be further refactored to improve restore backup logic
if first:
first = 0
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password, 1) == 0:
raise BaseException
res = mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password, 1)
if res == 0:
logging.CyberCPLogFileWriter.writeToFile(
'Failed to restore database %s. But it can be false positive, moving on..' % (
dbName))
### This function will not create database, only database user is created as third value is 0 for createDB