function gardens_site_data_json_alert_flag_clear in Acquia Cloud Site Factory Connector 8
Same name and namespace in other branches
- 8.2 acsf_init/lib/sites/g/sites.inc \gardens_site_data_json_alert_flag_clear()
Clears a 'sites.json alert' flag.
1 string reference to 'gardens_site_data_json_alert_flag_clear'
- gardens_site_data_refresh_domains in acsf_init/
lib/ sites/ g/ sites.inc - Returns data for the specified domains directly from the JSON file.
File
- acsf_init/
lib/ sites/ g/ sites.inc, line 728 - ACSF helper functions for Drupal's multi-site directory aliasing feature.
Code
function gardens_site_data_json_alert_flag_clear() {
$lock_file = sprintf(GARDENS_SITE_JSON_ALERT_LOCK_TEMPLATE, $_ENV['AH_SITE_GROUP'], $_ENV['AH_SITE_ENVIRONMENT']);
if (file_exists($lock_file)) {
// To prevent a situation where a slow process would remove the file just
// after it was created (i.e. the reverse of what is documented in
// gardens_site_data_json_alert_flag_set()), we lock the file and check
// again, and only remove the file if no issues were encountered. This isn't
// exactly symmetric in the sense that we have no domain name, so: if domain
// specific information was just lost somehow, then a slow process has a
// higher chance of clearing the flag when it shouldn't. The effect: two
// alerts would be sent out in sequence (because the flag is set, cleared
// here, and then set again). That is less problematic than the reverse,
// which would send out an alert at the moment the domain specific error was
// just solved.
$fh = @fopen($lock_file, 'r+');
if ($fh) {
if (flock($fh, LOCK_EX | LOCK_NB)) {
// Make sure that the issue is gone.
$issue_type = gardens_site_data_sites_json_issue_type_get();
// Send an all fine message to the Site Factory if the issue is gone.
$alert_sent = FALSE;
if (!$issue_type) {
$response = gardens_site_data_alert_send('sites_json', 'all_fine');
if ($response->code == 200 && !empty($response->body['received'])) {
$alert_sent = TRUE;
}
}
// Clear the flag if the all fine message was sent and processed.
if ($alert_sent) {
// There is no problem with unlinking a locked file; the file name
// gets freed up (while the 'orphaned' file itself is still locked).
// Removing a (locked) file like this does not introduce a race
// condition, if all processes try to lock the file in an exclusive
// and non-blocking manner. So unlinking the file should never fail.
// If it does, we could try to log to watchdog/syslog but that would
// completely flood the logs.
@unlink($lock_file);
}
// We could release the lock here but if the file is already unlinked
// that won't do much useful - and if it's not, we may be better off
// keeping it locked.
}
fclose($fh);
}
}
}