Do no retry ping after error the same month

This commit is contained in:
Laurent Destailleur 2020-01-31 17:27:48 +01:00
parent 8e18a08377
commit b81d223ab3
2 changed files with 67 additions and 58 deletions

View File

@ -53,8 +53,8 @@ print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"])
// If ok // If ok
if ($action == 'firstpingok') if ($action == 'firstpingok')
{ {
// Note: pings are by installation, done on entity 1. // Note: pings are per installed instances / entity.
// Once this constant are set, no more ping will be tried (except if we add parameter &forceping=1 on URL). So we can say this are 'first' ping. // Once this constants are set, no more ping will be tried (except if we add parameter &forceping=1 on URL). So we can say this are 'first' ping.
dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt')); dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'));
dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', $hash_unique_id); dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', $hash_unique_id);

View File

@ -2553,72 +2553,81 @@ if (!function_exists("llxFooter"))
// Add code for the asynchronous anonymous first ping (for telemetry) // Add code for the asynchronous anonymous first ping (for telemetry)
// You can use &forceping=1 in parameters to force the ping if the ping was already sent. // You can use &forceping=1 in parameters to force the ping if the ping was already sent.
if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || GETPOST('forceping', 'alpha')) $forceping = GETPOST('forceping', 'alpha');
if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping)
{ {
//print '<!-- instance_unique_id='.$conf->file->instance_unique_id.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' -->'; //print '<!-- instance_unique_id='.$conf->file->instance_unique_id.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' -->';
$hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id); $hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id);
if (empty($conf->global->MAIN_FIRST_PING_OK_DATE) if (empty($conf->global->MAIN_FIRST_PING_OK_DATE)
|| (!empty($conf->file->instance_unique_id) && ($hash_unique_id != $conf->global->MAIN_FIRST_PING_OK_ID) && ($conf->global->MAIN_FIRST_PING_OK_ID != 'disabled')) || (!empty($conf->file->instance_unique_id) && ($hash_unique_id != $conf->global->MAIN_FIRST_PING_OK_ID) && ($conf->global->MAIN_FIRST_PING_OK_ID != 'disabled'))
|| GETPOST('forceping', 'alpha')) || $forceping)
{ {
if (strpos('alpha', DOL_VERSION) > 0) { // No ping done if we are into an alpha version
if (strpos('alpha', DOL_VERSION) > 0 && ! $forceping) {
print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. It is an alpha version -->\n"; print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. It is an alpha version -->\n";
} }
elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id])) // Cookie is set when we uncheck the checkbox in the installation wizard. elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) // Cookie is set when we uncheck the checkbox in the installation wizard.
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // MAIN_LAST_PING_KO_DATE
// TODO Disable ping if MAIN_LAST_PING_KO_DATE is set and is recent
if (! empty($conf->global->MAIN_LAST_PING_KO_DATE) && substr($conf->global->MAIN_LAST_PING_KO_DATE, 0, 6) == dol_print_date(dol_now(), '%Y%m') && ! $forceping) {
print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. An error already occured this month, we will try later. -->\n";
} else {
print "\n".'<!-- Includes JS for Ping of Dolibarr MAIN_FIRST_PING_OK_DATE = '.$conf->global->MAIN_FIRST_PING_OK_DATE.' MAIN_FIRST_PING_OK_ID = '.$conf->global->MAIN_FIRST_PING_OK_ID.' -->'."\n"; include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
print "\n<!-- JS CODE TO ENABLE the anonymous Ping -->\n";
$url_for_ping = (empty($conf->global->MAIN_URL_FOR_PING) ? "https://ping.dolibarr.org/" : $conf->global->MAIN_URL_FOR_PING); print "\n".'<!-- Includes JS for Ping of Dolibarr forceping='.$forceping.' MAIN_FIRST_PING_OK_DATE='.$conf->global->MAIN_FIRST_PING_OK_DATE.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' MAIN_LAST_PING_KO_DATE='.$conf->global->MAIN_LAST_PING_KO_DATE.' -->'."\n";
// Try to guess the distrib used print "\n<!-- JS CODE TO ENABLE the anonymous Ping -->\n";
$distrib = 'standard'; $url_for_ping = (empty($conf->global->MAIN_URL_FOR_PING) ? "https://ping.dolibarr.org/" : $conf->global->MAIN_URL_FOR_PING);
if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') $distrib = 'doliwamp'; // Try to guess the distrib used
if (! empty($dolibarr_distrib)) $distrib = $dolibarr_distrib; $distrib = 'standard';
?> if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') $distrib = 'doliwamp';
<script> if (! empty($dolibarr_distrib)) $distrib = $dolibarr_distrib;
jQuery(document).ready(function (tmp) { ?>
$.ajax({ <script>
method: "POST", jQuery(document).ready(function (tmp) {
url: "<?php echo $url_for_ping ?>", $.ajax({
timeout: 500, // timeout milliseconds method: "POST",
cache: false, url: "<?php echo $url_for_ping ?>",
data: { timeout: 500, // timeout milliseconds
hash_algo: "md5", cache: false,
hash_unique_id: "<?php echo dol_escape_js($hash_unique_id); ?>", data: {
action: "dolibarrping", hash_algo: "md5",
version: "<?php echo (float) DOL_VERSION; ?>", hash_unique_id: "<?php echo dol_escape_js($hash_unique_id); ?>",
entity: "<?php echo (int) $conf->entity; ?>", action: "dolibarrping",
dbtype: "<?php echo dol_escape_js($db->type); ?>", version: "<?php echo (float) DOL_VERSION; ?>",
country_code: "<?php echo dol_escape_js($mysoc->country_code); ?>", entity: "<?php echo (int) $conf->entity; ?>",
php_version: "<?php echo phpversion(); ?>", dbtype: "<?php echo dol_escape_js($db->type); ?>",
os_version: "<?php echo version_os('smr'); ?>", country_code: "<?php echo dol_escape_js($mysoc->country_code); ?>",
distrib: "<?php echo $distrib ? $distrib : 'unknown'; ?>" php_version: "<?php echo phpversion(); ?>",
}, os_version: "<?php echo version_os('smr'); ?>",
success: function (data, status, xhr) { // success callback function (data contains body of response) distrib: "<?php echo $distrib ? $distrib : 'unknown'; ?>"
console.log("Ping ok"); },
$.ajax({ success: function (data, status, xhr) { // success callback function (data contains body of response)
method: "GET", console.log("Ping ok");
url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>", $.ajax({
timeout: 500, // timeout milliseconds method: "GET",
cache: false, url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>",
data: { hash_algo: "md5", hash_unique_id: "<?php echo dol_escape_js($hash_unique_id); ?>", action: "firstpingok" }, // to update timeout: 500, // timeout milliseconds
}); cache: false,
}, data: { hash_algo: "md5", hash_unique_id: "<?php echo dol_escape_js($hash_unique_id); ?>", action: "firstpingok" }, // to update
error: function (data,status,xhr) { // error callback function });
console.log("Ping ko: " + data); },
$.ajax({ error: function (data,status,xhr) { // error callback function
method: "GET", console.log("Ping ko: " + data);
url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>", $.ajax({
timeout: 500, // timeout milliseconds method: "GET",
cache: false, url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>",
data: { hash_algo: "md5", hash_unique_id: "<?php echo dol_escape_js($hash_unique_id); ?>", action: "firstpingko" }, timeout: 500, // timeout milliseconds
}); cache: false,
} data: { hash_algo: "md5", hash_unique_id: "<?php echo dol_escape_js($hash_unique_id); ?>", action: "firstpingko" },
}); });
}); }
</script> });
<?php });
</script>
<?php
}
} }
else else
{ {