Make OLDSERVER values available during CLONE_DOMAIN

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!

Status: 
Closed (fixed)

Comments

Title: Make OLD values available during CLONE_DOMAIN » Make OLDSERVER values available during CLONE_DOMAIN
Body: View changes
Assigned: Unassigned »

That's a good idea ... I'll add this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.