Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed performance issue when "Force update WHOIS.json" is ticked. #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,40 +375,32 @@ function synergywholesaledomains_getConfigArray(array $params)
}
}

// If the conversion option is ticked, then we need to process the conversion
if (isset($params['whoisUpdate']) && 'on' === $params['whoisUpdate']) {
$jsonPath = realpath(join(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', 'resources', 'domains', 'whois.json']));
$whoisBackup = file_get_contents($jsonPath);
$whois = file_get_contents(WHOIS_URL);

if (!file_exists($jsonPath)) {
$configuration['whoisUpdate']['Description'] .= "<br><b>NOTICE:</b> WHOIS.json update unsuccessful. File path invalid. The file at $jsonPath does not exist.";
return $configuration;
}

$whoisBackup = file_get_contents($jsonPath);
$whois = file_get_contents(WHOIS_URL);

if ($whois === $whoisBackup) {
$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> WHOIS.json file is already up to date.';
return $configuration;
}

// Testing to see if retrieved data is valid
@json_decode($whois);
if (JSON_ERROR_NONE !== json_last_error()) {
$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> WHOIS.json update unsuccessful. Unable to pull file.';
return $configuration;
}

if (!file_put_contents($jsonPath, $whois)) {
$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> <span style="color:red;">WHOIS.json update unsuccessful. Unable to update WHOIS.json file.</span>';

//Revert any changes made to backup file
file_put_contents($filePath, $whoisBackup);

return $configuration;
} else {
// Testing to see if retrieved data is valid
@json_decode($whois);
if (JSON_ERROR_NONE !== json_last_error()) {
$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> WHOIS.json update unsuccessful. Unable to pull file.';
} else if (!file_put_contents($jsonPath, $whois)) {
$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> <span style="color:red;">WHOIS.json update unsuccessful. Unable to update WHOIS.json file.</span>';
//Revert any changes made to backup file
file_put_contents($filePath, $whoisBackup);
} else {
$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> <span style="color:green;">WHOIS.json successfully updated.</span>';
}
}

$configuration['whoisUpdate']['Description'] .= '<br><b>NOTICE:</b> <span style="color:green;">WHOIS.json successfully updated.</span>';

try {
/**
* Finally disable the setting for the customer automatically so
Expand Down