Changing the primary domain once it has been set in the Domain Access settings can be quite the challenge. I encountered a problem, which required me to change the primary domain to one of the active domains. This would have been easier if there were no nodes associated with the domains and if the project was in its early development stage. However, this wasn't the case. I had no choice but to write a script that would do a simple swap algorithm, which would switch the current primary domain's settings with the new primary domain (an active domain).
Keep in mind that by the architectural design, the primary domain will always have an ID of “0”. The rest of the domains' ID will start with “1” and so on. For the purpose of this blog, let’s assume that the old primary domain is a.com and the new primary domain is z.com.
Here are the following steps I took in order to accomplish this task:
1) Switch the domain configurations of a.com and z.com.
To accomplish set some system variables for z.com:
“domain_root,” “domain_sitename,” “theme_default, “site_frontpage,” “site_name,” “site_offline_message.”
Then update the configuration of a.com in the domain_conf table.