We'd like to make it easier for our customers and automatically update the database names, usernames and passwords if they clone their websites. And it would be real piece of cake to just compare old and new values for both database name, username and password and if they are different, then to search and replace strings in all files within virtual server's HTML directory in post action script under if [ "$VIRTUALSERVER_ACTION" = "CLONE_DOMAIN" ]; then
clause.
However, we know from what James put on https://www.virtualmin.com/node/43090, that unfortunately
The OLDSERVER vars are only available when modifying a domain.
So since we can't compare the new and old values, we have to operate with only new virtual server's data as shown in example on https://www.virtualmin.com/node/43103:
if [ $VIRTUALSERVER_CLONE ]; then
if [ $SETTINGS ]; then
sed -i "s/^\( *'username' => '\)[^\,]*/\1"$VIRTUALSERVER_MYSQL_USER"'/" $VIRTUALSERVER_HOME$i$SETTINGS
sed -i "s/^\( *'password' => '\)[^\,]*/\1"$VIRTUALSERVER_PASS"'/" $VIRTUALSERVER_HOME$SETTINGS
sed -i "s/^\( *'database' => '\)[^\,]*/\1"$VIRTUALSERVER_DB"'/" $VIRTUALSERVER_HOME$i$SETTINGS
fi
exit 0;
fi
And it works fine if we know exact patterns where the database names, usernames and passwords are saved like in certain CMS like Drupal or WordPress. However, when adding other applications this approach does not work, because each application stores the database connections in its own ways: different files, different lines and variables. So the script gets messier and messier in attempt to cover more and more applications. So this method is not productive and should be ideally avoided.
The best and the easiest way of updating the database access details in ANY kind of applications would be to provide to the post action script the OLDSERVER database name, username and password. Then simple comparison and search and replace would suffice to make the end-users happy.
So please consider providing OLDSERVER values in CLONE_DOMAIN actions.
Thanks for consideration!
Comments
Submitted by yngens on Wed, 10/31/2018 - 13:40 Comment #1
Submitted by yngens on Thu, 11/01/2018 - 06:44 Comment #2
Submitted by andreychek on Thu, 11/01/2018 - 08:45 Comment #3
Submitted by JamieCameron on Fri, 11/02/2018 - 00:05 Comment #4
That's a good idea ... I'll add this.
Submitted by IssueBot on Thu, 02/28/2019 - 09:07 Comment #5
Automatically closed - issue fixed for 2 weeks with no activity.