From ed9a5e27c19c39200571fc31b5079affa6709e74 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 17 Jul 2021 13:24:05 +0500 Subject: [PATCH] fixed a bug that cause restore fail if 1 user have access to more then 1 database --- plogical/backupUtilities.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index bddaaca2f..a57ecb2dc 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -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