diff --git a/modules/registrars/keysystems/keysystems.php b/modules/registrars/keysystems/keysystems.php index a325ff8..8daede6 100644 --- a/modules/registrars/keysystems/keysystems.php +++ b/modules/registrars/keysystems/keysystems.php @@ -72,48 +72,13 @@ function keysystems_getConfigArray($params) } $dbChecked = true; } - - $oldModule = 'rrpproxy'; - $newModule = 'keysystems'; if (@$_GET['migrate']) { - $oldConfig = DB::table('tblregistrars') - ->where('registrar', $oldModule) - ->pluck('value', 'setting'); - if ($oldConfig) { - // This is needed for WHMCS v8 compatibility - if ((int) $params['whmcsVersion'][0] >= 8) { - $oldConfig = $oldConfig->toArray(); - } - $oldConfig['TestPassword'] = $oldConfig['Password']; - foreach ($oldConfig as $key => $val) { - DB::table('tblregistrars') - ->where('registrar', $newModule) - ->where('setting', $key) - ->update(['value' => $val]); - } - } - DB::table('tbldomains')->where('registrar', $oldModule)->update(['registrar' => $newModule]); - DB::table('tbldomainpricing')->where('autoreg', $oldModule)->update(['autoreg' => $newModule]); - DB::table('tblregistrars')->where('registrar', $oldModule)->delete(); - $reloadLink = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]?saved=true#keysystems"; - header("Location: $reloadLink"); + keysystems_migrateFromStockModule($params); } - if (!$params['Username'] && DB::table('tblregistrars')->where('registrar', $oldModule)->exists()) { + if (!$params['Username'] && DB::table('tblregistrars')->where('registrar', 'rrpproxy')->exists()) { $msgMigrate .= "
Migrate from old RRPproxy module"; } - - $data = file_get_contents('https://raw.githubusercontent.com/rrpproxy/whmcs-rrpproxy-registrar/master/release.json'); - if (!$data) { - $msgUpdate = '
Unable to check for updates'; - } else { - $json = json_decode($data); - if (version_compare(RRPPROXY_VERSION, $json->version, '<')) { - $msgUpdate = '
Update available! '; - $msgUpdate .= ' Get it on GitHub'; - } else { - $msgUpdate = '
You are up to date!'; - } - } + $msgUpdate = keysystems_checkForUpdates(); } return [ @@ -196,6 +161,57 @@ function keysystems_getConfigArray($params) ]; } +/** + * Migrates module config and domains from the WHMCS stock rrpproxy module to this one + * @param array $params + */ +function keysystems_migrateFromStockModule(array $params): void +{ + $oldModule = 'rrpproxy'; + $newModule = 'keysystems'; + $oldConfig = DB::table('tblregistrars') + ->where('registrar', $oldModule) + ->pluck('value', 'setting'); + if ($oldConfig) { + // This is needed for WHMCS v8 compatibility + if ((int) $params['whmcsVersion'][0] >= 8) { + $oldConfig = $oldConfig->toArray(); + } + $oldConfig['TestPassword'] = $oldConfig['Password']; + foreach ($oldConfig as $key => $val) { + DB::table('tblregistrars') + ->where('registrar', $newModule) + ->where('setting', $key) + ->update(['value' => $val]); + } + } + DB::table('tbldomains')->where('registrar', $oldModule)->update(['registrar' => $newModule]); + DB::table('tbldomainpricing')->where('autoreg', $oldModule)->update(['autoreg' => $newModule]); + DB::table('tblregistrars')->where('registrar', $oldModule)->delete(); + $reloadLink = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]?saved=true#keysystems"; + header("Location: $reloadLink"); +} + +/** + * @return string + */ +function keysystems_checkForUpdates(): string +{ + $data = file_get_contents('https://raw.githubusercontent.com/rrpproxy/whmcs-rrpproxy-registrar/master/release.json'); + if (!$data) { + $msgUpdate = '
Unable to check for updates'; + } else { + $json = json_decode($data); + if (version_compare(RRPPROXY_VERSION, $json->version, '<')) { + $msgUpdate = '
Update available! '; + $msgUpdate .= ' Get it on GitHub'; + } else { + $msgUpdate = '
You are up to date!'; + } + } + return $msgUpdate; +} + function keysystems_GetDomainInformation(array $params) { $domainName = $params["sld"] . "." . $params["tld"];